From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14F25C433F5 for ; Tue, 26 Apr 2022 07:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=H7DTiIlUVFX5mPjLZjzJ009doyyQfoIYjFoFGqqoHfY=; b=nS/Pc8Rgm3MspF 0l68uBO21l5PnhHXypZXWzpdbXkLuL3RC8YnWseUnJor+TYATbWJDcOq6LIYMNwVszeZvsGt6uxXe 25OCIP1zO7tfR1cl1lL26wAmLcyHKE29uxvlpzTU1f77mVNsbkZZq4+JmiAXFy1NqtZbVsRSz22CP xIFurWywZ/qr16bkn2WUpxewqwjMpbyKOzYOQPnhix/gWYS21WXMfSvH4p4WFuhkr12QTtzlwMo9B KV6GRdaLVK1jVpmLfKJg8bn3R1OcyhkBrc84I8aRIfyFoa2azcI1jocFogpkhTnhTFPsz9S35aN+9 gFvo5jkapMvKlox39wDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1njFj0-00CzaQ-Ug; Tue, 26 Apr 2022 07:35:07 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1njFix-00CzX6-E2 for linux-arm-kernel@lists.infradead.org; Tue, 26 Apr 2022 07:35:04 +0000 Received: by mail-il1-x12f.google.com with SMTP id k12so10881476ilv.3 for ; Tue, 26 Apr 2022 00:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=T6uVKqz/bxBh0XcbvcuRA0UyoUPF9VXe65F1cQD8y4Q=; b=ObEunFSl4crRLGfpGD9vb4uNjucdcW+SwMC5wjs68ErQM98eX2dd/1bhFqvb4MQrUZ aNBQiYOEZs6DAFrjwy4GxIX9P710BE5dNtb9ren8SoNbyoDCq1JSrqMW6bcxyN3g457u /+gBpA8szyFlMBKjZqPcqtIcg53tpCAgbfmBRZ+EQiSDL0bYkiLUkJAuAA+ESILGYbW5 jVcb61+A+66M7v7MKaJKTdQY27E/r9amtlm20dB0rHCxpqld0qjq5eRsqvCmPNleg1uA MTGwgfxKApBNNdQAeaBp8qoeybFa8FJ6gos+fYTUTeB4wg78apx7w8FkSb2oMxvxLXSe mDTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=T6uVKqz/bxBh0XcbvcuRA0UyoUPF9VXe65F1cQD8y4Q=; b=2AymktqLJH/4pNX8cql0WGkQanb4OC1c55/18KDGqf3+xorpJHnDDf0okyMrvPySlv sU/KxzTjvf0PPKOFBjDXrKXJUdho8txNv9CizmomCyk2G5JLv2T73XDFUjtO+iWI8e6E +JMmVUNnDrQz1cybBUsuO8CEG06o1IM8cToEVzeSC93fGW5HXJNZvwDqONqd2kDVKVku 0wMMmjHjRhoryg05rtgsgGWEylMHV0K8wkvr+R77JRkS7V+YbjRoE+hE82JHR7er/iF8 igFHfDh6srVlAEbE8VFutz0yhVzNlhtGcoMs18+k4egdo48nFRRaIU8SKLpEIJDk9SIN +0lA== X-Gm-Message-State: AOAM533eGJZvfIZLkbvgnUs2B2vXKNGVZko/HUybu9z/E6Qlb6ISGogx XdWFMDiyOr00y1LB+I+TsSvOQA== X-Google-Smtp-Source: ABdhPJzzgIPYx4mfeq03H4D4LkohxnIEdiAlT4JnSJ/rUPy7BWzzJro8BOalbut4cMQo3UF9wiXwfw== X-Received: by 2002:a05:6e02:b23:b0:2cd:89db:f685 with SMTP id e3-20020a056e020b2300b002cd89dbf685mr5194103ilu.296.1650958500701; Tue, 26 Apr 2022 00:35:00 -0700 (PDT) Received: from google.com (194.225.68.34.bc.googleusercontent.com. [34.68.225.194]) by smtp.gmail.com with ESMTPSA id w5-20020a05660205c500b006546d0b5f6dsm9257784iox.41.2022.04.26.00.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 00:34:59 -0700 (PDT) Date: Tue, 26 Apr 2022 07:34:56 +0000 From: Oliver Upton To: Yosry Ahmed Cc: Sean Christopherson , Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , James Morse , Catalin Marinas , Shameer Kolothum , Marc Zyngier , Alexandru Elisei , Suzuki K Poulose , linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v3 4/6] KVM: arm64/mmu: count KVM page table pages in pagetable stats Message-ID: References: <20220426053904.3684293-1-yosryahmed@google.com> <20220426053904.3684293-5-yosryahmed@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220426053904.3684293-5-yosryahmed@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220426_003503_496787_A4C15CAB X-CRM114-Status: GOOD ( 22.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Yosry, On Tue, Apr 26, 2022 at 05:39:02AM +0000, Yosry Ahmed wrote: > Count the pages used by KVM in arm64 for page tables in pagetable stats. > > Account pages allocated for PTEs in pgtable init functions and > kvm_set_table_pte(). > > Since most page table pages are freed using put_page(), add a helper > function put_pte_page() that checks if this is the last ref for a pte > page before putting it, and unaccounts stats accordingly. > > Signed-off-by: Yosry Ahmed > --- > arch/arm64/kernel/image-vars.h | 3 ++ > arch/arm64/kvm/hyp/pgtable.c | 50 +++++++++++++++++++++------------- > 2 files changed, 34 insertions(+), 19 deletions(-) > > diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h > index 241c86b67d01..25bf058714f6 100644 > --- a/arch/arm64/kernel/image-vars.h > +++ b/arch/arm64/kernel/image-vars.h > @@ -143,6 +143,9 @@ KVM_NVHE_ALIAS(__hyp_rodata_end); > /* pKVM static key */ > KVM_NVHE_ALIAS(kvm_protected_mode_initialized); > > +/* Called by kvm_account_pgtable_pages() to update pagetable stats */ > +KVM_NVHE_ALIAS(__mod_lruvec_page_state); > + > #endif /* CONFIG_KVM */ > > #endif /* __ARM64_KERNEL_IMAGE_VARS_H */ > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 2cb3867eb7c2..53e13c3313e9 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -152,6 +152,7 @@ static void kvm_set_table_pte(kvm_pte_t *ptep, kvm_pte_t *childp, > > WARN_ON(kvm_pte_valid(old)); > smp_store_release(ptep, pte); > + kvm_account_pgtable_pages((void *)childp, +1); What page tables do we want to account? KVM on ARM manages several page tables. For regular KVM, the host kernel manages allocations for the hyp stage 1 tables in addition to the stage 2 tables used for a particular VM. The former is system overhead whereas the latter could be attributed to a guest VM. I imagine protected KVM is out of scope, since it actually manages its own allocations outside of the host kernel. Given this, I would recommend adding the accounting hooks to mmu.c as that is where we alloc/free table pages and it is in the host address space. kvm_s2_mm_ops and kvm_hyp_mm_ops point to all the relevant functions, though the latter is only relevant if we want to count system page tables too. -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel