KVM: arm64: Get rid of HCRX_GUEST_FLAGS
authorMarc Zyngier <maz@kernel.org>
Tue, 25 Jun 2024 13:00:38 +0000 (14:00 +0100)
committerOliver Upton <oliver.upton@linux.dev>
Thu, 27 Jun 2024 00:04:25 +0000 (00:04 +0000)
HCRX_GUEST_FLAGS gives random KVM hackers the impression that
they can stuff bits in this macro and unconditionally enable
features in the guest.

In general, this is wrong (we have been there with FEAT_MOPS,
and again with FEAT_TCRX).

Document that HCRX_EL2.SMPME is an exception rather than the rule,
and get rid of HCRX_GUEST_FLAGS.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Link: https://lore.kernel.org/r/20240625130042.259175-3-maz@kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/include/asm/kvm_arm.h
arch/arm64/kvm/sys_regs.c

index e6682a3ace5af7a8215684a807f8158407bf2853..d81cc746e0ebd046fad4fc25fdff13f7bdc19c54 100644 (file)
 #define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
 #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
 
-#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME)
 #define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En | HCRX_EL2_EnFPM)
 
 /* TCR_EL2 Registers bits */
index 71996d36f37511760beb3f99bcce5fe8bafeec9b..8e22232c4b0f4eef8eb874f04206ca0868d4f32c 100644 (file)
@@ -4062,7 +4062,13 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu)
                vcpu->arch.hcr_el2 |= HCR_TTLBOS;
 
        if (cpus_have_final_cap(ARM64_HAS_HCX)) {
-               vcpu->arch.hcrx_el2 = HCRX_GUEST_FLAGS;
+               /*
+                * In general, all HCRX_EL2 bits are gated by a feature.
+                * The only reason we can set SMPME without checking any
+                * feature is that its effects are not directly observable
+                * from the guest.
+                */
+               vcpu->arch.hcrx_el2 = HCRX_EL2_SMPME;
 
                if (kvm_has_feat(kvm, ID_AA64ISAR2_EL1, MOPS, IMP))
                        vcpu->arch.hcrx_el2 |= (HCRX_EL2_MSCEn | HCRX_EL2_MCE2);