From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oliver Upton Subject: Re: [PATCH v5 4/4] KVM: arm64/mmu: count KVM s2 mmu usage in secondary pagetable stats Date: Tue, 28 Jun 2022 18:53:55 +0000 Message-ID: References: <20220606222058.86688-1-yosryahmed@google.com> <20220606222058.86688-5-yosryahmed@google.com> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656442441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=htPFhHOsa3d7/VGnFqnbz5VFkkx8xDdtzMvjjntEVQQ=; b=d6djTxUwEkHGAYEqJ+FSn4G/FZeJSZoQaoOZxxQhJaqcI2qvYIgXT+trdlZ0GWC661TwyO 1oiSHS8oHUyMAMhElHKJhcjJFylgZXvccpHWWmhbSO2Tv35HgJpLHoM6RfUaZ/baIXg/yK KB8JzslXVDM8K4q77AikRR+g7gpG87A= Content-Disposition: inline In-Reply-To: <20220606222058.86688-5-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Yosry Ahmed Cc: 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 , kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org Hi Yosry, On Mon, Jun 06, 2022 at 10:20:58PM +0000, Yosry Ahmed wrote: > Count the pages used by KVM in arm64 for stage2 mmu in secondary pagetable > stats. You could probably benefit from being a bit more verbose in the commit message here as well, per Sean's feedback. > Signed-off-by: Yosry Ahmed > --- > arch/arm64/kvm/mmu.c | 36 ++++++++++++++++++++++++++++++++---- > 1 file changed, 32 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index f5651a05b6a85..80bc92601fd96 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,21 @@ 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 +131,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); Probably more of a note to myself with the parallel fault series, but this is a race waiting to happen. This only works because stage 2 pages are dropped behind the write lock. Besides the commit message nit: Reviewed-by: Oliver Upton 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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB24AC433EF for ; Tue, 28 Jun 2022 18:54:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 2704F4B458; Tue, 28 Jun 2022 14:54:06 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@linux.dev Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2RcTiMpWfKTg; Tue, 28 Jun 2022 14:54:04 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BBE5C4B439; Tue, 28 Jun 2022 14:54:04 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 613D34B413 for ; Tue, 28 Jun 2022 14:54:04 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G6w6l6YKwOVj for ; Tue, 28 Jun 2022 14:54:03 -0400 (EDT) Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 1FFA54B402 for ; Tue, 28 Jun 2022 14:54:03 -0400 (EDT) Date: Tue, 28 Jun 2022 18:53:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656442441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=htPFhHOsa3d7/VGnFqnbz5VFkkx8xDdtzMvjjntEVQQ=; b=d6djTxUwEkHGAYEqJ+FSn4G/FZeJSZoQaoOZxxQhJaqcI2qvYIgXT+trdlZ0GWC661TwyO 1oiSHS8oHUyMAMhElHKJhcjJFylgZXvccpHWWmhbSO2Tv35HgJpLHoM6RfUaZ/baIXg/yK KB8JzslXVDM8K4q77AikRR+g7gpG87A= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Yosry Ahmed Subject: Re: [PATCH v5 4/4] KVM: arm64/mmu: count KVM s2 mmu usage in secondary pagetable stats Message-ID: References: <20220606222058.86688-1-yosryahmed@google.com> <20220606222058.86688-5-yosryahmed@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220606222058.86688-5-yosryahmed@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Cc: Wanpeng Li , kvm@vger.kernel.org, Roman Gushchin , Michal Hocko , linux-mm@kvack.org, Zefan Li , kvmarm@lists.cs.columbia.edu, Marc Zyngier , Joerg Roedel , Shakeel Butt , cgroups@vger.kernel.org, Andrew Morton , linux-arm-kernel@lists.infradead.org, Jim Mattson , linux-kernel@vger.kernel.org, Johannes Weiner , Tejun Heo , Paolo Bonzini , Vitaly Kuznetsov X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Hi Yosry, On Mon, Jun 06, 2022 at 10:20:58PM +0000, Yosry Ahmed wrote: > Count the pages used by KVM in arm64 for stage2 mmu in secondary pagetable > stats. You could probably benefit from being a bit more verbose in the commit message here as well, per Sean's feedback. > Signed-off-by: Yosry Ahmed > --- > arch/arm64/kvm/mmu.c | 36 ++++++++++++++++++++++++++++++++---- > 1 file changed, 32 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index f5651a05b6a85..80bc92601fd96 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,21 @@ 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 +131,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); Probably more of a note to myself with the parallel fault series, but this is a race waiting to happen. This only works because stage 2 pages are dropped behind the write lock. Besides the commit message nit: Reviewed-by: Oliver Upton _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 959B7C433EF for ; Tue, 28 Jun 2022 18:55:21 +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=ZYjaf/PebNZSnJVx1Mi99uDdl3/RtxpR5adi3W2pUbg=; b=4WIL+jyG/SX+8E EwWa6q8nzk9pQih7PP4sORniOpmLf9LYy1X2osUbPdHNoYe285Ha2nIILis6+9/M75aIcMapAi0GA JXA70yKv+UizvOu8aULUnjn+DGuVnCjlOMCJuQoC4Uh6wwR7L9M/c31k2BsAxmgY+is6aWgucH7lU DDE0q0wCp0PUrjJEspHenf2uLZ1Vi6g3GyxOZEEQGXVHFSLWqBkY2iH+0LW4HQ3Yks1jXsMkbJnQM vss98Tj1e5UB5JcxcYsWek30K8U/VkPPS1W+1ArzHHjlRCkqF4w2yWBt8TGvzPjIQbogplOa2Q2YB 6Ngm1m/QUArVkUBBmRLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6GLo-007gzD-4V; Tue, 28 Jun 2022 18:54:16 +0000 Received: from out2.migadu.com ([188.165.223.204]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6GLk-007gvh-FU for linux-arm-kernel@lists.infradead.org; Tue, 28 Jun 2022 18:54:14 +0000 Date: Tue, 28 Jun 2022 18:53:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656442441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=htPFhHOsa3d7/VGnFqnbz5VFkkx8xDdtzMvjjntEVQQ=; b=d6djTxUwEkHGAYEqJ+FSn4G/FZeJSZoQaoOZxxQhJaqcI2qvYIgXT+trdlZ0GWC661TwyO 1oiSHS8oHUyMAMhElHKJhcjJFylgZXvccpHWWmhbSO2Tv35HgJpLHoM6RfUaZ/baIXg/yK KB8JzslXVDM8K4q77AikRR+g7gpG87A= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Yosry Ahmed Cc: 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 , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v5 4/4] KVM: arm64/mmu: count KVM s2 mmu usage in secondary pagetable stats Message-ID: References: <20220606222058.86688-1-yosryahmed@google.com> <20220606222058.86688-5-yosryahmed@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220606222058.86688-5-yosryahmed@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220628_115412_852091_1F68E6C7 X-CRM114-Status: GOOD ( 20.40 ) 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 Mon, Jun 06, 2022 at 10:20:58PM +0000, Yosry Ahmed wrote: > Count the pages used by KVM in arm64 for stage2 mmu in secondary pagetable > stats. You could probably benefit from being a bit more verbose in the commit message here as well, per Sean's feedback. > Signed-off-by: Yosry Ahmed > --- > arch/arm64/kvm/mmu.c | 36 ++++++++++++++++++++++++++++++++---- > 1 file changed, 32 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index f5651a05b6a85..80bc92601fd96 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,21 @@ 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 +131,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); Probably more of a note to myself with the parallel fault series, but this is a race waiting to happen. This only works because stage 2 pages are dropped behind the write lock. Besides the commit message nit: Reviewed-by: Oliver Upton _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 115EFCCA47E for ; Tue, 28 Jun 2022 18:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232389AbiF1SyG (ORCPT ); Tue, 28 Jun 2022 14:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbiF1SyF (ORCPT ); Tue, 28 Jun 2022 14:54:05 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A81A22BD3; Tue, 28 Jun 2022 11:54:03 -0700 (PDT) Date: Tue, 28 Jun 2022 18:53:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656442441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=htPFhHOsa3d7/VGnFqnbz5VFkkx8xDdtzMvjjntEVQQ=; b=d6djTxUwEkHGAYEqJ+FSn4G/FZeJSZoQaoOZxxQhJaqcI2qvYIgXT+trdlZ0GWC661TwyO 1oiSHS8oHUyMAMhElHKJhcjJFylgZXvccpHWWmhbSO2Tv35HgJpLHoM6RfUaZ/baIXg/yK KB8JzslXVDM8K4q77AikRR+g7gpG87A= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Yosry Ahmed Cc: 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 , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v5 4/4] KVM: arm64/mmu: count KVM s2 mmu usage in secondary pagetable stats Message-ID: References: <20220606222058.86688-1-yosryahmed@google.com> <20220606222058.86688-5-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220606222058.86688-5-yosryahmed@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Yosry, On Mon, Jun 06, 2022 at 10:20:58PM +0000, Yosry Ahmed wrote: > Count the pages used by KVM in arm64 for stage2 mmu in secondary pagetable > stats. You could probably benefit from being a bit more verbose in the commit message here as well, per Sean's feedback. > Signed-off-by: Yosry Ahmed > --- > arch/arm64/kvm/mmu.c | 36 ++++++++++++++++++++++++++++++++---- > 1 file changed, 32 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index f5651a05b6a85..80bc92601fd96 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,21 @@ 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 +131,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); Probably more of a note to myself with the parallel fault series, but this is a race waiting to happen. This only works because stage 2 pages are dropped behind the write lock. Besides the commit message nit: Reviewed-by: Oliver Upton