Skip to content

Commit

Permalink
Add a feature named enable-console-log.
Browse files Browse the repository at this point in the history
This feature can be enable to print log messages to console in
addition to storing them in the log buffer.
Enable this feature by default for debug builds.

Signed-off-by: Vasant Karasulli <vkarasulli@suse.de>
  • Loading branch information
vsntk18 committed Jan 8, 2024
1 parent ca5a9fa commit 4df4c20
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
# ld to work, so build all the objects without performing the
# final linking step.
- name: Build
run: make FEATURES="default,enable-gdb" stage1/kernel.elf stage1/stage1.o stage1/reset.o
run: make FEATURES="default-debug,enable-gdb" stage1/kernel.elf stage1/stage1.o stage1/reset.o

- name: Run tests
run: make test
Expand Down Expand Up @@ -72,4 +72,4 @@ jobs:
- name: Check documentation
run: make doc
env:
RUSTDOCFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ test = { version = "0.1.0", path = "test" }

[features]
default = ["enable-stacktrace"]
default-debug = ["enable-stacktrace", "enable-console-log"]
enable-stacktrace = []
enable-gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
enable-console-log = []

[dev-dependencies]
memoffset = "0.9.0"
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
ifdef RELEASE
TARGET_PATH="release"
FEATURES ?= "default"
CARGO_ARGS = --features ${FEATURES}

ifdef RELEASE
TARGET_PATH=release
CARGO_ARGS += --release
else
TARGET_PATH=debug
TARGET_PATH="debug"
FEATURES ?= "default-debug"
CARGO_ARGS = --features ${FEATURES}
endif

ifeq ($(V), 1)
Expand Down
14 changes: 14 additions & 0 deletions src/cpu/line_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Copyright (c) 2022-2023 SUSE LLC
//
// Author: Vasant Karasulli <vkarasulli@suse.de>
#[cfg(feature = "enable-console-log")]
use crate::console::_print;

use crate::cpu::percpu::this_cpu_mut;
use crate::log_buffer::log_buffer;
Expand Down Expand Up @@ -71,18 +73,30 @@ impl log::Log for BufferLogger {
line_buf
.write_fmt(format_args!("[{}] {}: {}\n", comp, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}: {}\n", comp, lvl, rec_args));
}
}

log::Level::Info => {
line_buf
.write_fmt(format_args!("[{}] {}\n", comp, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}\n", comp, rec_args));
}
}

log::Level::Debug | log::Level::Trace => {
line_buf
.write_fmt(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args));
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/stage2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ use core::slice;
use cpuarch::snp_cpuid::SnpCpuidTable;
use svsm::address::{Address, PhysAddr, VirtAddr};
use svsm::config::SvsmConfig;
use svsm::console::{init_console, WRITER};

#[cfg(feature = "enable-console-log")]
use svsm::console::init_console;

use svsm::console::WRITER;
use svsm::cpu::cpuid::{dump_cpuid_table, register_cpuid_table};
use svsm::cpu::gdt::load_gdt;
use svsm::cpu::idt::stage2::{early_idt_init, early_idt_init_no_ghcb};
Expand Down Expand Up @@ -116,7 +120,10 @@ fn setup_env(config: &SvsmConfig) {
.expect("console serial output already configured");

WRITER.lock().set(&*CONSOLE_SERIAL);
init_console();
#[cfg(feature = "enable-console-log")]
{
init_console();
}
install_buffer_logger("Stage2");

// Console is fully working now and any unsupported configuration can be
Expand Down
11 changes: 9 additions & 2 deletions src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ use core::slice;
use cpuarch::snp_cpuid::SnpCpuidTable;
use svsm::address::{PhysAddr, VirtAddr};
use svsm::config::SvsmConfig;
use svsm::console::{init_console, WRITER};

#[cfg(feature = "enable-console-log")]
use svsm::console::init_console;

use svsm::console::WRITER;
use svsm::cpu::control_regs::{cr0_init, cr4_init};
use svsm::cpu::cpuid::{dump_cpuid_table, register_cpuid_table};
use svsm::cpu::efer::efer_init;
Expand Down Expand Up @@ -389,7 +393,10 @@ pub extern "C" fn svsm_start(li: &KernelLaunchInfo, mi: &MigrateInfo) {
.expect("console serial output already configured");

WRITER.lock().set(&*CONSOLE_SERIAL);
init_console();
#[cfg(feature = "enable-console-log")]
{
init_console();
}
install_buffer_logger("SVSM");

log::info!("COCONUT Secure Virtual Machine Service Module (SVSM)");
Expand Down

0 comments on commit 4df4c20

Please sign in to comment.