[RFC 03/12] KVM: arm64: Hide TLBID from guest sysregs
Kristina Martšenko
kristina.martsenko at arm.com
Thu Oct 1 04:06:46 PDT 2026
Don't expose FEAT_TLBID to guests. It wouldn't be useful in the general
case since a guest doesn't know which domains exist and its vCPUs can be
moved between any physical CPUs.
Try to hide TLBID sysregs and sysreg fields from the guest:
* Report the feature as not supported in the ID register
ID_AA64MMFR4_EL1.TLBID.
* Configure the TLBIDIDR_EL1 sysreg to UNDEF via the FGU mechanism.
Sanitize a nested hypervisor's HFGRTR2.nTLBIDIDR.
* Sanitize a nested hypervisor's HCRX.{VTLBIDEn,VTLBIDOSEn,FNB}.
* VTLBID{OS}<n>_EL2 registers are VNCR-backed and not exposed to
guests (apart from being able to read/write into the VNCR page) so
no need to handle them in sys_reg_descs or elsewhere.
* The guest is free to set SCTLR2_EL{1,2}.TLBOSNIS, which shouldn't
matter to KVM.
Signed-off-by: Kristina Martšenko <kristina.martsenko at arm.com>
---
arch/arm64/kvm/config.c | 6 ++++++
arch/arm64/kvm/emulate-nested.c | 1 +
arch/arm64/kvm/sys_regs.c | 3 +++
3 files changed, 10 insertions(+)
diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
index 1053676551af..6c116aa1864a 100644
--- a/arch/arm64/kvm/config.c
+++ b/arch/arm64/kvm/config.c
@@ -226,6 +226,7 @@ struct reg_feat_map_desc {
#define FEAT_S2PIE ID_AA64MMFR3_EL1, S2PIE, IMP
#define FEAT_GCIE ID_AA64PFR2_EL1, GCIE, IMP
#define FEAT_NV3 ID_AA64MMFR4_EL1, NV_frac, NV3
+#define FEAT_TLBID ID_AA64MMFR4_EL1, TLBID, IMP
static bool not_feat_aa64el3(struct kvm *kvm)
{
@@ -813,6 +814,7 @@ static const struct reg_bits_to_feat_map hfgrtr2_feat_map[] = {
HFGRTR2_EL2_nTCRMASK_EL1,
FEAT_SRMASK),
NEEDS_FEAT(HFGRTR2_EL2_nRCWSMASK_EL1, FEAT_THE),
+ NEEDS_FEAT(HFGRTR2_EL2_nTLBIDIDR_EL1, FEAT_TLBID),
};
static const DECLARE_FEAT_MAP_FGT(hfgrtr2_desc, hfgrtr2_masks,
@@ -911,6 +913,10 @@ static const struct reg_bits_to_feat_map hcrx_feat_map[] = {
HCRX_EL2_NVnTTLBOS,
FEAT_NV3),
NEEDS_FEAT(HCRX_EL2_SRMASKEn, FEAT_SRMASK),
+ NEEDS_FEAT(HCRX_EL2_FNB |
+ HCRX_EL2_VTLBIDOSEn |
+ HCRX_EL2_VTLBIDEn,
+ FEAT_TLBID),
NEEDS_FEAT(HCRX_EL2_PACMEn, feat_pauth_lr),
NEEDS_FEAT(HCRX_EL2_EnFPM, FEAT_FPMR),
NEEDS_FEAT(HCRX_EL2_GCSEn, FEAT_GCS),
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index 625604019fb3..cd8ad03028e7 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -1440,6 +1440,7 @@ static const struct encoding_to_trap_config encoding_to_fgt[] __initconst = {
SR_FGT(SYS_TCRALIAS_EL1, HFGRTR2, nTCRALIAS_EL1, 0),
SR_FGT(SYS_TCRMASK_EL1, HFGRTR2, nTCRMASK_EL1, 0),
SR_FGT(SYS_ERXGSR_EL1, HFGRTR2, nERXGSR_EL1, 0),
+ SR_FGT(SYS_TLBIDIDR_EL1, HFGRTR2, nTLBIDIDR_EL1, 0),
/* HFGITR_EL2 */
SR_FGT(OP_AT_S1E1A, HFGITR, ATS1E1A, 1),
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 44aae52c473d..6a025e1f3161 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1984,6 +1984,9 @@ static u64 __kvm_read_sanitised_id_reg(const struct kvm_vcpu *vcpu,
if (!system_supports_poe())
val &= ~ID_AA64MMFR3_EL1_S1POE;
break;
+ case SYS_ID_AA64MMFR4_EL1:
+ val &= ~ID_AA64MMFR4_EL1_TLBID;
+ break;
case SYS_ID_MMFR4_EL1:
val &= ~ID_MMFR4_EL1_CCIDX;
break;
--
2.43.0
More information about the linux-arm-kernel
mailing list