From patchwork Thu May 30 13:17:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Donnefort X-Patchwork-Id: 13680397 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 8EBBAC25B74 for ; Thu, 30 May 2024 13:17:58 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ZemEcoK5F1cT5f+B6+vlPz8dwv+meTZvV4kB15ZqRsE=; b=y5y sz8YT0bZvupHmBenlocrF26lOB9Yx+mmG6jm2MHjIHlmiv/0VrDekv8Hdg1PXvwiXpUG0my0f8S8c 8DaCqCdUzLoMgHKGTB0q9Fph7EpyPkxZxmHf9H9HBHHGgPxy2b4wv0iwDXIHHB+bCnFRItqTXZ46/ tvnDY8lpFnpcAfU1Tqt7cZ0xaoEukVgJ54UzaMWe+UjKYWyM8UuPIPEVmz3n4bnsi6+0E2me6oyJe BHUWMZ72i9CbVxlQfpK/8pS+CpKuUOcz6JFnw6pwL5pVefg8Ttd+M/OUPtPGEFaheFxuyeaH5DAr4 Ws13vlAhmmIm5nVuz/yggAjXNzBWdCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCff8-00000007KgQ-2a8a; Thu, 30 May 2024 13:17:46 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCff5-00000007Kfs-1CXZ for linux-arm-kernel@lists.infradead.org; Thu, 30 May 2024 13:17:44 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-42117a61bccso7919685e9.0 for ; Thu, 30 May 2024 06:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717075059; x=1717679859; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=A2h19ypI6tOBSYk6uWwSlGYJAlpWcvaEZOfEyoOEcjk=; b=lvImm+Wn3G4UASnnIl8mjstTglE0lze0IYGYdffvGJ9a548ZQfggJdesmt3nqsV8QY 2zb2YL0RpQyRoVsug/JqVBtG47EM4M7ef1CQ6lho7OKO5Dyt/pS7jcInD54w/qfSbf2k u1MWnlnIdUwF+bzcrVC70R6gPr8JaxWZGffCE0w17dXj1F35FrwqPOW1CnzpkkvoAQRy Fgx5tb1izfV2xYHmR4NYFbONhE+ZgZYpffC+Y2GMBI38hBOJuV7uM+v/0oUzqZpsc62V W7dbz2zNzVzxMKIBZzACYIXDC+qG1MhViwtYnCAzcF4YQ1H9JBeel2B7YKqSEhwdjT2O KauQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717075059; x=1717679859; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=A2h19ypI6tOBSYk6uWwSlGYJAlpWcvaEZOfEyoOEcjk=; b=gRwMTKM5evVTDA9IBHJJQLb//QPjrIl/5jw4u23QorLyjs2mdGxbD20ElnBBRE+ucN 6XX4KtYlcUNBN03+PH98J5kJKnn9ENw/hPpFtXoy2vAYXOfDry7eMd0gDowolR60mxd+ YZp4cSbu80INAIclchII3R+0h9cHLdH/m7fJQfZWJ4+ND7AyPPyx+ASm/trP6wuvBJVj M5+HjiY0x0bcUPw0XJKX5mazc4ehRTYdoI2HiVhKbPHR6lET/DWT84UBuvCOuHyDRN4T jERB+Gm/17FcP8vfCxJ27ECPhGOmedbRV0xKI43oT5mrUaX7ik0JnczK5EGEYNxEU8i7 yzag== X-Forwarded-Encrypted: i=1; AJvYcCXJIeGSyluH56E83SRha1f7oj6Jqrbz93Ftd3tBnhUgrbB8hrIPdJqi8BDzwU5WfkfePIGDiPVGJq65DF9Mb6mmhfY7lI4w/qfoLKjCFasZ2AKo91M= X-Gm-Message-State: AOJu0YxQeOq/77O1DCty9Jbyj8hXRe+31DvPEa9L6RHf5BYkS2+6g69h btBhcBdL8W4cBAkTt6lB9BfdsxpBGP042sfGDTFdV3AKtLggZMhw4uxxXF4yxfejtygUPd8XSDV 8zd8PBf7ipbcAabrQWw== X-Google-Smtp-Source: AGHT+IGh+KPdywzR45ey0MWLtb/lqdkOKtXl9CHjrK7tb6aGcEqLmSXkF7e0XyWNok1bVIvHaiwfYCYKB5tbSO2h X-Received: from vdonnefort.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:2eea]) (user=vdonnefort job=sendgmr) by 2002:a05:600c:3b94:b0:421:29f2:7958 with SMTP id 5b1f17b1804b1-42129f27c40mr69125e9.1.1717075058922; Thu, 30 May 2024 06:17:38 -0700 (PDT) Date: Thu, 30 May 2024 14:17:34 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240530131734.2724454-1-vdonnefort@google.com> Subject: [PATCH] KVM: arm64: FFA: Release hyp rx buffer From: Vincent Donnefort To: maz@kernel.org, oliver.upton@linux.dev, sudeep.holla@arm.com Cc: sebastianene@google.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kernel-team@android.com, Vincent Donnefort X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240530_061743_366410_BA19EB59 X-CRM114-Status: GOOD ( 11.37 ) 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 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. 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). Signed-off-by: Vincent Donnefort base-commit: 6d69b6c12fce479fde7bc06f686212451688a102 Reviewed-by: Sudeep Holla 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);