From: Fred Griffoul <griffoul@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: Mushahid Hussain <hmushi@amazon.co.uk>,
James Houghton <jthoughton@google.com>,
nh-open-source@amazon.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/5] KVM: x86: Count rmaps per level in a debugfs helper
Date: Wed, 4 Nov 2026 00:53:28 +0000 [thread overview]
Message-ID: <20261104005331.50600-3-griffoul@gmail.com> (raw)
In-Reply-To: <20261104005331.50600-1-griffoul@gmail.com>
From: Fred Griffoul <fgriffo@amazon.co.uk>
In preparation for storing memslot rmaps in chunks, move the counting
of one memslot level's rmaps into a helper, so that it can later walk
a level one chunk at a time.
No functional change intended.
Signed-off-by: Fred Griffoul <fgriffo@amazon.co.uk>
---
arch/x86/kvm/debugfs.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index 0074a56e45b4..923424011328 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -86,16 +86,30 @@ void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_
static const char *kvm_lpage_str[KVM_NR_PAGE_SIZES] = { "4K", "2M", "1G" };
+static void kvm_mmu_rmaps_stat_level(struct kvm_memory_slot *slot, int level,
+ unsigned int *cur)
+{
+ struct kvm_rmap_head *rmap = slot->arch.rmap[level - PG_LEVEL_4K];
+ unsigned long lpages = kvm_mmu_slot_lpages(slot, level);
+ unsigned int bucket;
+ unsigned long l;
+
+ for (l = 0; l < lpages; l++) {
+ bucket = fls(pte_list_count(&rmap[l]));
+ if (WARN_ON_ONCE(bucket >= RMAP_LOG_SIZE))
+ bucket = RMAP_LOG_SIZE - 1;
+ cur[bucket]++;
+ }
+}
+
static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v)
{
- struct kvm_rmap_head *rmap;
struct kvm *kvm = m->private;
struct kvm_memory_slot *slot;
struct kvm_memslots *slots;
- unsigned int lpage_size, index;
/* Still small enough to be on the stack */
unsigned int *log[KVM_NR_PAGE_SIZES], *cur;
- int i, j, k, l, ret;
+ int i, j, k, ret;
if (!kvm_memslots_have_rmaps(kvm))
return 0;
@@ -116,17 +130,8 @@ static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v)
slots = __kvm_memslots(kvm, i);
kvm_for_each_memslot(slot, bkt, slots)
- for (k = 0; k < KVM_NR_PAGE_SIZES; k++) {
- rmap = slot->arch.rmap[k];
- lpage_size = kvm_mmu_slot_lpages(slot, k + 1);
- cur = log[k];
- for (l = 0; l < lpage_size; l++) {
- index = fls(pte_list_count(&rmap[l]));
- if (WARN_ON_ONCE(index >= RMAP_LOG_SIZE))
- index = RMAP_LOG_SIZE - 1;
- cur[index]++;
- }
- }
+ for (k = 0; k < KVM_NR_PAGE_SIZES; k++)
+ kvm_mmu_rmaps_stat_level(slot, k + 1, log[k]);
}
write_unlock(&kvm->mmu_lock);
--
2.47.3
next prev parent reply other threads:[~2026-11-04 0:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 0:53 [RFC PATCH 0/5] KVM: x86/mmu: Allocate memslot rmaps on demand Fred Griffoul
2026-11-04 0:53 ` [RFC PATCH 1/5] KVM: x86/mmu: Walk memslot rmaps by index Fred Griffoul
2026-11-04 0:53 ` Fred Griffoul [this message]
2026-11-04 0:53 ` [RFC PATCH 3/5] KVM: x86/mmu: Allocate memslot rmaps in on-demand chunks Fred Griffoul
2026-11-04 0:53 ` [RFC PATCH 4/5] KVM: selftests: Declare __tdp_map() in the x86 processor header Fred Griffoul
2026-11-04 0:53 ` [RFC PATCH 5/5] KVM: selftests: Test dirty logging of sparse nested mappings Fred Griffoul
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=20261104005331.50600-3-griffoul@gmail.com \
--to=griffoul@gmail.com \
--cc=hmushi@amazon.co.uk \
--cc=jthoughton@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nh-open-source@amazon.com \
--cc=pbonzini@redhat.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
all inboxes | Powered by JetHome®