]> www.infradead.org Git - users/hch/block.git/commitdiff
KVM: selftests: arm64: Test that feature ID regs survive a reset
authorOliver Upton <oliver.upton@linux.dev>
Thu, 2 May 2024 23:35:28 +0000 (23:35 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 9 May 2024 17:41:56 +0000 (18:41 +0100)
One of the expectations with feature ID registers is that their values
survive a vCPU reset. Start testing that.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20240502233529.1958459-7-oliver.upton@linux.dev
Signed-off-by: Marc Zyngier <maz@kernel.org>
tools/testing/selftests/kvm/aarch64/set_id_regs.c

index 7c8d33fa2ae60a4c1413e14cb3eef3e2535197e2..24b248c78f5d5a66257c9d3165cf0c30eafd0efc 100644 (file)
@@ -457,13 +457,36 @@ static void test_guest_reg_read(struct kvm_vcpu *vcpu)
        }
 }
 
+static void test_assert_id_reg_unchanged(struct kvm_vcpu *vcpu, uint32_t encoding)
+{
+       size_t idx = encoding_to_range_idx(encoding);
+       uint64_t observed;
+
+       vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(encoding), &observed);
+       TEST_ASSERT_EQ(test_reg_vals[idx], observed);
+}
+
+static void test_reset_preserves_id_regs(struct kvm_vcpu *vcpu)
+{
+       /*
+        * Calls KVM_ARM_VCPU_INIT behind the scenes, which will do an
+        * architectural reset of the vCPU.
+        */
+       aarch64_vcpu_setup(vcpu, NULL);
+
+       for (int i = 0; i < ARRAY_SIZE(test_regs); i++)
+               test_assert_id_reg_unchanged(vcpu, test_regs[i].reg);
+
+       ksft_test_result_pass("%s\n", __func__);
+}
+
 int main(void)
 {
        struct kvm_vcpu *vcpu;
        struct kvm_vm *vm;
        bool aarch64_only;
        uint64_t val, el0;
-       int ftr_cnt;
+       int test_cnt;
 
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES));
 
@@ -476,18 +499,20 @@ int main(void)
 
        ksft_print_header();
 
-       ftr_cnt = ARRAY_SIZE(ftr_id_aa64dfr0_el1) + ARRAY_SIZE(ftr_id_dfr0_el1) +
-                 ARRAY_SIZE(ftr_id_aa64isar0_el1) + ARRAY_SIZE(ftr_id_aa64isar1_el1) +
-                 ARRAY_SIZE(ftr_id_aa64isar2_el1) + ARRAY_SIZE(ftr_id_aa64pfr0_el1) +
-                 ARRAY_SIZE(ftr_id_aa64mmfr0_el1) + ARRAY_SIZE(ftr_id_aa64mmfr1_el1) +
-                 ARRAY_SIZE(ftr_id_aa64mmfr2_el1) + ARRAY_SIZE(ftr_id_aa64zfr0_el1) -
-                 ARRAY_SIZE(test_regs);
+       test_cnt = ARRAY_SIZE(ftr_id_aa64dfr0_el1) + ARRAY_SIZE(ftr_id_dfr0_el1) +
+                  ARRAY_SIZE(ftr_id_aa64isar0_el1) + ARRAY_SIZE(ftr_id_aa64isar1_el1) +
+                  ARRAY_SIZE(ftr_id_aa64isar2_el1) + ARRAY_SIZE(ftr_id_aa64pfr0_el1) +
+                  ARRAY_SIZE(ftr_id_aa64mmfr0_el1) + ARRAY_SIZE(ftr_id_aa64mmfr1_el1) +
+                  ARRAY_SIZE(ftr_id_aa64mmfr2_el1) + ARRAY_SIZE(ftr_id_aa64zfr0_el1) -
+                  ARRAY_SIZE(test_regs) + 1;
 
-       ksft_set_plan(ftr_cnt);
+       ksft_set_plan(test_cnt);
 
        test_vm_ftr_id_regs(vcpu, aarch64_only);
        test_guest_reg_read(vcpu);
 
+       test_reset_preserves_id_regs(vcpu);
+
        kvm_vm_free(vm);
 
        ksft_finished();