From nobody Wed Oct 8 14:16:05 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DBAD219E8F; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; cv=none; b=H3F+ELJ1p5L305axvcokJdsFJ0oET4Hfi0qlptdCzALoYhWRYNpG6pWHsx2Xp9NYMUykSi7SA2FZSIymkTVyJwXRGE4We/KZWYXRSCFeGPAOsktwZDpJ+hjdnXtXWuqN2xY26KtqrD32/kYnvyd+Zss9uoTUlOo3qTepiOUJ0U4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; c=relaxed/simple; bh=coAKO9TLhK8MTIgf77yLemsOevi3hPcTUAqXS91Y2b4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=etgycJVdTABlk9sGgfeZ5JE5a36d6hjxtjEnEDm7PiBLxCs8KxLbrqbWLL1e8+2pL+QA7MXJDa9ROHnnYJ+0qL13U1xC8o7TPU+5d9y03UAUE6gzw02Aj/5GsvMDaLJRoq4GGS55FMnKoiGIjeFyFckinsNf/qGGsp2jSZnzJmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aMSokcvQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aMSokcvQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id B1AECC4CEEF; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751008380; bh=coAKO9TLhK8MTIgf77yLemsOevi3hPcTUAqXS91Y2b4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=aMSokcvQEDDbicaE47gZ49QnF0uXTYVm4CWSuRcLVeWymOEjhiZt8dPtXRKA3XcLd 6qGEjckOuz5daWTK32ymxgmr/eieMpkAyq/62IZTmaNuP4A2KO6f3aTQiD6OJD9S5a Mz+GrM1E0dn4uo1uQ0rWOcs7zx+k1+VZsmZU2ZAQAh/9Tmp7xiHHBunARnSMrN7vHy RFwpb8+e5O+da88tdYT+5vGyyN6a3p8eulbgwCCbOGdrggkC5BTMPwmJMw2qX3Y5IH ExhSlLEPDGTzEz+iNktuyIOnTTYYAoDhCbFIrTLAlSt7u7XGrJ3pMfnJMAoOe2aIkD 3ap9+L8S/uR3w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A04B0C7EE2A; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) From: Per Larsen via B4 Relay Date: Fri, 27 Jun 2025 07:12:25 +0000 Subject: [PATCH v6 1/5] KVM: arm64: Correct return value on host version downgrade attempt Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250627-virtio-msg-ffa-v6-1-8c02fd94edac@google.com> References: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> In-Reply-To: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> To: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, ahomescu@google.com, armellel@google.com, arve@android.com, ayrton@google.com, qperret@google.com, sebastianene@google.com, qwandor@google.com, Per Larsen X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751008380; l=1399; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=Dl9KrxrUP4K0W3dgejUfrC3aK93wdcqeauIVLeuo9f0=; b=CJMbpH5xzZ8rgxvBzjxjYPckK18PzpFrnU6uC2FRNTu3OnErumBY2HVduPw9JDT/ouvd34G6C XcqlEB0JOb6CLjObh8ahU9dR6Q7P3NUIGLg+6Ox6xuSNDRMcR5b+riE X-Developer-Key: i=perlarsen@google.com; a=ed25519; pk=jjc/Ta4VmrLRmMoahP6d1mBcKzvWU+nsmdtYe2oS2kQ= X-Endpoint-Received: by B4 Relay for perlarsen@google.com/20250508 with auth_id=402 X-Original-From: Per Larsen Reply-To: perlarsen@google.com From: Per Larsen Once the hypervisor negotiates the FF-A version with the host, it should remain locked-in. However, it is possible to load FF-A as a module first supporting version 1.1 and then 1.0. Without this patch, the FF-A 1.0 driver will use 1.0 data structures to make calls which the hypervisor will incorrectly interpret as 1.1 data structures. With this patch, negotiation will fail. This patch does not change existing functionality in the case where a FF-A 1.2 driver is loaded after a 1.1 driver; the 1.2 driver will need to use 1.1 in order to proceed. Acked-by: Will Deacon Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/ffa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 3369dd0c4009f84ad3cf9481c747bdc57a162370..2c199d40811efb5bfae199c4a67= d8ae3d9307357 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -712,7 +712,10 @@ static void do_ffa_version(struct arm_smccc_res *res, =20 hyp_spin_lock(&version_lock); if (has_version_negotiated) { - res->a0 =3D hyp_ffa_version; + if (FFA_MINOR_VERSION(ffa_req_version) < FFA_MINOR_VERSION(hyp_ffa_versi= on)) + res->a0 =3D FFA_RET_NOT_SUPPORTED; + else + res->a0 =3D hyp_ffa_version; goto unlock; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 14:16:05 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A4221A458; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; cv=none; b=nOzo6D0lrDjOekeNNUI9IlbIpzF55+n5GRiDgVI5rO7w/ulSr+WCcm1aXU++yW7qXUTmUo2e4NPKe59kcrSQO74K2pEj7s83lhqMH855VBvZB6VzLDpuhh3SSvTPlWwpHk+t3bFpRc/X95rS+a2uNHjepaDIVYcY6FC5pS99tKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; c=relaxed/simple; bh=4/v+TikyZeTWZ8dsV52PaQfU7mB9qWRTO5L/udvwGt8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ju0AmYDg2ECQt4MVC5FOTrySR4FiLPPZIemn7uGrm+bB59BIU/9T9NXretK8/+O8HdekVOofAbyocjmlHe+GNAjX61uJT+YQPcxsfJsTcNYtoq6N1cyeaQu0r1i4EiQhL7sOLigyaPRK5f2tBw+yRoesPYpT18ZEQo7yer8hKdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AudEmu0Y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AudEmu0Y" Received: by smtp.kernel.org (Postfix) with ESMTPS id C01B3C4AF09; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751008380; bh=4/v+TikyZeTWZ8dsV52PaQfU7mB9qWRTO5L/udvwGt8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AudEmu0YCCTCkLyaPng5+0rVuEDFwYePtGvfY2MnKrW3Yk+rCFQ/Quq1wKBLTiBlg QIoF/TFcL2w2uOPLUpxRhjlq/wJQW615aFdnQ2xZv07nmEHkS0MulGev8cxkDDkiPt omBjujqbkRhai8Edvt6f/zhYTZajZ5k+a10z68i62SjGhAw34fs3NVWrh62sijisU3 n/oSA2GC0VKK8znHYm0W/uoIIKAvR4X4xGO4Rz0sOH2vnaXWBZ6k4g9bo+LEDYAsJC KhtLDfDqea9udepN2Y86k2xtZkyxAS/pFUCZplXx++u9vXW3EvfvgLcbmhT8ZRL7td QkM4gOK89wYuw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEAC3C7EE31; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) From: Per Larsen via B4 Relay Date: Fri, 27 Jun 2025 07:12:26 +0000 Subject: [PATCH v6 2/5] KVM: arm64: Use SMCCC 1.2 for FF-A initialization and in host handler Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250627-virtio-msg-ffa-v6-2-8c02fd94edac@google.com> References: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> In-Reply-To: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> To: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, ahomescu@google.com, armellel@google.com, arve@android.com, ayrton@google.com, qperret@google.com, sebastianene@google.com, qwandor@google.com, Per Larsen X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751008380; l=12757; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=o6mY15uz5FBX5hG5cYhKQuI0kzM+cB2A7BI4Z1uCA8A=; b=KqcdIp6YGhljdCNo+cJav3UZPTw3zfsn9Wah3XK2U5fCcS8v+4CaIqKJVm9swxqMGH5gz1PPs 9h6jRWnie9tD7dAgscXFl+M0lE7NFWQsmflJM0Nh0TTnhG12/qr5j6G X-Developer-Key: i=perlarsen@google.com; a=ed25519; pk=jjc/Ta4VmrLRmMoahP6d1mBcKzvWU+nsmdtYe2oS2kQ= X-Endpoint-Received: by B4 Relay for perlarsen@google.com/20250508 with auth_id=402 X-Original-From: Per Larsen Reply-To: perlarsen@google.com From: Per Larsen SMCCC 1.1 and prior allows four registers to be sent back as a result of an FF-A interface. SMCCC 1.2 increases the number of results that can be sent back to 8 and 16 for 32-bit and 64-bit SMC/HVCs respectively. FF-A 1.0 references SMCCC 1.2 (reference [4] on page xi) and FF-A 1.2 explicitly requires SMCCC 1.2 so it should be safe to use this version unconditionally. Moreover, it is simpler to implement FF-A features without having to worry about compatibility with SMCCC 1.1 and older. Update the FF-A initialization and host handler code to use SMCCC 1.2. Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/Makefile | 1 + arch/arm64/kvm/hyp/nvhe/ffa.c | 193 +++++++++++++++++++++++++----------= ---- 2 files changed, 125 insertions(+), 69 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Mak= efile index a76522d63c3e630795db5972a99abc3d24bc5e26..f859a8fb41a25effea1edd977be= f889423153399 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -27,6 +27,7 @@ hyp-obj-y :=3D timer-sr.o sysreg-sr.o debug-sr.o switch.o= tlb.o hyp-init.o host.o cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o ffa.o hyp-obj-y +=3D ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../en= try.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o +hyp-obj-y +=3D ../../../kernel/smccc-call.o hyp-obj-$(CONFIG_LIST_HARDENED) +=3D list_debug.o hyp-obj-y +=3D $(lib-objs) =20 diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 2c199d40811efb5bfae199c4a67d8ae3d9307357..65d241ba32403d014b43cc4ef4d= 5bf9693813809 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -71,36 +71,68 @@ static u32 hyp_ffa_version; static bool has_version_negotiated; static hyp_spinlock_t version_lock; =20 -static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno) +static void ffa_to_smccc_error(struct arm_smccc_1_2_regs *res, u64 ffa_err= no) { - *res =3D (struct arm_smccc_res) { + *res =3D (struct arm_smccc_1_2_regs) { .a0 =3D FFA_ERROR, .a2 =3D ffa_errno, }; } =20 -static void ffa_to_smccc_res_prop(struct arm_smccc_res *res, int ret, u64 = prop) +static void ffa_to_smccc_res_prop(struct arm_smccc_1_2_regs *res, int ret,= u64 prop) { if (ret =3D=3D FFA_RET_SUCCESS) { - *res =3D (struct arm_smccc_res) { .a0 =3D FFA_SUCCESS, - .a2 =3D prop }; + *res =3D (struct arm_smccc_1_2_regs) { .a0 =3D FFA_SUCCESS, + .a2 =3D prop }; } else { ffa_to_smccc_error(res, ret); } } =20 -static void ffa_to_smccc_res(struct arm_smccc_res *res, int ret) +static void ffa_to_smccc_res(struct arm_smccc_1_2_regs *res, int ret) { ffa_to_smccc_res_prop(res, ret, 0); } =20 static void ffa_set_retval(struct kvm_cpu_context *ctxt, - struct arm_smccc_res *res) + struct arm_smccc_1_2_regs *res) { + DECLARE_REG(u64, func_id, ctxt, 0); cpu_reg(ctxt, 0) =3D res->a0; cpu_reg(ctxt, 1) =3D res->a1; cpu_reg(ctxt, 2) =3D res->a2; cpu_reg(ctxt, 3) =3D res->a3; + cpu_reg(ctxt, 4) =3D res->a4; + cpu_reg(ctxt, 5) =3D res->a5; + cpu_reg(ctxt, 6) =3D res->a6; + cpu_reg(ctxt, 7) =3D res->a7; + + /* + * DEN0028C 2.6: SMC32/HVC32 call from aarch64 must preserve x8-x30. + * + * The most straightforward approach is to look at the function ID + * sent by the caller. However, the caller could send FFA_MSG_WAIT + * which is a 32-bit interface but the reply could very well be 64-bit + * such as FFA_FN64_MSG_SEND_DIRECT_REQ or FFA_MSG_SEND_DIRECT_REQ2. + * + * Instead, we could look at the function ID in the response (a0) but + * that doesn't work either as FFA_VERSION responses put the version + * number (or error code) in w0. + * + * Set x8-x17 iff response contains 64-bit function ID in a0. + */ + if (func_id !=3D FFA_VERSION && ARM_SMCCC_IS_64(res->a0)) { + cpu_reg(ctxt, 8) =3D res->a8; + cpu_reg(ctxt, 9) =3D res->a9; + cpu_reg(ctxt, 10) =3D res->a10; + cpu_reg(ctxt, 11) =3D res->a11; + cpu_reg(ctxt, 12) =3D res->a12; + cpu_reg(ctxt, 13) =3D res->a13; + cpu_reg(ctxt, 14) =3D res->a14; + cpu_reg(ctxt, 15) =3D res->a15; + cpu_reg(ctxt, 16) =3D res->a16; + cpu_reg(ctxt, 17) =3D res->a17; + } } =20 static bool is_ffa_call(u64 func_id) @@ -113,82 +145,92 @@ static bool is_ffa_call(u64 func_id) =20 static int ffa_map_hyp_buffers(u64 ffa_page_count) { - struct arm_smccc_res res; + struct arm_smccc_1_2_regs res; =20 - arm_smccc_1_1_smc(FFA_FN64_RXTX_MAP, - hyp_virt_to_phys(hyp_buffers.tx), - hyp_virt_to_phys(hyp_buffers.rx), - ffa_page_count, - 0, 0, 0, 0, - &res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_FN64_RXTX_MAP, + .a1 =3D hyp_virt_to_phys(hyp_buffers.tx), + .a2 =3D hyp_virt_to_phys(hyp_buffers.rx), + .a3 =3D ffa_page_count, + }, &res); =20 return res.a0 =3D=3D FFA_SUCCESS ? FFA_RET_SUCCESS : res.a2; } =20 static int ffa_unmap_hyp_buffers(void) { - struct arm_smccc_res res; + struct arm_smccc_1_2_regs res; =20 - arm_smccc_1_1_smc(FFA_RXTX_UNMAP, - HOST_FFA_ID, - 0, 0, 0, 0, 0, 0, - &res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_RXTX_UNMAP, + .a1 =3D HOST_FFA_ID, + }, &res); =20 return res.a0 =3D=3D FFA_SUCCESS ? FFA_RET_SUCCESS : res.a2; } =20 -static void ffa_mem_frag_tx(struct arm_smccc_res *res, u32 handle_lo, +static void ffa_mem_frag_tx(struct arm_smccc_1_2_regs *res, u32 handle_lo, u32 handle_hi, u32 fraglen, u32 endpoint_id) { - arm_smccc_1_1_smc(FFA_MEM_FRAG_TX, - handle_lo, handle_hi, fraglen, endpoint_id, - 0, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_MEM_FRAG_TX, + .a1 =3D handle_lo, + .a2 =3D handle_hi, + .a3 =3D fraglen, + .a4 =3D endpoint_id, + }, res); } =20 -static void ffa_mem_frag_rx(struct arm_smccc_res *res, u32 handle_lo, +static void ffa_mem_frag_rx(struct arm_smccc_1_2_regs *res, u32 handle_lo, u32 handle_hi, u32 fragoff) { - arm_smccc_1_1_smc(FFA_MEM_FRAG_RX, - handle_lo, handle_hi, fragoff, HOST_FFA_ID, - 0, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_MEM_FRAG_RX, + .a1 =3D handle_lo, + .a2 =3D handle_hi, + .a3 =3D fragoff, + .a4 =3D HOST_FFA_ID, + }, res); } =20 -static void ffa_mem_xfer(struct arm_smccc_res *res, u64 func_id, u32 len, +static void ffa_mem_xfer(struct arm_smccc_1_2_regs *res, u64 func_id, u32 = len, u32 fraglen) { - arm_smccc_1_1_smc(func_id, len, fraglen, - 0, 0, 0, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D func_id, + .a1 =3D len, + .a2 =3D fraglen, + }, res); } =20 -static void ffa_mem_reclaim(struct arm_smccc_res *res, u32 handle_lo, +static void ffa_mem_reclaim(struct arm_smccc_1_2_regs *res, u32 handle_lo, u32 handle_hi, u32 flags) { - arm_smccc_1_1_smc(FFA_MEM_RECLAIM, - handle_lo, handle_hi, flags, - 0, 0, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_MEM_RECLAIM, + .a1 =3D handle_lo, + .a2 =3D handle_hi, + .a3 =3D flags, + }, res); } =20 -static void ffa_retrieve_req(struct arm_smccc_res *res, u32 len) +static void ffa_retrieve_req(struct arm_smccc_1_2_regs *res, u32 len) { - arm_smccc_1_1_smc(FFA_FN64_MEM_RETRIEVE_REQ, - len, len, - 0, 0, 0, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_FN64_MEM_RETRIEVE_REQ, + .a1 =3D len, + .a2 =3D len, + }, res); } =20 -static void ffa_rx_release(struct arm_smccc_res *res) +static void ffa_rx_release(struct arm_smccc_1_2_regs *res) { - arm_smccc_1_1_smc(FFA_RX_RELEASE, - 0, 0, - 0, 0, 0, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_RX_RELEASE, + }, res); } =20 -static void do_ffa_rxtx_map(struct arm_smccc_res *res, +static void do_ffa_rxtx_map(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(phys_addr_t, tx, ctxt, 1); @@ -267,7 +309,7 @@ static void do_ffa_rxtx_map(struct arm_smccc_res *res, goto out_unlock; } =20 -static void do_ffa_rxtx_unmap(struct arm_smccc_res *res, +static void do_ffa_rxtx_unmap(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, id, ctxt, 1); @@ -368,7 +410,7 @@ static int ffa_host_unshare_ranges(struct ffa_mem_regio= n_addr_range *ranges, return ret; } =20 -static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, +static void do_ffa_mem_frag_tx(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, handle_lo, ctxt, 1); @@ -427,7 +469,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *re= s, } =20 static void __do_ffa_mem_xfer(const u64 func_id, - struct arm_smccc_res *res, + struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, len, ctxt, 1); @@ -521,7 +563,7 @@ static void __do_ffa_mem_xfer(const u64 func_id, __do_ffa_mem_xfer((fid), (res), (ctxt)); \ } while (0); =20 -static void do_ffa_mem_reclaim(struct arm_smccc_res *res, +static void do_ffa_mem_reclaim(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, handle_lo, ctxt, 1); @@ -634,7 +676,7 @@ static bool ffa_call_supported(u64 func_id) return true; } =20 -static bool do_ffa_features(struct arm_smccc_res *res, +static bool do_ffa_features(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, id, ctxt, 1); @@ -666,17 +708,21 @@ static bool do_ffa_features(struct arm_smccc_res *res, static int hyp_ffa_post_init(void) { size_t min_rxtx_sz; - struct arm_smccc_res res; + struct arm_smccc_1_2_regs res; =20 - arm_smccc_1_1_smc(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs){ + .a0 =3D FFA_ID_GET, + }, &res); if (res.a0 !=3D FFA_SUCCESS) return -EOPNOTSUPP; =20 if (res.a2 !=3D HOST_FFA_ID) return -EINVAL; =20 - arm_smccc_1_1_smc(FFA_FEATURES, FFA_FN64_RXTX_MAP, - 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs){ + .a0 =3D FFA_FEATURES, + .a1 =3D FFA_FN64_RXTX_MAP, + }, &res); if (res.a0 !=3D FFA_SUCCESS) return -EOPNOTSUPP; =20 @@ -700,7 +746,7 @@ static int hyp_ffa_post_init(void) return 0; } =20 -static void do_ffa_version(struct arm_smccc_res *res, +static void do_ffa_version(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, ffa_req_version, ctxt, 1); @@ -724,9 +770,10 @@ static void do_ffa_version(struct arm_smccc_res *res, * first if TEE supports it. */ if (FFA_MINOR_VERSION(ffa_req_version) < FFA_MINOR_VERSION(hyp_ffa_versio= n)) { - arm_smccc_1_1_smc(FFA_VERSION, ffa_req_version, 0, - 0, 0, 0, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_VERSION, + .a1 =3D ffa_req_version, + }, res); if (res->a0 =3D=3D FFA_RET_NOT_SUPPORTED) goto unlock; =20 @@ -743,7 +790,7 @@ static void do_ffa_version(struct arm_smccc_res *res, hyp_spin_unlock(&version_lock); } =20 -static void do_ffa_part_get(struct arm_smccc_res *res, +static void do_ffa_part_get(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, uuid0, ctxt, 1); @@ -759,9 +806,14 @@ static void do_ffa_part_get(struct arm_smccc_res *res, goto out_unlock; } =20 - arm_smccc_1_1_smc(FFA_PARTITION_INFO_GET, uuid0, uuid1, - uuid2, uuid3, flags, 0, 0, - res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_PARTITION_INFO_GET, + .a1 =3D uuid0, + .a2 =3D uuid1, + .a3 =3D uuid2, + .a4 =3D uuid3, + .a5 =3D flags, + }, res); =20 if (res->a0 !=3D FFA_SUCCESS) goto out_unlock; @@ -794,7 +846,7 @@ static void do_ffa_part_get(struct arm_smccc_res *res, =20 bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) { - struct arm_smccc_res res; + struct arm_smccc_1_2_regs res; =20 /* * There's no way we can tell what a non-standard SMC call might @@ -863,13 +915,16 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *hos= t_ctxt, u32 func_id) =20 int hyp_ffa_init(void *pages) { - struct arm_smccc_res res; + struct arm_smccc_1_2_regs res; void *tx, *rx; =20 if (kvm_host_psci_config.smccc_version < ARM_SMCCC_VERSION_1_2) return 0; =20 - arm_smccc_1_1_smc(FFA_VERSION, FFA_VERSION_1_1, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_VERSION, + .a1 =3D FFA_VERSION_1_1, + }, &res); if (res.a0 =3D=3D FFA_RET_NOT_SUPPORTED) return 0; =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 14:16:05 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31AFB21ABBD; Fri, 27 Jun 2025 07:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; cv=none; b=IVr8f/oRT3rMXHqluGb1UNsigZAp68uTxWGLx5Uoz/1lQ1yxNXkr6czlQFyh8CMz9POgqkxoEi3zmQIt08XxNiqMloE+28HAymTurkii6gW0/KfWWAMwddTndrPqf1PGvF8PreR4lS4Ef+enMjAMyhxkt5XZSJ3qMgWYABN48w4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; c=relaxed/simple; bh=Hy1s1+7DoBD3FHcZVBMxtjRrk13K4R0eTQWvOyyFT0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E/YUfCZza+NpBgc7yxO1zEvnQqeBTlN8oyo44WIo3k8fc6HRO+A8DwW1ah0b5zFw8PIxrzx5jQgLQfwfc9ov7G6Dh8WubOrT1TIk/oydT5VHG1XsKn8kOA2j9kOqJ64Xrp3WQ02+jJ2cl+TgwMz8uldzvwwT9PvGqKB7oTrwAaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aJuiG4YM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aJuiG4YM" Received: by smtp.kernel.org (Postfix) with ESMTPS id C7D0CC4CEF0; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751008380; bh=Hy1s1+7DoBD3FHcZVBMxtjRrk13K4R0eTQWvOyyFT0s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=aJuiG4YMBOnUYy6Bf7lJDa7qxDSRvmdgAKOn4B7iplx2Fy+oduR2dEnRtg+qJUpxi kaVMIC+9HFzEzfylCWBrOTqHyp5TIbPCQQ8oE9GU+TYpiQSNMS6GyUsiPYOfQDYjbQ epjXvfmu/m+6gxl090tMsN9F501nGuh0V0bN2y7Pqf3BqiaPZMvGLLH4FfwWIN8tJ4 oH0G0lARu2ynDmTwMWyo+07hPqfMFUkKvIv9l2dlSE8T0hL4+XVn3zjFfHpew6NOre yRAusC8f76bYf2s1No8jrwfQm4s31u6sSnPumP2rdLWGsZtLRYum9YqBf1F4X6rYhm bz3EEldMOyzNg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC77BC7EE3A; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) From: Per Larsen via B4 Relay Date: Fri, 27 Jun 2025 07:12:27 +0000 Subject: [PATCH v6 3/5] KVM: arm64: Mark FFA_NOTIFICATION_* calls as unsupported Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250627-virtio-msg-ffa-v6-3-8c02fd94edac@google.com> References: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> In-Reply-To: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> To: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, ahomescu@google.com, armellel@google.com, arve@android.com, ayrton@google.com, qperret@google.com, sebastianene@google.com, qwandor@google.com, Per Larsen X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751008380; l=1008; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=r9z6my3JAUeiJyyoAaVHQBDOJAVkijitymt3p9hEt6g=; b=kSubU6hZxrun/Kj2M/soW1+JuFCU4uyHFxW4AbQLs9mrWTMeJ9SV9po1gQ77fETVLFj6YN6+5 gNhinik24APBQkzgpGRWnGeITmQ8tPmxwcO08HGPkgg3laRlxti4t9g X-Developer-Key: i=perlarsen@google.com; a=ed25519; pk=jjc/Ta4VmrLRmMoahP6d1mBcKzvWU+nsmdtYe2oS2kQ= X-Endpoint-Received: by B4 Relay for perlarsen@google.com/20250508 with auth_id=402 X-Original-From: Per Larsen Reply-To: perlarsen@google.com From: Per Larsen Prevent FFA_NOTIFICATION_* interfaces from being passed through to TZ. Acked-by: Will Deacon Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/ffa.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 65d241ba32403d014b43cc4ef4d5bf9693813809..5fd6474d96ae4b90d99796ee81b= b36373219afc4 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -670,6 +670,14 @@ static bool ffa_call_supported(u64 func_id) case FFA_RXTX_MAP: case FFA_MEM_DONATE: case FFA_MEM_RETRIEVE_REQ: + /* Optional notification interfaces added in FF-A 1.1 */ + case FFA_NOTIFICATION_BITMAP_CREATE: + case FFA_NOTIFICATION_BITMAP_DESTROY: + case FFA_NOTIFICATION_BIND: + case FFA_NOTIFICATION_UNBIND: + case FFA_NOTIFICATION_SET: + case FFA_NOTIFICATION_GET: + case FFA_NOTIFICATION_INFO_GET: return false; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 14:16:05 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A9E21ABB7; Fri, 27 Jun 2025 07:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; cv=none; b=LyCoftCGDnDa0YpMKHaQ+AuPmRc22G8RFKI0yAkK90VqFcQWkAsvc9d+YsFQ4aHrBCox1TaF3xjg6NQ0I7baFZooALVQiwHiehrQ0kg3jHANKQvyEyOGoLWBU3iC0Wzcm/7xxF4T4L6pkx1ya2cR5vlg5X/OE01/xJEtXIiR8JM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; c=relaxed/simple; bh=5aPHBqgghaNXr+qmy8IWnHIq6Bg8C3t/68W+2vw4Hqc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KjnNf/4gS22eSIzpgbVkQmRHlebczUwbK2LOdPECvMko0ATKiafwxO2Xa/JAtWV0YcIq3iFd5HBSaF1DHuoVIZtWZlgLeIXj9j0si+qdojo6aOHZN1PCdFLHSjB0koJ04TremEfw1lS+5j8jtZ8YKrB8jifkSm4Np2SybwtD6Rk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nb704Dww; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Nb704Dww" Received: by smtp.kernel.org (Postfix) with ESMTPS id D61CCC4CEF5; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751008380; bh=5aPHBqgghaNXr+qmy8IWnHIq6Bg8C3t/68W+2vw4Hqc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Nb704Dwwwr1W+SXUmHskF5rcaXk7HWza396g3R3+cyEsZnDlWVxduxXPwVOBWGH7W lg7yDGFxwPlcPMUy5m0xeb23IX2H41ZkxbdE4DixuRKyrfHUqV2dmsnDoRsrDj6p8/ qj1vJEIZvstHFGvGKxb1cJqqpqLhcrPP6NBGNuDaC0UYPYv0Ivkjp3FC375Rep0zL9 FUkuiCYZpmh5vkcfU1dXyrbyfxa/3Q44YsMLS9hAHfpaHCbHX02WF3A3pGpBDc4UiI MWgQ0i3uK0H7P+g+pq6zUN4YBBvBgOEtnG4PV2FAM3I8HO4VNSKxQaTv1fVVOA75Wo AzWaWB1qXBS4w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9823C7EE39; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) From: Per Larsen via B4 Relay Date: Fri, 27 Jun 2025 07:12:28 +0000 Subject: [PATCH v6 4/5] KVM: arm64: Bump the supported version of FF-A to 1.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250627-virtio-msg-ffa-v6-4-8c02fd94edac@google.com> References: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> In-Reply-To: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> To: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, ahomescu@google.com, armellel@google.com, arve@android.com, ayrton@google.com, qperret@google.com, sebastianene@google.com, qwandor@google.com, Per Larsen X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751008380; l=2907; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=7rEMvl8SoHWGrwsNRCeFHM4pJ2DEx095GGBAAYP+euA=; b=QnK7PyFg+Sp9K6Dvzow+2ecO2qkpCoOzOMEHl/0e83G3yL4lNUY+S4v5SH+Ij7bEHDL4HwwGk x3mbjSjVhOkC41qM06xylFeNwkfA+dNHlMPJqkD9QyOCWcBsxd9IFIY X-Developer-Key: i=perlarsen@google.com; a=ed25519; pk=jjc/Ta4VmrLRmMoahP6d1mBcKzvWU+nsmdtYe2oS2kQ= X-Endpoint-Received: by B4 Relay for perlarsen@google.com/20250508 with auth_id=402 X-Original-From: Per Larsen Reply-To: perlarsen@google.com From: Per Larsen FF-A version 1.2 introduces the DIRECT_REQ2 ABI. Bump the FF-A version preferred by the hypervisor as a precursor to implementing the 1.2-only FFA_MSG_SEND_DIRECT_REQ2 and FFA_MSG_SEND_RESP2 messaging interfaces. We must also use SMCCC 1.2 for 64-bit SMCs if hypervisor negotiated FF-A 1.2, so ffa_set_retval is updated and a new function to call 64-bit smcs using SMCCC 1.2 with fallback to SMCCC 1.1 is introduced. Update ffa_call_supported to mark FF-A 1.2 interfaces as unsupported lest they get forwarded. Co-developed-by: Ayrton Munoz Signed-off-by: Ayrton Munoz Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/ffa.c | 14 ++++++++++---- include/linux/arm_ffa.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 5fd6474d96ae4b90d99796ee81bb36373219afc4..d543d1f5ddd62fb15f8d39f4ff7= d5bb0006da4a1 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -678,6 +678,12 @@ static bool ffa_call_supported(u64 func_id) case FFA_NOTIFICATION_SET: case FFA_NOTIFICATION_GET: case FFA_NOTIFICATION_INFO_GET: + /* Unimplemented interfaces added in FF-A 1.2 */ + case FFA_MSG_SEND_DIRECT_REQ2: + case FFA_MSG_SEND_DIRECT_RESP2: + case FFA_CONSOLE_LOG: + case FFA_PARTITION_INFO_GET_REGS: + case FFA_EL3_INTR_HANDLE: return false; } =20 @@ -734,7 +740,7 @@ static int hyp_ffa_post_init(void) if (res.a0 !=3D FFA_SUCCESS) return -EOPNOTSUPP; =20 - switch (res.a2) { + switch (res.a2 & FFA_FEAT_RXTX_MIN_SZ_MASK) { case FFA_FEAT_RXTX_MIN_SZ_4K: min_rxtx_sz =3D SZ_4K; break; @@ -931,7 +937,7 @@ int hyp_ffa_init(void *pages) =20 arm_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { .a0 =3D FFA_VERSION, - .a1 =3D FFA_VERSION_1_1, + .a1 =3D FFA_VERSION_1_2, }, &res); if (res.a0 =3D=3D FFA_RET_NOT_SUPPORTED) return 0; @@ -952,10 +958,10 @@ int hyp_ffa_init(void *pages) if (FFA_MAJOR_VERSION(res.a0) !=3D 1) return -EOPNOTSUPP; =20 - if (FFA_MINOR_VERSION(res.a0) < FFA_MINOR_VERSION(FFA_VERSION_1_1)) + if (FFA_MINOR_VERSION(res.a0) < FFA_MINOR_VERSION(FFA_VERSION_1_2)) hyp_ffa_version =3D res.a0; else - hyp_ffa_version =3D FFA_VERSION_1_1; + hyp_ffa_version =3D FFA_VERSION_1_2; =20 tx =3D pages; pages +=3D KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE; diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 5bded24dc24fea8cdcbe42bf79c7c025c3fa5f4b..c0dd6183d956043192114a522b7= eef465e7078ac 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -128,6 +128,7 @@ #define FFA_FEAT_RXTX_MIN_SZ_4K 0 #define FFA_FEAT_RXTX_MIN_SZ_64K 1 #define FFA_FEAT_RXTX_MIN_SZ_16K 2 +#define FFA_FEAT_RXTX_MIN_SZ_MASK 3 =20 /* FFA Bus/Device/Driver related */ struct ffa_device { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 14:16:05 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 702F221C9E5; Fri, 27 Jun 2025 07:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; cv=none; b=VcFkuWY6DSVJxx37haabm25WCkC1RJVYGM0rpdt8S5Oq/c1hC9Ma2fG00DcI/qvDav0K9j+bY4QajMvXdMOAOHlVFgeb/2ZI5ISaJR6n2jDR5+atzguvhAxISdv8nZShOWQKdOzKFqwjBSMl9ZUiqJetBTSxJfWHh3wAqlVaRGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751008381; c=relaxed/simple; bh=klh+xDRcULbooF8MFi5xLowZY/xbmuqnM1SLK8gC+H0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V9MURxLzNjgxBDO9jclaD/v5IAWBDM4GoEEUcDGuUcHtoclSdS86F+cnS+LiEIokb+cejh3MzFDZLnU5kOI/9BIAFIPWOcea2FFNIkUyMX91sgX+ZWIxpNs2vuHe+1mzpOX0WYRWpqiX1Adx21G4x91VLwaqNoC7JiYT6aFkwAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IfAJPJ8S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IfAJPJ8S" Received: by smtp.kernel.org (Postfix) with ESMTPS id E310FC4CEF4; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751008380; bh=klh+xDRcULbooF8MFi5xLowZY/xbmuqnM1SLK8gC+H0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=IfAJPJ8SMCtd/QKuPwxsR3R5mn/1SvpH24+BqWVziK5kvI/Pj7RGNmR9dxxc7qWFS 6PFbbuI5I9xyJWEZbz7hh1MFR1Wm7NOr+nswUf8r3VobmXEdh8eIGYerwl53u3PEVg +AcVQasenUj4lJn048F3+adGJHeaI6fz2+J+DwtEwkdtKi+sCpmaaDBoQ2brQ54xQO F4k7ijn+8/uL1+SW/cgH3RNqLIsJPQAEOouIym/cusccU+5VbGMOZFV41UrOTt50gR pIRO4vN5gwzqsri57CETDLfhYlMS3bZpJNz30gJpuXXPOZMpwb3usVAHdUASO8jK5C 67TQXt8c8Tagg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9CBCC77B7F; Fri, 27 Jun 2025 07:13:00 +0000 (UTC) From: Per Larsen via B4 Relay Date: Fri, 27 Jun 2025 07:12:29 +0000 Subject: [PATCH v6 5/5] KVM: arm64: Support FFA_MSG_SEND_DIRECT_REQ2 in host handler Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250627-virtio-msg-ffa-v6-5-8c02fd94edac@google.com> References: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> In-Reply-To: <20250627-virtio-msg-ffa-v6-0-8c02fd94edac@google.com> To: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, ahomescu@google.com, armellel@google.com, arve@android.com, ayrton@google.com, qperret@google.com, sebastianene@google.com, qwandor@google.com, Per Larsen X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751008380; l=2999; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=Hltr6esYXys/fifuX4LJaE69K+4zBEQKpm9B+c1zcxQ=; b=3eyayw173eIS/U1YOT+pKH7Ed66MiRS9vDdxdwYsb5K9W5IEqrqub9hlfkRlkmLBHCm4nZ49W oCXO/uYF60hCMYXVCEeNHIw3tJZYAAeamsu38z42BsD5auTmlovJ35E X-Developer-Key: i=perlarsen@google.com; a=ed25519; pk=jjc/Ta4VmrLRmMoahP6d1mBcKzvWU+nsmdtYe2oS2kQ= X-Endpoint-Received: by B4 Relay for perlarsen@google.com/20250508 with auth_id=402 X-Original-From: Per Larsen Reply-To: perlarsen@google.com From: Per Larsen FF-A 1.2 adds the DIRECT_REQ2 messaging interface which is similar to the existing FFA_MSG_SEND_DIRECT_{REQ,RESP} functions except that it uses the SMC calling convention v1.2 which allows calls to use x4-x17 as argument and return registers. Add support for FFA_MSG_SEND_DIRECT_REQ2 in the host ffa handler. Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/ffa.c | 24 +++++++++++++++++++++++- include/linux/arm_ffa.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index d543d1f5ddd62fb15f8d39f4ff7d5bb0006da4a1..348c5aa93ab8ade2b26fc86ed21= 69d801784a892 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -679,7 +679,6 @@ static bool ffa_call_supported(u64 func_id) case FFA_NOTIFICATION_GET: case FFA_NOTIFICATION_INFO_GET: /* Unimplemented interfaces added in FF-A 1.2 */ - case FFA_MSG_SEND_DIRECT_REQ2: case FFA_MSG_SEND_DIRECT_RESP2: case FFA_CONSOLE_LOG: case FFA_PARTITION_INFO_GET_REGS: @@ -858,6 +857,22 @@ static void do_ffa_part_get(struct arm_smccc_1_2_regs = *res, hyp_spin_unlock(&host_buffers.lock); } =20 +static void do_ffa_direct_msg2(struct arm_smccc_1_2_regs *regs, + struct kvm_cpu_context *ctxt, + u64 vm_handle) +{ + DECLARE_REG(u32, endp, ctxt, 1); + + struct arm_smccc_1_2_regs *args =3D (void *)&ctxt->regs.regs[0]; + + if (FIELD_GET(FFA_SRC_ENDPOINT_MASK, endp) !=3D vm_handle) { + ffa_to_smccc_error(regs, FFA_RET_INVALID_PARAMETERS); + return; + } + + arm_smccc_1_2_smc(args, regs); +} + bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) { struct arm_smccc_1_2_regs res; @@ -916,11 +931,18 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *hos= t_ctxt, u32 func_id) case FFA_PARTITION_INFO_GET: do_ffa_part_get(&res, host_ctxt); goto out_handled; + case FFA_MSG_SEND_DIRECT_REQ2: + if (hyp_ffa_version >=3D FFA_VERSION_1_2) { + do_ffa_direct_msg2(&res, host_ctxt, HOST_FFA_ID); + goto out_handled; + } + goto out_not_supported; } =20 if (ffa_call_supported(func_id)) return false; /* Pass through */ =20 +out_not_supported: ffa_to_smccc_error(&res, FFA_RET_NOT_SUPPORTED); out_handled: ffa_set_retval(host_ctxt, &res); diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index c0dd6183d956043192114a522b7eef465e7078ac..82a35a3b22de426f7e9a8894e76= fdf1e933b3d6b 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -269,6 +269,8 @@ bool ffa_partition_check_property(struct ffa_device *de= v, u32 property) (ffa_partition_check_property(dev, FFA_PARTITION_DIRECT_REQ2_RECV) && \ !dev->mode_32bit) =20 +#define FFA_SRC_ENDPOINT_MASK GENMASK(31, 16) + /* For use with FFA_MSG_SEND_DIRECT_{REQ,RESP} which pass data via registe= rs */ struct ffa_send_direct_data { unsigned long data0; /* w3/x3 */ --=20 2.50.0.727.gbf7dc18ff4-goog