From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Yan Zhao <yan.y.zhao@intel.com>
Subject: [PATCH 2/2] KVM: x86/mmu: Register page-tracker on first shadow root allocation
Date: Thu, 10 Nov 2022 01:48:21 +0000 [thread overview]
Message-ID: <20221110014821.1548347-3-seanjc@google.com> (raw)
In-Reply-To: <20221110014821.1548347-1-seanjc@google.com>
Defer registering KVM's shadow page tracker until the first shadow root
allocation now that KVM doesn't rely on the tracker to zap+flush SPTEs
when a memslot is moved or deleted.
Cc: Yan Zhao <yan.y.zhao@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/mmu/mmu.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 0a5ae07a190e..d35a86a60d4f 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3678,11 +3678,14 @@ static int mmu_first_shadow_root_alloc(struct kvm *kvm)
}
}
+out_success:
+ /* Register KVM's page-tracker to react to guest writes to gPTEs. */
+ kvm_page_track_register_notifier(kvm, &kvm->arch.mmu_sp_tracker);
+
/*
* Ensure that shadow_root_allocated becomes true strictly after
* all the related pointers are set.
*/
-out_success:
smp_store_release(&kvm->arch.shadow_root_allocated, true);
out_unlock:
@@ -6001,7 +6004,6 @@ static bool kvm_has_zapped_obsolete_pages(struct kvm *kvm)
int kvm_mmu_init_vm(struct kvm *kvm)
{
- struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
int r;
INIT_LIST_HEAD(&kvm->arch.active_mmu_pages);
@@ -6013,8 +6015,7 @@ int kvm_mmu_init_vm(struct kvm *kvm)
if (r < 0)
return r;
- node->track_write = kvm_mmu_pte_write;
- kvm_page_track_register_notifier(kvm, node);
+ kvm->arch.mmu_sp_tracker.track_write = kvm_mmu_pte_write;
kvm->arch.split_page_header_cache.kmem_cache = mmu_page_header_cache;
kvm->arch.split_page_header_cache.gfp_zero = __GFP_ZERO;
@@ -6036,9 +6037,8 @@ static void mmu_free_vm_memory_caches(struct kvm *kvm)
void kvm_mmu_uninit_vm(struct kvm *kvm)
{
- struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
-
- kvm_page_track_unregister_notifier(kvm, node);
+ if (kvm_shadow_root_allocated(kvm))
+ kvm_page_track_unregister_notifier(kvm, &kvm->arch.mmu_sp_tracker);
kvm_mmu_uninit_tdp_mmu(kvm);
--
2.38.1.431.g37b22c650d-goog
next prev parent reply other threads:[~2022-11-10 1:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 1:48 [PATCH 0/2] KVM: x86/mmu: Use page-track only for... page tracking Sean Christopherson
2022-11-10 1:48 ` [PATCH 1/2] KVM: x86/mmu: Don't rely on page-track mechanism to flush on memslot change Sean Christopherson
2022-11-10 2:27 ` Yan Zhao
2022-11-10 17:08 ` Sean Christopherson
2022-11-11 2:18 ` Yan Zhao
2022-11-10 1:48 ` Sean Christopherson [this message]
2022-11-11 19:24 ` [PATCH 0/2] KVM: x86/mmu: Use page-track only for... page tracking 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=20221110014821.1548347-3-seanjc@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=yan.y.zhao@intel.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®