From e993310c96f5aa92e64e3e67aceaea6a7156d24f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 21 Nov 2025 09:13:38 +0000 Subject: [PATCH] hypervisor: kvm: Save KVM HyperV SynIC emulation state As well as saving the MSRs as it is currently does ensure that the KVM capability is enabled along with keeping the internal state updated. Signed-off-by: Rob Bradford Co-authored-by: Chengyu Fu --- hypervisor/src/kvm/mod.rs | 8 +++++++- hypervisor/src/kvm/x86_64/mod.rs | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index e005834b9..6a1b31607 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -2342,7 +2342,8 @@ impl cpu::Vcpu for KvmVcpu { // Save extra MSRs if the Hyper-V synthetic interrupt controller is // emulated. - if self.hyperv_synic.load(Ordering::Acquire) { + let hyperv_synic = self.hyperv_synic.load(Ordering::Acquire); + if hyperv_synic { let hyperv_synic_msrs = vec![ 0x40000020, 0x40000021, 0x40000080, 0x40000081, 0x40000082, 0x40000083, 0x40000084, 0x40000090, 0x40000091, 0x40000092, 0x40000093, 0x40000094, 0x40000095, 0x40000096, @@ -2407,6 +2408,7 @@ impl cpu::Vcpu for KvmVcpu { mp_state, tsc_khz, nested_state, + hyperv_synic, } .into()) } @@ -2574,6 +2576,10 @@ impl cpu::Vcpu for KvmVcpu { self.set_tsc_khz(freq)?; } + if state.hyperv_synic { + self.enable_hyperv_synic()?; + } + // Try to set all MSRs previously stored. // If the number of MSRs set from SET_MSRS is different from the // expected amount, we fallback onto a slower method by setting MSRs diff --git a/hypervisor/src/kvm/x86_64/mod.rs b/hypervisor/src/kvm/x86_64/mod.rs index c1bda9d9b..39db4a994 100644 --- a/hypervisor/src/kvm/x86_64/mod.rs +++ b/hypervisor/src/kvm/x86_64/mod.rs @@ -79,6 +79,8 @@ pub struct VcpuKvmState { // Option to prevent useless 8K (de)serialization when no nested // state exists. pub nested_state: Option, + #[serde(default)] + pub hyperv_synic: bool, } impl From for kvm_segment {