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 BB7BFECE577 for ; Mon, 9 Sep 2024 16:04:29 +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=fracQuYtQaObjYrVhxRAFzJFryVoL/0p6ZImg0NJDKk=; b=oOMqpIz0xI6P/2aPQol+QLuQoX wr9d/hQE40bPW0L1nxfLLPqSdEmawazU+cIIAkF4/CYSbZfmLk7MQp3QlDMYRBWTBp8iEvCsJUIxL ddYrc2apLe745W/MlNrBqtowFcG7LQDF0Tr74ADCYc9oLN+NqiJDSNvOhpIub7Z0ee6ecH0MOifva 4LM08HvTaUz6ajZ3TWUrOcORHj0RmACYtfXEk3kpnLR0YMwpPO5crzfHRJdLAHZi7AGlaBF16mQMe 16VE+btgKC2SBpBx2qxVVO8iGCIMNlPYvyBotl+oYWlY6tUUkSztMStMD2gmxV/GLpbELoWGkB/me KoG6jMlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sngsD-00000002aIQ-1pOK; Mon, 09 Sep 2024 16:04:17 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sngr9-00000002a1f-3xGO for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 16:03:13 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-53661d95508so12955e87.1 for ; Mon, 09 Sep 2024 09:03:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725897790; x=1726502590; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fracQuYtQaObjYrVhxRAFzJFryVoL/0p6ZImg0NJDKk=; b=hpKCBTMn7dbIbHAA5wwug6g0vSemc2kh0DmFXUgo6IIEq/+GiPvWKU7O/Tv7vr2ep9 92niWLeMeEoh/baX+bTqPsKtZBsyJdmWoXfUaHONs/PDIMccnb0GI/i5kneF5nWGyhHV Ah81ueQSONf2+wIVtxFlpCqh1eXL2gGfa7PKs0fHhl/yc/fF/PXD8djtw3g+BNmfJ54C k5EsiXottk2lEs7sHPJ3If7MImAkLaibW97FSGXrn3ODI4Is4xkUj3fF60LIICC9dl0Y icXEPASzOfHcadELHH3yuCm2kb9+R7JWdrd4lWebJQPAQ6g6EOp6vblEV8oi0MyoK/ZC 4hCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725897790; x=1726502590; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fracQuYtQaObjYrVhxRAFzJFryVoL/0p6ZImg0NJDKk=; b=SlUKh0H5XC5u7hg3DI+DOpsA94IkV2WNvSdPHs1nEh6WinqFkBH8kun3VbxmAPkvEo 6Kvym4QNf+UnSeg6pL3I3KUrNNDxxfXt94kt0EIRq9speE957Oa9kSfaxBGafTUvv2bs wFr7klpljay2DpyrsoFVwas7Dmuqct+3lycSj6jy0iigr5woDMpxHdHtF10Dww0LahDF NujFKIp4cfwWoiPN1DU4V0iiomL7FpOZnyXq7/NVzYrRNpAf96okzCxyeT3tWHr0Smxz OBt2FTCyCMbshZsbAhBETDHplJ2FJlKXpX45xJ2uZ3aZkjVmaTMT6Z6A+7PuUHXsJBer 7McA== X-Forwarded-Encrypted: i=1; AJvYcCXPNuASXvP5l7KZo5P2IG4pa89p3HXM2FeWRhJlfe3Q9Rb2EpOsMEsrLkgs6CwW2TAV7TUXTfH5+SiwF2zjviSY@lists.infradead.org X-Gm-Message-State: AOJu0YwKsFycsXIqziaXMLZ2jPKjJKxKsaAZHBGEFimOeNq8ZWZ27Npg V7RJRZB918D12Gc0TqITTzMwBuanIb71WntOSWm5eMMGTZ9eEY1smhUFhP35VQ== X-Google-Smtp-Source: AGHT+IFWWF4zQGbIYhYU4tYtK4Cq/myRRd+dsd+RU2EiYcad8RSM6sP31Dr6sN0cwJxGzs0Gz5dgqQ== X-Received: by 2002:a05:6512:3a95:b0:533:4620:ebe6 with SMTP id 2adb3069b0e04-5365debfedamr337407e87.4.1725897789707; Mon, 09 Sep 2024 09:03:09 -0700 (PDT) Received: from google.com (93.20.140.34.bc.googleusercontent.com. [34.140.20.93]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956dbf42sm6355955f8f.102.2024.09.09.09.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 09:03:09 -0700 (PDT) Date: Mon, 9 Sep 2024 16:03:07 +0000 From: Sebastian Ene To: Snehal Koukuntla Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla , Vincent Donnefort , Jean-Philippe Brucker , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer Message-ID: References: <20240909130832.1203849-1-snehalreddy@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240909130832.1203849-1-snehalreddy@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_090312_003707_91292498 X-CRM114-Status: GOOD ( 23.48 ) 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 Mon, Sep 09, 2024 at 01:08:32PM +0000, Snehal Koukuntla wrote: Hi, A couple of nits which weren't addressed in the first version. > Check size during allocation to fix discrepancy in memory reclaim path. > Currently only happens during memory reclaim, inconsistent with mem_xfer > Also do_ffa_mem_xfer() does not need __always_inline > Please enhance the description in the commit message as Mark suggested previously. Something like this should work: """ 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. Fixes: 43609000177625 Cc: stable@vger.kernel.org Signed-off-by: Snehal Koukuntla """ Otherwise, 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, > 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; > + } > + > buf = hyp_buffers.tx; > memcpy(buf, host_buffers.tx, fraglen); > > -- > 2.46.0.469.g59c65b2a67-goog > Thanks, Seb