From ee28e199b74c3ad84ee2bc965a8e4627c9a538bd Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Thu, 20 Mar 2025 23:44:40 +0800 Subject: [PATCH] Clarify TDX AP workaround --- ostd/src/arch/x86/boot/linux_boot/mod.rs | 37 +++++++++++++++--------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/ostd/src/arch/x86/boot/linux_boot/mod.rs b/ostd/src/arch/x86/boot/linux_boot/mod.rs index d6a80e194..57f90f047 100644 --- a/ostd/src/arch/x86/boot/linux_boot/mod.rs +++ b/ostd/src/arch/x86/boot/linux_boot/mod.rs @@ -133,22 +133,10 @@ fn parse_memory_regions(boot_params: &BootParams) -> MemoryRegionArray { // Add regions from E820. let num_entries = boot_params.e820_entries as usize; for e820_entry in &boot_params.e820_table[0..num_entries] { - if_tdx_enabled!({ - if (e820_entry.addr..(e820_entry.addr + e820_entry.size)).contains(&0x800000) { - regions - .push(MemoryRegion::new( - e820_entry.addr as usize, - e820_entry.size as usize, - MemoryRegionType::Reclaimable, - )) - .unwrap(); - continue; - } - }); regions .push(MemoryRegion::new( - e820_entry.addr as usize, - e820_entry.size as usize, + e820_entry.addr.try_into().unwrap(), + e820_entry.size.try_into().unwrap(), e820_entry.typ.into(), )) .unwrap(); @@ -179,6 +167,27 @@ fn parse_memory_regions(boot_params: &BootParams) -> MemoryRegionArray { .unwrap(); } + // FIXME: Early versions of TDVF did not correctly report the location of AP's page tables as + // EfiACPIMemoryNVS. We need to manually reserve this memory region to prevent them from being + // corrupted. TDVF has now been upstreamed to OVMF, and this issue has been fixed in OVMF + // stable-202411 or later. See the commit for details: + // . + if_tdx_enabled!({ + // The definition of these constants can be found in: + // + // + regions + .push(MemoryRegion::new( + // PcdOvmfSecPageTablesBase = $(MEMFD_BASE_ADDRESS) + 0x000000 = 0x800000 + 0x800000, + // PcdOvmfSecPageTablesSize = 0x006000 + 0x006000, + // EfiACPIMemoryNVS + MemoryRegionType::NonVolatileSleep, + )) + .unwrap(); + }); + regions.into_non_overlapping() }