public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/mmu: Remove KVM MMU write lock when accessing indirect_shadow_pages
@ 2023-06-05  0:43 Mingwei Zhang
  2023-06-05 16:55 ` Jim Mattson
  0 siblings, 1 reply; 17+ messages in thread
From: Mingwei Zhang @ 2023-06-05  0:43 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: H. Peter Anvin, kvm, linux-kernel, Jim Mattson, Mingwei Zhang,
	Ben Gardon

Remove KVM MMU write lock when accessing indirect_shadow_pages counter when
page role is direct because this counter value is used as a coarse-grained
heuristics to check if there is nested guest active. Racing with this
heuristics without mmu lock will be harmless because the corresponding
indirect shadow sptes for the GPA will either be zapped by this thread or
some other thread who has previously zapped all indirect shadow pages and
makes the value to 0.

Because of that, remove the KVM MMU write lock pair to potentially reduce
the lock contension and improve the performance of nested VM. In addition
opportunistically change the comment of 'direct mmu' to make the
description consistent with other places.

Reported-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Mingwei Zhang <mizhang@google.com>
---
 arch/x86/kvm/x86.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5ad55ef71433..97cfa5a00ff2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8585,15 +8585,9 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
 
 	kvm_release_pfn_clean(pfn);
 
-	/* The instructions are well-emulated on direct mmu. */
+	/* The instructions are well-emulated on Direct MMUs. */
 	if (vcpu->arch.mmu->root_role.direct) {
-		unsigned int indirect_shadow_pages;
-
-		write_lock(&vcpu->kvm->mmu_lock);
-		indirect_shadow_pages = vcpu->kvm->arch.indirect_shadow_pages;
-		write_unlock(&vcpu->kvm->mmu_lock);
-
-		if (indirect_shadow_pages)
+		if (READ_ONCE(vcpu->kvm->arch.indirect_shadow_pages))
 			kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(gpa));
 
 		return true;

base-commit: 31b4fc3bc64aadd660c5bfa5178c86a7ba61e0f7
-- 
2.41.0.rc0.172.g3f132b7071-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-06-26 20:43 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-05  0:43 [PATCH] KVM: x86/mmu: Remove KVM MMU write lock when accessing indirect_shadow_pages Mingwei Zhang
2023-06-05 16:55 ` Jim Mattson
2023-06-05 17:17   ` Ben Gardon
2023-06-05 17:53     ` Mingwei Zhang
2023-06-05 18:27     ` Paolo Bonzini
2023-06-05 17:42   ` Mingwei Zhang
2023-06-05 18:11     ` Jim Mattson
2023-06-05 18:23       ` Mingwei Zhang
2023-06-05 18:25     ` Sean Christopherson
2023-06-06 22:46       ` Mingwei Zhang
2023-06-06 22:48         ` Mingwei Zhang
2023-06-06 23:07         ` Sean Christopherson
2023-06-07  0:23           ` Mingwei Zhang
2023-06-07  0:28             ` Sean Christopherson
2023-06-15 23:57               ` Mingwei Zhang
2023-06-26 17:38                 ` Jim Mattson
2023-06-26 20:42                   ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox