-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
platform/snp: Add abstractions for FW operations
Add new abstractions to SvsmPlatform: - prepare_fw() performs preparations for launching guest boot firmware - launch_fw() launches guest boot firmware Move FW-related functions in svsm.rs to snp_fw.rs as they're SEV-specific. Make sure snp_fw doesn't export anything unnecessary to the outside world. Signed-off-by: Peter Fang <[email protected]>
- Loading branch information
Showing
8 changed files
with
223 additions
and
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,45 @@ | |
// | ||
// Author: Joerg Roedel <[email protected]> | ||
|
||
use crate::address::VirtAddr; | ||
use crate::types::PAGE_SIZE; | ||
use crate::utils::immut_after_init::ImmutAfterInitRef; | ||
use cpuarch::snp_cpuid::SnpCpuidTable; | ||
|
||
use core::arch::asm; | ||
|
||
static CPUID_PAGE: ImmutAfterInitRef<'_, SnpCpuidTable> = ImmutAfterInitRef::uninit(); | ||
|
||
const _: () = assert!(size_of::<SnpCpuidTable>() <= PAGE_SIZE); | ||
|
||
pub fn register_cpuid_table(table: &'static SnpCpuidTable) { | ||
CPUID_PAGE | ||
.init_from_ref(table) | ||
.expect("Could not initialize CPUID page"); | ||
} | ||
|
||
/// Copy a CPUID page's content to memory pointed to by a [`VirtAddr`] | ||
/// | ||
/// # Safety | ||
/// | ||
/// The caller should verify that `dst` points to mapped memory whose size is | ||
/// at least 4K. We assert above at compile time that SnpCpuidTable fits within | ||
/// a page, so the write is safe. | ||
/// | ||
/// The caller should verify not to corrupt arbitrary memory, as this function | ||
/// doesn't make any checks in that regard. | ||
pub unsafe fn copy_cpuid_table_to(dst: VirtAddr) { | ||
let start = dst.as_mut_ptr::<u8>(); | ||
// SAFETY: caller must ensure the address is valid and not aliased. | ||
unsafe { | ||
// Zero target and copy data | ||
start.write_bytes(0, PAGE_SIZE); | ||
start | ||
.cast::<SnpCpuidTable>() | ||
.copy_from_nonoverlapping(&*CPUID_PAGE, 1); | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
#[repr(C, packed)] | ||
pub struct CpuidLeaf { | ||
|
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 |
---|---|---|
|
@@ -4,14 +4,19 @@ | |
// | ||
// Author: Jon Lange <[email protected]> | ||
|
||
use super::snp_fw::{ | ||
copy_tables_to_fw, launch_fw, prepare_fw_launch, print_fw_meta, validate_fw, validate_fw_memory, | ||
}; | ||
use crate::address::{Address, PhysAddr, VirtAddr}; | ||
use crate::config::SvsmConfig; | ||
use crate::console::init_svsm_console; | ||
use crate::cpu::cpuid::{cpuid_table, CpuidResult}; | ||
use crate::cpu::percpu::{current_ghcb, this_cpu, PerCpu}; | ||
use crate::error::ApicError::Registration; | ||
use crate::error::SvsmError; | ||
use crate::greq::driver::guest_request_driver_init; | ||
use crate::io::IOPort; | ||
use crate::mm::memory::write_guest_memory_map; | ||
use crate::mm::{PerCPUPageMappingGuard, PAGE_SIZE, PAGE_SIZE_2M}; | ||
use crate::platform::{PageEncryptionMasks, PageStateChangeOp, PageValidateOp, SvsmPlatform}; | ||
use crate::sev::ghcb::GHCBIOSize; | ||
|
@@ -115,6 +120,31 @@ impl SvsmPlatform for SnpPlatform { | |
Ok(()) | ||
} | ||
|
||
fn prepare_fw( | ||
&self, | ||
config: &SvsmConfig<'_>, | ||
kernel_region: MemoryRegion<PhysAddr>, | ||
) -> Result<(), SvsmError> { | ||
let fw_metadata = config.get_fw_metadata(); | ||
if let Some(ref fw_meta) = fw_metadata { | ||
print_fw_meta(fw_meta); | ||
write_guest_memory_map(config).expect("Failed to write guest memory map"); | ||
validate_fw_memory(config, fw_meta, &kernel_region).expect("Failed to validate memory"); | ||
copy_tables_to_fw(fw_meta, &kernel_region).expect("Failed to copy firmware tables"); | ||
validate_fw(config, &kernel_region).expect("Failed to validate flash memory"); | ||
prepare_fw_launch(fw_meta).expect("Failed to setup guest VMSA/CAA"); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn launch_fw(&self, config: &SvsmConfig<'_>) -> Result<(), SvsmError> { | ||
if config.should_launch_fw() { | ||
launch_fw(config) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn setup_percpu(&self, cpu: &PerCpu) -> Result<(), SvsmError> { | ||
// Setup GHCB | ||
cpu.setup_ghcb() | ||
|
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
Oops, something went wrong.