From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FC3C3BAD95; Fri, 22 May 2026 09:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779443953; cv=none; b=YSVLO2O7fYke0xKNUMeUOGkuAnLNxTk6eYx0B/RPhy/5kizhM9xOKbdhPfh461oc4GZIp5sTkZyBTyZ68awscoOu3RIi7zKTmCR19RNBUSN1bwiRIkFGNVu+cwRrVvUCF05Fry09YSN4quKMJrOiQOQU8RBmNYb8E1y0QBbSPyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779443953; c=relaxed/simple; bh=yEYtEb4SmbesXXVSdXZGvvGFoQd7/PfTyCL1JseMGJc=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=fl7OMjB3BmZaaDf1kpZnsh5Pe4DLnxkYDtY2HEGkoZ/8U4+FHpw64NphdlgrKwL3sYs9AL2Z1DuK79BKeb7JHPjcnLBR8SLrFJv+oAwn6/fw/VIjcRbMueFLNEX4TQIJ39qn6LaGbFO1a4X058gIEwkH8RiMjTcBvr5r+4rDS1o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a+0BoIAN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a+0BoIAN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE2461F000E9; Fri, 22 May 2026 09:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779443952; bh=Lq6FzCC4KbteJ9kgvftpe86/zGobK0A72wn8P5God9Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=a+0BoIANfJoxAw5Ex6FiTjmcoAyM5OY+Tqu9spimOb+fiTeVzrfzisFmmBAZrQtBM a/xhzqo9ESOwirQxYbtIDkeGwoPZaYpSJUBDxGAGKZsC2P3wjyrTSkixc84M7AZEiG nki8LKsCzZ6iqZV4YBdzmDUH3Z3xZ9lbgv3oSCCpVjAviivm0PoYVKlAEcbCBQD/dg iYMzqyMLs1JCGdKrphV+SznVU9vSgN0d48e0fAFJJ0WdRo/3czCG5YMoFNgkD6qG5L bo3emt0Knfj1G+S7e57RVNZtzzWxj2tQXZ7uveEvtlP8DiJ1Tf1R0Ymht+2luf9RsL 650k9hqWWXEBQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=lobster-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 1wQMer-00000005AhL-2LWF; Fri, 22 May 2026 09:59:10 +0000 Date: Fri, 22 May 2026 11:02:20 +0100 Message-ID: <87ik8fahjn.wl-maz@kernel.org> From: Marc Zyngier To: Suzuki K Poulose Cc: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev, Catalin Marinas , Will Deacon , James Morse , Oliver Upton , 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: References: <20260513131757.116630-1-steven.price@arm.com> <20260513131757.116630-10-steven.price@arm.com> <867bowx3qx.wl-maz@kernel.org> 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) Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: suzuki.poulose@arm.com, 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, 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 On Thu, 21 May 2026 17:01:37 +0100, Suzuki K Poulose wrote: > > On 21/05/2026 14:59, Marc Zyngier wrote: > > 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? > > That is not true ? It triggers, top_bound error condition, for both. > > > pre: UInt(top) <= UInt(base) > post: result.status == RMI_ERROR_INPUT News flash, I can't read. Ignore me. M. -- Jazz isn't dead. It just smells funny.