Repository navigation
Description
Summary
cluster_mode() only accepts the flat (0b1111) and cluster (0b0000) DFR models. Any other model hits unreachable!("Unknown DFR value {value}") (lib.rs#L166-L172). In xAPIC mode a guest's DFR write reaches it without any filtering (lib.rs#L926-L927), so a single mov dword [0xfee000e0], 0x7fffffff in the guest aborts the VMM. restore also calls it on the saved DFR (lib.rs#L1911).
On WHP this affects the user-mode APIC configurations (--hypervisor whp:user_mode_apic, or --hv with whp:no_enlightenments). The SNP and TDX backends in virt_mshv_vtl use the same emulator. From reading the code, VTL0 could reach this path by disabling x2APIC and re-enabling the APIC in xAPIC mode. We have not tested that.
Repro
repro-test.patch adds this unit test to virt_support_apic. It needs no hypervisor.
#[test]
fn xapic_dfr_reserved_model() {
const DFR_ADDR: u64 = ((APIC_BASE_PAGE as u64) << 12) | 0xe0;
let (_set, mut apic) = new_apic();
let mut client = TestClient::default();
for (value, expected) in [
(0xffff_ffff, Dfr::FLAT_MODE.0),
(0x0fff_ffff, Dfr::CLUSTERED_MODE.0),
(0x0000_0000, Dfr::CLUSTERED_MODE.0),
// Reserved models.
(0xefff_ffff, Dfr::FLAT_MODE.0),
(0x8fff_ffff, Dfr::FLAT_MODE.0),
(0x7fff_ffff, Dfr::CLUSTERED_MODE.0),
(0x1234_5678, Dfr::CLUSTERED_MODE.0),
] {
apic.access(&mut client)
.mmio_write(DFR_ADDR, &u32::to_le_bytes(value));
let mut read = [0; 4];
apic.access(&mut client).mmio_read(DFR_ADDR, &mut read);
assert_eq!(u32::from_le_bytes(read), expected, "guest wrote DFR {value:#x}");
}
}$ cargo test -p virt_support_apic --lib -- xapic_dfr_reserved_model
panicked at vmm_core/virt_support_apic/src/lib.rs:170:14:
internal error: entered unreachable code: Unknown DFR value 4026531839
We also reproduced this with a real guest on WHP using the user-mode APIC: the VMM exits with 0xC0000409 and prints the same panic. The expected values in the test come from WHP's own APIC, which reads back 0xffffffff for 0xefffffff/0x8fffffff and 0x0fffffff for 0x7fffffff/0x12345678.
Suggested fix
For a reserved model, choose flat or cluster from bit 31, which matches WHP's APIC, and log a rate-limited warning instead of panicking. This fixes both the guest write path and the restore path. Patch attached (fix.patch):
diff --git a/vmm_core/virt_support_apic/src/lib.rs b/vmm_core/virt_support_apic/src/lib.rs
index 9a8d1c3..8ea6119 100644
--- a/vmm_core/virt_support_apic/src/lib.rs
+++ b/vmm_core/virt_support_apic/src/lib.rs
@@ -167,7 +167,14 @@ fn cluster_mode(value: u32) -> bool {
match Dfr(value | 0x0fff_ffff) {
Dfr::CLUSTERED_MODE => true,
Dfr::FLAT_MODE => false,
- _ => unreachable!("Unknown DFR value {value}"),
+ _ => {
+ // Only the flat (0b1111) and cluster (0b0000) models are
+ // architectural, but the value comes from a guest MMIO write or
+ // from saved state, so a reserved model must not panic. Pick the
+ // mode by the top bit, as Hyper-V's APIC emulation does.
+ tracelimit::warn_ratelimited!(value, "reserved DFR model");
+ value & 0x8000_0000 == 0
+ }
}
}
Activity