KVM: arm64: Support FF-A 1.2
Subsystems (3)
v10 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 v10:
- 2/6: Return registers x0-x17 unconditionally in ffa_set_retval for consistency with passthrough code
- 4/6: ffa_call_supported: Drop case FFA_EL3_INTR_HANDLE
Added Acked-by: Will Deacon <[email protected]>
- Link to v9: https://lore.kernel.org/r/[email protected]
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 | 212 +++++++++++++++++++++++++-------------- include/linux/arm_ffa.h | 1 + 3 files changed, 141 insertions(+), 73 deletions(-)
---
base-commit: 37816488247ddddbc3de113c78c83572274b1e2e
change-id: 20250506-virtio-msg-ffa-22af72c92150
Best regards,
Signature · 1 line
Per Larsen <[email protected]>
PATCH v10 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.51.0.rc0.155.g4a0f42376b-goog
PATCH v10 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.
SMCCC 1.2 requires that SMC32/HVC32 from aarch64 mode preserves x8-x30 but given that there is no reliable way to distinguish 32-bit/64-bit calls, we assume SMC64 unconditionally. This has the benefit of being consistent with the handling of calls that are passed through, i.e., not proxied. (A cleaner solution will become available in FF-A 1.3.)
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 | 188 +++++++++++++++++++++++++-------------- 2 files changed, 120 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 +119 -69
341 lines not on this page · raw message
Signature · 1 line
2.51.0.rc0.155.g4a0f42376b-goog
Will Deacon
maintainerRe: [PATCH v10 2/6] KVM: arm64: Use SMCCC 1.2 for FF-A initialization and in host handler
Quoted 82 lines · On Sat, Aug 09, 2025 at 02:33:20AM +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.
SMCCC 1.2 requires that SMC32/HVC32 from aarch64 mode preserves x8-x30 but given that there is no reliable way to distinguish 32-bit/64-bit calls, we assume SMC64 unconditionally. This has the benefit of being consistent with the handling of calls that are passed through, i.e., not proxied. (A cleaner solution will become available in FF-A 1.3.)
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 | 188 +++++++++++++++++++++++++-------------- 2 files changed, 120 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 +7
-7@@ -71,36 +71,63 @@ 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) {cpu_reg (ctxt,0 ) = res->a0;cpu_reg (ctxt,1 ) = res->a1;cpu_reg (ctxt,2 ) = res->a2;cpu_reg (ctxt,3 ) = res->a3;
arch/arm64/kvm/hyp/nvhe/ffa.c static u32 hyp_ffa_version; · line 113
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +10
-0+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. +* +* In FF-A 1.2, we cannot rely on the function ID sent by the caller to +* deteect 32-bit calls as there are cases where a 32-bit interface can
typo: deteect
arch/arm64/kvm/hyp/nvhe/ffa.c static u32 hyp_ffa_version; · line 116
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +3
-0+* have a 64-bit response 1.2 (e.g. FFA_MSG_WAIT or FFA_RUN). This will +* be addressed in FF-A 1.3. We also cannot rely on function IDs in the +* response.
Do you know what the FF-A 1.3 update is likely to say? It would be nice to get an idea of what the code might need to do in future in case this approach is going in a completely different direction.
arch/arm64/kvm/hyp/nvhe/ffa.c static bool do_ffa_features(struct arm_smccc_res *res, · line 710
Quoted 11 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +4
-2@@ -666,17 +703,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; -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 =FFA_ID_GET , + }, &res);
Regardless of the problems with the spec, it's really nice to get rid of all those zero arguments that come with the arm_smccc_1_1_smc() macro.
Will
PATCH v10 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
@@ -665,6 +665,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.51.0.rc0.155.g4a0f42376b-goog
PATCH v10 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.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/kvm/hyp/nvhe/ffa.c +5 -0
@@ -673,6 +673,11 @@ 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 */ return false; }
Signature · 1 line
2.51.0.rc0.155.g4a0f42376b-goog
PATCH v10 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
@@ -734,7 +734,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.51.0.rc0.155.g4a0f42376b-goog
PATCH v10 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
@@ -931,7 +931,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 ;
@@ -952,10 +952,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.51.0.rc0.155.g4a0f42376b-goog