]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: selftests: Provide kvm_arch_vm_post_create() in library code
authorOliver Upton <oliver.upton@linux.dev>
Wed, 17 Sep 2025 21:20:31 +0000 (14:20 -0700)
committerMarc Zyngier <maz@kernel.org>
Wed, 24 Sep 2025 18:23:31 +0000 (19:23 +0100)
In order to compel the default usage of EL2 in selftests, move
kvm_arch_vm_post_create() to library code and expose an opt-in for using
MTE by default.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
tools/testing/selftests/kvm/arm64/set_id_regs.c
tools/testing/selftests/kvm/include/arm64/processor.h
tools/testing/selftests/kvm/lib/arm64/processor.c

index 189321e969258c3151608214daf86882b1e51a74..a2d367a2c93c48757b8ce4cd0066ba6e2937f128 100644 (file)
@@ -15,8 +15,6 @@
 #include "test_util.h"
 #include <linux/bitfield.h>
 
-bool have_cap_arm_mte;
-
 enum ftr_type {
        FTR_EXACT,                      /* Use a predefined safe value */
        FTR_LOWER_SAFE,                 /* Smaller value is safe */
@@ -568,7 +566,9 @@ static void test_user_set_mte_reg(struct kvm_vcpu *vcpu)
        uint64_t mte_frac;
        int idx, err;
 
-       if (!have_cap_arm_mte) {
+       val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1));
+       mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val);
+       if (!mte) {
                ksft_test_result_skip("MTE capability not supported, nothing to test\n");
                return;
        }
@@ -593,9 +593,6 @@ static void test_user_set_mte_reg(struct kvm_vcpu *vcpu)
         * from unsupported (0xF) to supported (0).
         *
         */
-       val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1));
-
-       mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val);
        mte_frac = FIELD_GET(ID_AA64PFR1_EL1_MTE_frac, val);
        if (mte != ID_AA64PFR1_EL1_MTE_MTE2 ||
            mte_frac != ID_AA64PFR1_EL1_MTE_frac_NI) {
@@ -750,14 +747,6 @@ static void test_reset_preserves_id_regs(struct kvm_vcpu *vcpu)
        ksft_test_result_pass("%s\n", __func__);
 }
 
-void kvm_arch_vm_post_create(struct kvm_vm *vm)
-{
-       if (vm_check_cap(vm, KVM_CAP_ARM_MTE)) {
-               vm_enable_cap(vm, KVM_CAP_ARM_MTE, 0);
-               have_cap_arm_mte = true;
-       }
-}
-
 int main(void)
 {
        struct kvm_vcpu *vcpu;
@@ -769,6 +758,8 @@ int main(void)
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES));
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_WRITABLE_IMP_ID_REGS));
 
+       test_wants_mte();
+
        vm = vm_create(1);
        vm_enable_cap(vm, KVM_CAP_ARM_WRITABLE_IMP_ID_REGS, 0);
        vcpu = vm_vcpu_add(vm, 0, guest_code);
index 255fed769a8a54ece6876e2106d42f9184dafbc4..8370fc94041df3ca2fc7ccd2799a4be885860ad6 100644 (file)
@@ -300,4 +300,6 @@ void smccc_smc(uint32_t function_id, uint64_t arg0, uint64_t arg1,
 /* Execute a Wait For Interrupt instruction. */
 void wfi(void);
 
+void test_wants_mte(void);
+
 #endif /* SELFTEST_KVM_PROCESSOR_H */
index eb115123d74118035b6f09ecc52a4b51eca9be51..caed1998c7b38809b77fee598af9e696f0d63772 100644 (file)
@@ -653,3 +653,16 @@ void wfi(void)
 {
        asm volatile("wfi");
 }
+
+static bool request_mte;
+
+void test_wants_mte(void)
+{
+       request_mte = true;
+}
+
+void kvm_arch_vm_post_create(struct kvm_vm *vm)
+{
+       if (request_mte && vm_check_cap(vm, KVM_CAP_ARM_MTE))
+               vm_enable_cap(vm, KVM_CAP_ARM_MTE, 0);
+}