Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3559929pxj; Tue, 1 Jun 2021 08:04:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiFE2OmxAaTHt2r4FaQjkb6Ui/UmYosbN8vdtbpgbBZgwofaNlshsrD071Y6aE4OCYMJB8 X-Received: by 2002:a05:6402:1513:: with SMTP id f19mr19013940edw.235.1622559849073; Tue, 01 Jun 2021 08:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622559849; cv=none; d=google.com; s=arc-20160816; b=Yoi0rcALQkJDcgUm1RHZm8bQlFL22iUpTItMZIvpVOZm1IhAfiL7fwqWrJhrA5lkcI Vk8hCPD3mvYVhISX1UrYBNyeGC7Jng40YMomZAkWBg6YZXp37CwX500i/Hza/2YT/x7c Pzmq6KqNijnsW0h/TH3V0FR8idgW3Q6w9tHUDnAyMsiz4Uj9w6iptmlIEctej7cfwC63 SLkmqiOoyyCpItAqql651Fw5H+BrsplIo2t9s9aCiLSdWbq0qfnTuUIRubAcoqhP+g1s pJv7cvLq6ZQaRUHcW81j28wIj51yJrLRU+u7wdL4uJ1G0SEIRlQkGeMvumYFI25VFK59 Zqwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=G5k2/b3ONlddz9du7Ie1ginza7fdSO5Xyed8FJtZkdM=; b=ggDcC3pvsboiTBwqMq+da8Vhrb2T1BcIDw0nNdDGXZD4XLYXUitMXC+LaqcmahYu+Z Hv2My89ZX2RNVP9sqklOigLgeX762N9UElxr6nX3V9mvRO57+8pegde350olQiCj6Ye1 BL84myYq6afTCbX/2RiEgJk9gC6vNlujJ9weL7HRrbQdiKdeSrVMxEDUwAzEqIhJdVIf 2pKaVEWb8iM7MPu7gjCn5/NWHsy8upGMnxFe60ds7LCI5CKxd3b2aCr0aYsD/jLiiRN9 08YWtRjvPniKwr3M9RRUtL2L1ej8OuZImWsOIawLTl0K5QQhXlobLocJQCLEAnE2RuoP AUWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u21si9006587edy.178.2021.06.01.08.03.45; Tue, 01 Jun 2021 08:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234457AbhFAPBw (ORCPT + 99 others); Tue, 1 Jun 2021 11:01:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:40904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234386AbhFAPBt (ORCPT ); Tue, 1 Jun 2021 11:01:49 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 482B9613A9; Tue, 1 Jun 2021 15:00:08 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lo5sD-004qCS-QS; Tue, 01 Jun 2021 16:00:06 +0100 Date: Tue, 01 Jun 2021 16:00:04 +0100 Message-ID: <87im2x1vgr.wl-maz@kernel.org> From: Marc Zyngier To: Quentin Perret Cc: will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, catalin.marinas@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kernel-team@android.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/7] KVM: arm64: Remove hyp_pool pointer from struct hyp_page In-Reply-To: <20210527125134.2116404-6-qperret@google.com> References: <20210527125134.2116404-1-qperret@google.com> <20210527125134.2116404-6-qperret@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: qperret@google.com, will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, catalin.marinas@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kernel-team@android.com, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 May 2021 13:51:32 +0100, Quentin Perret wrote: > > Each struct hyp_page currently contains a pointer to a hyp_pool struct > where the page should be freed if its refcount reaches 0. However, this > information can always be inferred from the context in the EL2 code, so > drop the pointer to save a few bytes in the vmemmap. > > Signed-off-by: Quentin Perret > --- > arch/arm64/kvm/hyp/include/nvhe/gfp.h | 4 ++-- > arch/arm64/kvm/hyp/include/nvhe/memory.h | 2 -- > arch/arm64/kvm/hyp/nvhe/mem_protect.c | 13 +++++++++++-- > arch/arm64/kvm/hyp/nvhe/page_alloc.c | 7 ++----- > arch/arm64/kvm/hyp/nvhe/setup.c | 14 ++++++++++++-- > 5 files changed, 27 insertions(+), 13 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/include/nvhe/gfp.h b/arch/arm64/kvm/hyp/include/nvhe/gfp.h > index aada4d97de49..9ed374648364 100644 > --- a/arch/arm64/kvm/hyp/include/nvhe/gfp.h > +++ b/arch/arm64/kvm/hyp/include/nvhe/gfp.h > @@ -42,8 +42,8 @@ static inline void hyp_set_page_refcounted(struct hyp_page *p) > > /* Allocation */ > void *hyp_alloc_pages(struct hyp_pool *pool, unsigned int order); > -void hyp_get_page(void *addr); > -void hyp_put_page(void *addr); > +void hyp_get_page(void *addr, struct hyp_pool *pool); > +void hyp_put_page(void *addr, struct hyp_pool *pool); It'd be good to be consistent with __hyp_put_page(), which has these arguments in the opposite order. See below for an example. > > /* Used pages cannot be freed */ > int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, > diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h > index 7691ab495eb4..991636be2f46 100644 > --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h > +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h > @@ -7,11 +7,9 @@ > > #include > > -struct hyp_pool; > struct hyp_page { > unsigned int refcount; > unsigned int order; > - struct hyp_pool *pool; > }; > > extern u64 __hyp_vmemmap; > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > index fdd5b5702e8a..3603311eb41c 100644 > --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c > +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > @@ -42,6 +42,15 @@ static void *host_s2_zalloc_page(void *pool) > { > return hyp_alloc_pages(pool, 0); > } > +static void host_s2_get_page(void *addr) nit: missing blank line. > +{ > + hyp_get_page(addr, &host_s2_pool); > +} > + > +static void host_s2_put_page(void *addr) > +{ > + hyp_put_page(addr, &host_s2_pool); > +} > > static int prepare_s2_pool(void *pgt_pool_base) > { > @@ -60,8 +69,8 @@ static int prepare_s2_pool(void *pgt_pool_base) > .phys_to_virt = hyp_phys_to_virt, > .virt_to_phys = hyp_virt_to_phys, > .page_count = hyp_page_count, > - .get_page = hyp_get_page, > - .put_page = hyp_put_page, > + .get_page = host_s2_get_page, > + .put_page = host_s2_put_page, > }; > > return 0; > diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c > index ce7379f1480b..e453108a2d95 100644 > --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c > +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c > @@ -150,20 +150,18 @@ static void __hyp_put_page(struct hyp_pool *pool, struct hyp_page *p) > __hyp_attach_page(pool, p); > } > > -void hyp_put_page(void *addr) > +void hyp_put_page(void *addr, struct hyp_pool *pool) > { > struct hyp_page *p = hyp_virt_to_page(addr); > - struct hyp_pool *pool = hyp_page_to_pool(p); > > hyp_spin_lock(&pool->lock); > __hyp_put_page(pool, p); When I see this, my eyes get crossed, and I don't know what I'm reading anymore! ;-) In general, I like the "container" as a first argument, followed by the element that can be contained. > hyp_spin_unlock(&pool->lock); > } > > -void hyp_get_page(void *addr) > +void hyp_get_page(void *addr, struct hyp_pool *pool) > { > struct hyp_page *p = hyp_virt_to_page(addr); > - struct hyp_pool *pool = hyp_page_to_pool(p); > > hyp_spin_lock(&pool->lock); > hyp_page_ref_inc(p); > @@ -212,7 +210,6 @@ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, > /* Init the vmemmap portion */ > p = hyp_phys_to_page(phys); > for (i = 0; i < nr_pages; i++) { > - p[i].pool = pool; > p[i].order = 0; > hyp_set_page_refcounted(&p[i]); > } > diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c > index 709cb3d19eb7..bf61abd4a330 100644 > --- a/arch/arm64/kvm/hyp/nvhe/setup.c > +++ b/arch/arm64/kvm/hyp/nvhe/setup.c > @@ -137,6 +137,16 @@ static void *hyp_zalloc_hyp_page(void *arg) > return hyp_alloc_pages(&hpool, 0); > } > > +static void hpool_get_page(void *addr) > +{ > + hyp_get_page(addr, &hpool); > +} > + > +static void hpool_put_page(void *addr) > +{ > + hyp_put_page(addr, &hpool); > +} > + > void __noreturn __pkvm_init_finalise(void) > { > struct kvm_host_data *host_data = this_cpu_ptr(&kvm_host_data); > @@ -160,8 +170,8 @@ void __noreturn __pkvm_init_finalise(void) > .zalloc_page = hyp_zalloc_hyp_page, > .phys_to_virt = hyp_phys_to_virt, > .virt_to_phys = hyp_virt_to_phys, > - .get_page = hyp_get_page, > - .put_page = hyp_put_page, > + .get_page = hpool_get_page, > + .put_page = hpool_put_page, > }; > pkvm_pgtable.mm_ops = &pkvm_pgtable_mm_ops; > > -- > 2.31.1.818.g46aad6cb9e-goog > > Thanks, M. -- Without deviation from the norm, progress is not possible.