Skip to content

Commit eb60963

Browse files
committed
KVM: arm64: Describe RES0/RES1 bits of MDCR_EL2
Add support for sanitising MDCR_EL2 and describe the RES0/RES1 bits according to the feature set exposed to the VM. Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 3ecb1fe commit eb60963

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ enum vcpu_sysreg {
471471
/* EL2 registers */
472472
SCTLR_EL2, /* System Control Register (EL2) */
473473
ACTLR_EL2, /* Auxiliary Control Register (EL2) */
474-
MDCR_EL2, /* Monitor Debug Configuration Register (EL2) */
475474
CPTR_EL2, /* Architectural Feature Trap Register (EL2) */
476475
HACR_EL2, /* Hypervisor Auxiliary Control Register */
477476
ZCR_EL2, /* SVE Control Register (EL2) */
@@ -499,6 +498,7 @@ enum vcpu_sysreg {
499498

500499
/* Anything from this can be RES0/RES1 sanitised */
501500
MARKER(__SANITISED_REG_START__),
501+
MDCR_EL2, /* Monitor Debug Configuration Register (EL2) */
502502

503503
/* Any VNCR-capable reg goes after this point */
504504
MARKER(__VNCR_START__),

arch/arm64/kvm/nested.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,43 @@ int kvm_init_nv_sysregs(struct kvm *kvm)
12111211
res0 |= SCTLR_EL1_EPAN;
12121212
set_sysreg_masks(kvm, SCTLR_EL1, res0, res1);
12131213

1214+
/* MDCR_EL2 */
1215+
res0 = MDCR_EL2_RES0;
1216+
res1 = MDCR_EL2_RES1;
1217+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMUVer, IMP))
1218+
res0 |= (MDCR_EL2_HPMN | MDCR_EL2_TPMCR |
1219+
MDCR_EL2_TPM | MDCR_EL2_HPME);
1220+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMSVer, IMP))
1221+
res0 |= MDCR_EL2_E2PB | MDCR_EL2_TPMS;
1222+
if (!kvm_has_feat(kvm, ID_AA64DFR1_EL1, SPMU, IMP))
1223+
res0 |= MDCR_EL2_EnSPM;
1224+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMUVer, V3P1))
1225+
res0 |= MDCR_EL2_HPMD;
1226+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, TraceFilt, IMP))
1227+
res0 |= MDCR_EL2_TTRF;
1228+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMUVer, V3P5))
1229+
res0 |= MDCR_EL2_HCCD | MDCR_EL2_HLP;
1230+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, TraceBuffer, IMP))
1231+
res0 |= MDCR_EL2_E2TB;
1232+
if (!kvm_has_feat(kvm, ID_AA64MMFR0_EL1, FGT, IMP))
1233+
res0 |= MDCR_EL2_TDCC;
1234+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, MTPMU, IMP) ||
1235+
kvm_has_feat(kvm, ID_AA64PFR0_EL1, EL3, IMP))
1236+
res0 |= MDCR_EL2_MTPME;
1237+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMUVer, V3P7))
1238+
res0 |= MDCR_EL2_HPMFZO;
1239+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMSS, IMP))
1240+
res0 |= MDCR_EL2_PMSSE;
1241+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMSVer, V1P2))
1242+
res0 |= MDCR_EL2_HPMFZS;
1243+
if (!kvm_has_feat(kvm, ID_AA64DFR1_EL1, EBEP, IMP))
1244+
res0 |= MDCR_EL2_PMEE;
1245+
if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, DebugVer, V8P9))
1246+
res0 |= MDCR_EL2_EBWE;
1247+
if (!kvm_has_feat(kvm, ID_AA64DFR2_EL1, STEP, IMP))
1248+
res0 |= MDCR_EL2_EnSTEPOP;
1249+
set_sysreg_masks(kvm, MDCR_EL2, res0, res1);
1250+
12141251
return 0;
12151252
}
12161253

0 commit comments

Comments
 (0)