Commit cfb0e130 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: VMX: Read Posted Interrupt "control" exactly once per loop iteration

Use READ_ONCE() when loading the posted interrupt descriptor control
field to ensure "old" and "new" have the same base value.  If the
compiler emits separate loads, and loads into "new" before "old", KVM
could theoretically drop the ON bit if it were set between the loads.

Fixes: 28b835d6 ("KVM: Update Posted-Interrupts Descriptor when vCPU is preempted")
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20211009021236.4122790-27-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 89ef0f21
...@@ -54,7 +54,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) ...@@ -54,7 +54,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
/* The full case. */ /* The full case. */
do { do {
old.control = new.control = pi_desc->control; old.control = new.control = READ_ONCE(pi_desc->control);
dest = cpu_physical_id(cpu); dest = cpu_physical_id(cpu);
...@@ -107,7 +107,7 @@ static void __pi_post_block(struct kvm_vcpu *vcpu) ...@@ -107,7 +107,7 @@ static void __pi_post_block(struct kvm_vcpu *vcpu)
unsigned int dest; unsigned int dest;
do { do {
old.control = new.control = pi_desc->control; old.control = new.control = READ_ONCE(pi_desc->control);
WARN(old.nv != POSTED_INTR_WAKEUP_VECTOR, WARN(old.nv != POSTED_INTR_WAKEUP_VECTOR,
"Wakeup handler not enabled while the VCPU is blocked\n"); "Wakeup handler not enabled while the VCPU is blocked\n");
...@@ -160,7 +160,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu) ...@@ -160,7 +160,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu)
spin_unlock(&per_cpu(blocked_vcpu_on_cpu_lock, vcpu->cpu)); spin_unlock(&per_cpu(blocked_vcpu_on_cpu_lock, vcpu->cpu));
do { do {
old.control = new.control = pi_desc->control; old.control = new.control = READ_ONCE(pi_desc->control);
WARN((pi_desc->sn == 1), WARN((pi_desc->sn == 1),
"Warning: SN field of posted-interrupts " "Warning: SN field of posted-interrupts "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment