Skip to content

Commit 8ecdccb

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Make TLBI OS/Range UNDEF if not advertised to the guest
Outer Shareable and Range TLBI instructions shouldn't be made available to the guest if they are not advertised. Use FGU to disable those, and set HCR_EL2.TLBIOS in the case the host doesn't have FGT. Note that in that later case, we cannot efficiently disable TLBI Range instructions, as this would require to trap all TLBIs. 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 d196c20 commit 8ecdccb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,6 +3948,14 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu)
39483948

39493949
mutex_lock(&kvm->arch.config_lock);
39503950

3951+
/*
3952+
* In the absence of FGT, we cannot independently trap TLBI
3953+
* Range instructions. This isn't great, but trapping all
3954+
* TLBIs would be far worse. Live with it...
3955+
*/
3956+
if (!kvm_has_feat(kvm, ID_AA64ISAR0_EL1, TLB, OS))
3957+
vcpu->arch.hcr_el2 |= HCR_TTLBOS;
3958+
39513959
if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags))
39523960
goto out;
39533961

@@ -3960,6 +3968,32 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu)
39603968
HFGxTR_EL2_nSMPRI_EL1_MASK |
39613969
HFGxTR_EL2_nTPIDR2_EL0_MASK);
39623970

3971+
if (!kvm_has_feat(kvm, ID_AA64ISAR0_EL1, TLB, OS))
3972+
kvm->arch.fgu[HFGITR_GROUP] |= (HFGITR_EL2_TLBIRVAALE1OS|
3973+
HFGITR_EL2_TLBIRVALE1OS |
3974+
HFGITR_EL2_TLBIRVAAE1OS |
3975+
HFGITR_EL2_TLBIRVAE1OS |
3976+
HFGITR_EL2_TLBIVAALE1OS |
3977+
HFGITR_EL2_TLBIVALE1OS |
3978+
HFGITR_EL2_TLBIVAAE1OS |
3979+
HFGITR_EL2_TLBIASIDE1OS |
3980+
HFGITR_EL2_TLBIVAE1OS |
3981+
HFGITR_EL2_TLBIVMALLE1OS);
3982+
3983+
if (!kvm_has_feat(kvm, ID_AA64ISAR0_EL1, TLB, RANGE))
3984+
kvm->arch.fgu[HFGITR_GROUP] |= (HFGITR_EL2_TLBIRVAALE1 |
3985+
HFGITR_EL2_TLBIRVALE1 |
3986+
HFGITR_EL2_TLBIRVAAE1 |
3987+
HFGITR_EL2_TLBIRVAE1 |
3988+
HFGITR_EL2_TLBIRVAALE1IS|
3989+
HFGITR_EL2_TLBIRVALE1IS |
3990+
HFGITR_EL2_TLBIRVAAE1IS |
3991+
HFGITR_EL2_TLBIRVAE1IS |
3992+
HFGITR_EL2_TLBIRVAALE1OS|
3993+
HFGITR_EL2_TLBIRVALE1OS |
3994+
HFGITR_EL2_TLBIRVAAE1OS |
3995+
HFGITR_EL2_TLBIRVAE1OS);
3996+
39633997
set_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags);
39643998
out:
39653999
mutex_unlock(&kvm->arch.config_lock);

0 commit comments

Comments
 (0)