From patchwork Mon Apr 4 23:41:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12800947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5D1EC433F5 for ; Mon, 4 Apr 2022 23:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbiDDXoz (ORCPT ); Mon, 4 Apr 2022 19:44:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbiDDXoy (ORCPT ); Mon, 4 Apr 2022 19:44:54 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 822E96A017 for ; Mon, 4 Apr 2022 16:42:50 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id d11-20020a17090a628b00b001ca8fc92b9eso2847668pjj.9 for ; Mon, 04 Apr 2022 16:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=K/C6C11bbKyaV99qw+OE+b8BddCrOUCezOjrhVsGtWE=; b=SJM89U7DX9auP5Efty5wonK9wAYJnkGwZ+yCUpzXGngk3AdkiPP/FlEeacVDxTcHzy HsBIy2xxwycYfRyIDstlwTVfWpbRJYYCwpohusdMYR6XvAw6QGZ7vLmaKM17K0i2hSog eBvgtw8dbSKzt8aCE+rdgLw8bBikRyPjPsyk/ObkMrCuLv7sJe9h0edppM+6naMxpp2Y NMpQ7n+Hw52XoL7s5gqA3PVjP9/EfodgNtCX/RvYg4nAWYrw3gDyUyRNHsnnJt3XidSC FlkEpXeWnfMVWX3IPZai5/ju+N7azTeX28p0knQDKXyRx0s4srdab1zZOf6j+YU0KEqV THPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=K/C6C11bbKyaV99qw+OE+b8BddCrOUCezOjrhVsGtWE=; b=scJ46LpoyJg7pFVqGe0Xt2dd8Z5sIYUSyI7hZkdwP4LEfvGXWoiYUdk0EmZMkPWIi0 dFcFytOgIQADHQDxtJfOW+/Mfn6poH/fYFgD1Lh6SNFnA8eWf4IZipX7AntpoDdYlRMx Q4xLtqgF2rrWIBSNXCnAi2RjAxdk7wjLtP3Y3I5tWPJVRbyXFy9sASmvqxw5+j8l04D9 SAMgFUWQnsAxuNa/xS7hTEIbWwEObLU2E6hNQtkmRZ5F2IpiRsbF0S7F4ZRev1gYTWaV gQwBcwLd1BO1bCYgDbfT0daRRTSlBdSid2tKUGiRo+3zvhoce0PKjclwyzrh6xfuGz9O kVwA== X-Gm-Message-State: AOAM531Y+sGses8rIh8tTEUYHiIcD4JXJunrUv+Kt/wjf0P334sHbQF3 FPoHpsjwB1UmjT2M0oPfPEjH9xOKAzwF9b+S X-Google-Smtp-Source: ABdhPJzORRgTHWZDqgAJmEQ9S4nEbpi3R6OCs7d6aUuWSbmaM3HnKYNNIS5dFfWTXWVVd/6JvKSw7F30c/15SR2s X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:db48:b0:1ca:ab67:d75 with SMTP id u8-20020a17090adb4800b001caab670d75mr74003pjx.1.1649115732725; Mon, 04 Apr 2022 16:42:12 -0700 (PDT) Date: Mon, 4 Apr 2022 23:41:54 +0000 In-Reply-To: <20220404234154.1251388-1-yosryahmed@google.com> Message-Id: <20220404234154.1251388-6-yosryahmed@google.com> Mime-Version: 1.0 References: <20220404234154.1251388-1-yosryahmed@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH v2 5/5] KVM: mips: mm: count KVM page table pages in pagetable stats From: Yosry Ahmed To: Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: mizhang@google.com, David Matlack , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt , Andrew Morton , Yosry Ahmed Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Count the pages used by KVM in mips for page tables in pagetable stats. Signed-off-by: Yosry Ahmed --- 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;