Skip to content

Commit e170717

Browse files
ryanhrobMarc Zyngier
authored andcommitted
KVM: selftests: arm64: Fix ttbr0_el1 encoding for PA bits > 48
Bits [51:48] of the pgd address are stored at bits [5:2] of ttbr0_el1. page_table_test stores its page tables at the far end of IPA space so was tripping over this when run on a system that supports FEAT_LPA (or FEAT_LPA2). Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230308110948.1820163-4-ryan.roberts@arm.com
1 parent e659bab commit e170717

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void aarch64_vcpu_setup(struct kvm_vcpu *vcpu, struct kvm_vcpu_init *init)
242242
{
243243
struct kvm_vcpu_init default_init = { .target = -1, };
244244
struct kvm_vm *vm = vcpu->vm;
245-
uint64_t sctlr_el1, tcr_el1;
245+
uint64_t sctlr_el1, tcr_el1, ttbr0_el1;
246246

247247
if (!init)
248248
init = &default_init;
@@ -293,10 +293,13 @@ void aarch64_vcpu_setup(struct kvm_vcpu *vcpu, struct kvm_vcpu_init *init)
293293
TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode);
294294
}
295295

296+
ttbr0_el1 = vm->pgd & GENMASK(47, vm->page_shift);
297+
296298
/* Configure output size */
297299
switch (vm->mode) {
298300
case VM_MODE_P52V48_64K:
299301
tcr_el1 |= 6ul << 32; /* IPS = 52 bits */
302+
ttbr0_el1 |= FIELD_GET(GENMASK(51, 48), vm->pgd) << 2;
300303
break;
301304
case VM_MODE_P48V48_4K:
302305
case VM_MODE_P48V48_16K:
@@ -326,7 +329,7 @@ void aarch64_vcpu_setup(struct kvm_vcpu *vcpu, struct kvm_vcpu_init *init)
326329
vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_SCTLR_EL1), sctlr_el1);
327330
vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_TCR_EL1), tcr_el1);
328331
vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MAIR_EL1), DEFAULT_MAIR_EL1);
329-
vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_TTBR0_EL1), vm->pgd);
332+
vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_TTBR0_EL1), ttbr0_el1);
330333
vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_TPIDR_EL1), vcpu->id);
331334
}
332335

0 commit comments

Comments
 (0)