Skip to content

Commit 8943763

Browse files
Sebastian Eneoupton
authored andcommitted
KVM: arm64: Add support for FFA_PARTITION_INFO_GET
Handle the FFA_PARTITION_INFO_GET host call inside the pKVM hypervisor and copy the response message back to the host buffers. Signed-off-by: Sebastian Ene <[email protected]> Reviewed-by: Sudeep Holla <[email protected]> Tested-by: Sudeep Holla <[email protected]> Acked-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent c9c0126 commit 8943763

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

arch/arm64/kvm/hyp/nvhe/ffa.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,55 @@ static void do_ffa_version(struct arm_smccc_res *res,
719719
hyp_spin_unlock(&version_lock);
720720
}
721721

722+
static void do_ffa_part_get(struct arm_smccc_res *res,
723+
struct kvm_cpu_context *ctxt)
724+
{
725+
DECLARE_REG(u32, uuid0, ctxt, 1);
726+
DECLARE_REG(u32, uuid1, ctxt, 2);
727+
DECLARE_REG(u32, uuid2, ctxt, 3);
728+
DECLARE_REG(u32, uuid3, ctxt, 4);
729+
DECLARE_REG(u32, flags, ctxt, 5);
730+
u32 count, partition_sz, copy_sz;
731+
732+
hyp_spin_lock(&host_buffers.lock);
733+
if (!host_buffers.rx) {
734+
ffa_to_smccc_res(res, FFA_RET_BUSY);
735+
goto out_unlock;
736+
}
737+
738+
arm_smccc_1_1_smc(FFA_PARTITION_INFO_GET, uuid0, uuid1,
739+
uuid2, uuid3, flags, 0, 0,
740+
res);
741+
742+
if (res->a0 != FFA_SUCCESS)
743+
goto out_unlock;
744+
745+
count = res->a2;
746+
if (!count)
747+
goto out_unlock;
748+
749+
if (hyp_ffa_version > FFA_VERSION_1_0) {
750+
/* Get the number of partitions deployed in the system */
751+
if (flags & 0x1)
752+
goto out_unlock;
753+
754+
partition_sz = res->a3;
755+
} else {
756+
/* FFA_VERSION_1_0 lacks the size in the response */
757+
partition_sz = FFA_1_0_PARTITON_INFO_SZ;
758+
}
759+
760+
copy_sz = partition_sz * count;
761+
if (copy_sz > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) {
762+
ffa_to_smccc_res(res, FFA_RET_ABORTED);
763+
goto out_unlock;
764+
}
765+
766+
memcpy(host_buffers.rx, hyp_buffers.rx, copy_sz);
767+
out_unlock:
768+
hyp_spin_unlock(&host_buffers.lock);
769+
}
770+
722771
bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)
723772
{
724773
struct arm_smccc_res res;
@@ -773,6 +822,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)
773822
case FFA_VERSION:
774823
do_ffa_version(&res, host_ctxt);
775824
goto out_handled;
825+
case FFA_PARTITION_INFO_GET:
826+
do_ffa_part_get(&res, host_ctxt);
827+
goto out_handled;
776828
}
777829

778830
if (ffa_call_supported(func_id))

include/linux/arm_ffa.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev) { return false; }
212212

213213
extern const struct bus_type ffa_bus_type;
214214

215+
/* The FF-A 1.0 partition structure lacks the uuid[4] */
216+
#define FFA_1_0_PARTITON_INFO_SZ (8)
217+
215218
/* FFA transport related */
216219
struct ffa_partition_info {
217220
u16 id;

0 commit comments

Comments
 (0)