Skip to content

Commit 2f41a61

Browse files
author
Marc Zyngier
committed
KVM: selftests: arm64: Rework TCR_EL1 configuration
The current way we initialise TCR_EL1 is a bit cumbersome, as we mix setting TG0 and IPS in the same swtch statement. Split it into two statements (one for the base granule size, and another for the IPA size), allowing new modes to be added in a more elegant way. No functional change intended. Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0303ffd commit 2f41a61

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tools/testing/selftests/kvm/lib/aarch64/processor.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_vcpu_init
238238
get_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_SCTLR_EL1), &sctlr_el1);
239239
get_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TCR_EL1), &tcr_el1);
240240

241+
/* Configure base granule size */
241242
switch (vm->mode) {
242243
case VM_MODE_P52V48_4K:
243244
TEST_FAIL("AArch64 does not support 4K sized pages "
@@ -246,23 +247,29 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_vcpu_init
246247
TEST_FAIL("AArch64 does not support 4K sized pages "
247248
"with ANY-bit physical address ranges");
248249
case VM_MODE_P52V48_64K:
250+
case VM_MODE_P48V48_64K:
251+
case VM_MODE_P40V48_64K:
249252
tcr_el1 |= 1ul << 14; /* TG0 = 64KB */
250-
tcr_el1 |= 6ul << 32; /* IPS = 52 bits */
251253
break;
252254
case VM_MODE_P48V48_4K:
255+
case VM_MODE_P40V48_4K:
253256
tcr_el1 |= 0ul << 14; /* TG0 = 4KB */
254-
tcr_el1 |= 5ul << 32; /* IPS = 48 bits */
255257
break;
258+
default:
259+
TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode);
260+
}
261+
262+
/* Configure output size */
263+
switch (vm->mode) {
264+
case VM_MODE_P52V48_64K:
265+
tcr_el1 |= 6ul << 32; /* IPS = 52 bits */
266+
break;
267+
case VM_MODE_P48V48_4K:
256268
case VM_MODE_P48V48_64K:
257-
tcr_el1 |= 1ul << 14; /* TG0 = 64KB */
258269
tcr_el1 |= 5ul << 32; /* IPS = 48 bits */
259270
break;
260271
case VM_MODE_P40V48_4K:
261-
tcr_el1 |= 0ul << 14; /* TG0 = 4KB */
262-
tcr_el1 |= 2ul << 32; /* IPS = 40 bits */
263-
break;
264272
case VM_MODE_P40V48_64K:
265-
tcr_el1 |= 1ul << 14; /* TG0 = 64KB */
266273
tcr_el1 |= 2ul << 32; /* IPS = 40 bits */
267274
break;
268275
default:

0 commit comments

Comments
 (0)