Skip to content

Commit 84de212

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Make FEAT_MOPS UNDEF if not advertised to the guest
We unconditionally enable FEAT_MOPS, which is obviously wrong. So let's only do that when it is advertised to the guest. Which means we need to rely on a per-vcpu HCRX_EL2 shadow register. 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 b03e8bb commit 84de212

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

arch/arm64/include/asm/kvm_arm.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@
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 \
106-
(HCRX_EL2_SMPME | HCRX_EL2_TCR2En | \
107-
(cpus_have_final_cap(ARM64_HAS_MOPS) ? (HCRX_EL2_MSCEn | HCRX_EL2_MCE2) : 0))
105+
#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME | HCRX_EL2_TCR2En)
108106
#define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En)
109107

110108
/* TCR_EL2 Registers bits */

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ struct kvm_vcpu_arch {
584584

585585
/* Values of trap registers for the guest. */
586586
u64 hcr_el2;
587+
u64 hcrx_el2;
587588
u64 mdcr_el2;
588589
u64 cptr_el2;
589590

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
236236
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
237237

238238
if (cpus_have_final_cap(ARM64_HAS_HCX)) {
239-
u64 hcrx = HCRX_GUEST_FLAGS;
239+
u64 hcrx = vcpu->arch.hcrx_el2;
240240
if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) {
241241
u64 clr = 0, set = 0;
242242

arch/arm64/kvm/sys_regs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,13 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu)
39563956
if (!kvm_has_feat(kvm, ID_AA64ISAR0_EL1, TLB, OS))
39573957
vcpu->arch.hcr_el2 |= HCR_TTLBOS;
39583958

3959+
if (cpus_have_final_cap(ARM64_HAS_HCX)) {
3960+
vcpu->arch.hcrx_el2 = HCRX_GUEST_FLAGS;
3961+
3962+
if (kvm_has_feat(kvm, ID_AA64ISAR2_EL1, MOPS, IMP))
3963+
vcpu->arch.hcrx_el2 |= (HCRX_EL2_MSCEn | HCRX_EL2_MCE2);
3964+
}
3965+
39593966
if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags))
39603967
goto out;
39613968

0 commit comments

Comments
 (0)