Skip to content

Commit 07eabd8

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: selftests: arm64: Test that feature ID regs survive a reset
One of the expectations with feature ID registers is that their values survive a vCPU reset. Start testing that. Signed-off-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 46247a3 commit 07eabd8

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

tools/testing/selftests/kvm/aarch64/set_id_regs.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,36 @@ static void test_guest_reg_read(struct kvm_vcpu *vcpu)
457457
}
458458
}
459459

460+
static void test_assert_id_reg_unchanged(struct kvm_vcpu *vcpu, uint32_t encoding)
461+
{
462+
size_t idx = encoding_to_range_idx(encoding);
463+
uint64_t observed;
464+
465+
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(encoding), &observed);
466+
TEST_ASSERT_EQ(test_reg_vals[idx], observed);
467+
}
468+
469+
static void test_reset_preserves_id_regs(struct kvm_vcpu *vcpu)
470+
{
471+
/*
472+
* Calls KVM_ARM_VCPU_INIT behind the scenes, which will do an
473+
* architectural reset of the vCPU.
474+
*/
475+
aarch64_vcpu_setup(vcpu, NULL);
476+
477+
for (int i = 0; i < ARRAY_SIZE(test_regs); i++)
478+
test_assert_id_reg_unchanged(vcpu, test_regs[i].reg);
479+
480+
ksft_test_result_pass("%s\n", __func__);
481+
}
482+
460483
int main(void)
461484
{
462485
struct kvm_vcpu *vcpu;
463486
struct kvm_vm *vm;
464487
bool aarch64_only;
465488
uint64_t val, el0;
466-
int ftr_cnt;
489+
int test_cnt;
467490

468491
TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES));
469492

@@ -476,18 +499,20 @@ int main(void)
476499

477500
ksft_print_header();
478501

479-
ftr_cnt = ARRAY_SIZE(ftr_id_aa64dfr0_el1) + ARRAY_SIZE(ftr_id_dfr0_el1) +
480-
ARRAY_SIZE(ftr_id_aa64isar0_el1) + ARRAY_SIZE(ftr_id_aa64isar1_el1) +
481-
ARRAY_SIZE(ftr_id_aa64isar2_el1) + ARRAY_SIZE(ftr_id_aa64pfr0_el1) +
482-
ARRAY_SIZE(ftr_id_aa64mmfr0_el1) + ARRAY_SIZE(ftr_id_aa64mmfr1_el1) +
483-
ARRAY_SIZE(ftr_id_aa64mmfr2_el1) + ARRAY_SIZE(ftr_id_aa64zfr0_el1) -
484-
ARRAY_SIZE(test_regs);
502+
test_cnt = ARRAY_SIZE(ftr_id_aa64dfr0_el1) + ARRAY_SIZE(ftr_id_dfr0_el1) +
503+
ARRAY_SIZE(ftr_id_aa64isar0_el1) + ARRAY_SIZE(ftr_id_aa64isar1_el1) +
504+
ARRAY_SIZE(ftr_id_aa64isar2_el1) + ARRAY_SIZE(ftr_id_aa64pfr0_el1) +
505+
ARRAY_SIZE(ftr_id_aa64mmfr0_el1) + ARRAY_SIZE(ftr_id_aa64mmfr1_el1) +
506+
ARRAY_SIZE(ftr_id_aa64mmfr2_el1) + ARRAY_SIZE(ftr_id_aa64zfr0_el1) -
507+
ARRAY_SIZE(test_regs) + 1;
485508

486-
ksft_set_plan(ftr_cnt);
509+
ksft_set_plan(test_cnt);
487510

488511
test_vm_ftr_id_regs(vcpu, aarch64_only);
489512
test_guest_reg_read(vcpu);
490513

514+
test_reset_preserves_id_regs(vcpu);
515+
491516
kvm_vm_free(vm);
492517

493518
ksft_finished();

0 commit comments

Comments
 (0)