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 C99E3EDE9B0 for ; Tue, 10 Sep 2024 19:50:47 +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=NUqtZgI+aHA5H4dM4w4oYWAf9J64aMYAL5HkiJHaRYY=; b=kQU5oNvAweM75t4rYGeWOCOQhC AUJSj1SAPuu9jmm2wXIxZeOs/kdga//UpRscLtZ1iAgqHkdGDODVQPOa7rBYwP1dncaBO3qykZ497 XBHBaQqmjY6k8o41BsSIXQBdX3D8LnJMCCDbE7DFt0ZybHBqu8iMTgteVRDt7yDRNRnJCPGPDo6Sn ny0R55SIRe+qvwAGAXaOfyBN224qrxkc8O+WJ7igonJxOxXAi/j9coc+MrWo7bqSpGlpo1LxIgPE6 3VGuEyDZOe1KK0RwQeS0k9bL3G0b+Z2l3AARCLosOcbjhE+QmwBddRPCOzb4q/3sJLbemf2lKNkK0 ygdIDvxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1so6sm-00000006xAf-42kE; Tue, 10 Sep 2024 19:50:36 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1so6rk-00000006x05-1LEO for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2024 19:49:33 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DBA7F5C0509; Tue, 10 Sep 2024 19:49:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1966DC4CEC3; Tue, 10 Sep 2024 19:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725997771; bh=WeJYGSqNPinOi/i72aoMwHeFytB58XDIlbPCMg7IpcI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WD2HTelgMn18myn/iTh5fxPpWrVOUt9wCDMMBP+BuTkRo7LMkPYCbSZF4FVhydHze QHFZIfBw8BmPK6+0Ica+jH0v+cy5mjol5+ubhAmoUWgajB2R9aaLcNAb8iKKWFsyfi jcdbNvKJIZ2DK0eUeLa8rHaklU5icysta40CmHgqNsoyJcOhfoB5Xy6OBaAioi8c4Q 9AtTCYK7BnOJz7R1ai7u3fqiH9XPIIVZ0eviMrvAFHS0lflpwoaqI8DnI9K3fR7vaQ cVZbPSMc7e46LzJSP3LrRs1cfWcGwfrEwYm0wBkWPtsILXrul2MSUr2RRctcHASEQA 4WAlliLJxEymQ== 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.95) (envelope-from ) id 1so6rg-00Brkl-QO; Tue, 10 Sep 2024 20:49:28 +0100 Date: Tue, 10 Sep 2024 20:49:28 +0100 Message-ID: <86r09r70hj.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: Wei-Lin Chang , Snehal Koukuntla , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla , Sebastian Ene , Vincent Donnefort , Jean-Philippe Brucker , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v3] KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer In-Reply-To: References: <20240909180154.3267939-1-snehalreddy@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/29.4 (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: oliver.upton@linux.dev, r09922117@csie.ntu.edu.tw, snehalreddy@google.com, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, sudeep.holla@arm.com, sebastianene@google.com, vdonnefort@google.com, jean-philippe@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240910_124932_517110_EEBAF1E5 X-CRM114-Status: GOOD ( 44.82 ) 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 Tue, 10 Sep 2024 19:18:41 +0100, Oliver Upton wrote: > > On Wed, Sep 11, 2024 at 12:32:29AM +0800, Wei-Lin Chang wrote: > > Hi everyone, > > > > On Mon, Sep 09, 2024 at 06:01:54PM GMT, Snehal Koukuntla wrote: > > > When we share memory through FF-A and the description of the buffers > > > exceeds the size of the mapped buffer, the fragmentation API is used. > > > The fragmentation API allows specifying chunks of descriptors in subsequent > > > FF-A fragment calls and no upper limit has been established for this. > > > The entire memory region transferred is identified by a handle which can be > > > used to reclaim the transferred memory. > > > To be able to reclaim the memory, the description of the buffers has to fit > > > in the ffa_desc_buf. > > > Add a bounds check on the FF-A sharing path to prevent the memory reclaim > > > from failing. > > > > > > Also do_ffa_mem_xfer() does not need __always_inline > > > > > > Fixes: 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host") > > > Cc: stable@vger.kernel.org > > > Reviewed-by: Sebastian Ene > > > Signed-off-by: Snehal Koukuntla > > > --- > > > arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++- > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c > > > index e715c157c2c4..637425f63fd1 100644 > > > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > > > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > > > @@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, > > > return; > > > } > > > > > > -static __always_inline void do_ffa_mem_xfer(const u64 func_id, > > > +static void do_ffa_mem_xfer(const u64 func_id, > > > > I am seeing a compilation error because of this. > > Thanks for reporting this. Looks like the __always_inline was slightly > more load bearing... > > Marc, can you put something like this on top? > > > From c2712eaa94989ae6457baad3ec459cf363ec5119 Mon Sep 17 00:00:00 2001 > From: Oliver Upton > Date: Tue, 10 Sep 2024 16:45:30 +0000 > Subject: [PATCH] KVM: arm64: Drop BUILD_BUG_ON() from do_ffa_mem_xfer() > > __always_inline was recently discarded from do_ffa_mem_xfer() since it > appeared to be unnecessary. Of course, this was ~immediately proven > wrong, as the compile-time check against @func_id depends on inlining > for the value to be known. > > Just downgrade to a WARN_ON() instead of putting the old mess back in > place. Fix the wrapping/indentation of the function parameters while at > it. > > Fixes: 39dacbeeee70 ("KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer") > Reported-by: Wei-Lin Chang > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/hyp/nvhe/ffa.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c > index 637425f63fd1..316d269341f3 100644 > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > @@ -426,9 +426,8 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, > return; > } > > -static void do_ffa_mem_xfer(const u64 func_id, > - struct arm_smccc_res *res, > - struct kvm_cpu_context *ctxt) > +static void do_ffa_mem_xfer(const u64 func_id, struct arm_smccc_res *res, > + struct kvm_cpu_context *ctxt) > { > DECLARE_REG(u32, len, ctxt, 1); > DECLARE_REG(u32, fraglen, ctxt, 2); > @@ -440,8 +439,10 @@ static void do_ffa_mem_xfer(const u64 func_id, > u32 offset, nr_ranges; > int ret = 0; > > - BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE && > - func_id != FFA_FN64_MEM_LEND); > + if (WARN_ON(func_id != FFA_FN64_MEM_SHARE && func_id != FFA_FN64_MEM_LEND)) { > + ret = SMCCC_RET_NOT_SUPPORTED; > + goto out; > + } I'm not overly on the WARN_ON(), as it has pretty fatal effects on pKVM (it simply panics). What do you think of this instead, which compiles with my prehistoric version of clang (14.0.6): diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 637425f63fd1b..e433dfab882aa 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -426,9 +426,9 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, return; } -static void do_ffa_mem_xfer(const u64 func_id, - struct arm_smccc_res *res, - struct kvm_cpu_context *ctxt) +static void __do_ffa_mem_xfer(const u64 func_id, + struct arm_smccc_res *res, + struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, len, ctxt, 1); DECLARE_REG(u32, fraglen, ctxt, 2); @@ -440,9 +440,6 @@ static void do_ffa_mem_xfer(const u64 func_id, u32 offset, nr_ranges; int ret = 0; - BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE && - func_id != FFA_FN64_MEM_LEND); - if (addr_mbz || npages_mbz || fraglen > len || fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) { ret = FFA_RET_INVALID_PARAMETERS; @@ -517,6 +514,13 @@ static void do_ffa_mem_xfer(const u64 func_id, goto out_unlock; } +#define do_ffa_mem_xfer(fid, res, ctxt) \ + do { \ + BUILD_BUG_ON((fid) != FFA_FN64_MEM_SHARE && \ + (fid) != FFA_FN64_MEM_LEND); \ + __do_ffa_mem_xfer((fid), (res), (ctxt)); \ + } while (0); + static void do_ffa_mem_reclaim(struct arm_smccc_res *res, struct kvm_cpu_context *ctxt) { It preserves the build-time assertion, which was the intention of the original author. I can easily squash that in the original commit, avoiding the headache of backporting both patch to stable. M. -- Without deviation from the norm, progress is not possible.