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 B1C9DECE589 for ; Mon, 9 Sep 2024 22:37:35 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From: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=PAOwxfQaHCQqtI5pUon/+UOel8KmgsVnMsfbJQaWVLE=; b=sXJfDuUlGtHQCHOxvBw6R1QQF1 Nb23mQtKSYPiu1YctaPoXAV8QuG3Etlfm0aoFQ3GnoJ8aIwzeABAjN5yZOEjQho+OnalVbD8M5HBF xa6OXd7val2Zd8itDyg4uH+NoE+K8U9p3/c7r0F64xOmwA6/oDs4dh/G0q0Dz6/KzPl1DZ3aSvxTA QV9CadP5JZ82su4upCtUvr4QnE9Cr9J0IbHctwPhMFF/JZPG9TCRoz0u36xNAGExXpcJZnPL/7RS6 m1Jq7We2Pd7CMcxDgBeXhG5XgSwcCl1Yyus+jPHTDIDk8ubtqKsxHiy/FNG+aX1KB0uETpjiTjULj PCh9SW/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snn0g-00000003UyO-2wHq; Mon, 09 Sep 2024 22:37:26 +0000 Received: from out-178.mta0.migadu.com ([91.218.175.178]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1snmzd-00000003UO2-4Anz for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 22:36:23 +0000 Date: Mon, 9 Sep 2024 22:36:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1725921377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PAOwxfQaHCQqtI5pUon/+UOel8KmgsVnMsfbJQaWVLE=; b=VfNbR2YxKTO00M+E11bjDCcDKgJZ2grBhvATdSx/2QjmfxN4lxvtuk5Z3kqt5qkxivgrpC T+u3r1Lhjv2mx1FWGqIBqaBcynm2XlN/prAeu0U5cdnh0yh78e1qIwyd+9GxWZxXLxvjJ9 Uc+l3d4Vpb6IWmDO16ynNlFVed5g6fA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Snehal Koukuntla Cc: Marc Zyngier , 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 Message-ID: References: <20240909180154.3267939-1-snehalreddy@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240909180154.3267939-1-snehalreddy@google.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_153622_481846_39D18A4F X-CRM114-Status: GOOD ( 24.49 ) 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 Hi Snehal, On Mon, Sep 09, 2024 at 06:01:54PM +0000, 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 > --- Next time around, please include some notes on what's changed between versions and ideally a link to the last patch. It helps latecomers (i.e. me) get an idea of what's happening w/ a patch. > 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, > struct arm_smccc_res *res, > struct kvm_cpu_context *ctxt) > { > @@ -461,6 +461,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id, > goto out_unlock; > } > > + if (len > ffa_desc_buf.len) { > + ret = FFA_RET_NO_MEMORY; > + goto out_unlock; > + } > + This check doesn't need to happen behind the host_buffers spinlock. Of course, keeping it behind the lock is benign, but this sort of thing prompts a reviewer to ask "why?" Besides that, Reviewed-by: Oliver Upton -- Thanks, Oliver