From: James Houghton <jthoughton@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>
Cc: Vipin Sharma <vipinsh@google.com>,
David Matlack <dmatlack@google.com>,
James Houghton <jthoughton@google.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v5 4/7] KVM: x86/mmu: Only grab RCU lock for nx hugepage recovery for TDP MMU
Date: Mon, 7 Jul 2025 22:47:17 +0000 [thread overview]
Message-ID: <20250707224720.4016504-5-jthoughton@google.com> (raw)
In-Reply-To: <20250707224720.4016504-1-jthoughton@google.com>
Now that we have separate paths for the TDP MMU, it is trivial to only
grab rcu_read_lock() for the TDP MMU case. We do not need to grab it
for the shadow MMU, as pages are not RCU-freed in that case.
Signed-off-by: James Houghton <jthoughton@google.com>
---
arch/x86/kvm/mmu/mmu.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 7df1b4ead705b..c8f7dd747d524 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -7577,17 +7577,18 @@ static void kvm_recover_nx_huge_pages(struct kvm *kvm,
nx_huge_pages = &kvm->arch.possible_nx_huge_pages[mmu_type].pages;
rcu_idx = srcu_read_lock(&kvm->srcu);
- if (is_tdp_mmu)
+ if (is_tdp_mmu) {
read_lock(&kvm->mmu_lock);
- else
+ /*
+ * Zapping TDP MMU shadow pages, including the remote TLB flush,
+ * must be done under RCU protection, because the pages are
+ * freed via RCU callback.
+ */
+ rcu_read_lock();
+ } else {
write_lock(&kvm->mmu_lock);
+ }
- /*
- * Zapping TDP MMU shadow pages, including the remote TLB flush, must
- * be done under RCU protection, because the pages are freed via RCU
- * callback.
- */
- rcu_read_lock();
for ( ; to_zap; --to_zap) {
#ifdef CONFIG_X86_64
@@ -7641,25 +7642,27 @@ static void kvm_recover_nx_huge_pages(struct kvm *kvm,
if (need_resched() || rwlock_needbreak(&kvm->mmu_lock)) {
kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush);
- rcu_read_unlock();
- if (is_tdp_mmu)
+ if (is_tdp_mmu) {
+ rcu_read_unlock();
cond_resched_rwlock_read(&kvm->mmu_lock);
- else
+ rcu_read_lock();
+ } else {
cond_resched_rwlock_write(&kvm->mmu_lock);
+ }
flush = false;
- rcu_read_lock();
}
}
kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush);
- rcu_read_unlock();
- if (is_tdp_mmu)
+ if (is_tdp_mmu) {
+ rcu_read_unlock();
read_unlock(&kvm->mmu_lock);
- else
+ } else {
write_unlock(&kvm->mmu_lock);
+ }
srcu_read_unlock(&kvm->srcu, rcu_idx);
}
--
2.50.0.727.gbf7dc18ff4-goog
next prev parent reply other threads:[~2025-07-07 22:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 22:47 [PATCH v5 0/7] KVM: x86/mmu: Run TDP MMU NX huge page recovery under MMU read lock James Houghton
2025-07-07 22:47 ` [PATCH v5 1/7] KVM: x86/mmu: Track TDP MMU NX huge pages separately James Houghton
2025-08-19 17:57 ` Sean Christopherson
2025-07-07 22:47 ` [PATCH v5 2/7] KVM: x86/mmu: Rename kvm_tdp_mmu_zap_sp() to better indicate its purpose James Houghton
2025-07-07 22:47 ` [PATCH v5 3/7] KVM: x86/mmu: Recover TDP MMU NX huge pages using MMU read lock James Houghton
2025-07-23 20:34 ` Sean Christopherson
2025-07-28 18:07 ` James Houghton
2025-07-28 18:17 ` David Matlack
2025-07-28 21:38 ` Sean Christopherson
2025-07-28 21:48 ` James Houghton
2025-08-01 18:17 ` David Matlack
2025-08-01 22:00 ` Sean Christopherson
2025-08-12 19:21 ` David Matlack
2025-07-07 22:47 ` James Houghton [this message]
2025-07-23 20:38 ` [PATCH v5 4/7] KVM: x86/mmu: Only grab RCU lock for nx hugepage recovery for TDP MMU Sean Christopherson
2025-07-28 17:51 ` James Houghton
2025-07-07 22:47 ` [PATCH v5 5/7] KVM: selftests: Introduce a selftest to measure execution performance James Houghton
2025-07-23 20:50 ` Sean Christopherson
2025-07-29 0:18 ` James Houghton
2025-07-07 22:47 ` [PATCH v5 6/7] KVM: selftests: Provide extra mmap flags in vm_mem_add() James Houghton
2025-07-07 22:47 ` [PATCH v5 7/7] KVM: selftests: Add an NX huge pages jitter test James Houghton
2025-07-23 21:04 ` Sean Christopherson
2025-07-28 18:40 ` James Houghton
2025-08-01 14:11 ` Sean Christopherson
2025-08-01 18:45 ` James Houghton
2025-08-01 22:30 ` Sean Christopherson
2025-07-23 20:44 ` [PATCH v5 0/7] KVM: x86/mmu: Run TDP MMU NX huge page recovery under MMU read lock Sean Christopherson
2025-07-29 0:19 ` James Houghton
2025-08-19 23:12 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250707224720.4016504-5-jthoughton@google.com \
--to=jthoughton@google.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vipinsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®