From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: seanjc@google.com, ignat@cloudflare.com, bgardon@google.com,
dmatlack@google.com, stevensd@chromium.org,
kernel-team@cloudflare.com, stable@vger.kernel.org
Subject: [PATCH 1/2] KVM: x86: allow kvm_tdp_mmu_zap_invalidated_roots with write-locked mmu_lock
Date: Mon, 13 Dec 2021 06:25:13 -0500 [thread overview]
Message-ID: <20211213112514.78552-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20211213112514.78552-1-pbonzini@redhat.com>
Zapping within a write-side critical section is more efficient, so it is
desirable if we know that no vCPU is running (such as within the .release
MMU notifier callback). Prepare for reusing kvm_tdp_mmu_zap_invalidated_roots
in such scenarios.
Fixes: b7cccd397f31 ("KVM: x86/mmu: Fast invalidation for TDP MMU")
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/mmu/mmu.c | 2 +-
arch/x86/kvm/mmu/tdp_mmu.c | 17 +++++++++--------
arch/x86/kvm/mmu/tdp_mmu.h | 2 +-
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 4a3bcdd3cfe7..6fe4ab8fc0ca 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -5695,7 +5695,7 @@ static void kvm_mmu_zap_all_fast(struct kvm *kvm)
if (is_tdp_mmu_enabled(kvm)) {
read_lock(&kvm->mmu_lock);
- kvm_tdp_mmu_zap_invalidated_roots(kvm);
+ kvm_tdp_mmu_zap_invalidated_roots(kvm, true);
read_unlock(&kvm->mmu_lock);
}
}
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index 1db8496259ad..f2dd5c97bbc2 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -821,14 +821,18 @@ static struct kvm_mmu_page *next_invalidated_root(struct kvm *kvm,
* only has to do a trivial amount of work. Since the roots are invalid,
* no new SPTEs should be created under them.
*/
-void kvm_tdp_mmu_zap_invalidated_roots(struct kvm *kvm)
+void kvm_tdp_mmu_zap_invalidated_roots(struct kvm *kvm, bool shared)
{
struct kvm_mmu_page *next_root;
struct kvm_mmu_page *root;
bool flush = false;
- lockdep_assert_held_read(&kvm->mmu_lock);
+ kvm_lockdep_assert_mmu_lock_held(kvm, shared);
+ /*
+ * rcu_read_lock is only needed for shared == true, but we
+ * always take it for simplicity.
+ */
rcu_read_lock();
root = next_invalidated_root(kvm, NULL);
@@ -838,13 +842,10 @@ void kvm_tdp_mmu_zap_invalidated_roots(struct kvm *kvm)
rcu_read_unlock();
- flush = zap_gfn_range(kvm, root, 0, -1ull, true, flush, true);
+ flush = zap_gfn_range(kvm, root, 0, -1ull, true, flush, shared);
- /*
- * Put the reference acquired in
- * kvm_tdp_mmu_invalidate_roots
- */
- kvm_tdp_mmu_put_root(kvm, root, true);
+ /* Put the reference acquired in kvm_tdp_mmu_invalidate_roots. */
+ kvm_tdp_mmu_put_root(kvm, root, shared);
root = next_root;
diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
index 3899004a5d91..24809f4ed090 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.h
+++ b/arch/x86/kvm/mmu/tdp_mmu.h
@@ -46,7 +46,7 @@ static inline bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp)
void kvm_tdp_mmu_zap_all(struct kvm *kvm);
void kvm_tdp_mmu_invalidate_all_roots(struct kvm *kvm);
-void kvm_tdp_mmu_zap_invalidated_roots(struct kvm *kvm);
+void kvm_tdp_mmu_zap_invalidated_roots(struct kvm *kvm, bool shared);
int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault);
--
2.31.1
next prev parent reply other threads:[~2021-12-13 11:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-13 11:25 [PATCH 0/2] KVM: x86: Fix dangling page reference in TDP MMU Paolo Bonzini
2021-12-13 11:25 ` Paolo Bonzini [this message]
2021-12-13 11:25 ` [PATCH 2/2] KVM: x86: zap invalid roots in kvm_tdp_mmu_zap_all Paolo Bonzini
2021-12-13 16:36 ` Sean Christopherson
2021-12-14 19:45 ` Sean Christopherson
2021-12-13 13:43 ` [PATCH 0/2] KVM: x86: Fix dangling page reference in TDP MMU Ignat Korchagin
2021-12-13 15:06 ` Paolo Bonzini
2021-12-13 16:47 ` Sean Christopherson
2021-12-13 18:28 ` Paolo Bonzini
2021-12-13 19:44 ` Sean Christopherson
2021-12-13 20:18 ` Ignat Korchagin
2021-12-14 3: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=20211213112514.78552-2-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=bgardon@google.com \
--cc=dmatlack@google.com \
--cc=ignat@cloudflare.com \
--cc=kernel-team@cloudflare.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=stable@vger.kernel.org \
--cc=stevensd@chromium.org \
/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®