-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svsm: permit early initialization of console logging
On platforms that do not require extensive platform setup (e.g. GHCB) for console output services, initialize the console logger as early as possible to facilitate earlier logging of initialization activity. Signed-off-by: Jon Lange <[email protected]>
- Loading branch information
1 parent
5573dd5
commit 9b31de7
Showing
8 changed files
with
86 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,21 @@ | |
// Author: Jon Lange <[email protected]> | ||
|
||
use crate::address::{PhysAddr, VirtAddr}; | ||
use crate::console::init_console; | ||
use crate::cpu::cpuid::CpuidResult; | ||
use crate::cpu::msr::write_msr; | ||
use crate::cpu::percpu::PerCpu; | ||
use crate::error::SvsmError; | ||
use crate::platform::{IOPort, PageEncryptionMasks, PageStateChangeOp, SvsmPlatform}; | ||
use crate::io::IOPort; | ||
use crate::platform::{PageEncryptionMasks, PageStateChangeOp, SvsmPlatform}; | ||
use crate::serial::SerialPort; | ||
use crate::svsm_console::NativeIOPort; | ||
use crate::types::PageSize; | ||
use crate::utils::immut_after_init::ImmutAfterInitCell; | ||
use crate::utils::MemoryRegion; | ||
|
||
static CONSOLE_IO: NativeIOPort = NativeIOPort::new(); | ||
static CONSOLE_SERIAL: ImmutAfterInitCell<SerialPort<'_>> = ImmutAfterInitCell::uninit(); | ||
|
||
const APIC_MSR_ICR: u32 = 0x830; | ||
|
||
|
@@ -34,8 +39,19 @@ impl Default for NativePlatform { | |
} | ||
|
||
impl SvsmPlatform for NativePlatform { | ||
fn env_setup(&mut self) {} | ||
fn env_setup_late(&mut self) {} | ||
fn env_setup(&mut self, debug_serial_port: u16) -> Result<(), SvsmError> { | ||
// In the native platform, console output does not require the use of | ||
// any platform services, so it can be initialized immediately. | ||
CONSOLE_SERIAL | ||
.init(&SerialPort::new(&CONSOLE_IO, debug_serial_port)) | ||
.map_err(|_| SvsmError::Console)?; | ||
(*CONSOLE_SERIAL).init(); | ||
init_console(&*CONSOLE_SERIAL).map_err(|_| SvsmError::Console) | ||
} | ||
|
||
fn env_setup_late(&mut self, _debug_serial_port: u16) -> Result<(), SvsmError> { | ||
Ok(()) | ||
} | ||
|
||
fn setup_percpu(&self, _cpu: &PerCpu) -> Result<(), SvsmError> { | ||
Ok(()) | ||
|
@@ -58,7 +74,7 @@ impl SvsmPlatform for NativePlatform { | |
|
||
fn setup_guest_host_comm(&mut self, _cpu: &PerCpu, _is_bsp: bool) {} | ||
|
||
fn get_console_io_port(&self) -> &'static dyn IOPort { | ||
fn get_io_port(&self) -> &'static dyn IOPort { | ||
&CONSOLE_IO | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,14 @@ | |
// Author: Jon Lange <[email protected]> | ||
|
||
use crate::address::{PhysAddr, VirtAddr}; | ||
use crate::console::init_console; | ||
use crate::cpu::cpuid::cpuid_table; | ||
use crate::cpu::percpu::{current_ghcb, PerCpu}; | ||
use crate::error::ApicError::Registration; | ||
use crate::error::SvsmError; | ||
use crate::io::IOPort; | ||
use crate::platform::{PageEncryptionMasks, PageStateChangeOp, SvsmPlatform}; | ||
use crate::serial::SerialPort; | ||
use crate::sev::hv_doorbell::current_hv_doorbell; | ||
use crate::sev::msr_protocol::{hypervisor_ghcb_features, verify_ghcb_version, GHCBHvFeatures}; | ||
use crate::sev::status::vtom_enabled; | ||
|
@@ -19,11 +21,13 @@ use crate::sev::{ | |
}; | ||
use crate::svsm_console::SVSMIOPort; | ||
use crate::types::PageSize; | ||
use crate::utils::immut_after_init::ImmutAfterInitCell; | ||
use crate::utils::MemoryRegion; | ||
|
||
use core::sync::atomic::{AtomicU32, Ordering}; | ||
|
||
static CONSOLE_IO: SVSMIOPort = SVSMIOPort::new(); | ||
static CONSOLE_SERIAL: ImmutAfterInitCell<SerialPort<'_>> = ImmutAfterInitCell::uninit(); | ||
|
||
static APIC_EMULATION_REG_COUNT: AtomicU32 = AtomicU32::new(0); | ||
|
||
|
@@ -43,13 +47,20 @@ impl Default for SnpPlatform { | |
} | ||
|
||
impl SvsmPlatform for SnpPlatform { | ||
fn env_setup(&mut self) { | ||
fn env_setup(&mut self, _debug_serial_port: u16) -> Result<(), SvsmError> { | ||
sev_status_init(); | ||
Ok(()) | ||
} | ||
|
||
fn env_setup_late(&mut self) { | ||
fn env_setup_late(&mut self, debug_serial_port: u16) -> Result<(), SvsmError> { | ||
CONSOLE_SERIAL | ||
.init(&SerialPort::new(&CONSOLE_IO, debug_serial_port)) | ||
.map_err(|_| SvsmError::Console)?; | ||
(*CONSOLE_SERIAL).init(); | ||
init_console(&*CONSOLE_SERIAL).map_err(|_| SvsmError::Console)?; | ||
sev_status_verify(); | ||
init_hypervisor_ghcb_features().expect("Failed to obtain hypervisor GHCB features"); | ||
init_hypervisor_ghcb_features()?; | ||
Ok(()) | ||
} | ||
|
||
fn setup_percpu(&self, cpu: &PerCpu) -> Result<(), SvsmError> { | ||
|
@@ -102,7 +113,7 @@ impl SvsmPlatform for SnpPlatform { | |
cpu.register_ghcb().expect("Failed to register GHCB"); | ||
} | ||
|
||
fn get_console_io_port(&self) -> &'static dyn IOPort { | ||
fn get_io_port(&self) -> &'static dyn IOPort { | ||
&CONSOLE_IO | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,22 @@ | |
// Author: Peter Fang <[email protected]> | ||
|
||
use crate::address::{PhysAddr, VirtAddr}; | ||
use crate::console::init_console; | ||
use crate::cpu::cpuid::CpuidResult; | ||
use crate::cpu::percpu::PerCpu; | ||
use crate::error::SvsmError; | ||
use crate::io::IOPort; | ||
use crate::platform::{PageEncryptionMasks, PageStateChangeOp, SvsmPlatform}; | ||
use crate::serial::SerialPort; | ||
use crate::svsm_console::SVSMIOPort; | ||
use crate::types::PageSize; | ||
use crate::utils::immut_after_init::ImmutAfterInitCell; | ||
use crate::utils::MemoryRegion; | ||
|
||
// FIXME - SVSMIOPort doesn't work on TDP, but the platform does not yet have | ||
// an alternative available. | ||
static CONSOLE_IO: SVSMIOPort = SVSMIOPort::new(); | ||
static CONSOLE_SERIAL: ImmutAfterInitCell<SerialPort<'_>> = ImmutAfterInitCell::uninit(); | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct TdpPlatform {} | ||
|
@@ -32,9 +38,17 @@ impl Default for TdpPlatform { | |
} | ||
|
||
impl SvsmPlatform for TdpPlatform { | ||
fn env_setup(&mut self) {} | ||
fn env_setup(&mut self, _debug_serial_port: u16) -> Result<(), SvsmError> { | ||
Ok(()) | ||
} | ||
|
||
fn env_setup_late(&mut self) {} | ||
fn env_setup_late(&mut self, debug_serial_port: u16) -> Result<(), SvsmError> { | ||
CONSOLE_SERIAL | ||
.init(&SerialPort::new(&CONSOLE_IO, debug_serial_port)) | ||
.map_err(|_| SvsmError::Console)?; | ||
(*CONSOLE_SERIAL).init(); | ||
init_console(&*CONSOLE_SERIAL).map_err(|_| SvsmError::Console) | ||
} | ||
|
||
fn setup_percpu(&self, _cpu: &PerCpu) -> Result<(), SvsmError> { | ||
Err(SvsmError::Tdx) | ||
|
@@ -57,7 +71,7 @@ impl SvsmPlatform for TdpPlatform { | |
|
||
fn setup_guest_host_comm(&mut self, _cpu: &PerCpu, _is_bsp: bool) {} | ||
|
||
fn get_console_io_port(&self) -> &'static dyn IOPort { | ||
fn get_io_port(&self) -> &'static dyn IOPort { | ||
&CONSOLE_IO | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters