diff --git a/Cargo.lock b/Cargo.lock index 184991228..d535bc0e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1608,6 +1608,8 @@ dependencies = [ "litebox_platform_multiplex", "litebox_platform_windows_userland", "litebox_shim_linux", + "litebox_util_log", + "tracing-subscriber", ] [[package]] @@ -1635,12 +1637,15 @@ dependencies = [ name = "litebox_runner_lvbs" version = "0.1.0" dependencies = [ + "arrayvec", "litebox", "litebox_common_linux", "litebox_common_optee", "litebox_platform_lvbs", "litebox_platform_multiplex", "litebox_shim_optee", + "litebox_util_log", + "log", "once_cell", "spin 0.10.0", "x86_64", @@ -1661,8 +1666,10 @@ dependencies = [ "litebox_platform_multiplex", "litebox_shim_optee", "litebox_syscall_rewriter", + "litebox_util_log", "serde", "serde_json", + "tracing-subscriber", ] [[package]] @@ -1675,6 +1682,8 @@ dependencies = [ "litebox_platform_linux_kernel", "litebox_platform_multiplex", "litebox_shim_linux", + "litebox_util_log", + "log", ] [[package]] diff --git a/dev_tests/src/ratchet.rs b/dev_tests/src/ratchet.rs index 276452d4d..61e3137e8 100644 --- a/dev_tests/src/ratchet.rs +++ b/dev_tests/src/ratchet.rs @@ -41,8 +41,8 @@ fn ratchet_globals() -> Result<()> { ("litebox_platform_multiplex/", 1), ("litebox_platform_windows_userland/", 8), ("litebox_runner_linux_userland/", 1), - ("litebox_runner_lvbs/", 5), - ("litebox_runner_snp/", 1), + ("litebox_runner_lvbs/", 6), + ("litebox_runner_snp/", 2), ("litebox_shim_linux/", 1), ("litebox_shim_optee/", 3), ], diff --git a/litebox_runner_linux_on_windows_userland/Cargo.toml b/litebox_runner_linux_on_windows_userland/Cargo.toml index a897f6908..d97fe5786 100644 --- a/litebox_runner_linux_on_windows_userland/Cargo.toml +++ b/litebox_runner_linux_on_windows_userland/Cargo.toml @@ -11,5 +11,7 @@ litebox_common_linux = { version = "0.1.0", path = "../litebox_common_linux" } litebox_platform_windows_userland = { version = "0.1.0", path = "../litebox_platform_windows_userland" } litebox_platform_multiplex = { version = "0.1.0", path = "../litebox_platform_multiplex", default-features = false, features = ["platform_windows_userland"] } litebox_shim_linux = { version = "0.1.0", path = "../litebox_shim_linux", default-features = false, features = ["platform_windows_userland"] } +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log", features = ["backend_tracing"] } +tracing-subscriber = { version = "0.3.22", features = ["env-filter"] } [lints] workspace = true \ No newline at end of file diff --git a/litebox_runner_linux_on_windows_userland/src/lib.rs b/litebox_runner_linux_on_windows_userland/src/lib.rs index c5afcbc71..5afc2a208 100644 --- a/litebox_runner_linux_on_windows_userland/src/lib.rs +++ b/litebox_runner_linux_on_windows_userland/src/lib.rs @@ -51,6 +51,16 @@ pub struct CliArgs { /// panic. If it does actually panic, then ping the authors of LiteBox, and likely a better error /// message could be thrown instead. pub fn run(cli_args: CliArgs) -> Result<()> { + tracing_subscriber::fmt() + .with_timer(tracing_subscriber::fmt::time::uptime()) + .with_level(true) + .with_env_filter( + tracing_subscriber::EnvFilter::builder() + .with_env_var("LITEBOX_LOG") + .from_env_lossy(), + ) + .init(); + let tar_file = &cli_args.initial_files; if tar_file.extension().and_then(|x| x.to_str()) != Some("tar") { anyhow::bail!("Expected a .tar file, found {}", tar_file.display()); diff --git a/litebox_runner_lvbs/Cargo.toml b/litebox_runner_lvbs/Cargo.toml index 34f6635c7..58f33e03b 100644 --- a/litebox_runner_lvbs/Cargo.toml +++ b/litebox_runner_lvbs/Cargo.toml @@ -4,12 +4,15 @@ version = "0.1.0" edition = "2024" [dependencies] +arrayvec = { version = "0.7.6", default-features = false } litebox = { version = "0.1.0", path = "../litebox" } litebox_platform_lvbs = { version = "0.1.0", path = "../litebox_platform_lvbs", default-features = false } litebox_platform_multiplex = { version = "0.1.0", path = "../litebox_platform_multiplex", default-features = false, features = ["platform_lvbs"] } litebox_common_optee = { path = "../litebox_common_optee/", version = "0.1.0" } litebox_common_linux = { path = "../litebox_common_linux/", version = "0.1.0" } litebox_shim_optee = { path = "../litebox_shim_optee/", version = "0.1.0" } +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log" } +log = { version = "0.4", default-features = false } spin = { version = "0.10.0", default-features = false, features = ["spin_mutex"] } once_cell = { version = "1.21.3", default-features = false, features = ["race", "alloc"] } diff --git a/litebox_runner_lvbs/src/main.rs b/litebox_runner_lvbs/src/main.rs index d6a393e68..8cb99f6bd 100644 --- a/litebox_runner_lvbs/src/main.rs +++ b/litebox_runner_lvbs/src/main.rs @@ -21,6 +21,26 @@ use litebox_platform_lvbs::{ use x86_64::VirtAddr; use x86_64::structures::paging::PageTableFlags; +/// `log` backend that forwards to the serial console. +struct HostLogger; + +impl log::Log for HostLogger { + fn enabled(&self, _metadata: &log::Metadata) -> bool { + true + } + + fn log(&self, record: &log::Record) { + use core::fmt::Write; + let mut buf: arrayvec::ArrayString<1024> = arrayvec::ArrayString::new(); + let _ = writeln!(buf, "[{}] {}", record.level(), record.args()); + litebox_platform_lvbs::arch::ioport::serial_print_string(&buf); + } + + fn flush(&self) {} +} + +static HOST_LOGGER: HostLogger = HostLogger; + /// Spinlock protecting the shared AP boot stack (`VTL1_KERNEL_STACK_PAGE`). /// /// All APs receive the same initial RSP via `hvcall_enable_vp_vtl`. VTL0 @@ -425,6 +445,9 @@ pub unsafe extern "C" fn _start() -> ! { unsafe extern "C" fn kernel_main(is_bsp: bool) -> ! { if is_bsp { + let _ = log::set_logger(&HOST_LOGGER); + log::set_max_level(log::LevelFilter::Trace); + serial_println!("=============================="); serial_println!(" Hello from LiteBox for LVBS! "); serial_println!("=============================="); diff --git a/litebox_runner_optee_on_linux_userland/Cargo.toml b/litebox_runner_optee_on_linux_userland/Cargo.toml index 54d59b665..dbd3513c7 100644 --- a/litebox_runner_optee_on_linux_userland/Cargo.toml +++ b/litebox_runner_optee_on_linux_userland/Cargo.toml @@ -15,6 +15,8 @@ litebox_platform_linux_userland = { version = "0.1.0", path = "../litebox_platfo litebox_platform_multiplex = { version = "0.1.0", path = "../litebox_platform_multiplex", default-features = false, features = ["platform_linux_userland_with_optee_syscall", "systrap_backend"] } litebox_shim_optee = { version = "0.1.0", path = "../litebox_shim_optee", default-features = false, features = ["platform_linux_userland"] } litebox_syscall_rewriter = { version = "0.1.0", path = "../litebox_syscall_rewriter" } +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log", features = ["backend_tracing"] } +tracing-subscriber = { version = "0.3.22", features = ["env-filter"] } serde = { version = "1.0.142", features = ["derive"] } serde_json = "1.0.142" diff --git a/litebox_runner_optee_on_linux_userland/src/lib.rs b/litebox_runner_optee_on_linux_userland/src/lib.rs index 4cc021dea..1c5547225 100644 --- a/litebox_runner_optee_on_linux_userland/src/lib.rs +++ b/litebox_runner_optee_on_linux_userland/src/lib.rs @@ -63,6 +63,16 @@ pub enum InterceptionBackend { /// panic. If it does actually panic, then ping the authors of LiteBox, and likely a better error /// message could be thrown instead. pub fn run(cli_args: CliArgs) -> Result<()> { + tracing_subscriber::fmt() + .with_timer(tracing_subscriber::fmt::time::uptime()) + .with_level(true) + .with_env_filter( + tracing_subscriber::EnvFilter::builder() + .with_env_var("LITEBOX_LOG") + .from_env_lossy(), + ) + .init(); + let ldelf_data: Vec = { let ldelf = PathBuf::from(&cli_args.ldelf); let data = std::fs::read(ldelf).unwrap(); diff --git a/litebox_runner_snp/Cargo.toml b/litebox_runner_snp/Cargo.toml index 772cbc6f9..dad0e6135 100644 --- a/litebox_runner_snp/Cargo.toml +++ b/litebox_runner_snp/Cargo.toml @@ -13,6 +13,8 @@ litebox_common_linux = { path = "../litebox_common_linux/", version = "0.1.0" } litebox_platform_multiplex = { path = "../litebox_platform_multiplex", version = "0.1.0", default-features = false, features = ["platform_linux_snp"] } litebox_platform_linux_kernel = { path = "../litebox_platform_linux_kernel/", version = "0.1.0" } litebox_shim_linux = { version = "0.1.0", path = "../litebox_shim_linux", default-features = false, features = ["platform_linux_snp"] } +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log" } +log = { version = "0.4", default-features = false } [lints] workspace = true diff --git a/litebox_runner_snp/src/main.rs b/litebox_runner_snp/src/main.rs index 30b3096bf..80529321e 100644 --- a/litebox_runner_snp/src/main.rs +++ b/litebox_runner_snp/src/main.rs @@ -17,6 +17,26 @@ use litebox::{ }; use litebox_platform_linux_kernel::{HostInterface, host::snp::ghcb::ghcb_prints}; +/// `log` backend that forwards to the GHCB serial console. +struct HostLogger; + +impl log::Log for HostLogger { + fn enabled(&self, _metadata: &log::Metadata) -> bool { + true + } + + fn log(&self, record: &log::Record) { + use core::fmt::Write; + let mut buf: arrayvec::ArrayString<1024> = arrayvec::ArrayString::new(); + let _ = writeln!(buf, "[{}] {}", record.level(), record.args()); + ghcb_prints(&buf); + } + + fn flush(&self) {} +} + +static HOST_LOGGER: HostLogger = HostLogger; + type Platform = litebox_platform_linux_kernel::host::snp::snp_impl::SnpLinuxKernel; type DefaultFS = litebox::fs::layered::FileSystem< Platform, @@ -104,6 +124,10 @@ pub extern "C" fn sandbox_kernel_init( boot_params: &'static litebox_platform_linux_kernel::host::snp::snp_impl::vmpl2_boot_params, ) { ghcb_prints("sandbox_kernel_init called\n"); + + let _ = log::set_logger(&HOST_LOGGER); + log::set_max_level(log::LevelFilter::Trace); + let ghcb_page = litebox_platform_linux_kernel::arch::PhysAddr::new(boot_params.ghcb_page); let ghcb_page_va = litebox_platform_linux_kernel::arch::VirtAddr::new(boot_params.ghcb_page_va); if litebox_platform_linux_kernel::host::snp::ghcb::GhcbProtocol::setup_ghcb_page(