]> git.hungrycats.org Git - linux/commitdiff
KVM: x86: Ensure a full memory barrier is emitted in the VM-Exit path
authorYan Zhao <yan.y.zhao@intel.com>
Sat, 9 Mar 2024 01:09:28 +0000 (17:09 -0800)
committerSean Christopherson <seanjc@google.com>
Fri, 7 Jun 2024 14:18:02 +0000 (07:18 -0700)
Ensure a full memory barrier is emitted in the VM-Exit path, as a full
barrier is required on Intel CPUs to evict WC buffers.  This will allow
unconditionally honoring guest PAT on Intel CPUs that support self-snoop.

As srcu_read_lock() is always called in the VM-Exit path and it internally
has a smp_mb(), call smp_mb__after_srcu_read_lock() to avoid adding a
second fence and make sure smp_mb() is called without dependency on
implementation details of srcu_read_lock().

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
[sean: massage changelog]
Tested-by: Xiangfei Ma <xiangfeix.ma@intel.com>
Tested-by: Yongwei Ma <yongwei.ma@intel.com>
Link: https://lore.kernel.org/r/20240309010929.1403984-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/x86.c

index 869cfaa980bdeca45d04df4f6402a8e3992418b8..121907049190f72e8ea183362b3a72c6ad066518 100644 (file)
@@ -11135,6 +11135,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 
        kvm_vcpu_srcu_read_lock(vcpu);
 
+       /*
+        * Call this to ensure WC buffers in guest are evicted after each VM
+        * Exit, so that the evicted WC writes can be snooped across all cpus
+        */
+       smp_mb__after_srcu_read_lock();
+
        /*
         * Profile KVM exit RIPs:
         */