[PATCH v2 5/5] KVM: mips: mm: count KVM page table pages in pagetable stats
Yosry Ahmed
yosryahmed at google.com
Mon Apr 4 16:41:54 PDT 2022
Count the pages used by KVM in mips for page tables in pagetable stats.
Signed-off-by: Yosry Ahmed <yosryahmed at google.com>
---
arch/mips/kvm/mips.c | 1 +
arch/mips/kvm/mmu.c | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index a25e0b73ee70..e60c1920a408 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -175,6 +175,7 @@ static void kvm_mips_free_gpa_pt(struct kvm *kvm)
{
/* It should always be safe to remove after flushing the whole range */
WARN_ON(!kvm_mips_flush_gpa_pt(kvm, 0, ~0));
+ kvm_account_pgtable_pages((void *)kvm->arch.gpa_mm.pgd, -1);
pgd_free(NULL, kvm->arch.gpa_mm.pgd);
}
diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c
index 1bfd1b501d82..18da2ac2ded7 100644
--- a/arch/mips/kvm/mmu.c
+++ b/arch/mips/kvm/mmu.c
@@ -81,8 +81,10 @@ pgd_t *kvm_pgd_alloc(void)
pgd_t *ret;
ret = (pgd_t *)__get_free_pages(GFP_KERNEL, PGD_ORDER);
- if (ret)
+ if (ret) {
kvm_pgd_init(ret);
+ kvm_account_pgtable_pages((void *)ret, +1);
+ }
return ret;
}
@@ -125,6 +127,7 @@ static pte_t *kvm_mips_walk_pgd(pgd_t *pgd, struct kvm_mmu_memory_cache *cache,
pmd_init((unsigned long)new_pmd,
(unsigned long)invalid_pte_table);
pud_populate(NULL, pud, new_pmd);
+ kvm_account_pgtable_pages((void *)new_pmd, +1);
}
pmd = pmd_offset(pud, addr);
if (pmd_none(*pmd)) {
@@ -135,6 +138,7 @@ static pte_t *kvm_mips_walk_pgd(pgd_t *pgd, struct kvm_mmu_memory_cache *cache,
new_pte = kvm_mmu_memory_cache_alloc(cache);
clear_page(new_pte);
pmd_populate_kernel(NULL, pmd, new_pte);
+ kvm_account_pgtable_pages((void *)new_pte, +1);
}
return pte_offset_kernel(pmd, addr);
}
@@ -189,6 +193,7 @@ static bool kvm_mips_flush_gpa_pmd(pmd_t *pmd, unsigned long start_gpa,
if (kvm_mips_flush_gpa_pte(pte, start_gpa, end)) {
pmd_clear(pmd + i);
+ kvm_account_pgtable_pages((void *)pte, -1);
pte_free_kernel(NULL, pte);
} else {
safe_to_remove = false;
@@ -217,6 +222,7 @@ static bool kvm_mips_flush_gpa_pud(pud_t *pud, unsigned long start_gpa,
if (kvm_mips_flush_gpa_pmd(pmd, start_gpa, end)) {
pud_clear(pud + i);
+ kvm_account_pgtable_pages((void *)pmd, -1);
pmd_free(NULL, pmd);
} else {
safe_to_remove = false;
@@ -247,6 +253,7 @@ static bool kvm_mips_flush_gpa_pgd(pgd_t *pgd, unsigned long start_gpa,
if (kvm_mips_flush_gpa_pud(pud, start_gpa, end)) {
pgd_clear(pgd + i);
+ kvm_account_pgtable_pages((void *)pud, -1);
pud_free(NULL, pud);
} else {
safe_to_remove = false;
--
2.35.1.1094.g7c7d902a7c-goog
More information about the kvm-riscv
mailing list