summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorLai Jiangshan <laijs@linux.alibaba.com>2021-05-31 19:46:28 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2021-06-08 19:15:20 +0200
commitaf3511ff7fa2107d6410831f3d71030f5e8d2b25 (patch)
tree2f97e39acd2001b3c473b61754b52cf8af63d553 /arch
parentKVM: X86: MMU: Use the correct inherited permissions to get shadow page (diff)
downloadlinux-af3511ff7fa2107d6410831f3d71030f5e8d2b25.tar.xz
linux-af3511ff7fa2107d6410831f3d71030f5e8d2b25.zip
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 <laijs@linux.alibaba.com> Message-Id: <20210531174628.10265-1-jiangshanlai@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kvm/x86.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1cd6d4685932..e2144eedaf79 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3101,9 +3101,11 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
* expensive IPIs.
*/
if (guest_pv_has(vcpu, KVM_FEATURE_PV_TLB_FLUSH)) {
+ u8 st_preempted = xchg(&st->preempted, 0);
+
trace_kvm_pv_tlb_flush(vcpu->vcpu_id,
- st->preempted & KVM_VCPU_FLUSH_TLB);
- if (xchg(&st->preempted, 0) & KVM_VCPU_FLUSH_TLB)
+ st_preempted & KVM_VCPU_FLUSH_TLB);
+ if (st_preempted & KVM_VCPU_FLUSH_TLB)
kvm_vcpu_flush_tlb_guest(vcpu);
} else {
st->preempted = 0;