[RFC PATCH v2 18/31] KVM: x86: hyperv: Truncate higher-VTL vAPIC MSR writes

From: David Woodhouse

Date: Fri Nov 13 2026 - 14:16:51 EST


From: David Woodhouse <dwmw@xxxxxxxxxxxx>

The Windows secure kernel writes the Hyper-V vAPIC MSRs, HV_X64_MSR_EOI
among them, with stale data in bits 63:32. Those bits are reserved for
every register but the ICR, so KVM injects #GP, and a #GP there is a
VTL1 bugcheck.

Truncate non-ICR writes through kvm_hv_vapic_msr_write() from a
non-zero plane to 32 bits. The exemption covers only this paravirtual
path; a native x2APIC WRMSR still takes the architectural #GP on any
plane.

Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
arch/x86/kvm/lapic.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 79e4998da644..81bf72e83e8c 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -3589,6 +3589,18 @@ int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 reg, u64 data)
if (!lapic_in_kernel(vcpu))
return 1;

+ /*
+ * Bits 63:32 are reserved in non-ICR registers, but the Windows
+ * secure kernel leaves stale data in the high bits when writing
+ * the Hyper-V vAPIC MSRs from a higher VTL, and takes a #GP here
+ * as a VTL1 bugcheck. Truncate those writes instead, as the Nitro
+ * VSM implementation does. The exemption covers only this PV
+ * path: a native x2APIC WRMSR takes the architectural #GP whatever
+ * the plane.
+ */
+ if (vcpu->plane_level && reg != APIC_ICR)
+ data = (u32)data;
+
return kvm_lapic_msr_write(vcpu->arch.apic, reg, data);
}

--
2.50.1