From: Fred Griffoul 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 --- 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