KVM: arm64: Support FF-A 1.2
Subsystems (3)
v9 cover KVM: arm64: Support FF-A 1.2
Hi,
The FF-A 1.2 specification introduces a new SEND_DIRECT2 ABI which allows registers x4-x17 to be used for the message payload. This patch set prevents the host from using a lower FF-A version than what has already been negotiated with the hypervisor. This is necessary because the hypervisor does not have the necessary compatibility paths to translate from the hypervisor FF-A version to a previous version.
Support for FF-A 1.2 in the hypervisor is added as a precursor to the addition of the FFA_MSG_SEND_DIRECT_REQ2 messaging interface. Notably, this patch updates all smc calls to use SMCCC 1.2 as it makes it simpler to support interfaces that need to accept more than 8 arguments and/or return more than 4 values. The list of optional/unsupported interfaces was updated to reflect additions in FF-A 1.2.
Tested by booting Android under QEMU and loading Trusty as the guest VM and observing the SEND_DIRECT2 ABI being used successfully during guest boot.
Changes in v9:
- 2/7 -> 2/6: Updated explanatory comment in ffa_set_retval
- 4/7 -> 4/6: Restore to v7: Mark FFA_MSG_SEND_DIRECT_REQ2 unsupported
- 5/7 -> 5/6: Added Acked-by: Will Deacon <[email protected]>
- 6/7 -> 6/6: Added Acked-by: Will Deacon <[email protected]>
- 7/7: Dropped
- Link to v8: https://lore.kernel.org/r/[email protected]
Changes in v8:
- 2/5 -> 2/7: Use func_id argument to distinguish SMC32/SMC64. Update rationale.
- 4/5 -> 4/7: Split up 4/5: Add optional FF-A 1.2 interfaces
- 4/5 -> 5/7: Split up 4/5: Mask FFA_RXTX_MAP minium buffer size in a2. Don't check MBZ bits.
- 4/5 -> 6/7: Remainder of 4/5: Bump supported version to FF-A 1.2
- 5/5 -> 7/7: Don't check src id in do_ffa_direct_msg2
- Link to v7: https://lore.kernel.org/r/[email protected]
Changes in v7:
- 0/6: Revised cover letter slightly
- 4/6: ffa_call_supported: Clarify optional interfaces
hyp_ffa_post_init: Sanitize MBZ bits in x2 and x3
address nit: use GENMASK
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes since v5:
- 3/6 -> 2/5: Merged with parent patch as they were closely related
Don't rename variables from "res" to "regs" to avoid churn Update and clarify reasoning for condition added to ffa_set_retval Adopt style suggested by Marc when passing regs to arm_smccc_1_2_smc Fix inadvertent duplicate statements in ffa_{map,unmap}_hyp_buffers
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes since v4:
- 1/5 -> 1/6: Added Acked-by: Will Deacon <[email protected]>y
Reworded patch subject and description
- 2/5: Dropped patch: zero x4-x7 in ffa_set_retval
- 2/6: New: use SMCCC 1.2 during hyp init
- 3/6: New: use SMCCC 1.2 in host FF-A handler
- 3/5 -> 4/6: No change; can revisit denylist design in later patchset
Added Acked-by: Will Deacon <[email protected]>
- 4/5 -> 5/6: No change
- 5/5 -> 6/6: No change
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes since v3:
- all: Remove Signed-off-by: Per Larsen <[email protected]> - 2/5: Split out from 2/3, zero x4-x7 in set_ffa_retval - 3/5: Split out from 2/3, Mark FFA_NOTIFICATION_* calls as
unsupported
- 2/3 -> 4/5: Drop ffa_get_hypervisor_version, access hyp_ffa_version directly when version negotiation is complete.
- 3/3 -> 5/5: Call ffa_to_smccc_1_2_error directly in
do_do_ffa_direct_msg2
Push call to ffa_call_needs_smccc_1_2 lower down by adding ffa_get_func_id and ffa_set_retval_smccc_1_x.
Drop ffa_to_smccc_1_2_regs and ffa_to_smccc_1_2_regs_prop
as they are no longer used.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes since v2:
- 2/3: Removed files added by mistake.
Add and use ffa_get_hypervisor_version to access hyp_ffa_version
- 3/3: Use ffa_get_hypervisor_version to access hyp_ffa_version safely
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes since v1:
- 1/3: Simplify commit message; drop long comment in do_ffa_version
- 2/3: Correct use of Co-developed-by: footer s/arm_smccc_1_2_smc_fallback/arm_smccc_1_x_smc/ Always access hyp_ffa_version w/lock held
Remove superfluous comments in ffa_call_supported Add and use FFA_FEAT_RXTX_MIN_SZ_MASK instead of constant Add FFA_PARTITION_INFO_GET_REGS to calls that require SMCCC 1.2
- 3/3: Always access hyp_ffa_version w/lock held
Correct formatting
Thanks,
Per Larsen
--
2.49.0
---
Per Larsen (6):
KVM: arm64: Correct return value on host version downgrade attempt
KVM: arm64: Use SMCCC 1.2 for FF-A initialization and in host handler
KVM: arm64: Mark FFA_NOTIFICATION_* calls as unsupported
KVM: arm64: Mark optional FF-A 1.2 interfaces as unsupported
KVM: arm64: Mask response to FFA_FEATURE call
KVM: arm64: Bump the supported version of FF-A to 1.2
arch/arm64/kvm/hyp/nvhe/Makefile | 1 + arch/arm64/kvm/hyp/nvhe/ffa.c | 215 ++++++++++++++++++++++++++------------- include/linux/arm_ffa.h | 1 + 3 files changed, 144 insertions(+), 73 deletions(-)
---
base-commit: 4b290aae788e06561754b28c6842e4080957d3f7
change-id: 20250506-virtio-msg-ffa-22af72c92150
Best regards,
Signature · 1 line
Per Larsen <[email protected]>
PATCH v9 1/6 KVM: arm64: Correct return value on host version downgrade attempt
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.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +4 -1
@@ -712,7 +712,10 @@ static void do_ffa_version(struct arm_smccc_res *res,hyp_spin_lock (&version_lock);if (has_version_negotiated) { - res->a0 = hyp_ffa_version; +if (FFA_MINOR_VERSION (ffa_req_version) <FFA_MINOR_VERSION (hyp_ffa_version)) + res->a0 =FFA_RET_NOT_SUPPORTED ; +else + res->a0 = hyp_ffa_version; goto unlock; }
Signature · 1 line
2.50.1.552.g942d659e1b-goog
PATCH v9 2/6 KVM: arm64: Use SMCCC 1.2 for FF-A initialization and in host handler
In reply to Per LarsenSMCCC 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.
--- arch/arm64/kvm/hyp/nvhe/Makefile | 1 + arch/arm64/kvm/hyp/nvhe/ffa.c | 189 +++++++++++++++++++++++++-------------- 2 files changed, 121 insertions(+), 69 deletions(-)
arch/arm64/kvm/hyp/nvhe/Makefile +1 -0
@@ -27,6 +27,7 @@ hyp-obj-y := 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 += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o +hyp-obj-y += ../../../kernel/smccc-call.o hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o hyp-obj-y += $(lib-objs)
arch/arm64/kvm/hyp/nvhe/ffa.c +120 -69
342 lines not on this page · raw message
Signature · 1 line
2.50.1.552.g942d659e1b-goog
Will Deacon
maintainerRe: [PATCH v9 2/6] KVM: arm64: Use SMCCC 1.2 for FF-A initialization and in host handler
Quoted 94 lines · On Wed, Jul 30, 2025 at 09:15:05PM +0000, Per Larsen via B4 Relay wrote:
From: Per Larsen <[email protected]>
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 <[email protected]>--- arch/arm64/kvm/hyp/nvhe/Makefile | 1 + arch/arm64/kvm/hyp/nvhe/ffa.c | 189 +++++++++++++++++++++++++-------------- 2 files changed, 121 insertions(+), 69 deletions(-)arch/arm64/kvm/hyp/nvhe/Makefile +1
-0@@ -27,6 +27,7 @@ hyp-obj-y := 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 += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o +hyp-obj-y += ../../../kernel/smccc-call.o hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o hyp-obj-y += $(lib-objs)arch/arm64/kvm/hyp/nvhe/ffa.c +25
-7@@ -71,36 +71,64 @@ static u32 hyp_ffa_version;static bool has_version_negotiated;static hyp_spinlock_t version_lock; -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_errno) { - *res = (struct arm_smccc_res ) { + *res = (struct arm_smccc_1_2_regs ) { .a0 =FFA_ERROR , .a2 = ffa_errno, }; } -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 ==FFA_RET_SUCCESS ) { - *res = (struct arm_smccc_res ) { .a0 =FFA_SUCCESS , - .a2 = prop }; + *res = (struct arm_smccc_1_2_regs ) { .a0 =FFA_SUCCESS , + .a2 = prop }; }else {ffa_to_smccc_error (res, ret); } } -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 ); }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 ) = res->a0;cpu_reg (ctxt,1 ) = res->a1;cpu_reg (ctxt,2 ) = res->a2;cpu_reg (ctxt,3 ) = res->a3; +cpu_reg (ctxt,4 ) = res->a4; +cpu_reg (ctxt,5 ) = res->a5; +cpu_reg (ctxt,6 ) = res->a6; +cpu_reg (ctxt,7 ) = res->a7; + +/* +* DEN0028C 2.6: SMC32/HVC32 call from aarch64 must preserve x8-x30. +* +* We rely on the function ID sent by the caller. Note that there +* are cases where a 32-bit interface can have a 64-bit response in FF-A +* 1.2 (e.g. FFA_MSG_WAIT or FFA_RUN). This will be addressed in a future +* version of the FF-A spec. Moreover, these corner cases are not relevant +* on this code path (FFA_RUN is passed through [not proxied] by the +* hypervisor and FFA_MSG_WAIT calls are made from the secure partition). +*/ +if (ARM_SMCCC_IS_64 (func_id)) { +cpu_reg (ctxt,8 ) = res->a8;
arch/arm64/kvm/hyp/nvhe/ffa.c static u32 hyp_ffa_version; · line 131
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +10
-0+cpu_reg (ctxt,9 ) = res->a9; +cpu_reg (ctxt,10 ) = res->a10; +cpu_reg (ctxt,11 ) = res->a11; +cpu_reg (ctxt,12 ) = res->a12; +cpu_reg (ctxt,13 ) = res->a13; +cpu_reg (ctxt,14 ) = res->a14; +cpu_reg (ctxt,15 ) = res->a15; +cpu_reg (ctxt,16 ) = res->a16; +cpu_reg (ctxt,17 ) = res->a17; + }
As discussed previously:
https://lore.kernel.org/all/aH-0cx9YhdWRe2nq@willie-the-truck/
I think we should just do this unconditionally. We know that looking at the function ID isn't correct and so my vote is for compatability with with the SMC proxy code.
Will
PATCH v9 3/6 KVM: arm64: Mark FFA_NOTIFICATION_* calls as unsupported
In reply to Per LarsenPrevent FFA_NOTIFICATION_* interfaces from being passed through to TZ.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm64/kvm/hyp/nvhe/ffa.c +8 -0
@@ -666,6 +666,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; }
Signature · 1 line
2.50.1.552.g942d659e1b-goog
PATCH v9 4/6 KVM: arm64: Mark optional FF-A 1.2 interfaces as unsupported
In reply to Per LarsenMark FF-A 1.2 interfaces as unsupported lest they get proxied. Also mark FFA_EL3_INTR_HANDLE as unsupported as it is only valid for physical instances.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/kvm/hyp/nvhe/ffa.c +7 -0
@@ -674,6 +674,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 13.1 */ +/* Unsupported interfaces added in FF-A 1.2 */ +case FFA_EL3_INTR_HANDLE :/* Only valid for secure physical instances */ return false; }
Signature · 1 line
2.50.1.552.g942d659e1b-goog
Re: [PATCH v9 4/6] KVM: arm64: Mark optional FF-A 1.2 interfaces as unsupported
Quoted 16 lines · On Wed, Jul 30, 2025 at 09:15:07PM +0000, Per Larsen via B4 Relay wrote:
From: Per Larsen <[email protected]>
Mark FF-A 1.2 interfaces as unsupported lest they get proxied. Also mark
FFA_EL3_INTR_HANDLEas unsupported as it is only valid for physical instances.Signed-off-by Per Larsen <[email protected]>--- arch/arm64/kvm/hyp/nvhe/ffa.c | 7 +++++++ 1 file changed, 7 insertions(+)arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0
arch/arm64/kvm/hyp/nvhe/ffa.c static bool ffa_call_supported(u64 func_id) · line 683
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +7
-0@@ -674,6 +674,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 13.1 */ +/* Unsupported interfaces added in FF-A 1.2 */ +case FFA_EL3_INTR_HANDLE :/* Only valid for secure physical instances */
Shouldn't the secure side be rejecting that one for us, then?
arch/arm64/kvm/hyp/nvhe/ffa.c static bool ffa_call_supported(u64 func_id) · line 685
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0return false; }
Regardless,
Will
PATCH v9 5/6 KVM: arm64: Mask response to FFA_FEATURE call
In reply to Per LarsenThe minimum size and alignment boundary for FFA_RXTX_MAP is returned in bit[1:0]. Mask off any other bits in w2 when reading the minimum buffer size in hyp_ffa_post_init.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 2 +- include/linux/arm_ffa.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -1
@@ -737,7 +737,7 @@ static int hyp_ffa_post_init(void)if (res.a0 !=FFA_SUCCESS )return -EOPNOTSUPP ; -switch (res.a2) { +switch (res.a2 &FFA_FEAT_RXTX_MIN_SZ_MASK ) {case FFA_FEAT_RXTX_MIN_SZ_4K : min_rxtx_sz =SZ_4K ;break ;
include/linux/arm_ffa.h +1 -0
@@ -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)/* FFA Bus/Device/Driver related */ struct ffa_device {
Signature · 1 line
2.50.1.552.g942d659e1b-goog
PATCH v9 6/6 KVM: arm64: Bump the supported version of FF-A to 1.2
In reply to Per LarsenFF-A version 1.2 introduces the DIRECT_REQ2 ABI. Bump the FF-A version preferred by the hypervisor to enable implementation of the 1.2-only FFA_MSG_SEND_DIRECT_REQ2 and FFA_MSG_SEND_RESP2 messaging interfaces.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +3 -3
@@ -934,7 +934,7 @@ int hyp_ffa_init(void *pages)arm_smccc_1_2_smc (&(struct arm_smccc_1_2_regs ) { .a0 =FFA_VERSION , - .a1 =FFA_VERSION_1_1 , + .a1 =FFA_VERSION_1_2 , }, &res);if (res.a0 ==FFA_RET_NOT_SUPPORTED )return 0 ;
@@ -955,10 +955,10 @@ int hyp_ffa_init(void *pages)if (FFA_MAJOR_VERSION (res.a0) !=1 )return -EOPNOTSUPP ; -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 = res.a0;else - hyp_ffa_version =FFA_VERSION_1_1 ; + hyp_ffa_version =FFA_VERSION_1_2 ; tx = pages; pages +=KVM_FFA_MBOX_NR_PAGES *PAGE_SIZE ;
Signature · 1 line
2.50.1.552.g942d659e1b-goog