From patchwork Wed Sep 14 08:34:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12975778 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 6A106ECAAD3 for ; Wed, 14 Sep 2022 08:36:58 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hg8ntGWuePpC5m6NApZ5UhwCMzwPp4ghfoygCN/m49c=; b=sk1TnU81XNmJcC CLrJ11ptBaL3862ohmhVppInrdk7Az41wH+pSy5ZYopVCCU6s4hHmbTXDaDndrJ13oyxfohdwmbVP dUnyagfvUCCvy+D3KVRTtMUfWkHEjenuCK61ftbjSXCmyaiSfIZ4nVrI41QFjgMywJgQdc9Uk7Ajq 0PSm36KzEU99IBjNkxuqPLvORqCIdn0PcJgQXky251eJf3jnx2SsgIMhRBiNMx1scHpxD5FsPuckE BxAseAQTRgOXS9mOAhCw+YBg9AY8/+9jnPkDNcW3KO69PZat0ipbdnkVI3ib8xrtE93LudltnIfre TlsihFGg9wMXmhE4MgQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oYNs4-00Dc9c-He; Wed, 14 Sep 2022 08:35:48 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oYNrY-00Dbrn-8j for linux-arm-kernel@lists.infradead.org; Wed, 14 Sep 2022 08:35:19 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 70713B81670; Wed, 14 Sep 2022 08:35:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20475C433D7; Wed, 14 Sep 2022 08:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663144513; bh=wU55wKAQiWOPw2GVwEciR9xyeam6blJip5bVSN4bKYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIF2/7G5V6tl9zZ+lZardjx0o2onsy42Z+OoeFPtVgsc3Hxlg7fGSanPcJSxTQh51 DbSJHw8flNhWqe4HLJDzOd4igxOCzj1odnD9tkh5S3LM4gZoR1Gtsk6I6IFRjP4I0e wlkJP3YAgwONmvZRPIYsEYM4jN6pzG6n+QzkiLln9dudniwAAKHWn+w0E7Fsw5ktWy KoSavgaTImwqMbTsnoBWJzaEeHlzNb2Q5WHL9jZ1LmFZK9W2/WbVtOqoAS3VmKQpTY rXselAKl3bBqJpkjRWgWRRpZdWpIkBVboqNnCd2FZRVkenYLJg8VNRVXk9pE60X8Bb ujyWCWYxaUXTg== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Sean Christopherson , Vincent Donnefort , Alexandru Elisei , Catalin Marinas , James Morse , Chao Peng , Quentin Perret , Suzuki K Poulose , Mark Rutland , Fuad Tabba , Oliver Upton , Marc Zyngier , kernel-team@android.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 01/25] KVM: arm64: Move hyp refcount manipulation helpers to common header file Date: Wed, 14 Sep 2022 09:34:36 +0100 Message-Id: <20220914083500.5118-2-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220914083500.5118-1-will@kernel.org> References: <20220914083500.5118-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220914_013516_638261_7823D26B X-CRM114-Status: GOOD ( 12.86 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Quentin Perret We will soon need to manipulate 'struct hyp_page' refcounts from outside page_alloc.c, so move the helpers to a common header file to allow them to be reused easily. Signed-off-by: Quentin Perret Signed-off-by: Will Deacon Reviewed-by: Oliver Upton --- arch/arm64/kvm/hyp/include/nvhe/memory.h | 18 ++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/page_alloc.c | 19 ------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h index 592b7edb3edb..418b66a82a50 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h @@ -45,4 +45,22 @@ static inline int hyp_page_count(void *addr) return p->refcount; } +static inline void hyp_page_ref_inc(struct hyp_page *p) +{ + BUG_ON(p->refcount == USHRT_MAX); + p->refcount++; +} + +static inline int hyp_page_ref_dec_and_test(struct hyp_page *p) +{ + BUG_ON(!p->refcount); + p->refcount--; + return (p->refcount == 0); +} + +static inline void hyp_set_page_refcounted(struct hyp_page *p) +{ + BUG_ON(p->refcount); + p->refcount = 1; +} #endif /* __KVM_HYP_MEMORY_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c index d40f0b30b534..1ded09fc9b10 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -144,25 +144,6 @@ static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool, return p; } -static inline void hyp_page_ref_inc(struct hyp_page *p) -{ - BUG_ON(p->refcount == USHRT_MAX); - p->refcount++; -} - -static inline int hyp_page_ref_dec_and_test(struct hyp_page *p) -{ - BUG_ON(!p->refcount); - p->refcount--; - return (p->refcount == 0); -} - -static inline void hyp_set_page_refcounted(struct hyp_page *p) -{ - BUG_ON(p->refcount); - p->refcount = 1; -} - static void __hyp_put_page(struct hyp_pool *pool, struct hyp_page *p) { if (hyp_page_ref_dec_and_test(p))