Skip to content

Commit be02aa1

Browse files
committed
KVM: nVMX: Explicitly invalidate posted_intr_nv if PI is disabled at VM-Enter
Explicitly set posted_intr_nv to -1 when emulating nested VM-Enter and posted interrupts are disabled to make it clear that posted_intr_nv is valid if and only if nested posted interrupts are enabled, and as a cheap way to harden against KVM bugs. Note, KVM initializes posted_intr_nv to -1 at vCPU creation and when resets it to -1 when unloading vmcs12 and/or leaving nested mode, i.e. this is not a bug fix (or at least, it's not intended to be a bug fix). Cc: stable@vger.kernel.org Reviewed-by: Chao Gao <chao.gao@intel.com> Link: https://lore.kernel.org/r/20240720000138.3027780-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent ab9cbe0 commit be02aa1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,10 +2317,12 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct loaded_vmcs *vmcs0
23172317

23182318
/* Posted interrupts setting is only taken from vmcs12. */
23192319
vmx->nested.pi_pending = false;
2320-
if (nested_cpu_has_posted_intr(vmcs12))
2320+
if (nested_cpu_has_posted_intr(vmcs12)) {
23212321
vmx->nested.posted_intr_nv = vmcs12->posted_intr_nv;
2322-
else
2322+
} else {
2323+
vmx->nested.posted_intr_nv = -1;
23232324
exec_control &= ~PIN_BASED_POSTED_INTR;
2325+
}
23242326
pin_controls_set(vmx, exec_control);
23252327

23262328
/*

0 commit comments

Comments
 (0)