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 <rbradford@rivosinc.com>
Co-authored-by: Chengyu Fu <chengyu.fu@linux.alibaba.com>
This commit is contained in:
Rob Bradford 2025-11-21 09:13:38 +00:00
parent 16fbab30b1
commit e993310c96
2 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -79,6 +79,8 @@ pub struct VcpuKvmState {
// Option to prevent useless 8K (de)serialization when no nested
// state exists.
pub nested_state: Option<KvmNestedStateBuffer>,
#[serde(default)]
pub hyperv_synic: bool,
}
impl From<SegmentRegister> for kvm_segment {