From: Yan Zhao <yan.y.zhao@intel.com>
To: pbonzini@redhat.com, seanjc@google.com
Cc: peterx@redhat.com, rick.p.edgecombe@intel.com,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
Yan Zhao <yan.y.zhao@intel.com>
Subject: [PATCH v3 2/3] KVM: Skip invoking shared memory handler for entirely private GFN ranges
Date: Fri, 22 Aug 2025 16:02:34 +0800 [thread overview]
Message-ID: <20250822080235.27274-1-yan.y.zhao@intel.com> (raw)
In-Reply-To: <20250822080100.27218-1-yan.y.zhao@intel.com>
When a GFN range is entirely private, it's unnecessary for
kvm_handle_hva_range() to invoke handlers for the GFN range, because
1) the gfn_range.attr_filter for the handler is KVM_FILTER_SHARED, which
is for shared mappings only;
2) KVM has already zapped all shared mappings before setting the memory
attribute to private.
This can avoid unnecessary zaps on private mappings for VMs of type
KVM_X86_SW_PROTECTED_VM, e.g., during auto numa balancing scans of VMAs.
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
virt/kvm/kvm_main.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index f769d1dccc21..e615ad405ce4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -620,6 +620,17 @@ static __always_inline kvm_mn_ret_t kvm_handle_hva_range(struct kvm *kvm,
gfn_range.slot = slot;
gfn_range.lockless = range->lockless;
+#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES
+ /*
+ * If GFN range are all private, no need to invoke the
+ * handler.
+ */
+ if (kvm_range_has_memory_attributes(kvm, gfn_range.start,
+ gfn_range.end, ~0,
+ KVM_MEMORY_ATTRIBUTE_PRIVATE))
+ continue;
+#endif
+
if (!r.found_memslot) {
r.found_memslot = true;
if (!range->lockless) {
--
2.43.2
next prev parent reply other threads:[~2025-08-22 8:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 8:01 [PATCH v3 0/3] KVM: Do not reset dirty GFNs in a memslot not enabling dirty tracking Yan Zhao
2025-08-22 8:02 ` [PATCH v3 1/3] " Yan Zhao
2025-08-25 20:42 ` Sean Christopherson
2025-08-26 1:22 ` Yan Zhao
2025-08-22 8:02 ` Yan Zhao [this message]
2025-08-25 21:05 ` [PATCH v3 2/3] KVM: Skip invoking shared memory handler for entirely private GFN ranges Sean Christopherson
2025-08-26 6:51 ` Yan Zhao
2025-08-22 8:03 ` [PATCH v3 3/3] KVM: selftests: Test resetting dirty ring in gmem slots in protected VMs Yan Zhao
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=20250822080235.27274-1-yan.y.zhao@intel.com \
--to=yan.y.zhao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@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;
as well as URLs for NNTP newsgroup(s).