Skip to content

Commit 11a31be

Browse files
Sebastian Ottoupton
authored andcommitted
KVM: selftests: arm64: Test writes to CTR_EL0
Test that CTR_EL0 is modifiable from userspace, that changes are visible to guests, and that they are preserved across a vCPU reset. Signed-off-by: Sebastian Ott <[email protected]> Reviewed-by: Eric Auger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 76d3601 commit 11a31be

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static void guest_code(void)
219219
GUEST_REG_SYNC(SYS_ID_AA64MMFR1_EL1);
220220
GUEST_REG_SYNC(SYS_ID_AA64MMFR2_EL1);
221221
GUEST_REG_SYNC(SYS_ID_AA64ZFR0_EL1);
222+
GUEST_REG_SYNC(SYS_CTR_EL0);
222223

223224
GUEST_DONE();
224225
}
@@ -490,11 +491,25 @@ static void test_clidr(struct kvm_vcpu *vcpu)
490491
test_reg_vals[encoding_to_range_idx(SYS_CLIDR_EL1)] = clidr;
491492
}
492493

494+
static void test_ctr(struct kvm_vcpu *vcpu)
495+
{
496+
u64 ctr;
497+
498+
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CTR_EL0), &ctr);
499+
ctr &= ~CTR_EL0_DIC_MASK;
500+
if (ctr & CTR_EL0_IminLine_MASK)
501+
ctr--;
502+
503+
vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CTR_EL0), ctr);
504+
test_reg_vals[encoding_to_range_idx(SYS_CTR_EL0)] = ctr;
505+
}
506+
493507
static void test_vcpu_ftr_id_regs(struct kvm_vcpu *vcpu)
494508
{
495509
u64 val;
496510

497511
test_clidr(vcpu);
512+
test_ctr(vcpu);
498513

499514
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &val);
500515
val++;
@@ -525,6 +540,7 @@ static void test_reset_preserves_id_regs(struct kvm_vcpu *vcpu)
525540
test_assert_id_reg_unchanged(vcpu, test_regs[i].reg);
526541

527542
test_assert_id_reg_unchanged(vcpu, SYS_CLIDR_EL1);
543+
test_assert_id_reg_unchanged(vcpu, SYS_CTR_EL0);
528544

529545
ksft_test_result_pass("%s\n", __func__);
530546
}

0 commit comments

Comments
 (0)