Skip to content

Commit af3511f

Browse files
Lai Jiangshanbonzini
authored andcommitted
KVM: x86: Ensure PV TLB flush tracepoint reflects KVM behavior
In record_steal_time(), st->preempted is read twice, and trace_kvm_pv_tlb_flush() might output result inconsistent if kvm_vcpu_flush_tlb_guest() see a different st->preempted later. It is a very trivial problem and hardly has actual harm and can be avoided by reseting and reading st->preempted in atomic way via xchg(). Signed-off-by: Lai Jiangshan <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent b1bd5cb commit af3511f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,9 +3101,11 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
31013101
* expensive IPIs.
31023102
*/
31033103
if (guest_pv_has(vcpu, KVM_FEATURE_PV_TLB_FLUSH)) {
3104+
u8 st_preempted = xchg(&st->preempted, 0);
3105+
31043106
trace_kvm_pv_tlb_flush(vcpu->vcpu_id,
3105-
st->preempted & KVM_VCPU_FLUSH_TLB);
3106-
if (xchg(&st->preempted, 0) & KVM_VCPU_FLUSH_TLB)
3107+
st_preempted & KVM_VCPU_FLUSH_TLB);
3108+
if (st_preempted & KVM_VCPU_FLUSH_TLB)
31073109
kvm_vcpu_flush_tlb_guest(vcpu);
31083110
} else {
31093111
st->preempted = 0;

0 commit comments

Comments
 (0)