Skip to content

Commit af84210

Browse files
authored
ohcl_boot: Always enable logging ASAP (#1876)
There's no reason not to have it. This also removes the configuration of logging and the ability to disable it, since we still only have the one output backend.
1 parent 5670cbb commit af84210

File tree

3 files changed

+13
-109
lines changed

3 files changed

+13
-109
lines changed

openhcl/openhcl_boot/src/boot_logger.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ use core::fmt::Write;
1919
use minimal_rt::arch::InstrIoAccess;
2020
use minimal_rt::arch::Serial;
2121

22-
/// The logging type to use.
23-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24-
pub enum LoggerType {
25-
Serial,
26-
}
27-
2822
enum Logger {
2923
#[cfg(target_arch = "x86_64")]
3024
Serial(Serial<InstrIoAccess>),
@@ -55,19 +49,16 @@ pub static BOOT_LOGGER: BootLogger = BootLogger {
5549
};
5650

5751
/// Initialize the boot logger. This replaces any previous init calls.
58-
///
59-
/// If a given `logger_type` is unavailable on a given isolation type, the
60-
/// logger will ignore it, and no logging will be initialized.
61-
pub fn boot_logger_init(isolation_type: IsolationType, logger_type: LoggerType) {
52+
pub fn boot_logger_init(isolation_type: IsolationType, com3_serial_available: bool) {
6253
let mut logger = BOOT_LOGGER.logger.borrow_mut();
6354

64-
*logger = match (isolation_type, logger_type) {
55+
*logger = match (isolation_type, com3_serial_available) {
6556
#[cfg(target_arch = "x86_64")]
66-
(IsolationType::None, LoggerType::Serial) => Logger::Serial(Serial::init(InstrIoAccess)),
57+
(IsolationType::None, true) => Logger::Serial(Serial::init(InstrIoAccess)),
6758
#[cfg(target_arch = "aarch64")]
68-
(IsolationType::None, LoggerType::Serial) => Logger::Serial(Serial::init()),
59+
(IsolationType::None, true) => Logger::Serial(Serial::init()),
6960
#[cfg(target_arch = "x86_64")]
70-
(IsolationType::Tdx, LoggerType::Serial) => Logger::TdxSerial(Serial::init(TdxIoAccess)),
61+
(IsolationType::Tdx, true) => Logger::TdxSerial(Serial::init(TdxIoAccess)),
7162
_ => Logger::None,
7263
};
7364
}

openhcl/openhcl_boot/src/cmdline.rs

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33

44
//! Command line arguments and parsing for openhcl_boot.
55
6-
use crate::boot_logger::LoggerType;
76
use underhill_confidentiality::OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME;
87

9-
/// Enable boot logging in the bootloader.
10-
///
11-
/// Format of `OPENHCL_BOOT_LOG=<logger>`, with valid loggers being:
12-
/// - `com3`: use the com3 serial port, available on no isolation or Tdx.
13-
const BOOT_LOG: &str = "OPENHCL_BOOT_LOG=";
14-
const SERIAL_LOGGER: &str = "com3";
15-
168
/// Enable the private VTL2 GPA pool for page allocations. This is only enabled
179
/// via the command line, because in order to support the VTL2 GPA pool
1810
/// generically, the boot shim must read serialized data from the previous
@@ -36,7 +28,6 @@ const SIDECAR: &str = "OPENHCL_SIDECAR=";
3628

3729
#[derive(Debug, PartialEq)]
3830
pub struct BootCommandLineOptions {
39-
pub logger: Option<LoggerType>,
4031
pub confidential_debug: bool,
4132
pub enable_vtl2_gpa_pool: Option<u64>,
4233
pub sidecar: bool,
@@ -46,7 +37,6 @@ pub struct BootCommandLineOptions {
4637
impl BootCommandLineOptions {
4738
pub const fn new() -> Self {
4839
BootCommandLineOptions {
49-
logger: None,
5040
confidential_debug: false,
5141
enable_vtl2_gpa_pool: None,
5242
sidecar: true, // sidecar is enabled by default
@@ -59,18 +49,10 @@ impl BootCommandLineOptions {
5949
/// Parse arguments from a command line.
6050
pub fn parse(&mut self, cmdline: &str) {
6151
for arg in cmdline.split_whitespace() {
62-
if arg.starts_with(BOOT_LOG) {
63-
if let Some(SERIAL_LOGGER) = arg.split_once('=').map(|(_, arg)| arg) {
64-
self.logger = Some(LoggerType::Serial)
65-
}
66-
} else if arg.starts_with(OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME) {
52+
if arg.starts_with(OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME) {
6753
let arg = arg.split_once('=').map(|(_, arg)| arg);
6854
if arg.is_some_and(|a| a != "0") {
6955
self.confidential_debug = true;
70-
// Explicit logger specification overrides this default.
71-
if self.logger.is_none() {
72-
self.logger = Some(LoggerType::Serial);
73-
}
7456
}
7557
} else if arg.starts_with(ENABLE_VTL2_GPA_POOL) {
7658
self.enable_vtl2_gpa_pool = arg.split_once('=').and_then(|(_, arg)| {
@@ -105,59 +87,6 @@ mod tests {
10587
options
10688
}
10789

108-
#[test]
109-
fn test_console_parsing() {
110-
assert_eq!(
111-
parse_boot_command_line("OPENHCL_BOOT_LOG=com3"),
112-
BootCommandLineOptions {
113-
logger: Some(LoggerType::Serial),
114-
..BootCommandLineOptions::new()
115-
}
116-
);
117-
118-
assert_eq!(
119-
parse_boot_command_line("OPENHCL_BOOT_LOG=1"),
120-
BootCommandLineOptions {
121-
logger: None,
122-
..BootCommandLineOptions::new()
123-
}
124-
);
125-
126-
assert_eq!(
127-
parse_boot_command_line("OPENHCL_BOOT_LOG=random"),
128-
BootCommandLineOptions {
129-
logger: None,
130-
..BootCommandLineOptions::new()
131-
}
132-
);
133-
134-
assert_eq!(
135-
parse_boot_command_line("OPENHCL_BOOT_LOG==com3"),
136-
BootCommandLineOptions {
137-
logger: None,
138-
..BootCommandLineOptions::new()
139-
}
140-
);
141-
142-
assert_eq!(
143-
parse_boot_command_line("OPENHCL_BOOT_LOGserial"),
144-
BootCommandLineOptions {
145-
logger: None,
146-
..BootCommandLineOptions::new()
147-
}
148-
);
149-
150-
let cmdline = format!("{OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME}=1");
151-
assert_eq!(
152-
parse_boot_command_line(&cmdline),
153-
BootCommandLineOptions {
154-
logger: Some(LoggerType::Serial),
155-
confidential_debug: true,
156-
..BootCommandLineOptions::new()
157-
}
158-
);
159-
}
160-
16190
#[test]
16291
fn test_vtl2_gpa_pool_parsing() {
16392
assert_eq!(

openhcl/openhcl_boot/src/main.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use crate::hypercall::hvcall;
3030
use crate::single_threaded::off_stack;
3131
use arrayvec::ArrayString;
3232
use arrayvec::ArrayVec;
33-
use boot_logger::LoggerType;
3433
use cmdline::BootCommandLineOptions;
3534
use core::fmt::Write;
3635
use dt::BootTimes;
@@ -652,6 +651,8 @@ fn shim_main(shim_params_raw_offset: isize) -> ! {
652651
enable_enlightened_panic();
653652
}
654653

654+
let boot_reftime = get_ref_time(p.isolation_type);
655+
655656
// The support code for the fast hypercalls does not set
656657
// the Guest ID if it is not set yet as opposed to the slow
657658
// hypercall code path where that is done automatically.
@@ -662,24 +663,16 @@ fn shim_main(shim_params_raw_offset: isize) -> ! {
662663
hvcall().initialize();
663664
}
664665

665-
// Enable early log output if requested in the static command line.
666-
// Also check for confidential debug mode if we're isolated.
667666
let mut static_options = BootCommandLineOptions::new();
668667
if let Some(cmdline) = p.command_line().command_line() {
669668
static_options.parse(cmdline);
670669
}
671-
if let Some(typ) = static_options.logger {
672-
boot_logger_init(p.isolation_type, typ);
673-
log!("openhcl_boot: early debugging enabled");
674-
}
675670

676671
let hw_debug_bit = get_hw_debug_bit(p.isolation_type);
677672
let can_trust_host = p.isolation_type == IsolationType::None
678673
|| static_options.confidential_debug
679674
|| hw_debug_bit;
680675

681-
let boot_reftime = get_ref_time(p.isolation_type);
682-
683676
let mut dt_storage = off_stack!(PartitionInfo, PartitionInfo::new());
684677
let partition_info =
685678
match PartitionInfo::read_from_dt(&p, &mut dt_storage, static_options, can_trust_host) {
@@ -688,6 +681,11 @@ fn shim_main(shim_params_raw_offset: isize) -> ! {
688681
Err(e) => panic!("unable to read device tree params {}", e),
689682
};
690683

684+
// Enable logging ASAP. This is fine even when isolated, as we don't have
685+
// any access to secrets in the boot shim.
686+
boot_logger_init(p.isolation_type, partition_info.com3_serial_available);
687+
log!("openhcl_boot: logging enabled");
688+
691689
// Confidential debug will show up in boot_options only if included in the
692690
// static command line, or if can_trust_host is true (so the dynamic command
693691
// line has been parsed).
@@ -724,20 +722,6 @@ fn shim_main(shim_params_raw_offset: isize) -> ! {
724722
partition_info.vtl0_alias_map = None;
725723
}
726724

727-
if can_trust_host {
728-
// Enable late log output if requested in the dynamic command line.
729-
// Confidential debug is only allowed in the static command line.
730-
if let Some(typ) = partition_info.boot_options.logger {
731-
boot_logger_init(p.isolation_type, typ);
732-
} else if partition_info.com3_serial_available && cfg!(target_arch = "x86_64") {
733-
// If COM3 is available and we can trust the host, enable log output even
734-
// if it wasn't otherwise requested.
735-
boot_logger_init(p.isolation_type, LoggerType::Serial);
736-
}
737-
}
738-
739-
log!("openhcl_boot: entered shim_main");
740-
741725
if partition_info.cpus.is_empty() {
742726
panic!("no cpus");
743727
}

0 commit comments

Comments
 (0)