diff --git a/arch/src/x86_64/tdx/mod.rs b/arch/src/x86_64/tdx/mod.rs index 1e0831e00..0b38ff0ed 100644 --- a/arch/src/x86_64/tdx/mod.rs +++ b/arch/src/x86_64/tdx/mod.rs @@ -61,57 +61,6 @@ impl Default for TdvfSectionType { } } -#[repr(C)] -#[derive(Clone, Copy, Default, Debug)] -pub struct TdVmmDataRegion { - pub start_address: u64, - pub length: u64, - pub region_type: TdVmmDataRegionType, -} - -#[repr(u16)] -#[derive(Clone, Copy, Debug)] -pub enum TdVmmDataRegionType { - Signature = 0x0000, - InterfaceVersion = 0x0001, - SystemUuid = 0x0002, - RamSize = 0x0003, - GraphicsEnabled = 0x0004, - SmpCpuCount = 0x0005, - MachineId = 0x0006, - KernelAddress = 0x0007, - KernelSize = 0x0008, - KernelCommandLine = 0x0009, - InitrdAddress = 0x000a, - InitrdSize = 0x000b, - BootDevice = 0x000c, - NumaData = 0x000d, - BootMenu = 0x000e, - MaximumCpuCount = 0x000f, - KernelEntry = 0x0010, - KernelData = 0x0011, - InitrdData = 0x0012, - CommandLineAddress = 0x0013, - CommandLineSize = 0x0014, - CommandLineData = 0x0015, - KernelSetupAddress = 0x0016, - KernelSetupSize = 0x0017, - KernelSetupData = 0x0018, - FileDir = 0x0019, - AcpiTables = 0x8000, - SmbiosTables = 0x8001, - Irq0Override = 0x8002, - E820Table = 0x8003, - HpetData = 0x8004, - Reserved = 0xffff, -} - -impl Default for TdVmmDataRegionType { - fn default() -> Self { - TdVmmDataRegionType::Reserved - } -} - pub fn parse_tdvf_sections(file: &mut File) -> Result, TdvfError> { // The 32-bit offset to the TDVF metadata is located 32 bytes from // the end of the file. @@ -231,20 +180,11 @@ struct HobGuidType { name: EfiGuid, } -#[repr(C)] -#[derive(Copy, Clone, Default, Debug)] -struct TdVmmData { - guid_type: HobGuidType, - region: TdVmmDataRegion, -} - // SAFETY: These data structures only contain a series of integers -unsafe impl ByteValued for TdVmmDataRegion {} unsafe impl ByteValued for HobHeader {} unsafe impl ByteValued for HobHandoffInfoTable {} unsafe impl ByteValued for HobResourceDescriptor {} unsafe impl ByteValued for HobGuidType {} -unsafe impl ByteValued for TdVmmData {} pub struct TdHob { start_offset: u64, @@ -375,38 +315,6 @@ impl TdHob { 0x403, ) } - - pub fn add_td_vmm_data( - &mut self, - mem: &GuestMemoryMmap, - region: TdVmmDataRegion, - ) -> Result<(), TdvfError> { - let td_vmm_data = TdVmmData { - guid_type: HobGuidType { - header: HobHeader { - r#type: HobType::GuidExtension, - length: std::mem::size_of::() as u16, - reserved: 0, - }, - // TD_VMM_DATA_GUID CF2643E4-C0D3-46FF-0000-72EE623DDE38 - name: EfiGuid { - data1: 0xcf26_43e4, - data2: 0xc0d3, - data3: 0x46ff, - data4: [0x00, 0x00, 0x72, 0xee, 0x62, 0x3d, 0xde, 0x38], - }, - }, - region, - }; - info!( - "Writing HOB TD_VMM_DATA {:x} {:x?}", - self.current_offset, td_vmm_data - ); - mem.write_obj(td_vmm_data, GuestAddress(self.current_offset)) - .map_err(TdvfError::GuestMemoryWriteHob)?; - self.update_offset::(); - Ok(()) - } } #[cfg(test)] diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 0a95a7eec..b270b27be 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -33,10 +33,8 @@ use anyhow::anyhow; use arch::get_host_cpu_phys_bits; #[cfg(target_arch = "x86_64")] use arch::layout::{KVM_IDENTITY_MAP_START, KVM_TSS_START}; -#[cfg(all(feature = "tdx", feature = "acpi"))] -use arch::x86_64::tdx::TdVmmDataRegionType; #[cfg(feature = "tdx")] -use arch::x86_64::tdx::{TdVmmDataRegion, TdvfSection}; +use arch::x86_64::tdx::TdvfSection; use arch::EntryPoint; #[cfg(target_arch = "aarch64")] use arch::PciSpaceInfo; @@ -1709,11 +1707,7 @@ impl Vm { } #[cfg(feature = "tdx")] - fn populate_tdx_sections( - &mut self, - sections: &[TdvfSection], - vmm_data_regions: &[TdVmmDataRegion], - ) -> Result> { + fn populate_tdx_sections(&mut self, sections: &[TdvfSection]) -> Result> { use arch::x86_64::tdx::*; // Get the memory end *before* we start adding TDVF ram regions let boot_guest_memory = self @@ -1780,19 +1774,6 @@ impl Vm { !matches!(section.r#type, TdvfSectionType::Bfv | TdvfSectionType::Cfv) }); - // Add VMM specific data memory region to TdvfSections as TdHob type - // to ensure the firmware won't ignore/reject the ranges. - for region in vmm_data_regions { - sorted_sections.push(TdvfSection { - data_offset: 0, - data_size: 0, - address: region.start_address, - size: region.length, - r#type: TdvfSectionType::TdHob, - attributes: 0, - }); - } - sorted_sections.sort_by_key(|section| section.address); sorted_sections.reverse(); let mut current_section = sorted_sections.pop(); @@ -1860,25 +1841,13 @@ impl Vm { ) .map_err(Error::PopulateHob)?; - // Add VMM specific data to the TdHob. The content of the data is - // is written as part of the HOB, which will be retrieved from the - // firmware, and processed accordingly to the type. - for region in vmm_data_regions { - hob.add_td_vmm_data(&mem, *region) - .map_err(Error::PopulateHob)?; - } - hob.finish(&mem).map_err(Error::PopulateHob)?; Ok(hob_offset) } #[cfg(feature = "tdx")] - fn init_tdx_memory( - &mut self, - sections: &[TdvfSection], - regions: &[TdVmmDataRegion], - ) -> Result<()> { + fn init_tdx_memory(&mut self, sections: &[TdvfSection]) -> Result<()> { let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory(); let mem = guest_memory.memory(); @@ -1894,21 +1863,6 @@ impl Vm { .map_err(Error::InitializeTdxMemoryRegion)?; } - // The same way we let the hypervisor know about the TDVF sections, we - // must declare the VMM specific regions shared with the guest so that - // they won't be discarded. - for region in regions { - self.vm - .tdx_init_memory_region( - mem.get_host_address(GuestAddress(region.start_address)) - .unwrap() as u64, - region.start_address, - region.length, - false, - ) - .map_err(Error::InitializeTdxMemoryRegion)?; - } - Ok(()) } @@ -2019,23 +1973,11 @@ impl Vm { rsdp_addr }; - #[cfg(all(feature = "tdx", not(feature = "acpi")))] - let vmm_data_regions: Vec = Vec::new(); - - // Create a VMM specific data region to share the ACPI tables with - // the guest. Reserving 64kiB to ensure the ACPI tables will fit. - #[cfg(all(feature = "tdx", feature = "acpi"))] - let vmm_data_regions = vec![TdVmmDataRegion { - start_address: rsdp_addr.0, - length: 0x10000, - region_type: TdVmmDataRegionType::AcpiTables, - }]; - // Configuring the TDX regions requires that the vCPUs are created. #[cfg(feature = "tdx")] let hob_address = if self.config.lock().unwrap().tdx.is_some() { // TDX sections are written to memory. - self.populate_tdx_sections(§ions, &vmm_data_regions)? + self.populate_tdx_sections(§ions)? } else { None }; @@ -2062,7 +2004,7 @@ impl Vm { // Let the hypervisor know which memory ranges are shared with the // guest. This prevents the guest from ignoring/discarding memory // regions provided by the host. - self.init_tdx_memory(§ions, &vmm_data_regions)?; + self.init_tdx_memory(§ions)?; // With TDX memory and CPU state configured TDX setup is complete self.vm.tdx_finalize().map_err(Error::FinalizeTdx)?; }