Skip to content

Commit 9b58e66

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Correctly honor the presence of FEAT_TCRX
We currently blindly enable TCR2_EL1 use in a guest, irrespective of the feature set. This is obviously wrong, and we should actually honor the guest configuration and handle the possible trap resulting from the guest being buggy. 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 83a7eef commit 9b58e66

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

arch/arm64/include/asm/kvm_arm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
#define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
103103
#define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
104104

105-
#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME | HCRX_EL2_TCR2En)
105+
#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME)
106106
#define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En | HCRX_EL2_EnFPM)
107107

108108
/* TCR_EL2 Registers bits */

arch/arm64/kvm/sys_regs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu,
383383
bool was_enabled = vcpu_has_cache_enabled(vcpu);
384384
u64 val, mask, shift;
385385

386+
if (reg_to_encoding(r) == SYS_TCR2_EL1 &&
387+
!kvm_has_feat(vcpu->kvm, ID_AA64MMFR3_EL1, TCRX, IMP)) {
388+
kvm_inject_undefined(vcpu);
389+
return false;
390+
}
391+
386392
BUG_ON(!p->is_write);
387393

388394
get_access_mask(r, &mask, &shift);
@@ -4060,6 +4066,9 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu)
40604066

40614067
if (kvm_has_feat(kvm, ID_AA64ISAR2_EL1, MOPS, IMP))
40624068
vcpu->arch.hcrx_el2 |= (HCRX_EL2_MSCEn | HCRX_EL2_MCE2);
4069+
4070+
if (kvm_has_feat(kvm, ID_AA64MMFR3_EL1, TCRX, IMP))
4071+
vcpu->arch.hcrx_el2 |= HCRX_EL2_TCR2En;
40634072
}
40644073

40654074
if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags))

0 commit comments

Comments
 (0)