From patchwork Tue Jun 11 17:53:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Donnefort X-Patchwork-Id: 13694076 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 99650C27C65 for ; Tue, 11 Jun 2024 17:53:48 +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:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=jNNUQKkDrCnecnYCTT00rCZOmSlFkAs3089jG7rC2ac=; b=MIQhDVlZ09o3DUiFm+dx60tTG8 23x/B8Jbx/zOldeAE1de2o4+5NrnJPNqyPOY+tngB9WyUj3kWvpVW2jvh0X18Z+bBXxcz6JCcoTKH otHVQvTbRBVreWF/Q4DQpOzNdKJdJpYS4vUBzbsHXvOXIGdjmnIHrHo23z5w6vZy+E94PePE/Q+Pd de4cv7FBxj3eBZg59ARbA+uEEiKA8+NrU4dDl+6yb6fC4N5y5pdXkRE3jDcrl/b5PRpSTZVs+ptmi +iYt+aUCeZU5pxfkLJrJF7OBen3doZY8b5mUou0ArrEC/eoHSSlDXFSGZYlYAPMAnDA7YHF/hERry h6MIBv6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sH5gb-00000009jtx-3Ztg; Tue, 11 Jun 2024 17:53:33 +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 1sH5gY-00000009jsX-1Vho for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 17:53:31 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-421179fd82bso44958535e9.1 for ; Tue, 11 Jun 2024 10:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718128405; x=1718733205; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=jNNUQKkDrCnecnYCTT00rCZOmSlFkAs3089jG7rC2ac=; b=k+oSBoxulwQxA7Nzd4vqZsISE11RlgIHvwjWVraPA5k+TfKLM7EApwQDnF2M9B7hg8 6xyYN1jLjB5LWsv+UzbxjdBjUbBtwtdeOc3c1xi4P5ZSMakqHs4AQWWsaAMrEaUIv6S6 PCIerSSx/j2te927/J53pNi/VfOVtbCUE5wkXSuDjsSi5OeqCunM8OCpRHK1gq3A7heI OiK1+nBfW4DFwIqi2oTiUIZpFPjTSuFCaC2vbAgDuAZsZJRMGsqiSu01A9L9ZAL9b8bG KLCzbwT3na2cmOJAafkCvO6bnt5cKCW3R7BgiOYUrKth3dLkC/nsdh/uS4joZW8Ctb9m kIpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718128405; x=1718733205; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jNNUQKkDrCnecnYCTT00rCZOmSlFkAs3089jG7rC2ac=; b=w50z7k7WN5u2+QAe6D+GwDPI/sYljX68e6l+uQA0HR0dyPlCdPY3b3lSlg87YVnYRQ CPooRdsYPcA7Q74zz7eRc1klQAoiemQxRdcIShMOdw3v5u1/RrfX8vZ5fAKpLTPHKvPU Uw3CG8khfsLRrJpVM6QqOR6B5Adva4R54fQ7hiBqxWLRga490WsygAaNmBSJJqnOILNI 8i3Ew3nTi68s8NYRBXqLxxy0jmKf1wKFhpYZTIg+Lde7J8Zaup8fCAWi+OH9ky6Ifbf4 8PwRR0AQ2yhfP2d5/G+RVKLWRv2YM6vJQ9050gWMxJFNPoXCsusqTgZBcR3rsCkTFveg 99Pw== X-Forwarded-Encrypted: i=1; AJvYcCV+PJtlQxC4VB+0Z3eUd1YQu5L2HRkq8PhI5r5qpCiRpedlxdp72R8KHBgJeaiABcgfILCSpcsS77Ofjf3xwzMVbEKOCu1DpTrc4SAr82RbmTroAa4= X-Gm-Message-State: AOJu0YwU/6S73Q5LzIIi7CGfk1755UVEnkL5ysP7SVYSxWphxGKH5pUs LBB01WNMNxELL+fO2zztjKYfT6AuoMdDiAxxpAhu5QzkHovbaemy1OPhxL/gxYH1qXnT0sr0QJx Auv/jJKwW7o69K31nHA== X-Google-Smtp-Source: AGHT+IEdZAfoZ4LDqjGnbpGpQjreFI4VULQxzKYqfTIseY0dz3/8fUXV0eI6QWfpdii1eUzbGB8RM1wSDTdOnXqx X-Received: from vdonnefort.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:2eea]) (user=vdonnefort job=sendgmr) by 2002:a05:600c:1c10:b0:41f:cec2:f853 with SMTP id 5b1f17b1804b1-42164a3bdeamr2236685e9.7.1718128404863; Tue, 11 Jun 2024 10:53:24 -0700 (PDT) Date: Tue, 11 Jun 2024 18:53:17 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240611175317.1220842-1-vdonnefort@google.com> Subject: [PATCH v2] 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-20240611_105330_449922_338C3F39 X-CRM114-Status: GOOD ( 11.31 ) 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 (Buffer states and ownership), after a producer has written into a buffer, it is "full" and now owned by the consumer. The producer won't be able to use that buffer, until the consumer hands it over with an invocation such as RX_RELEASE. It is clear in the following paragraph (Transfer of buffer ownership), that MEM_RETRIEVE_RESP is transferring the ownership from producer (in our case SPM) to consumer (hypervisor). RX_RELEASE is therefore mandatory here. 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 (see paragraph "Transmission of transaction descriptor in fragments"). 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 Reviewed-by: Sudeep Holla --- v1 -> v2: * Use FF-A paragraph names instead of numbers * Reword commit * Collect Reviewed-by base-commit: 6d69b6c12fce479fde7bc06f686212451688a102 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);