Skip to content

Commit a3ee9ce

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Get rid of HCRX_GUEST_FLAGS
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 <[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 9b58e66 commit a3ee9ce

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

arch/arm64/include/asm/kvm_arm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
#define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
103103
#define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
104104

105-
#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME)
106105
#define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En | HCRX_EL2_EnFPM)
107106

108107
/* TCR_EL2 Registers bits */

arch/arm64/kvm/sys_regs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4062,7 +4062,13 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu)
40624062
vcpu->arch.hcr_el2 |= HCR_TTLBOS;
40634063

40644064
if (cpus_have_final_cap(ARM64_HAS_HCX)) {
4065-
vcpu->arch.hcrx_el2 = HCRX_GUEST_FLAGS;
4065+
/*
4066+
* In general, all HCRX_EL2 bits are gated by a feature.
4067+
* The only reason we can set SMPME without checking any
4068+
* feature is that its effects are not directly observable
4069+
* from the guest.
4070+
*/
4071+
vcpu->arch.hcrx_el2 = HCRX_EL2_SMPME;
40664072

40674073
if (kvm_has_feat(kvm, ID_AA64ISAR2_EL1, MOPS, IMP))
40684074
vcpu->arch.hcrx_el2 |= (HCRX_EL2_MSCEn | HCRX_EL2_MCE2);

0 commit comments

Comments
 (0)