Skip to content

Commit d72543a

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Select SMCCC conduit based on current EL
HVCs are taken within the VM when EL2 is in use. Ensure tests use the SMC instruction when running at EL2 to interact with the host. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent a1b91ac commit d72543a

5 files changed

Lines changed: 21 additions & 8 deletions

File tree

tools/testing/selftests/kvm/arm64/hypercalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void guest_test_hvc(const struct test_hvc_info *hc_info)
108108

109109
for (i = 0; i < hvc_info_arr_sz; i++, hc_info++) {
110110
memset(&res, 0, sizeof(res));
111-
smccc_hvc(hc_info->func_id, hc_info->arg1, 0, 0, 0, 0, 0, 0, &res);
111+
do_smccc(hc_info->func_id, hc_info->arg1, 0, 0, 0, 0, 0, 0, &res);
112112

113113
switch (stage) {
114114
case TEST_STAGE_HVC_IFACE_FEAT_DISABLED:

tools/testing/selftests/kvm/arm64/kvm-uuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void guest_code(void)
2525
{
2626
struct arm_smccc_res res = {};
2727

28-
smccc_hvc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, 0, 0, 0, 0, 0, 0, 0, &res);
28+
do_smccc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, 0, 0, 0, 0, 0, 0, 0, &res);
2929

3030
__GUEST_ASSERT(res.a0 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 &&
3131
res.a1 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 &&

tools/testing/selftests/kvm/arm64/psci_test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static uint64_t psci_cpu_on(uint64_t target_cpu, uint64_t entry_addr,
2727
{
2828
struct arm_smccc_res res;
2929

30-
smccc_hvc(PSCI_0_2_FN64_CPU_ON, target_cpu, entry_addr, context_id,
30+
do_smccc(PSCI_0_2_FN64_CPU_ON, target_cpu, entry_addr, context_id,
3131
0, 0, 0, 0, &res);
3232

3333
return res.a0;
@@ -38,7 +38,7 @@ static uint64_t psci_affinity_info(uint64_t target_affinity,
3838
{
3939
struct arm_smccc_res res;
4040

41-
smccc_hvc(PSCI_0_2_FN64_AFFINITY_INFO, target_affinity, lowest_affinity_level,
41+
do_smccc(PSCI_0_2_FN64_AFFINITY_INFO, target_affinity, lowest_affinity_level,
4242
0, 0, 0, 0, 0, &res);
4343

4444
return res.a0;
@@ -48,7 +48,7 @@ static uint64_t psci_system_suspend(uint64_t entry_addr, uint64_t context_id)
4848
{
4949
struct arm_smccc_res res;
5050

51-
smccc_hvc(PSCI_1_0_FN64_SYSTEM_SUSPEND, entry_addr, context_id,
51+
do_smccc(PSCI_1_0_FN64_SYSTEM_SUSPEND, entry_addr, context_id,
5252
0, 0, 0, 0, 0, &res);
5353

5454
return res.a0;
@@ -58,7 +58,7 @@ static uint64_t psci_system_off2(uint64_t type, uint64_t cookie)
5858
{
5959
struct arm_smccc_res res;
6060

61-
smccc_hvc(PSCI_1_3_FN64_SYSTEM_OFF2, type, cookie, 0, 0, 0, 0, 0, &res);
61+
do_smccc(PSCI_1_3_FN64_SYSTEM_OFF2, type, cookie, 0, 0, 0, 0, 0, &res);
6262

6363
return res.a0;
6464
}
@@ -67,7 +67,7 @@ static uint64_t psci_features(uint32_t func_id)
6767
{
6868
struct arm_smccc_res res;
6969

70-
smccc_hvc(PSCI_1_0_FN_PSCI_FEATURES, func_id, 0, 0, 0, 0, 0, 0, &res);
70+
do_smccc(PSCI_1_0_FN_PSCI_FEATURES, func_id, 0, 0, 0, 0, 0, 0, &res);
7171

7272
return res.a0;
7373
}

tools/testing/selftests/kvm/include/arm64/processor.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,17 @@ static __always_inline u64 ctxt_reg_alias(struct kvm_vcpu *vcpu, u32 encoding)
359359

360360
void kvm_get_default_vcpu_target(struct kvm_vm *vm, struct kvm_vcpu_init *init);
361361

362+
static inline unsigned int get_current_el(void)
363+
{
364+
return (read_sysreg(CurrentEL) >> 2) & 0x3;
365+
}
366+
367+
#define do_smccc(...) \
368+
do { \
369+
if (get_current_el() == 2) \
370+
smccc_smc(__VA_ARGS__); \
371+
else \
372+
smccc_hvc(__VA_ARGS__); \
373+
} while (0)
374+
362375
#endif /* SELFTEST_KVM_PROCESSOR_H */

tools/testing/selftests/kvm/steal_time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int64_t smccc(uint32_t func, uint64_t arg)
118118
{
119119
struct arm_smccc_res res;
120120

121-
smccc_hvc(func, arg, 0, 0, 0, 0, 0, 0, &res);
121+
do_smccc(func, arg, 0, 0, 0, 0, 0, 0, &res);
122122
return res.a0;
123123
}
124124

0 commit comments

Comments
 (0)