From patchwork Fri Apr 29 20:11:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12832700 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 872FCC433FE for ; Fri, 29 Apr 2022 20:11:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5D976B0075; Fri, 29 Apr 2022 16:11:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96FD46B007B; Fri, 29 Apr 2022 16:11:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E8686B007D; Fri, 29 Apr 2022 16:11:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 6FB8E6B0075 for ; Fri, 29 Apr 2022 16:11:52 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 558FA605CE for ; Fri, 29 Apr 2022 20:11:52 +0000 (UTC) X-FDA: 79411012464.09.768EA62 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf25.hostedemail.com (Postfix) with ESMTP id 62C3EA007A for ; Fri, 29 Apr 2022 20:11:42 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id c9-20020a17090a108900b001d5793b605aso4412028pja.4 for ; Fri, 29 Apr 2022 13:11:51 -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=S3BBsZ5bvk4uzoCkIECYzRGc2TYJKfjLopd3GTSDAKA=; b=jyU87f8rJUN/0hbg4f3kdULDqmUiyc07Xb66s8cBmC8eSW5afxPVORIXgO/XcbFugu /GO6FtfJ4ZPnIibnkDPCd2vWdazZzlWxhMF1+MfgeVHE4EB8soDI4WiD7pxUHc0XysjZ dz0NPsguoIx0yCM0GzW+6AJFD3eMtBn5IljqCyl24S9cni2H7/qF97uyykmSQ8zzR3qj 0ctQn1mlUvVg2EZJl93vg7f3fTcTbPn8ws29rj4RPyM04s2wTJC2/9P5OL5vwTLWBxg5 QDDNee7lmxpZqa2y/Fn8/pPEocI38Oecy4dHL012AY61PD0PXJ/gQDtUls02A2N8uheX E/zA== 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=S3BBsZ5bvk4uzoCkIECYzRGc2TYJKfjLopd3GTSDAKA=; b=BMw6SCugs4mCdHOLHw4gpjX1m4N+Zy3BGMc29qeEbQVSgW71xYHSQVwZD+Qt4YXDiH hAfiK+EhX2NKsYZvzTI71MxWD4ih3vZH/cLRnJkb64XlM/LmcTtu4ciwgtjNq4D0HCUT cLyfttUQo59c1Nq83H88bwA2RlZkPuyIcJL6VeHtFmrfPTTUxJ4rX/MYf246erPFEQcR iyPg1hgBn5b8kVJbKG4ndK85Hr+ruwV2whNbvpy/DiAklsRkdQ4WtrwPntxfvPI7bl96 1GO+f5n9kUMmTWSTsR/D81W4jej/qF/PyhPxf3FbNX8jl99dH2PZJd3JyuPMYMVB78Kk HwRA== X-Gm-Message-State: AOAM530mSkasuO32TtdZsoimjBPvcde3IL1+1SdIaWD53VxbDESX3ahk W9hSB+GQ2R6XIMPpWU7kxxN38EX29DGuNMDP X-Google-Smtp-Source: ABdhPJxOmVuJGvLk2Hjh+EQ9JUFzd7qmz4ZeddVRcuaWheP9plljXX7Xz37I8NLuX36SAI5J9foHUODTgkzaf7D4 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:1411:b0:4fd:e594:fac0 with SMTP id l17-20020a056a00141100b004fde594fac0mr831484pfu.79.1651263110818; Fri, 29 Apr 2022 13:11:50 -0700 (PDT) Date: Fri, 29 Apr 2022 20:11:31 +0000 In-Reply-To: <20220429201131.3397875-1-yosryahmed@google.com> Message-Id: <20220429201131.3397875-5-yosryahmed@google.com> Mime-Version: 1.0 References: <20220429201131.3397875-1-yosryahmed@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v4 4/4] KVM: arm64/mmu: count KVM s2 mmu usage in secondary pagetable stats From: Yosry Ahmed To: Tejun Heo , Johannes Weiner , Zefan Li , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspamd-Queue-Id: 62C3EA007A X-Stat-Signature: gdqbh4ccb53dwajdiy1ofr1b5ph4ds8d Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=jyU87f8r; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3hkZsYgoKCN0XNRQX9GLDCFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--yosryahmed.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3hkZsYgoKCN0XNRQX9GLDCFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--yosryahmed.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1651263102-621243 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Count the pages used by KVM in arm64 for stage2 mmu in secondary pagetable stats. Signed-off-by: Yosry Ahmed --- arch/arm64/kvm/mmu.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 53ae2c0640bc..fc5030307cce 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -92,9 +92,13 @@ static bool kvm_is_device_pfn(unsigned long pfn) static void *stage2_memcache_zalloc_page(void *arg) { struct kvm_mmu_memory_cache *mc = arg; + void *virt; /* Allocated with __GFP_ZERO, so no need to zero */ - return kvm_mmu_memory_cache_alloc(mc); + virt = kvm_mmu_memory_cache_alloc(mc); + if (virt) + kvm_account_pgtable_pages(virt, +1); + return virt; } static void *kvm_host_zalloc_pages_exact(size_t size) @@ -102,6 +106,20 @@ static void *kvm_host_zalloc_pages_exact(size_t size) return alloc_pages_exact(size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); } +static void *kvm_s2_zalloc_pages_exact(size_t size) +{ + void *virt = kvm_host_zalloc_pages_exact(size); + if (virt) + kvm_account_pgtable_pages(virt, +(size >> PAGE_SHIFT)); + return virt; +} + +static void kvm_s2_free_pages_exact(void *virt, size_t size) +{ + kvm_account_pgtable_pages(virt, -(size >> PAGE_SHIFT)); + free_pages_exact(virt, size); +} + static void kvm_host_get_page(void *addr) { get_page(virt_to_page(addr)); @@ -112,6 +130,15 @@ static void kvm_host_put_page(void *addr) put_page(virt_to_page(addr)); } +static void kvm_s2_put_page(void *addr) +{ + struct page *p = virt_to_page(addr); + /* Dropping last refcount, the page will be freed */ + if (page_count(p) == 1) + kvm_account_pgtable_pages(addr, -1); + put_page(p); +} + static int kvm_host_page_count(void *addr) { return page_count(virt_to_page(addr)); @@ -603,10 +630,10 @@ static int get_user_mapping_size(struct kvm *kvm, u64 addr) static struct kvm_pgtable_mm_ops kvm_s2_mm_ops = { .zalloc_page = stage2_memcache_zalloc_page, - .zalloc_pages_exact = kvm_host_zalloc_pages_exact, - .free_pages_exact = free_pages_exact, + .zalloc_pages_exact = kvm_s2_zalloc_pages_exact, + .free_pages_exact = kvm_s2_free_pages_exact, .get_page = kvm_host_get_page, - .put_page = kvm_host_put_page, + .put_page = kvm_s2_put_page, .page_count = kvm_host_page_count, .phys_to_virt = kvm_host_va, .virt_to_phys = kvm_host_pa,