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 B578AC25B76 for ; Tue, 11 Jun 2024 13:57:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1/Ygnp8t4bMAsvSPAMkHvhnev5tIGpYBUvYh3fINDOg=; b=GK5OTEaiZ0ceKU 31QbAIv3IN/qkIUZqB1G7X+Ms8Jg5HDr50QJn3G3rvaACZxIJsYA0Kj8PiNC/9a/gBQEcALsunBZU 1ECMD9+uEOJ/lEdRIiNm6p+gLj4h/VHPcuEdWumNmSXXjkSRzON98AqddIR+c0BG8zL95HvbGkHpT UbqlvMXIkCfX/m0rCbmYViaMrSG6qjQEtSDerPOOSUjpKR8xRoNEIskwlaT5STqtKRxiMvWU4q0RV 88kisnDuU1m3UMLBirmY9AgILVnqZtrBDH0ZV/Nb7lobE46SpOskm7FG2dDCFDvt4tk35ZrGkFhBx wzMgQLqmyPOvzpXBIp1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sH1zb-000000094Pe-1VQj; Tue, 11 Jun 2024 13:56:55 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sH1zY-000000094M5-2rq5 for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 13:56:54 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42175bce556so58235e9.1 for ; Tue, 11 Jun 2024 06:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718114208; x=1718719008; 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=bNs4f6KkzdoND96Om9u51cQHwE7THMPFJe5WQOvE0Us=; b=pBYobtZg8nt7/+c7UlT5yZnM/ikCMLmk2o9pEEgxQU6KumRK/6LUzmjObiD477iFfr flBE9v0DUlq7eYG640a+imkBxEdtZqLtKByrWgGHyuFw2SufHnWz3eeUrZpx0415lw1t u6eM944fH2umOmewFoRHP9AiYa8ZGzVWwg1itGZh7zCqgTcniEShNfn3kZhbjq3loQaw zqQED6cuAlmdGE/bKuxy+s/X3SIPGq9YIgBd4N/T61SZPweOS2Mr9o35fOzHhsze7qN3 few+lLHvYhmnmJwq1cgIGQVD5LnCi79VIaTAHy9k4X47Bpg60xYkeSBS5uZB9cX62/Z5 2GIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718114208; x=1718719008; 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=bNs4f6KkzdoND96Om9u51cQHwE7THMPFJe5WQOvE0Us=; b=LqsV6Xsg8eCrUL8gKaJJPD0H1NS+Gw/OryNu5Wl8/Z28uaT1npp908hfgdYTMz7N6h Kr4bIbZ1AXxeUXd/Rz/z+zsDtzz+6pI3TbwPpMV6gaH2XzLzr+QZoCSO4OKgHlXhOR+R kTulAezmovnweJk1gH2hQaYZG8u/Dz8kyMOqOFlyrDg48yAHeyMwMRJiGb0LpZNxdr9g Xe/LwiaHkV/E7PtDj57ewYLrXtCd4E6sLNNaUw9MZs5n2Q3R28JxDrI8NbFU/yKMPnjT Sw1rgS5m9cxyLSfAtoUse2hMNCZOHfLoqNgIlJvPXKrI/H6CJjw37qvu024o45s2DdWw 7bIQ== X-Forwarded-Encrypted: i=1; AJvYcCVxeo9zbjOBXtWvxDlREdhb6oFMKJrWvlcvTNqv3nMrpDuDf5w/4VfhbqufhPOWo4Tn4EvlVkdCO+kIg94ziFp24NX5lD9iwbzspPx2E5flI9vQOsE= X-Gm-Message-State: AOJu0YxkT8Qzz8nqfvYRSzXDe7uN+4OFdziMSt5ZBas2jswit2XW1dGb PBFwOYQaDBEE2eKhNpRF4v+p61q1OFG8CEKhsdkVpe1YN5tYTu3BN9yQBaH2Yw== X-Google-Smtp-Source: AGHT+IHrxnZpMaofCEPMIPgkh50ftY/UilMd2LpIHinhFHRgSwGMkJDMQJbDsDyhj10rSyoSp3kUig== X-Received: by 2002:a05:600c:1e14:b0:41a:444b:e1d9 with SMTP id 5b1f17b1804b1-42244f4723emr1656375e9.4.1718114208215; Tue, 11 Jun 2024 06:56:48 -0700 (PDT) Received: from google.com (216.131.76.34.bc.googleusercontent.com. [34.76.131.216]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4215c0fe4b3sm178946825e9.0.2024.06.11.06.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 06:56:47 -0700 (PDT) Date: Tue, 11 Jun 2024 13:56:46 +0000 From: Sebastian Ene To: Vincent Donnefort Cc: maz@kernel.org, oliver.upton@linux.dev, sudeep.holla@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kernel-team@android.com Subject: Re: [PATCH] KVM: arm64: FFA: Release hyp rx buffer Message-ID: References: <20240530131734.2724454-1-vdonnefort@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240530131734.2724454-1-vdonnefort@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240611_065652_780277_584FB0E1 X-CRM114-Status: GOOD ( 25.62 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, May 30, 2024 at 02:17:34PM +0100, Vincent Donnefort wrote: Hello Vincent, > According to the FF-A spec (1.2 BET0 7.2.2.4.2), after a producer has > written into a buffer, it is "full" and now owned by the consumer until > it is read and "empty". This must be signaled by the consumer with the > RX_RELEASE invocation. I agree the spec is a bit unclear in the ownership transfer of the buffer: - it mentions that the producer owns it when it is empty (I think it is a separate state the ownership transfer than being "full"). Some FF-A ABIs do the ownership transfer when they are invoked, but not all of them and this is why we need calls like RX_RELEASE, to signal the availability of the buffer and to transfer the ownership from the Consumer to the Producer. Can we add this explanation as part of the commit message to justify why we need this ? I think it is also worth mentioning that this is how TF-A (Trusted Firmware) deals with the ownership transfer of the buffer. > > It is clear from the spec (7.2.2.4.2), that MEM_RETRIEVE_RESP is > transferring the ownership from producer (in our case SPM) to consumer > (hypervisor). We must then subsequently invoke RX_RELEASE to transfer > back the ownership (i.e. to let SPM mark the buffer as "empty"). > > It is less clear though what is happening with MEM_FRAG_TX. But this > invocation, as a response to MEM_FRAG_RX writes into the same hypervisor > RX buffer. Also this is matching the TF-A implementation where the RX > buffer is marked "full" during a MEM_FRAG_RX. > > Release the RX hypervisor buffer in those two cases. This will unblock > later invocations using this buffer which would otherwise fail. > (RETRIEVE_REQ, MEM_FRAG_RX and PARTITION_INFO_GET). > Thanks, Seb > Signed-off-by: Vincent Donnefort > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c > index 02746f9d0980..efb053af331c 100644 > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > @@ -177,6 +177,14 @@ static void ffa_retrieve_req(struct arm_smccc_res *res, u32 len) > res); > } > > +static void ffa_rx_release(struct arm_smccc_res *res) > +{ > + arm_smccc_1_1_smc(FFA_RX_RELEASE, > + 0, 0, > + 0, 0, 0, 0, 0, > + res); > +} > + > static void do_ffa_rxtx_map(struct arm_smccc_res *res, > struct kvm_cpu_context *ctxt) > { > @@ -543,16 +551,19 @@ static void do_ffa_mem_reclaim(struct arm_smccc_res *res, > if (WARN_ON(offset > len || > fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE)) { > ret = FFA_RET_ABORTED; > + ffa_rx_release(res); > goto out_unlock; > } > > if (len > ffa_desc_buf.len) { > ret = FFA_RET_NO_MEMORY; > + ffa_rx_release(res); > goto out_unlock; > } > > buf = ffa_desc_buf.buf; > memcpy(buf, hyp_buffers.rx, fraglen); > + ffa_rx_release(res); > > for (fragoff = fraglen; fragoff < len; fragoff += fraglen) { > ffa_mem_frag_rx(res, handle_lo, handle_hi, fragoff); > @@ -563,6 +574,7 @@ static void do_ffa_mem_reclaim(struct arm_smccc_res *res, > > fraglen = res->a3; > memcpy((void *)buf + fragoff, hyp_buffers.rx, fraglen); > + ffa_rx_release(res); > } > > ffa_mem_reclaim(res, handle_lo, handle_hi, flags); > > base-commit: 6d69b6c12fce479fde7bc06f686212451688a102 > -- > 2.45.1.288.g0e0cd299f1-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel