Skip to content

Commit ad4f6ef

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Sanitise TCR2_EL2
TCR2_EL2 is a bag of control bits, all of which are only valid if certain features are present, and RES0 otherwise. Describe these constraints and register them with the masking infrastructure. 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 69c19e0 commit ad4f6ef

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

arch/arm64/kvm/nested.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,28 @@ int kvm_init_nv_sysregs(struct kvm *kvm)
12041204
res0 |= ~(res0 | res1);
12051205
set_sysreg_masks(kvm, HAFGRTR_EL2, res0, res1);
12061206

1207+
/* TCR2_EL2 */
1208+
res0 = TCR2_EL2_RES0;
1209+
res1 = TCR2_EL2_RES1;
1210+
if (!kvm_has_feat(kvm, ID_AA64MMFR3_EL1, D128, IMP))
1211+
res0 |= (TCR2_EL2_DisCH0 | TCR2_EL2_DisCH1 | TCR2_EL2_D128);
1212+
if (!kvm_has_feat(kvm, ID_AA64MMFR3_EL1, MEC, IMP))
1213+
res0 |= TCR2_EL2_AMEC1 | TCR2_EL2_AMEC0;
1214+
if (!kvm_has_feat(kvm, ID_AA64MMFR1_EL1, HAFDBS, HAFT))
1215+
res0 |= TCR2_EL2_HAFT;
1216+
if (!kvm_has_feat(kvm, ID_AA64PFR1_EL1, THE, IMP))
1217+
res0 |= TCR2_EL2_PTTWI | TCR2_EL2_PnCH;
1218+
if (!kvm_has_feat(kvm, ID_AA64MMFR3_EL1, AIE, IMP))
1219+
res0 |= TCR2_EL2_AIE;
1220+
if (!kvm_has_feat(kvm, ID_AA64MMFR3_EL1, S1POE, IMP))
1221+
res0 |= TCR2_EL2_POE | TCR2_EL2_E0POE;
1222+
if (!kvm_has_feat(kvm, ID_AA64MMFR3_EL1, S1PIE, IMP))
1223+
res0 |= TCR2_EL2_PIE;
1224+
if (!kvm_has_feat(kvm, ID_AA64MMFR1_EL1, VH, IMP))
1225+
res0 |= (TCR2_EL2_E0POE | TCR2_EL2_D128 |
1226+
TCR2_EL2_AMEC1 | TCR2_EL2_DisCH0 | TCR2_EL2_DisCH1);
1227+
set_sysreg_masks(kvm, TCR2_EL2, res0, res1);
1228+
12071229
/* SCTLR_EL1 */
12081230
res0 = SCTLR_EL1_RES0;
12091231
res1 = SCTLR_EL1_RES1;

0 commit comments

Comments
 (0)