]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: selftests: Select SMCCC conduit based on current EL
authorOliver Upton <oliver.upton@linux.dev>
Wed, 17 Sep 2025 21:20:38 +0000 (14:20 -0700)
committerMarc Zyngier <maz@kernel.org>
Wed, 24 Sep 2025 18:23:32 +0000 (19:23 +0100)
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>
tools/testing/selftests/kvm/arm64/hypercalls.c
tools/testing/selftests/kvm/arm64/kvm-uuid.c
tools/testing/selftests/kvm/arm64/psci_test.c
tools/testing/selftests/kvm/include/arm64/processor.h
tools/testing/selftests/kvm/steal_time.c

index 44cfcf8a7f46766649aa3f1188ae4577b70c9fac..bf038a0371f44a6329bd588e1770e912f0cd37a2 100644 (file)
@@ -108,7 +108,7 @@ static void guest_test_hvc(const struct test_hvc_info *hc_info)
 
        for (i = 0; i < hvc_info_arr_sz; i++, hc_info++) {
                memset(&res, 0, sizeof(res));
-               smccc_hvc(hc_info->func_id, hc_info->arg1, 0, 0, 0, 0, 0, 0, &res);
+               do_smccc(hc_info->func_id, hc_info->arg1, 0, 0, 0, 0, 0, 0, &res);
 
                switch (stage) {
                case TEST_STAGE_HVC_IFACE_FEAT_DISABLED:
index af9581b860f143b1e08d8263fa98799d09cd3d1c..b5be9133535a2038dda97a4767489e6f71f1cdde 100644 (file)
@@ -25,7 +25,7 @@ static void guest_code(void)
 {
        struct arm_smccc_res res = {};
 
-       smccc_hvc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, 0, 0, 0, 0, 0, 0, 0, &res);
+       do_smccc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, 0, 0, 0, 0, 0, 0, 0, &res);
 
        __GUEST_ASSERT(res.a0 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 &&
                       res.a1 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 &&
index 0d4680da66d11e6af75574d8d635f5fcc13ffd0f..98e49f710aef97b0a28ff54b8a8dacba42fbdd94 100644 (file)
@@ -27,7 +27,7 @@ static uint64_t psci_cpu_on(uint64_t target_cpu, uint64_t entry_addr,
 {
        struct arm_smccc_res res;
 
-       smccc_hvc(PSCI_0_2_FN64_CPU_ON, target_cpu, entry_addr, context_id,
+       do_smccc(PSCI_0_2_FN64_CPU_ON, target_cpu, entry_addr, context_id,
                  0, 0, 0, 0, &res);
 
        return res.a0;
@@ -38,7 +38,7 @@ static uint64_t psci_affinity_info(uint64_t target_affinity,
 {
        struct arm_smccc_res res;
 
-       smccc_hvc(PSCI_0_2_FN64_AFFINITY_INFO, target_affinity, lowest_affinity_level,
+       do_smccc(PSCI_0_2_FN64_AFFINITY_INFO, target_affinity, lowest_affinity_level,
                  0, 0, 0, 0, 0, &res);
 
        return res.a0;
@@ -48,7 +48,7 @@ static uint64_t psci_system_suspend(uint64_t entry_addr, uint64_t context_id)
 {
        struct arm_smccc_res res;
 
-       smccc_hvc(PSCI_1_0_FN64_SYSTEM_SUSPEND, entry_addr, context_id,
+       do_smccc(PSCI_1_0_FN64_SYSTEM_SUSPEND, entry_addr, context_id,
                  0, 0, 0, 0, 0, &res);
 
        return res.a0;
@@ -58,7 +58,7 @@ static uint64_t psci_system_off2(uint64_t type, uint64_t cookie)
 {
        struct arm_smccc_res res;
 
-       smccc_hvc(PSCI_1_3_FN64_SYSTEM_OFF2, type, cookie, 0, 0, 0, 0, 0, &res);
+       do_smccc(PSCI_1_3_FN64_SYSTEM_OFF2, type, cookie, 0, 0, 0, 0, 0, &res);
 
        return res.a0;
 }
@@ -67,7 +67,7 @@ static uint64_t psci_features(uint32_t func_id)
 {
        struct arm_smccc_res res;
 
-       smccc_hvc(PSCI_1_0_FN_PSCI_FEATURES, func_id, 0, 0, 0, 0, 0, 0, &res);
+       do_smccc(PSCI_1_0_FN_PSCI_FEATURES, func_id, 0, 0, 0, 0, 0, 0, &res);
 
        return res.a0;
 }
index 87f50efed720f56e7fd640974fbde68bab600b24..f037c1bb8e6328b4b087705f3707dd61d9fcc331 100644 (file)
@@ -359,4 +359,17 @@ static __always_inline u64 ctxt_reg_alias(struct kvm_vcpu *vcpu, u32 encoding)
 
 void kvm_get_default_vcpu_target(struct kvm_vm *vm, struct kvm_vcpu_init *init);
 
+static inline unsigned int get_current_el(void)
+{
+       return (read_sysreg(CurrentEL) >> 2) & 0x3;
+}
+
+#define do_smccc(...)                          \
+do {                                           \
+       if (get_current_el() == 2)              \
+               smccc_smc(__VA_ARGS__);         \
+       else                                    \
+               smccc_hvc(__VA_ARGS__);         \
+} while (0)
+
 #endif /* SELFTEST_KVM_PROCESSOR_H */
index cce2520af720e93c95bed60a0c5032b2a098dfc9..8edc1fca345bae9903d7b8cafda946240739b76a 100644 (file)
@@ -118,7 +118,7 @@ static int64_t smccc(uint32_t func, uint64_t arg)
 {
        struct arm_smccc_res res;
 
-       smccc_hvc(func, arg, 0, 0, 0, 0, 0, 0, &res);
+       do_smccc(func, arg, 0, 0, 0, 0, 0, 0, &res);
        return res.a0;
 }