From 98f949d35d926c800ce0c5ca4cfbcd8c79bae07f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 11 Aug 2022 11:43:16 +0200 Subject: [PATCH] vmm: Add new I/O ports for ACPI shutdown and PM timer devices Adding new I/O ports for both the ACPI shutdown and the ACPI PM timer devices so they can be triggered from both addresses. The reason for this change is that TDX expects only certain I/O ports to be enabled based on what QEMU exposes. We follow this to avoid new ports from being opened exclusively for Cloud Hypervisor. We have to keep the former I/O ports available given all firmwares haven't been updated yet. Once we reach a point where we know both Rust Hypervisor Firmware, OVMF, TDVF and TDSHIM have been updated with the new port values, we'll be able to remove the former ports. Signed-off-by: Sebastien Boeuf --- vmm/src/device_manager.rs | 49 ++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 83fe9e84c..19ce15be3 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1411,6 +1411,10 @@ impl DeviceManager { #[cfg(target_arch = "x86_64")] { + let shutdown_pio_address: u16 = 0x600; + + // TODO: Remove the entry for 0x3c0 once all firmwares will have been + // updated with the new value. self.address_manager .allocator .lock() @@ -1418,16 +1422,31 @@ impl DeviceManager { .allocate_io_addresses(Some(GuestAddress(0x3c0)), 0x8, None) .ok_or(DeviceManagerError::AllocateIoPort)?; + self.address_manager + .allocator + .lock() + .unwrap() + .allocate_io_addresses(Some(GuestAddress(shutdown_pio_address.into())), 0x8, None) + .ok_or(DeviceManagerError::AllocateIoPort)?; + + // TODO: Remove the entry for 0x3c0 once all firmwares will have been + // updated with the new value. self.address_manager .io_bus - .insert(shutdown_device, 0x3c0, 0x4) + .insert(shutdown_device.clone(), 0x3c0, 0x4) .map_err(DeviceManagerError::BusError)?; + + self.address_manager + .io_bus + .insert(shutdown_device, shutdown_pio_address.into(), 0x4) + .map_err(DeviceManagerError::BusError)?; + self.acpi_platform_addresses.sleep_control_reg_address = - Some(GenericAddress::io_port_address::(0x3c0)); + Some(GenericAddress::io_port_address::(shutdown_pio_address)); self.acpi_platform_addresses.sleep_status_reg_address = - Some(GenericAddress::io_port_address::(0x3c0)); + Some(GenericAddress::io_port_address::(shutdown_pio_address)); self.acpi_platform_addresses.reset_reg_address = - Some(GenericAddress::io_port_address::(0x3c0)); + Some(GenericAddress::io_port_address::(shutdown_pio_address)); } let ged_irq = self @@ -1476,6 +1495,10 @@ impl DeviceManager { #[cfg(target_arch = "x86_64")] { + let pm_timer_pio_address: u16 = 0x608; + + // TODO: Remove the entry for 0xb008 once all firmwares will have been + // updated with the new value. self.address_manager .allocator .lock() @@ -1483,13 +1506,27 @@ impl DeviceManager { .allocate_io_addresses(Some(GuestAddress(0xb008)), 0x4, None) .ok_or(DeviceManagerError::AllocateIoPort)?; + self.address_manager + .allocator + .lock() + .unwrap() + .allocate_io_addresses(Some(GuestAddress(pm_timer_pio_address.into())), 0x4, None) + .ok_or(DeviceManagerError::AllocateIoPort)?; + + // TODO: Remove the entry for 0xb008 once all firmwares will have been + // updated with the new value. self.address_manager .io_bus - .insert(pm_timer_device, 0xb008, 0x4) + .insert(pm_timer_device.clone(), 0xb008, 0x4) + .map_err(DeviceManagerError::BusError)?; + + self.address_manager + .io_bus + .insert(pm_timer_device, pm_timer_pio_address.into(), 0x4) .map_err(DeviceManagerError::BusError)?; self.acpi_platform_addresses.pm_timer_address = - Some(GenericAddress::io_port_address::(0xb008)); + Some(GenericAddress::io_port_address::(pm_timer_pio_address)); } Ok(Some(ged_device))