From f6ed896f6882cc9b6eb6334ad54c06f7b06726ba Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Wed, 29 Apr 2026 15:35:31 -0700 Subject: [PATCH] vmm: gate reserve_bootloader_regions on KVM hypervisor type The reserve_bootloader_regions() call allocates RAM regions at KVM-specific addresses (0xffc00000 for stage0, 0xfffffffff000 for VMSA) that are only needed by the KVM SEV-SNP boot path. The existing #[cfg(all(feature = "kvm", feature = "sev_snp"))] compile-time guard is insufficient when both 'mshv' and 'kvm' features are enabled in the same binary. The runtime check only verified sev_snp_enabled() but not the hypervisor type, causing these KVM-specific memory regions to be allocated on MSHV. On MSHV, these spurious RAM mappings at high addresses interfere with the hypervisor's address space layout. When the guest kernel subsequently accesses MMIO regions (e.g., IOAPIC at 0xFEC00000), MSHV incorrectly reports HVMSG_UNACCEPTED_GPA instead of routing the access through MMIO emulation, crashing the guest. Add a runtime hypervisor type check to ensure these regions are only reserved when running on KVM. Assisted-by: Claude:Opus-4.6 Signed-off-by: Muminul Islam --- vmm/src/vm.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index e4df94b76..3d5315b19 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1547,7 +1547,9 @@ impl Vm { // Only reserve bootloader/VMSA regions for KVM + SEV-SNP; other hypervisors // (e.g. MSHV) handle this through their own import path. #[cfg(all(feature = "kvm", feature = "sev_snp"))] - if cpu_manager.lock().unwrap().sev_snp_enabled() { + if cpu_manager.lock().unwrap().sev_snp_enabled() + && cpu_manager.lock().unwrap().hypervisor_type() == hypervisor::HypervisorType::Kvm + { Self::reserve_bootloader_regions(&memory_manager)?; }