From nobody Mon Dec 15 01:34:17 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 BDF5B2FE386; Tue, 1 Jul 2025 22:06:47 +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=1751407607; cv=none; b=Q9xb0eVSdBZ9Ja+ghtPVq0eOaKjs3Ex/6QU0isieniU7YWslbjEaGpKEn56+5l1LN0VHYGb+wRfqH31Y4Ml/VtUaYoQzPVVmrFXEXOUKhfsZGTNBs1bqY2yTnubThyS+NqrY0kzfPJmoMXquuia+3w7BiDYIowwTNlLLInQDS48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751407607; c=relaxed/simple; bh=coAKO9TLhK8MTIgf77yLemsOevi3hPcTUAqXS91Y2b4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qLeNxqTHDJDik8BKW+gIkp0C146jGw6sXc4ixJEtXneotUaJ86IhUo9777+lrW/x6zjra7mW82F1Z8FzWoXal0GTkMb5Rl8BYaey8lhG/7T4bOtuO7Z5OZB9j6C7Z7lWD5pFz0eRRxC4cCQ1DOwFQgPmMb7+Qqdk7eI3P0Hdufs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ou9N1VQW; 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="ou9N1VQW" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6688AC4CEF3; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751407607; bh=coAKO9TLhK8MTIgf77yLemsOevi3hPcTUAqXS91Y2b4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ou9N1VQWEpWqTJgnCNRhMvXIzHw+LyYwPmDO37rQ0wuMJYADInvEcSP7RvEEPV/Hv mVqafQKIUYfwd+DySyV4CkmOKFysZAppyNhCCyaW9eDiZRCLpJhfgKSPqrYYhfYsTR /7BVBY/MaGyayNxtNwxudldX73TfASMmOL6567TXwhrtYAOsfHvQWnwBMAFNdSfiKK AMWosxvMUEo6svrC0FM8qEiNOB11a6HiTt2O/s+26rztwzSVpZP618MK8p9vbU4OP+ Om5/EQ8pF8Q+ZsvRT9xtmLam1uNeiEwWs4onSDsdnQ7/i9G80Me0aAUuQ+dF49n2B2 0caV0cTO9jN4A== 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 54480C8303D; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) From: Per Larsen via B4 Relay Date: Tue, 01 Jul 2025 22:06:34 +0000 Subject: [PATCH v7 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: <20250701-virtio-msg-ffa-v7-1-995afc3d385e@google.com> References: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@google.com> In-Reply-To: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@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=1751407606; l=1399; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=Dl9KrxrUP4K0W3dgejUfrC3aK93wdcqeauIVLeuo9f0=; b=5+AIZdXIIvjP+RFQX4/gsaepjpoFaUB3whIL6rjGFeBYlFyAuLRkoOvgzhSwRQhsyy388yIym 3qKnZpyTKsYCmPGQlh0pIPCa2Xcoa7Q6uUDbGY9Mzwew3tvIgMN7r6E 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 Mon Dec 15 01:34:17 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 BDFCA306DA1; Tue, 1 Jul 2025 22:06:47 +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=1751407607; cv=none; b=gInjQBsXGx2khX4is4ppRPKJ0wnHlA3Sxws6N6Uxg6sDnyckihKO8zA9ruJAgunY63+7T16r8F/ZeMnDlskzgyHRpNlGJ7CtQTfMg9/uOKPYMPpSzQppUCuSHVzyL4LqCtiz7NyD25D4ACHKXqPVuh/1axWxttutGOEgs2e14zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751407607; 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=FmFQtXadwc0b+s/DhZZfW6t7WWLqxHwdoI9L3TRIIKO0+b8QVluuVtSeXXsAz8VDg+fTj+03YJnfBGw5LDbfJ75r66EaXc5ckPrtR6JpfJUBsxA7GYNpDvAJYXYDEdNxMRQ6Ku8AplLhIm953SIzew9tEhWU+iO8LQIIxkLUXQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e3xkc+56; 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="e3xkc+56" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7457CC4CEF4; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751407607; bh=4/v+TikyZeTWZ8dsV52PaQfU7mB9qWRTO5L/udvwGt8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=e3xkc+563OqXVkCMwu2fMxf7QJtluJFxsHz6mPlJgRmH/IxvTdQR5tYV1UTAzGm7s LUC+3LrB2iGkrphu2uRq7rRJzCCtq9rKAUe4ts1Ski7xZ4QxJIOm2VKHfJT0xE1XZ+ VG1crPjvGb3E4sEt0RINV4vu3G8ewHQhGU7Gi+4aR/ezRriMS4aL4FvKWNBZ9NZHz3 oFzs9GcjDEbeeM7aSSwFIJILkvFG0odGy3IT2lIRrY7HYcA/lEiiTndjSNzNYVhRcf y39u7NMD3f16opCyLRNYFjkk9fsW2RX933FfPOOvAX9PQUQLgv26CJqDOWvCJAvg8X H93uQ/UOSsNNg== 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 63C4BC83F03; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) From: Per Larsen via B4 Relay Date: Tue, 01 Jul 2025 22:06:35 +0000 Subject: [PATCH v7 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: <20250701-virtio-msg-ffa-v7-2-995afc3d385e@google.com> References: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@google.com> In-Reply-To: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@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=1751407606; l=12757; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=o6mY15uz5FBX5hG5cYhKQuI0kzM+cB2A7BI4Z1uCA8A=; b=mcGPSy0qTQGnn9qLdg6UFOCsre/3QuIflJb7RmvLMjbZXUnEbVbh4PNYS/NcUGeY1cVhf+9Ao dIwcBV5i547CMYIFH9jcpBc/sAaaKJHC8zznQMhAjW78wXOjGss1+JS 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 Mon Dec 15 01:34:17 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 DC253306DA4; Tue, 1 Jul 2025 22:06:47 +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=1751407608; cv=none; b=QqhtAWylhOYocFC2K4mhLxY38I9tDlStQ/6hwITfM7dLaHZY14v2tHROO73JBvHyGFeomqsgx64D4gVeJmQS7YgAvNaBI+bN+pJVg/n+rAi4iFbB7NCVbp7L9tyDmBDGnY1ZuY/kvzBERz1j5+5DZM7H4Ej4HbyjiMuMNfUBbn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751407608; c=relaxed/simple; bh=Hy1s1+7DoBD3FHcZVBMxtjRrk13K4R0eTQWvOyyFT0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LBD30tzUrs5Id57oQFq33Zo3zWbr9e5IlX2th84Qa3MPxOM6gYKJ3ByLjkOZGG3Wlu7GOQTa/mUZHeKNLxka5t8z5/duFoTYfBKwK8QkIDmSuygsICxzhK0x5yG8inyZp0ifipcElgnQqsVGsvQ9qRku5E8gfpP+3tLthRyhLDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UEShh4f7; 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="UEShh4f7" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7C2A3C4CEF1; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751407607; bh=Hy1s1+7DoBD3FHcZVBMxtjRrk13K4R0eTQWvOyyFT0s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=UEShh4f7Yd6TXm/z3mtUsRgFdiLxNCQESiIRdkKNSU9aojoVlGwKkLSlSVhhkkR6D qI/oma+AaYDzEvc1iSQmfuTO8pJ9OOhCyR2CdXC3IBtfUn88AhyufuzhlPqBYXks/f Jn/B9hrxCmzLsT8rQLuRxW+nkeHw+hFEO9R2tE61zgqluRAuCPv4pX/SyZG/DsjY4m 3dpWbNCB6M8X5zucdjrHYUBPayGYPx3GsIKK5ctxUVUo4mlcdkGVRlKLRkUJAQGAX6 4g80jPXt4OwKVH1rHHQM75Y01NGjYjvNKISgVnU1O2hNPKsIB6klHpQC4odeKyXrnk 4Jzx9GVgQBCjg== 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 71AD5C83038; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) From: Per Larsen via B4 Relay Date: Tue, 01 Jul 2025 22:06:36 +0000 Subject: [PATCH v7 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: <20250701-virtio-msg-ffa-v7-3-995afc3d385e@google.com> References: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@google.com> In-Reply-To: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@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=1751407606; l=1008; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=r9z6my3JAUeiJyyoAaVHQBDOJAVkijitymt3p9hEt6g=; b=GhtpikNRmTzy093EmL+2jycBtO99E2KOmwD5uhU5MgIsakYL1LIJrYOh35MHfpMxGs4qbniZ+ iVGc03BtiMoDmu0KjAYsVfKexjQTzOHor1q82VSfde2DuEpyULX5jYT 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 Mon Dec 15 01:34:17 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 DC1E6306DA3; Tue, 1 Jul 2025 22:06:47 +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=1751407608; cv=none; b=Nr/V4F11QJhraV+BHV/tRGdXreLg2fbgWVnj+yo6aRz+tDaIOmnbdx/nDQJWJc1ZPeNSXXOcIAq8GqZwf+gbqhiryo2lmnuuQc0pTu3U7bGV6hMK6OCTXWvtOkGINKllF/5lFe/iZXJ6tCbdjWh8c1eFeyJ+0sYJSPep7hq/JVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751407608; c=relaxed/simple; bh=v87fKIepQDax6CCtv55KhnspaODxyLj4B/eE3f1J14M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lwW54EsYvV+27fUzYKEJHOzjI6Jf1pBkrse1wfzcQubJInYcwwJAkLi37kvk80J6m9VtCPgR5bZQLGICaRW/oCIBfEsjdPK85qxt7HhluUhsENEv60/nmnVo6vG08g9UsYGrWNnE4CxjefdoTjf4gXzAWuWhzl/hMO/TbrD4fMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lqe9fi5X; 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="Lqe9fi5X" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8B7FFC4CEF8; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751407607; bh=v87fKIepQDax6CCtv55KhnspaODxyLj4B/eE3f1J14M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Lqe9fi5XWxmmhryJ5inzf8n2TuD6rbR1mcOsSMljGsNLDu2hLXR0qutNDAP02n5tW z4cF3pFnm9sOfpNU6JMEyQFVSMMuzz1e6q34JzZLVBhXcNOcpnXNCUBxeIXECe+JZg ncqnywamLg+diHjzkM3JzgcIiaMjHXRt/UynHtX1GqSS3sz3/yZSqd2BLVht2Pvoby zFPf7LZYU8ftPbQCQzpQBUetsrhy5IjYmRlpdz2rNTUbupoPl8yGmTc2jP8XnSmyJ+ ma/2UbLuGWmFOfuNKSAQgGrWAFV87kVdZO1/Z3EYvw2kMxCKNzEDiCfUITA585/iVn rRo1U4WhJjRFw== 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 8059AC83F05; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) From: Per Larsen via B4 Relay Date: Tue, 01 Jul 2025 22:06:37 +0000 Subject: [PATCH v7 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: <20250701-virtio-msg-ffa-v7-4-995afc3d385e@google.com> References: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@google.com> In-Reply-To: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@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=1751407606; l=3237; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=4he4cZtemMwoa6JfwKc3JGNrR9f7OHS22E7VbF8a/Pk=; b=FHdZmZrWvbVBeML2mF2oAPjSDUHvOh77fpyLimRhHGC+TfxAYg0SbdOuEcnTdrJ6AmYBOj3li 4v/V9JT9YuICvZ7Dy9TgMkHdgI1HJlMlHNuN/2vhnlHAtYpSE1OTrkD 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 | 18 ++++++++++++++---- include/linux/arm_ffa.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 5fd6474d96ae4b90d99796ee81bb36373219afc4..79d834120a3f3d26e17e9170c60= 012b60c6f5a5e 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -678,6 +678,13 @@ static bool ffa_call_supported(u64 func_id) case FFA_NOTIFICATION_SET: case FFA_NOTIFICATION_GET: case FFA_NOTIFICATION_INFO_GET: + /* Optional interfaces added in FF-A 1.2 */ + case FFA_MSG_SEND_DIRECT_REQ2: /* Optional per 7.5.1 */ + case FFA_MSG_SEND_DIRECT_RESP2: /* Optional per 7.5.1 */ + case FFA_CONSOLE_LOG: /* Optional per 13.1: not in Table 13.1 */ + case FFA_PARTITION_INFO_GET_REGS: /* Optional for virtual instances per 1= 3.1 */ + /* Unsupported interfaces added in FF-A 1.2 */ + case FFA_EL3_INTR_HANDLE: /* Only valid for secure physical instances */ return false; } =20 @@ -734,7 +741,10 @@ static int hyp_ffa_post_init(void) if (res.a0 !=3D FFA_SUCCESS) return -EOPNOTSUPP; =20 - switch (res.a2) { + if ((res.a2 & GENMASK(15, 2)) !=3D 0 || res.a3 !=3D 0) + return -EINVAL; + + 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 +941,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 +962,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..2b760bede9c0a4bcb58bf697681= c32e77c08a5d9 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 GENMASK(1, 0) =20 /* FFA Bus/Device/Driver related */ struct ffa_device { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Dec 15 01:34:17 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 38917306DB7; Tue, 1 Jul 2025 22:06:47 +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=1751407608; cv=none; b=H/x+6DjIvPPvt7y035SeVNGITTJ4mnJzx0CbK+wr2J/PTBXy6KprT5yB3FkdktBgVy9OYMnb5nL/PtwurkoFfiM9nHQZw4wcEfaFdFlGjAyPYNzpcNm1osYwMQv1dhd+2KpNHHFna9KgzfLgVmzRTocc/0dnK81va6rUu1J6q5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751407608; c=relaxed/simple; bh=CERXC+GluGq6gtdcghOIPnpwBCg94n3hc0LrBMl8mcw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X0Y92/u7oJgS6QrRw5xQme+2X1ZGqxqat9e1JvnUZIz9hJlJlun+bUCfvtlLtCss1BcwgpnNMozdfbt8B4xKvo0tw06bO8lxNrnJg2LdULSztUxC0DjIpodD/7ES3nrMNS9vdUB3Kb1/UOQzU0Qi2OZLTx+riF1SwqvsikD6zvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mS12TZGz; 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="mS12TZGz" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9E260C4CEFC; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751407607; bh=CERXC+GluGq6gtdcghOIPnpwBCg94n3hc0LrBMl8mcw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mS12TZGzxpBysun1h0QARInTRMYTmwdl5X3lLoc1pu8gmASkMsBHPPFxl1vxUUpGk RgpoW5G4HYF7iq/YA5E4+SWQl24cdivDna8Qj0FB2engzVI04QKkoYwtKrVe2S+xji a2cADh1Qx+klTiOSVhGBCtjD4tvu0zzEaV6xHJ4daRtET14OHguDl9hiW/4Rd0+VzX wWoRA6ImsGWIJLkMafmwAiFUNrZXcgP2o6VoxPzsLYRSrwsIzdAe9oUbquJCBlakrg jpapwATl03D2VORuh4TIEaltm4ll15yy9bwOOTL1pfbHH3ur9OqFNYvmEKhTrXqAza MPg8SV/jSC99w== 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 9239DC83F03; Tue, 1 Jul 2025 22:06:47 +0000 (UTC) From: Per Larsen via B4 Relay Date: Tue, 01 Jul 2025 22:06:38 +0000 Subject: [PATCH v7 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: <20250701-virtio-msg-ffa-v7-5-995afc3d385e@google.com> References: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@google.com> In-Reply-To: <20250701-virtio-msg-ffa-v7-0-995afc3d385e@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=1751407606; l=3137; i=perlarsen@google.com; s=20250508; h=from:subject:message-id; bh=GEqKX+GAadj0SfI9NfXASrGnNrJoxc4Z5cAFtJ2/kCw=; b=OPfG6n4vrx37ckpdyrTzIO1OA/BbDYa0ENcgj7Q/JIDX4NTK1LSJuwKRpLHEGoe2PF2eywnPs Ka1PeLLCVFjCZJ4KeUoKU+SJpH+D/KUIG6tH9oYRbLjo/hvbaxURu1I 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 79d834120a3f3d26e17e9170c60012b60c6f5a5e..21225988a9365219ccfd69e8e59= 9d7403b5cdf05 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: /* Optional interfaces added in FF-A 1.2 */ - case FFA_MSG_SEND_DIRECT_REQ2: /* Optional per 7.5.1 */ case FFA_MSG_SEND_DIRECT_RESP2: /* Optional per 7.5.1 */ case FFA_CONSOLE_LOG: /* Optional per 13.1: not in Table 13.1 */ case FFA_PARTITION_INFO_GET_REGS: /* Optional for virtual instances per 1= 3.1 */ @@ -862,6 +861,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; @@ -920,11 +935,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 2b760bede9c0a4bcb58bf697681c32e77c08a5d9..db63a96190545c9f65943909de2= d73cf8e7b9615 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