Skip to content

Commit 23e7a34

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Add AT fast-path support for S1PIE
Emulating AT using AT instructions requires that the live state matches the translation regime the AT instruction targets. If targeting the EL1&0 translation regime and that S1PIE is supported, we also need to restore that state (covering TCR2_EL1, PIR_EL1, and PIRE0_EL1). Add the required system register switcheroo. Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Joey Gouly <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 874ae1d commit 23e7a34

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

arch/arm64/kvm/at.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ struct mmu_config {
412412
u64 ttbr1;
413413
u64 tcr;
414414
u64 mair;
415+
u64 tcr2;
416+
u64 pir;
417+
u64 pire0;
415418
u64 sctlr;
416419
u64 vttbr;
417420
u64 vtcr;
@@ -424,6 +427,13 @@ static void __mmu_config_save(struct mmu_config *config)
424427
config->ttbr1 = read_sysreg_el1(SYS_TTBR1);
425428
config->tcr = read_sysreg_el1(SYS_TCR);
426429
config->mair = read_sysreg_el1(SYS_MAIR);
430+
if (cpus_have_final_cap(ARM64_HAS_TCR2)) {
431+
config->tcr2 = read_sysreg_el1(SYS_TCR2);
432+
if (cpus_have_final_cap(ARM64_HAS_S1PIE)) {
433+
config->pir = read_sysreg_el1(SYS_PIR);
434+
config->pire0 = read_sysreg_el1(SYS_PIRE0);
435+
}
436+
}
427437
config->sctlr = read_sysreg_el1(SYS_SCTLR);
428438
config->vttbr = read_sysreg(vttbr_el2);
429439
config->vtcr = read_sysreg(vtcr_el2);
@@ -444,6 +454,13 @@ static void __mmu_config_restore(struct mmu_config *config)
444454
write_sysreg_el1(config->ttbr1, SYS_TTBR1);
445455
write_sysreg_el1(config->tcr, SYS_TCR);
446456
write_sysreg_el1(config->mair, SYS_MAIR);
457+
if (cpus_have_final_cap(ARM64_HAS_TCR2)) {
458+
write_sysreg_el1(config->tcr2, SYS_TCR2);
459+
if (cpus_have_final_cap(ARM64_HAS_S1PIE)) {
460+
write_sysreg_el1(config->pir, SYS_PIR);
461+
write_sysreg_el1(config->pire0, SYS_PIRE0);
462+
}
463+
}
447464
write_sysreg_el1(config->sctlr, SYS_SCTLR);
448465
write_sysreg(config->vttbr, vttbr_el2);
449466
write_sysreg(config->vtcr, vtcr_el2);
@@ -914,6 +931,13 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)
914931
write_sysreg_el1(vcpu_read_sys_reg(vcpu, TTBR1_EL1), SYS_TTBR1);
915932
write_sysreg_el1(vcpu_read_sys_reg(vcpu, TCR_EL1), SYS_TCR);
916933
write_sysreg_el1(vcpu_read_sys_reg(vcpu, MAIR_EL1), SYS_MAIR);
934+
if (kvm_has_feat(vcpu->kvm, ID_AA64MMFR3_EL1, TCRX, IMP)) {
935+
write_sysreg_el1(vcpu_read_sys_reg(vcpu, TCR2_EL1), SYS_TCR2);
936+
if (kvm_has_feat(vcpu->kvm, ID_AA64MMFR3_EL1, S1PIE, IMP)) {
937+
write_sysreg_el1(vcpu_read_sys_reg(vcpu, PIR_EL1), SYS_PIR);
938+
write_sysreg_el1(vcpu_read_sys_reg(vcpu, PIRE0_EL1), SYS_PIRE0);
939+
}
940+
}
917941
write_sysreg_el1(vcpu_read_sys_reg(vcpu, SCTLR_EL1), SYS_SCTLR);
918942
__load_stage2(mmu, mmu->arch);
919943

0 commit comments

Comments
 (0)