Xen FF-A mediator
cover Xen FF-A mediator
Hi,
This patch sets add a FF-A [1] mediator modeled after the TEE mediator already present in Xen. The FF-A mediator implements the subset of the FF-A 1.1 specification needed to communicate with OP-TEE using FF-A as transport mechanism instead of SMC/HVC as with the TEE mediator. It allows a similar design in OP-TEE as with the TEE mediator where OP-TEE presents one virtual partition of itself to each guest in Xen.
The FF-A mediator is generic in the sense it has nothing OP-TEE specific except that only the subset needed for OP-TEE is implemented so far. The hooks needed to inform OP-TEE that a guest is created or destroyed is part of the FF-A specification.
It should be possible to extend the FF-A mediator to implement a larger portion of the FF-A 1.1 specification without breaking with the way OP-TEE is communicated with here. So it should be possible to support any TEE or Secure Partition using FF-A as transport with this mediator.
[1] https://developer.arm.com/documentation/den0077/latest
Thanks,
Jens
Jens Wiklander (2):
xen/arm: smccc: add support for SMCCCv1.2 extended input/output
registers
xen/arm: add FF-A mediator
xen/arch/arm/Kconfig | 11 + xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/smc.S | 43 + xen/arch/arm/domain.c | 10 + xen/arch/arm/ffa.c | 1624 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 19 +- xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/ffa.h | 71 ++ xen/include/asm-arm/smccc.h | 42 + 9 files changed, 1821 insertions(+), 4 deletions(-) create mode 100644 xen/arch/arm/ffa.c create mode 100644 xen/include/asm-arm/ffa.h
Signature · 1 line
2.31.1
PATCH 1/2 xen/arm: smccc: add support for SMCCCv1.2 extended input/output registers
SMCCC v1.2 AArch64 allows x0-x17 to be used as both parameter registers and result registers for the SMC and HVC instructions.
Arm Firmware Framework for Armv8-A specification makes use of x0-x7 as parameter and result registers.
Let us add new interface to support this extended set of input/output registers.
This is based on 3fdc0cb59d97 ("arm64: smccc: Add support for SMCCCv1.2 extended input/output registers") by Sudeep Holla from the Linux kernel
--- xen/arch/arm/arm64/smc.S | 43 +++++++++++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 2 +- xen/include/asm-arm/smccc.h | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-)
xen/arch/arm/arm64/smc.S +43 -0
@@ -30,3 +30,46 @@ ENTRY(__arm_smccc_1_0_smc) stp x2, x3, [x4, #SMCCC_RES_a2] 1: ret + + +/* + * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args, + * struct arm_smccc_1_2_regs *res) + */ +ENTRY(arm_smccc_1_2_smc) + /* Save `res` and free a GPR that won't be clobbered */ + stp x1, x19, [sp, #-16]! + + /* Ensure `args` won't be clobbered while loading regs in next step */ + mov x19, x0 + + /* Load the registers x0 - x17 from the struct arm_smccc_1_2_regs */ + ldp x0, x1, [x19, #0] + ldp x2, x3, [x19, #16] + ldp x4, x5, [x19, #32] + ldp x6, x7, [x19, #48] + ldp x8, x9, [x19, #64] + ldp x10, x11, [x19, #80] + ldp x12, x13, [x19, #96] + ldp x14, x15, [x19, #112] + ldp x16, x17, [x19, #128] + + smc #0 + + /* Load the `res` from the stack */ + ldr x19, [sp] + + /* Store the registers x0 - x17 into the result structure */ + stp x0, x1, [x19, #0] + stp x2, x3, [x19, #16] + stp x4, x5, [x19, #32] + stp x6, x7, [x19, #48] + stp x8, x9, [x19, #64] + stp x10, x11, [x19, #80] + stp x12, x13, [x19, #96] + stp x14, x15, [x19, #112] + stp x16, x17, [x19, #128] + + /* Restore original x19 */ + ldp xzr, x19, [sp], #16 + ret
xen/arch/arm/vsmc.c +1 -1
@@ -93,7 +93,7 @@ static bool handle_arch(struct cpu_user_regs *regs)switch ( fid ) {case ARM_SMCCC_VERSION_FID : -set_user_reg (regs,0 ,ARM_SMCCC_VERSION_1_1 ); +set_user_reg (regs,0 ,ARM_SMCCC_VERSION_1_2 );return true;case ARM_SMCCC_ARCH_FEATURES_FID :
xen/include/asm-arm/smccc.h +42 -0
62 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 2/2 xen/arm: add FF-A mediator
In reply to Jens WiklanderAdds a FF-A version 1.1 [1] mediator to communicate with a Secure Partition in secure world.
The implementation is the bare minimum to be able to communicate with OP-TEE running as an SPMC at S-EL1.
This is loosely based on the TEE mediator framework and the OP-TEE mediator.
[1] https://developer.arm.com/documentation/den0077/latest
--- xen/arch/arm/Kconfig | 11 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 10 + xen/arch/arm/ffa.c | 1624 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 17 +- xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/ffa.h | 71 ++ 7 files changed, 1735 insertions(+), 3 deletions(-) create mode 100644 xen/arch/arm/ffa.c create mode 100644 xen/include/asm-arm/ffa.h
xen/arch/arm/Kconfig +11 -0
@@ -114,6 +114,17 @@ config TEE source "arch/arm/tee/Kconfig" +config FFA + bool "Enable FF-A mediator support" if EXPERT + default n + depends on ARM_64 + help + This option enables a minamal FF-A mediator. The mediator is + generic as it follows the FF-A specification [1], but it only + implements a small substet of the specification. + + [1] https://developer.arm.com/documentation/den0077/latest + endmenu menu "ARM errata workaround via the alternative framework"
xen/arch/arm/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-y += domain.o obj-y += domain_build.init.o obj-y += domctl.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o +obj-$(CONFIG_FFA) += ffa.o obj-y += gic.o obj-y += gic-v2.o obj-$(CONFIG_GICV3) += gic-v3.o
xen/arch/arm/domain.c +10 -0
@@ -25,6 +25,7 @@#include <asm/cpufeature.h> #include <asm/current.h> #include <asm/event.h> +#include <asm/ffa.h> #include <asm/gic.h> #include <asm/guest_access.h> #include <asm/guest_atomics.h>
@@ -737,6 +738,9 @@ int arch_domain_create(struct domain *d,if ( (rc =tee_domain_init (d, config->arch.tee_type)) !=0 ) goto fail; +if ( (rc =ffa_domain_init (d)) !=0 ) + goto fail; +update_domain_wallclock_time (d);/*
@@ -974,6 +978,7 @@ static int relinquish_memory(struct domain *d, struct page_list_head *list)*/ enum { PROG_tee =1 , + PROG_ffa, PROG_xen, PROG_page, PROG_mapping,
@@ -1012,6 +1017,11 @@ int domain_relinquish_resources(struct domain *d)if (ret )return ret; + PROGRESS(ffa): + ret =ffa_relinquish_resources (d); +if (ret ) +return ret; + PROGRESS(xen): ret =relinquish_memory (d, &d->xenpage_list);if ( ret )
xen/arch/arm/ffa.c new file +1624 -0
1,624 lines not on this page · raw message
xen/arch/arm/vsmc.c +14 -3
@@ -20,6 +20,7 @@#include <public/arch-arm/smccc.h> #include <asm/cpuerrata.h> #include <asm/cpufeature.h> +#include <asm/ffa.h> #include <asm/monitor.h> #include <asm/regs.h> #include <asm/smccc.h>
@@ -32,7 +33,7 @@#define XEN_SMCCC_FUNCTION_COUNT 3/* Number of functions currently supported by Standard Service Service Calls. */ -#define SSSC_SMCCC_FUNCTION_COUNT (3 + VPSCI_NR_FUNCS) +#define SSSC_SMCCC_FUNCTION_COUNT (3 + VPSCI_NR_FUNCS + FFA_NR_FUNCS)static bool fill_uid (struct cpu_user_regs *regs,xen_uuid_t uuid) {
@@ -186,13 +187,23 @@ static bool handle_existing_apis(struct cpu_user_regs *regs)return do_vpsci_0_1_call (regs, fid); } +static bool is_psci_fid (uint32_t fid) +{ +uint32_t fn = fid &ARM_SMCCC_FUNC_MASK ; + +return fn >=0 && fn <=0x1fU ; +} +/* PSCI 0.2 interface and other Standard Secure Calls */ static bool handle_sssc (struct cpu_user_regs *regs) {uint32_t fid = (uint32_t )get_user_reg (regs,0 ); -if (do_vpsci_0_2_call (regs, fid) ) -return true; +if (is_psci_fid (fid) ) +return do_vpsci_0_2_call (regs, fid); + +if (is_ffa_fid (fid) ) +return ffa_handle_call (regs, fid);switch ( fid ) {
xen/include/asm-arm/domain.h +4 -0
@@ -91,6 +91,10 @@ struct arch_domain#ifdef CONFIG_TEE void *tee;#endif + +#ifdef CONFIG_FFA +void *ffa; +#endif } __cacheline_aligned;struct arch_vcpu
xen/include/asm-arm/ffa.h new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 19 lines · Jens Wiklander
Hi,
This patch sets add a FF-A [1] mediator modeled after the TEE mediator already present in Xen. The FF-A mediator implements the subset of the FF-A 1.1 specification needed to communicate with OP-TEE using FF-A as transport mechanism instead of SMC/HVC as with the TEE mediator. It allows a similar design in OP-TEE as with the TEE mediator where OP-TEE presents one virtual partition of itself to each guest in Xen.
The FF-A mediator is generic in the sense it has nothing OP-TEE specific except that only the subset needed for OP-TEE is implemented so far. The hooks needed to inform OP-TEE that a guest is created or destroyed is part of the FF-A specification.
It should be possible to extend the FF-A mediator to implement a larger portion of the FF-A 1.1 specification without breaking with the way OP-TEE is communicated with here. So it should be possible to support any TEE or Secure Partition using FF-A as transport with this mediator.
Quoted 4 lines
[1] https://developer.arm.com/documentation/den0077/latest
Thanks,
Jens
Hi Jens,
Many thanks for the patches! I tried to apply them to the master branch but unfortunately they don't apply any longer. Could you please rebase them on master (or even better rebase them on staging) and resend?
Thank you!
Quoted 17 lines
Jens Wiklander (2):
xen/arm: smccc: add support for SMCCCv1.2 extended input/output
registers
xen/arm: add FF-A mediatorxen/arch/arm/Kconfig | 11 + xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/smc.S | 43 + xen/arch/arm/domain.c | 10 + xen/arch/arm/ffa.c | 1624 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 19 +- xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/ffa.h | 71 ++ xen/include/asm-arm/smccc.h | 42 + 9 files changed, 1821 insertions(+), 4 deletions(-) create mode 100644 xen/arch/arm/ffa.c create mode 100644 xen/include/asm-arm/ffa.h
Quoted 25 lines · Stefano Stabellini
Quoted 19 lines · Jens Wiklander
Hi,
This patch sets add a FF-A [1] mediator modeled after the TEE mediator already present in Xen. The FF-A mediator implements the subset of the FF-A 1.1 specification needed to communicate with OP-TEE using FF-A as transport mechanism instead of SMC/HVC as with the TEE mediator. It allows a similar design in OP-TEE as with the TEE mediator where OP-TEE presents one virtual partition of itself to each guest in Xen.
The FF-A mediator is generic in the sense it has nothing OP-TEE specific except that only the subset needed for OP-TEE is implemented so far. The hooks needed to inform OP-TEE that a guest is created or destroyed is part of the FF-A specification.
It should be possible to extend the FF-A mediator to implement a larger portion of the FF-A 1.1 specification without breaking with the way OP-TEE is communicated with here. So it should be possible to support any TEE or Secure Partition using FF-A as transport with this mediator.
Quoted 4 lines
[1] https://developer.arm.com/documentation/den0077/latest
Thanks,
Jens
Quoted 7 lines
Hi Jens,
Many thanks for the patches! I tried to apply them to the master branch but unfortunately they don't apply any longer. Could you please rebase them on master (or even better rebase them on staging) and resend?
Thank you!
One question without having looked at the patches in details. These patches are necessary to mediate OS (e.g. Linux) interactions with OPTEE. The difference between xen/arch/arm/ffa.c and xen/arch/arm/tee/optee.c is the transport mechanism: shared mem vs. SMC. Is that right?
If only the transport is different, would it make sense to place ffa.c under xen/arch/arm/tee?
Without having looked at the details of the transport or the FF-A protocol let me ask you a question. Do you think it would be possible to share part of the implementation with xen/arch/arm/tee/optee.c? I am asking because intuitively, if only the transport is differenti I would have thought that some things could be common. But it doesn't look like the current patches are reusing anything from xen/arch/arm/tee/optee.c. Are the two protocols too different?
Quoted 35 lines · Stefano Stabellini
Quoted 25 lines · Stefano Stabellini
Quoted 19 lines · Jens Wiklander
Hi,
This patch sets add a FF-A [1] mediator modeled after the TEE mediator already present in Xen. The FF-A mediator implements the subset of the FF-A 1.1 specification needed to communicate with OP-TEE using FF-A as transport mechanism instead of SMC/HVC as with the TEE mediator. It allows a similar design in OP-TEE as with the TEE mediator where OP-TEE presents one virtual partition of itself to each guest in Xen.
The FF-A mediator is generic in the sense it has nothing OP-TEE specific except that only the subset needed for OP-TEE is implemented so far. The hooks needed to inform OP-TEE that a guest is created or destroyed is part of the FF-A specification.
It should be possible to extend the FF-A mediator to implement a larger portion of the FF-A 1.1 specification without breaking with the way OP-TEE is communicated with here. So it should be possible to support any TEE or Secure Partition using FF-A as transport with this mediator.
Quoted 4 lines
[1] https://developer.arm.com/documentation/den0077/latest
Thanks,
JensQuoted 7 lines
Hi Jens,
Many thanks for the patches! I tried to apply them to the master branch but unfortunately they don't apply any longer. Could you please rebase them on master (or even better rebase them on staging) and resend?
Thank you!
Quoted 8 lines
One question without having looked at the patches in details. These patches are necessary to mediate OS (e.g. Linux) interactions with OPTEE. The difference between
xen/arch/arm/ffa.candxen/arch/arm/tee/optee.cis the transport mechanism: shared mem vs. SMC. Is that right?If only the transport is different, would it make sense to place
ffa.cunder xen/arch/arm/tee?
FF-A is a standard Arm service with a different range of SMC Function Identifiers. FF-A is used to communicate with SPs, Secure Partitions. An SP can be a TEE but also something different.
There are similarities between xen/arch/arm/ffa.c and xen/arch/arm/tee/optee.c, but I believe it's more in broader terms on the surface.
FF-A is a generic transport protocol that is generic enough that Xen doesn't even need to know anything about the entity it's facilitating communication with except what's provided by FF-A. The idea is that it's only the end points that need to be aware of details of the protocol run on top of FF-A. This means that EL2 (Xen), EL3 (SPMD/TF-A) and S-EL2 (SPMC/Hafnium) in principle can be kept unchanged and agnostic to Trusted OSes and what not.
Quoted 8 lines
Without having looked at the details of the transport or the FF-A protocol let me ask you a question. Do you think it would be possible to share part of the implementation with
xen/arch/arm/tee/optee.c? I am asking because intuitively, if only the transport is differenti I would have thought that some things could be common. But it doesn't look like the current patches are reusing anything fromxen/arch/arm/tee/optee.c. Are the two protocols too different?
The two protocols are quite different. So far I haven't been able to identify suitable common helper functions.
Thanks,
Jens
Hi Stefano,
Quoted 23 lines · Stefano Stabellini
Quoted 21 lines · Jens Wiklander
Hi,
This patch sets add a FF-A [1] mediator modeled after the TEE mediator already present in Xen. The FF-A mediator implements the subset of the FF-A 1.1 specification needed to communicate with OP-TEE using FF-A as transport mechanism instead of SMC/HVC as with the TEE mediator. It allows a similar design in OP-TEE as with the TEE mediator where OP-TEE presents one virtual partition of itself to each guest in Xen.
The FF-A mediator is generic in the sense it has nothing OP-TEE specific except that only the subset needed for OP-TEE is implemented so far. The hooks needed to inform OP-TEE that a guest is created or destroyed is part of the FF-A specification.
It should be possible to extend the FF-A mediator to implement a larger portion of the FF-A 1.1 specification without breaking with the way OP-TEE is communicated with here. So it should be possible to support any TEE or Secure Partition using FF-A as transport with this mediator.
Quoted 8 lines
Quoted 2 lines
Thanks,
JensHi Jens,
Many thanks for the patches! I tried to apply them to the master branch but unfortunately they don't apply any longer. Could you please rebase them on master (or even better rebase them on staging) and resend?
No problem, I'll rebase and send out a v2.
Thanks,
Jens
Quoted 23 lines
Thank you!
Quoted 17 lines
Jens Wiklander (2):
xen/arm: smccc: add support for SMCCCv1.2 extended input/output
registers
xen/arm: add FF-A mediatorxen/arch/arm/Kconfig | 11 + xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/smc.S | 43 + xen/arch/arm/domain.c | 10 + xen/arch/arm/ffa.c | 1624 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 19 +- xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/ffa.h | 71 ++ xen/include/asm-arm/smccc.h | 42 + 9 files changed, 1821 insertions(+), 4 deletions(-) create mode 100644 xen/arch/arm/ffa.c create mode 100644 xen/include/asm-arm/ffa.h