From 8a5d88140d43ae0240d623c370ae83238d433875 Mon Sep 17 00:00:00 2001 From: Vasant Karasulli Date: Tue, 11 Jul 2023 18:48:45 +0200 Subject: [PATCH] Add a feature named enable-console-log. 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 --- .github/workflows/rust.yml | 2 +- Cargo.toml | 4 +++- Makefile | 7 ++++--- src/cpu/line_buffer.rs | 14 ++++++++++++++ src/stage2.rs | 5 ++++- src/svsm.rs | 6 +++++- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1a3042c86..f790b74c6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,7 +31,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/stage1.o stage1/reset.o + run: make FEATURES="default-debug,enable-gdb" stage1/stage1.o stage1/reset.o - name: Run tests run: make test diff --git a/Cargo.toml b/Cargo.toml index 78e6b674b..d18df774d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,8 @@ packit = { git = "https://github.com/coconut-svsm/packit", version = "0.1.0" } [build-dependencies] [features] -default = ["enable-stacktrace"] +default-release = ["enable-stacktrace"] +default-debug = ["enable-stacktrace", "enable-console-log"] enable-stacktrace = [] enable-gdb = ["dep:gdbstub", "dep:gdbstub_arch"] +enable-console-log = [] diff --git a/Makefile b/Makefile index 83d528a9d..773ca1f28 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ -FEATURES ?= "default" -CARGO_ARGS = --features ${FEATURES} - ifdef RELEASE TARGET_PATH="release" +FEATURES ?= "default-release" +CARGO_ARGS = --features ${FEATURES} CARGO_ARGS += --release else TARGET_PATH="debug" +FEATURES ?= "default-debug" +CARGO_ARGS = --features ${FEATURES} endif diff --git a/src/cpu/line_buffer.rs b/src/cpu/line_buffer.rs index 21bc5b0a6..2f497b190 100644 --- a/src/cpu/line_buffer.rs +++ b/src/cpu/line_buffer.rs @@ -3,6 +3,8 @@ // Copyright (c) 2022-2023 SUSE LLC // // Author: Vasant Karasulli +#[cfg(feature = "enable-console-log")] +use crate::console::_print; use crate::cpu::percpu::this_cpu_mut; use crate::log_buffer::LB; @@ -87,18 +89,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)); + } } } } diff --git a/src/stage2.rs b/src/stage2.rs index 84a42d0d7..c75d0983e 100644 --- a/src/stage2.rs +++ b/src/stage2.rs @@ -105,7 +105,10 @@ fn setup_env() { WRITER.lock().set(&mut CONSOLE_SERIAL); } - init_console(); + #[cfg(feature = "enable-console-log")] + { + init_console(); + } install_buffer_logger("Stage2"); diff --git a/src/svsm.rs b/src/svsm.rs index e4afd9f64..56bdff61e 100644 --- a/src/svsm.rs +++ b/src/svsm.rs @@ -387,7 +387,11 @@ pub extern "C" fn svsm_start(li: &KernelLaunchInfo, mi: &MigrateInfo) { WRITER.lock().set(&mut CONSOLE_SERIAL); } - init_console(); + #[cfg(feature = "enable-console-log")] + { + init_console(); + } + install_buffer_logger("SVSM"); log::info!("COCONUT Secure Virtual Machine Service Module (SVSM)");