Skip to content

Commit 4de5c54

Browse files
committed
KVM: nVMX: clean up posted interrupt descriptor try_cmpxchg
Rely on try_cmpxchg64 for re-reading the PID on failure, using READ_ONCE only right before the first iteration. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4b88b1a commit 4de5c54

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

arch/x86/kvm/vmx/posted_intr.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ static inline struct pi_desc *vcpu_to_pi_desc(struct kvm_vcpu *vcpu)
3434
return &(to_vmx(vcpu)->pi_desc);
3535
}
3636

37-
static int pi_try_set_control(struct pi_desc *pi_desc, u64 old, u64 new)
37+
static int pi_try_set_control(struct pi_desc *pi_desc, u64 *pold, u64 new)
3838
{
3939
/*
4040
* PID.ON can be set at any time by a different vCPU or by hardware,
4141
* e.g. a device. PID.control must be written atomically, and the
4242
* update must be retried with a fresh snapshot an ON change causes
4343
* the cmpxchg to fail.
4444
*/
45-
if (!try_cmpxchg64(&pi_desc->control, &old, new))
45+
if (!try_cmpxchg64(&pi_desc->control, pold, new))
4646
return -EBUSY;
4747

4848
return 0;
@@ -96,8 +96,9 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
9696
if (!x2apic_mode)
9797
dest = (dest << 8) & 0xFF00;
9898

99+
old.control = READ_ONCE(pi_desc->control);
99100
do {
100-
old.control = new.control = READ_ONCE(pi_desc->control);
101+
new.control = old.control;
101102

102103
/*
103104
* Clear SN (as above) and refresh the destination APIC ID to
@@ -111,7 +112,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
111112
* descriptor was modified on "put" to use the wakeup vector.
112113
*/
113114
new.nv = POSTED_INTR_VECTOR;
114-
} while (pi_try_set_control(pi_desc, old.control, new.control));
115+
} while (pi_try_set_control(pi_desc, &old.control, new.control));
115116

116117
local_irq_restore(flags);
117118

@@ -156,12 +157,12 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
156157

157158
WARN(pi_desc->sn, "PI descriptor SN field set before blocking");
158159

160+
old.control = READ_ONCE(pi_desc->control);
159161
do {
160-
old.control = new.control = READ_ONCE(pi_desc->control);
161-
162162
/* set 'NV' to 'wakeup vector' */
163+
new.control = old.control;
163164
new.nv = POSTED_INTR_WAKEUP_VECTOR;
164-
} while (pi_try_set_control(pi_desc, old.control, new.control));
165+
} while (pi_try_set_control(pi_desc, &old.control, new.control));
165166

166167
/*
167168
* Send a wakeup IPI to this CPU if an interrupt may have been posted

0 commit comments

Comments
 (0)