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 C43B4CD5BB4 for ; Thu, 21 May 2026 13:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tQmPHR8IIsKYlTunVpaYrqEdOMUQnYuy4Tn1SyW9oC4=; b=jzmTFfsvrxTrLm+k+XUcOkyLis dP9MtH4YtzfnrVZDK0xqoMaijXlJuSuFm4ZS2Hm6QwK/uvo/uiGEfbRj2MfuAlRRn38pk4YDd8Gt5 SdZNnZ7vDNtygxoB48p6Z+H4i7fmHSBJYh2MxqK7Pgenvbdx7A0TSay4shCaxfihptXb8HdEaQwWi Ay5ELL3pfKGngy6HYVWHvS7GL2GPShmwBcnXQE76+xkxpLvEIbhu9MXEG3eYSV1XOY6xp81aZ91IN znkxyp16xDgRo+att63A0Z6gN4p74eH/QFCwHdXKA1uvHkTmR5pDAVQT3cjz2Kv06F/soMlICaGnE pzNkF10A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wQ3w3-00000007yYu-2JcH; Thu, 21 May 2026 13:59:39 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wQ3w2-00000007yYM-1tIX for linux-arm-kernel@lists.infradead.org; Thu, 21 May 2026 13:59:38 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 7F67960210; Thu, 21 May 2026 13:59:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2141A1F000E9; Thu, 21 May 2026 13:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779371977; bh=tQmPHR8IIsKYlTunVpaYrqEdOMUQnYuy4Tn1SyW9oC4=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=WzSEaSuip34hyMd7P7xa21XSm/RfjS6Pe5CnL//09oCRDLtbqd9PAzzRRO/MB+Xog ivOACqeJjhtEhasOeK279vNZ3f40idhHL/UOONb9DcMB31xmzmnpIujbHxsn9Jm8sF bHHmP3cnsgs/otnaG7kXS2N20hYUkFCxJpKZvWkMLzeLazt4SI1ovEUj8EtznIjJqp NcfjqIqnTTCYZIOMsCCHsAo+MP+gGXnWBboKizR/tpT558s+Yy51yXuSto/uFMf8jl Z6Amwr8nfZzx5Bbq4fbDhKookvbNe+LqwowPKnwUxPqKKtsTFrOD2tHzDulIgxioYo GpOasUlQ3j4zQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wQ3vz-00000004r81-0Hyn; Thu, 21 May 2026 13:59:35 +0000 Date: Thu, 21 May 2026 14:59:34 +0100 Message-ID: <867bowx3qx.wl-maz@kernel.org> From: Marc Zyngier To: Steven Price Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Catalin Marinas , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo.Pieralisi2@arm.com Subject: Re: [PATCH v14 09/44] arm64: RMI: Provide functions to delegate/undelegate ranges of memory In-Reply-To: <20260513131757.116630-10-steven.price@arm.com> References: <20260513131757.116630-1-steven.price@arm.com> <20260513131757.116630-10-steven.price@arm.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/30.1 (aarch64-unknown-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: 185.219.108.64 X-SA-Exim-Rcpt-To: steven.price@arm.com, kvm@vger.kernel.org, kvmarm@lists.linux.dev, catalin.marinas@arm.com, will@kernel.org, james.morse@arm.com, oliver.upton@linux.dev, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, joey.gouly@arm.com, alexandru.elisei@arm.com, christoffer.dall@arm.com, tabba@google.com, linux-coco@lists.linux.dev, gankulkarni@os.amperecomputing.com, gshan@redhat.com, sdonthineni@nvidia.com, alpergun@google.com, aneesh.kumar@kernel.org, fj0570is@fujitsu.com, vannapurve@google.com, WeiLin.Chang@arm.com, Lorenzo.Pieralisi2@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false 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 On Wed, 13 May 2026 14:17:17 +0100, Steven Price wrote: > > The RMM requires memory is 'delegated' to it so that it can be used > either for a realm guest or for various tracking purposes within the RMM > (e.g. for metadata or page tables). Memory that has been delegated > cannot be accessed by the host (it will result in a Granule Protection > Fault). > > Undelegation may fail if the memory is still in use by the RMM. This > shouldn't happen (Linux should ensure it has destroyed the RMM objects > before attempting to undelegate). In the event that it does happen this > points to a programming bug and the only reasonable approach is for the > physical pages to be leaked - it is up to the caller of > rmi_undelegate_range() to handle this. > > Signed-off-by: Steven Price > --- > v14: > * Split into separate patch and moved out of KVM > --- > arch/arm64/include/asm/rmi_cmds.h | 13 +++++++++++ > arch/arm64/kernel/rmi.c | 36 +++++++++++++++++++++++++++++++ > 2 files changed, 49 insertions(+) > > diff --git a/arch/arm64/include/asm/rmi_cmds.h b/arch/arm64/include/asm/rmi_cmds.h > index 9078a2920a7c..eb213c8e6f26 100644 > --- a/arch/arm64/include/asm/rmi_cmds.h > +++ b/arch/arm64/include/asm/rmi_cmds.h > @@ -33,6 +33,19 @@ struct rmi_sro_state { > } while (RMI_RETURN_STATUS(res.a0) == RMI_BUSY || \ > RMI_RETURN_STATUS(res.a0) == RMI_BLOCKED) > > +int rmi_delegate_range(phys_addr_t phys, unsigned long size); > +int rmi_undelegate_range(phys_addr_t phys, unsigned long size); > + > +static inline int rmi_delegate_page(phys_addr_t phys) > +{ > + return rmi_delegate_range(phys, PAGE_SIZE); > +} > + > +static inline int rmi_undelegate_page(phys_addr_t phys) > +{ > + return rmi_undelegate_range(phys, PAGE_SIZE); > +} > + > bool rmi_is_available(void); > > unsigned long rmi_sro_execute(struct rmi_sro_state *sro, gfp_t gfp); > diff --git a/arch/arm64/kernel/rmi.c b/arch/arm64/kernel/rmi.c > index 52a415e99500..08cef54acadb 100644 > --- a/arch/arm64/kernel/rmi.c > +++ b/arch/arm64/kernel/rmi.c > @@ -12,6 +12,42 @@ static bool arm64_rmi_is_available; > unsigned long rmm_feat_reg0; > unsigned long rmm_feat_reg1; > > +int rmi_delegate_range(phys_addr_t phys, unsigned long size) > +{ > + unsigned long ret = 0; > + unsigned long top = phys + size; > + unsigned long out_top; > + > + while (phys < top) { > + ret = rmi_granule_range_delegate(phys, top, &out_top); > + if (ret == RMI_SUCCESS) > + phys = out_top; > + else if (ret != RMI_BUSY && ret != RMI_BLOCKED) > + return ret; > + } > + > + return ret; > +} > + > +int rmi_undelegate_range(phys_addr_t phys, unsigned long size) > +{ > + unsigned long ret = 0; > + unsigned long top = phys + size; > + unsigned long out_top; > + > + WARN_ON(size == 0); I find it odd to warn on size = 0. After all, free(NULL) is not an error. But even then, you continue feeding this to the RMM. You also don't seem to be bothered with that on the delegation side... > + > + while (phys < top) { > + ret = rmi_granule_range_undelegate(phys, top, &out_top); > + if (ret == RMI_SUCCESS) > + phys = out_top; and size==0 doesn't violate any of the failure conditions listed in B4.5.18.2 (beta2). Will you end-up looping around forever? Same questions for the delegation, obviously. M. -- Without deviation from the norm, progress is not possible.