Skip to content

Commit

Permalink
stage2: Prefer using IGVM memory map to place SVSM kernel
Browse files Browse the repository at this point in the history
If the IGVM memory map contains a PARAVISOR_RESERVED entry, then place
the SVSM kernel at that region instead of the region specified in the
IgvmParamBlock. If no such entry exists in the memory map, then continue
using the IgvmParamBlock.

This allows the hypervisor to dynamically resize the SVSM based on the
machine shape without changing the IgvmParamBlock and thus the launch
measurement. This is necessary because the SVSM uses more memory when
there are more vCPUs (and, in the future, guest memory).

Signed-off-by: Adam Dunlap <[email protected]>
  • Loading branch information
AdamCDunlap committed Jan 8, 2025
1 parent d1c31ac commit 28a194c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kernel/src/igvm_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ impl IgvmParams<'_> {
}

pub fn find_kernel_region(&self) -> Result<MemoryRegion<PhysAddr>, SvsmError> {
// First check the memory map if there's a paravisor region to use.
for entry in self.igvm_memory_map.memory_map.iter() {
if entry.entry_type == MemoryMapEntryType::PARAVISOR_RESERVED {
let starting_page: usize = entry.starting_gpa_page_number.try_into().unwrap();
let number_of_pages: usize = entry.number_of_pages.try_into().unwrap();
return Ok(MemoryRegion::new(
PhysAddr::new(starting_page * PAGE_SIZE),
number_of_pages * PAGE_SIZE,
));
}
}

// Otherwise, use the region specified in the IgvmParamBlock.
let kernel_base = PhysAddr::from(self.igvm_param_block.kernel_base);
let kernel_size: usize = self.igvm_param_block.kernel_size.try_into().unwrap();
Ok(MemoryRegion::<PhysAddr>::new(kernel_base, kernel_size))
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/stage2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ pub extern "C" fn stage2_main(launch_info: &Stage2LaunchInfo) {
.find_kernel_region()
.expect("Failed to find memory region for SVSM kernel");

log::info!("SVSM memory region: {kernel_region:?}");

init_valid_bitmap_alloc(kernel_region).expect("Failed to allocate valid-bitmap");

// The physical memory region we've loaded so far
Expand Down

0 comments on commit 28a194c

Please sign in to comment.