KVM: arm64: Separate the hyp FF-A buffers init from the host
Subsystems (3)
v3 cover KVM: arm64: Separate the hyp FF-A buffers init from the host
Hello,
This moves the initialization of the hypervisor FF-A buffers away from the host FF-A map calling path. If the hypervisor cannot map the buffers with Trustzone, it rejects any FF-A call when it runs under protected mode.
Other than that it moves the definitions of the ffa_to_linux_err map from the arm_ffa driver to the ffa header so that the hyp code can make use of it.
*** Changelog ***
v2 -> this version:
- dropped the "Map the hypervisor FF-A buffers on ffa init" patch
- added ack & reviewed-by tags
- don't release the ownership of the RX buffer if the flag from FFA_GET_PARTITION is (1)
v1 -> v2:
Split the patch that maps the ff-a buffers of ffa init and introduce "Move the ffa_to_linux definition to the ffa header".
Thanks,
Sebastian Ene (3):
KVM: arm64: Use the static initializer for the version lock
firmware: arm_ffa: Move the ffa_to_linux definition to the ffa header
KVM: arm64: Release the ownership of the hyp rx buffer to Trustzone
arch/arm64/kvm/hyp/nvhe/ffa.c | 12 +++++++----- drivers/firmware/arm_ffa/driver.c | 24 ------------------------ include/linux/arm_ffa.h | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 29 deletions(-)
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
PATCH v3 1/3 KVM: arm64: Use the static initializer for the version lock
Replace the definition of the hypervisor version lock with a static initializer.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -2
@@ -69,7 +69,7 @@ static struct kvm_ffa_buffers hyp_buffers;static struct kvm_ffa_buffers host_buffers;static u32 hyp_ffa_version;static bool has_version_negotiated; -static hyp_spinlock_t version_lock; +static DEFINE_HYP_SPINLOCK (version_lock);static void ffa_to_smccc_error (struct arm_smccc_res *res,u64 ffa_errno) {
@@ -911,6 +911,5 @@ int hyp_ffa_init(void *pages) .lock = __HYP_SPIN_LOCK_UNLOCKED, }; - version_lock = __HYP_SPIN_LOCK_UNLOCKED;return 0 ; }
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
PATCH v3 2/3 firmware: arm_ffa: Move the ffa_to_linux definition to the ffa header
In reply to Sebastian EneKeep the ffa_to_linux error map in the header and move it away from the arm ffa driver to make it accessible for other components.
--- drivers/firmware/arm_ffa/driver.c | 24 ------------------------ include/linux/arm_ffa.h | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-)
drivers/firmware/arm_ffa/driver.c +0 -24
@@ -61,30 +61,6 @@static ffa_fn *invoke_ffa_fn; -static const int ffa_linux_errmap[] = { -/* better than switch case as long as return value is continuous */ -0 ,/* FFA_RET_SUCCESS */ - -EOPNOTSUPP ,/* FFA_RET_NOT_SUPPORTED */ - -EINVAL ,/* FFA_RET_INVALID_PARAMETERS */ - -ENOMEM ,/* FFA_RET_NO_MEMORY */ - -EBUSY ,/* FFA_RET_BUSY */ - -EINTR ,/* FFA_RET_INTERRUPTED */ - -EACCES ,/* FFA_RET_DENIED */ - -EAGAIN ,/* FFA_RET_RETRY */ - -ECANCELED ,/* FFA_RET_ABORTED */ - -ENODATA ,/* FFA_RET_NO_DATA */ - -EAGAIN ,/* FFA_RET_NOT_READY */ -}; - -static inline int ffa_to_linux_errno (int errno) -{ -int err_idx = -errno; - -if (err_idx >=0 && err_idx <ARRAY_SIZE (ffa_linux_errmap)) -return ffa_linux_errmap[err_idx]; -return -EINVAL ; -} -struct ffa_pcpu_irq {struct ffa_drv_info *info; };
include/linux/arm_ffa.h +24 -0
@@ -475,4 +475,28 @@ struct ffa_ops { const struct ffa_notifier_ops *notifier_ops; }; +static const int ffa_linux_errmap[] = { +/* better than switch case as long as return value is continuous */ +0 ,/* FFA_RET_SUCCESS */ + -EOPNOTSUPP ,/* FFA_RET_NOT_SUPPORTED */ + -EINVAL ,/* FFA_RET_INVALID_PARAMETERS */ + -ENOMEM ,/* FFA_RET_NO_MEMORY */ + -EBUSY ,/* FFA_RET_BUSY */ + -EINTR ,/* FFA_RET_INTERRUPTED */ + -EACCES ,/* FFA_RET_DENIED */ + -EAGAIN ,/* FFA_RET_RETRY */ + -ECANCELED ,/* FFA_RET_ABORTED */ + -ENODATA ,/* FFA_RET_NO_DATA */ + -EAGAIN ,/* FFA_RET_NOT_READY */ +}; + +static inline int ffa_to_linux_errno (int errno) +{ +int err_idx = -errno; + +if (err_idx >=0 && err_idx <ARRAY_SIZE (ffa_linux_errmap)) +return ffa_linux_errmap[err_idx]; +return -EINVAL ; +} +#endif /* _LINUX_ARM_FFA_H */
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
PATCH v3 3/3 KVM: arm64: Release the ownership of the hyp rx buffer to Trustzone
In reply to Sebastian EneIntroduce the release FF-A call to notify Trustzone that the hypervisor has finished copying the data from the buffer shared with Trustzone to the non-secure partition.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 9 ++++++--- include/linux/arm_ffa.h | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +6 -3
@@ -749,6 +749,7 @@ static void do_ffa_part_get(struct arm_smccc_res *res,DECLARE_REG (u32, uuid3, ctxt,4 );DECLARE_REG (u32, flags, ctxt,5 );u32 count, partition_sz, copy_sz; +struct arm_smccc_res _res;hyp_spin_lock (&host_buffers.lock);if (!host_buffers.rx) {
@@ -765,11 +766,11 @@ static void do_ffa_part_get(struct arm_smccc_res *res, count = res->a2;if (!count) - goto out_unlock; + goto release_rx;if (hyp_ffa_version >FFA_VERSION_1_0 ) {/* Get the number of partitions deployed in the system */ -if (flags &0x1 ) +if (flags &PARTITION_INFO_GET_RETURN_COUNT_ONLY ) goto out_unlock; partition_sz = res->a3;
@@ -781,10 +782,12 @@ static void do_ffa_part_get(struct arm_smccc_res *res, copy_sz = partition_sz * count;if (copy_sz >KVM_FFA_MBOX_NR_PAGES *PAGE_SIZE ) {ffa_to_smccc_res (res,FFA_RET_ABORTED ); - goto out_unlock; + goto release_rx; }memcpy (host_buffers.rx, hyp_buffers.rx, copy_sz); +release_rx: +ffa_rx_release (&_res); out_unlock:hyp_spin_unlock (&host_buffers.lock); }
include/linux/arm_ffa.h +3 -0
@@ -223,6 +223,9 @@ extern const struct bus_type ffa_bus_type;/* The FF-A 1.0 partition structure lacks the uuid[4] */ #define FFA_1_0_PARTITON_INFO_SZ (8) +/* Return the count of partitions deployed in the system */ +#define PARTITION_INFO_GET_RETURN_COUNT_ONLY (1) +/* FFA transport related */ struct ffa_partition_info {u16 id;
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog