Skip to content

Commit

Permalink
Map the IGVM parameters into the page tables constructed by the kernel
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Lange <jlange@microsoft.com>
  • Loading branch information
msft-jlange committed Dec 4, 2023
1 parent 3df27ec commit 9080fab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/kernel_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub struct KernelLaunchInfo {
pub kernel_fs_end: u64,
pub cpuid_page: u64,
pub secrets_page: u64,
pub igvm_params: u64,
pub igvm_params_phys_addr: u64,
pub igvm_params_virt_addr: u64,
pub igvm_params_size: u64,
}

impl KernelLaunchInfo {
Expand Down
4 changes: 3 additions & 1 deletion src/stage2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ pub extern "C" fn stage2_main(launch_info: &Stage1LaunchInfo) {
kernel_fs_end: u64::from(launch_info.kernel_fs_end),
cpuid_page: config.get_cpuid_page_address(),
secrets_page: config.get_secrets_page_address(),
igvm_params: u64::from(igvm_params_virt_address),
igvm_params_phys_addr: launch_info.igvm_params as u64,
igvm_params_virt_addr: u64::from(igvm_params_virt_address),
igvm_params_size: igvm_params_size as u64,
};

let mem_info = memory_info();
Expand Down
4 changes: 2 additions & 2 deletions src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ pub extern "C" fn svsm_main() {
//debug_break();

let launch_info = &*LAUNCH_INFO;
let config = if launch_info.igvm_params != 0 {
let igvm_params = IgvmParams::new(VirtAddr::from(launch_info.igvm_params));
let config = if launch_info.igvm_params_virt_addr != 0 {
let igvm_params = IgvmParams::new(VirtAddr::from(launch_info.igvm_params_virt_addr));
SvsmConfig::IgvmConfig(igvm_params)
} else {
SvsmConfig::FirmwareConfig(FwCfg::new(&CONSOLE_IO))
Expand Down
20 changes: 18 additions & 2 deletions src/svsm_paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ pub fn init_page_table(launch_info: &KernelLaunchInfo, kernel_elf: &elf::Elf64Fi

// Install mappings for the kernel's ELF segments each.
// The memory backing the kernel ELF segments gets allocated back to back
// from the physical memory region by the Stage2 loader.
let mut phys = PhysAddr::from(launch_info.kernel_region_phys_start);
// from the physical memory region by the Stage2 loader, following
// the IGVM parameters (if any).
let igvm_params_size: usize = launch_info.igvm_params_size.try_into().unwrap();
let mut phys = PhysAddr::from(launch_info.kernel_region_phys_start) + igvm_params_size;
for segment in kernel_elf.image_load_segment_iter(launch_info.kernel_region_virt_start) {
let vaddr_start = VirtAddr::from(segment.vaddr_range.vaddr_begin);
let vaddr_end = VirtAddr::from(segment.vaddr_range.vaddr_end);
Expand All @@ -45,6 +47,20 @@ pub fn init_page_table(launch_info: &KernelLaunchInfo, kernel_elf: &elf::Elf64Fi
phys = phys + segment_len;
}

// Map the IGVM parameters if present.
if launch_info.igvm_params_virt_addr != 0 {
let igvm_params_virt_addr = VirtAddr::from(launch_info.igvm_params_virt_addr);

pgtable
.map_region(
igvm_params_virt_addr,
igvm_params_virt_addr + igvm_params_size,
PhysAddr::from(launch_info.igvm_params_phys_addr),
PTEntryFlags::data(),
)
.expect("Failed to map IGVM parameters");
}

// Map subsequent heap area.
pgtable
.map_region(
Expand Down

0 comments on commit 9080fab

Please sign in to comment.