Repository navigation
Description
Summary
A VP that idles through HV_X64_MSR_GUEST_IDLE under the default WHP configuration with hv is saved as MpState::Idle. If that snapshot is restored with --hypervisor whp:user_mode_apic (or whp:no_enlightenments), restore_activity reaches vp::MpState::Idle => unimplemented!() (apic.rs#L231) and the VMM aborts. The restore is not rejected earlier, because the snapshot manifest does not record the hypervisor or its options (snapshot.rs#L57).
The user-mode APIC never saves Idle itself. Its save_activity only produces Running, Halted or WaitForSipi. So the input is always a snapshot from another configuration. For the same input, virt_kvm returns InvalidState("Hyper-V idle state not supported") (vp_state.rs#L351).
Repro
This needs a Windows host with WHP. repro-test.patch adds vmm_core/virt_whp/tests/vp_state.rs, which has small helpers for building partitions, running guest code, and saving and restoring VPs. The guest is real-mode code: out 0x80, 'I'; cli; mov ecx, 0x400000f0; rdmsr.
#[test]
fn user_mode_apic_restore_idle_state() {
with_time(|time| {
let (saved, ram) = {
let vm = run_to_suspend(WHP_HV1, IDLE, b'I', time);
assert_eq!(vm.activity(0).mp_state, vp::MpState::Idle);
(vm.save(0), vm.ram())
};
let mut hv = whp(WHP_USER_MODE_APIC_HV1);
let mut vm = Vm::new(&mut hv, WHP_USER_MODE_APIC_HV1, 1, time);
vm.mem.write_at(0, &ram).unwrap();
let r = vm.restore(0, &saved);
assert!(
!r.as_ref().is_err_and(|e| e.starts_with("VMM panic")),
"restore_all: {r:?}"
);
})
}$ cargo test -p virt_whp --test vp_state -- user_mode_apic_restore_idle_state
panicked at vmm_core\virt_whp\src\apic.rs:231:42:
not implemented
This panics before the write that fails in #1472 , so fixing that issue alone does not fix this one.
Suggested fix
Return an error, as virt_kvm does. The patch (fix.patch) adds Error::InvalidState(&'static str):
diff --git a/vmm_core/virt_whp/src/apic.rs b/vmm_core/virt_whp/src/apic.rs
index 60fcb73ae..ee3cf33e1 100644
--- a/vmm_core/virt_whp/src/apic.rs
+++ b/vmm_core/virt_whp/src/apic.rs
@@ -228,7 +228,15 @@ pub(crate) fn restore_activity(&mut self, vtl: Vtl, value: &vp::Activity) -> Res
startup_suspend = false;
halted = true;
}
- vp::MpState::Idle => unimplemented!(),
+ vp::MpState::Idle => {
+ // This configuration never saves the Hyper-V idle
+ // state (only the hypervisor reports it, for a guest
+ // idling through HV_X64_MSR_GUEST_IDLE), so this is
+ // state saved with another configuration.
+ return Err(Error::InvalidState(
+ "Hyper-V idle state not supported with the user-mode APIC",
+ ));
+ }
}
lapic.startup_suspend = startup_suspend;
diff --git a/vmm_core/virt_whp/src/lib.rs b/vmm_core/virt_whp/src/lib.rs
index f3088f4f4..e9a459d80 100644
--- a/vmm_core/virt_whp/src/lib.rs
+++ b/vmm_core/virt_whp/src/lib.rs
@@ -839,6 +839,8 @@ pub enum Error {
AcceptPages(#[source] anyhow::Error),
#[error("invalid apic base")]
InvalidApicBase(#[source] virt_support_apic::InvalidApicBase),
+ #[error("invalid state while restoring: {0}")]
+ InvalidState(&'static str),
#[error("host does not support required cpu capabilities")]
Capabilities(virt::PartitionCapabilitiesError),
#[error("WHP does not support GICv2; only GICv3 is supported")]Restoring Idle as Halted would be wrong. Per the TLFS, an interrupt wakes a VP in guest idle even when IF = 0, and the user-mode APIC cannot represent that.
Activity