Skip to content

Commit 12bdce4

Browse files
willdeaconoupton
authored andcommitted
KVM: arm64: Probe FF-A version and host/hyp partition ID during init
Probe FF-A during pKVM initialisation so that we can detect any inconsistencies in the version or partition ID early on. Signed-off-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20230523101828.7328-3-will@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 048be5f commit 12bdce4

5 files changed

Lines changed: 38 additions & 0 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ struct kvm_host_data {
405405
struct kvm_host_psci_config {
406406
/* PSCI version used by host. */
407407
u32 version;
408+
u32 smccc_version;
408409

409410
/* Function IDs used by host if version is v0.1. */
410411
struct psci_0_1_function_ids function_ids_0_1;

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,7 @@ static bool __init init_psci_relay(void)
19101910
}
19111911

19121912
kvm_host_psci_config.version = psci_ops.get_version();
1913+
kvm_host_psci_config.smccc_version = arm_smccc_get_version();
19131914

19141915
if (kvm_host_psci_config.version == PSCI_VERSION(0, 1)) {
19151916
kvm_host_psci_config.function_ids_0_1 = get_psci_0_1_function_ids();

arch/arm64/kvm/hyp/include/nvhe/ffa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define FFA_MIN_FUNC_NUM 0x60
1212
#define FFA_MAX_FUNC_NUM 0x7F
1313

14+
int hyp_ffa_init(void);
1415
bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt);
1516

1617
#endif /* __KVM_HYP_FFA_H */

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
#include <nvhe/ffa.h>
3232
#include <nvhe/trap_handler.h>
3333

34+
/*
35+
* "ID value 0 must be returned at the Non-secure physical FF-A instance"
36+
* We share this ID with the host.
37+
*/
38+
#define HOST_FFA_ID 0
39+
3440
static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno)
3541
{
3642
*res = (struct arm_smccc_res) {
@@ -117,3 +123,27 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt)
117123
ffa_set_retval(host_ctxt, &res);
118124
return true;
119125
}
126+
127+
int hyp_ffa_init(void)
128+
{
129+
struct arm_smccc_res res;
130+
131+
if (kvm_host_psci_config.smccc_version < ARM_SMCCC_VERSION_1_2)
132+
return 0;
133+
134+
arm_smccc_1_1_smc(FFA_VERSION, FFA_VERSION_1_0, 0, 0, 0, 0, 0, 0, &res);
135+
if (res.a0 == FFA_RET_NOT_SUPPORTED)
136+
return 0;
137+
138+
if (res.a0 != FFA_VERSION_1_0)
139+
return -EOPNOTSUPP;
140+
141+
arm_smccc_1_1_smc(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0, &res);
142+
if (res.a0 != FFA_SUCCESS)
143+
return -EOPNOTSUPP;
144+
145+
if (res.a2 != HOST_FFA_ID)
146+
return -EINVAL;
147+
148+
return 0;
149+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <asm/kvm_pkvm.h>
1212

1313
#include <nvhe/early_alloc.h>
14+
#include <nvhe/ffa.h>
1415
#include <nvhe/fixed_config.h>
1516
#include <nvhe/gfp.h>
1617
#include <nvhe/memory.h>
@@ -314,6 +315,10 @@ void __noreturn __pkvm_init_finalise(void)
314315
if (ret)
315316
goto out;
316317

318+
ret = hyp_ffa_init();
319+
if (ret)
320+
goto out;
321+
317322
pkvm_hyp_vm_table_init(vm_table_base);
318323
out:
319324
/*

0 commit comments

Comments
 (0)