Skip to content

Commit 20936cd

Browse files
Fuad Tabbaoupton
authored andcommitted
KVM: arm64: Handle FFA_FEATURES call from the host
Filter out advertising unsupported features, and only advertise features and properties that are supported by the hypervisor proxy. Signed-off-by: Fuad Tabba <tabba@google.com> Signed-off-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20230523101828.7328-10-will@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 634d90c commit 20936cd

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

  • arch/arm64/kvm/hyp/nvhe

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,21 @@ static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno)
6464
};
6565
}
6666

67-
static void ffa_to_smccc_res(struct arm_smccc_res *res, int ret)
67+
static void ffa_to_smccc_res_prop(struct arm_smccc_res *res, int ret, u64 prop)
6868
{
6969
if (ret == FFA_RET_SUCCESS) {
70-
*res = (struct arm_smccc_res) { .a0 = FFA_SUCCESS };
70+
*res = (struct arm_smccc_res) { .a0 = FFA_SUCCESS,
71+
.a2 = prop };
7172
} else {
7273
ffa_to_smccc_error(res, ret);
7374
}
7475
}
7576

77+
static void ffa_to_smccc_res(struct arm_smccc_res *res, int ret)
78+
{
79+
ffa_to_smccc_res_prop(res, ret, 0);
80+
}
81+
7682
static void ffa_set_retval(struct kvm_cpu_context *ctxt,
7783
struct arm_smccc_res *res)
7884
{
@@ -484,14 +490,41 @@ static bool ffa_call_supported(u64 func_id)
484490
case FFA_RXTX_MAP:
485491
case FFA_MEM_DONATE:
486492
case FFA_MEM_RETRIEVE_REQ:
487-
/* Don't advertise any features just yet */
488-
case FFA_FEATURES:
489493
return false;
490494
}
491495

492496
return true;
493497
}
494498

499+
static bool do_ffa_features(struct arm_smccc_res *res,
500+
struct kvm_cpu_context *ctxt)
501+
{
502+
DECLARE_REG(u32, id, ctxt, 1);
503+
u64 prop = 0;
504+
int ret = 0;
505+
506+
if (!ffa_call_supported(id)) {
507+
ret = FFA_RET_NOT_SUPPORTED;
508+
goto out_handled;
509+
}
510+
511+
switch (id) {
512+
case FFA_MEM_SHARE:
513+
case FFA_FN64_MEM_SHARE:
514+
case FFA_MEM_LEND:
515+
case FFA_FN64_MEM_LEND:
516+
ret = FFA_RET_SUCCESS;
517+
prop = 0; /* No support for dynamic buffers */
518+
goto out_handled;
519+
default:
520+
return false;
521+
}
522+
523+
out_handled:
524+
ffa_to_smccc_res_prop(res, ret, prop);
525+
return true;
526+
}
527+
495528
bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt)
496529
{
497530
DECLARE_REG(u64, func_id, host_ctxt, 0);
@@ -514,6 +547,10 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt)
514547
return false;
515548

516549
switch (func_id) {
550+
case FFA_FEATURES:
551+
if (!do_ffa_features(&res, host_ctxt))
552+
return false;
553+
goto out_handled;
517554
/* Memory management */
518555
case FFA_FN64_RXTX_MAP:
519556
do_ffa_rxtx_map(&res, host_ctxt);

0 commit comments

Comments
 (0)