Skip to content

Commit 44f979b

Browse files
Fuad Tabbaoupton
authored andcommitted
KVM: arm64: Factor out setting HCRX_EL2 traps into separate function
Factor out the code for setting a vcpu's HCRX_EL2 traps in to a separate inline function. This allows us to share the logic with pKVM when setting the traps in protected mode. No functional change intended. Reviewed-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Fuad Tabba <tabba@google.com> Link: https://lore.kernel.org/r/20250314111832.4137161-2-tabba@google.com Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 79ea662 commit 44f979b

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,4 +649,28 @@ static inline bool guest_hyp_sve_traps_enabled(const struct kvm_vcpu *vcpu)
649649
{
650650
return __guest_hyp_cptr_xen_trap_enabled(vcpu, ZEN);
651651
}
652+
653+
static inline void vcpu_set_hcrx(struct kvm_vcpu *vcpu)
654+
{
655+
struct kvm *kvm = vcpu->kvm;
656+
657+
if (cpus_have_final_cap(ARM64_HAS_HCX)) {
658+
/*
659+
* In general, all HCRX_EL2 bits are gated by a feature.
660+
* The only reason we can set SMPME without checking any
661+
* feature is that its effects are not directly observable
662+
* from the guest.
663+
*/
664+
vcpu->arch.hcrx_el2 = HCRX_EL2_SMPME;
665+
666+
if (kvm_has_feat(kvm, ID_AA64ISAR2_EL1, MOPS, IMP))
667+
vcpu->arch.hcrx_el2 |= (HCRX_EL2_MSCEn | HCRX_EL2_MCE2);
668+
669+
if (kvm_has_tcr2(kvm))
670+
vcpu->arch.hcrx_el2 |= HCRX_EL2_TCR2En;
671+
672+
if (kvm_has_fpmr(kvm))
673+
vcpu->arch.hcrx_el2 |= HCRX_EL2_EnFPM;
674+
}
675+
}
652676
#endif /* __ARM64_KVM_EMULATE_H__ */

arch/arm64/kvm/sys_regs.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4971,25 +4971,7 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu)
49714971
mutex_lock(&kvm->arch.config_lock);
49724972
vcpu_set_hcr(vcpu);
49734973
vcpu_set_ich_hcr(vcpu);
4974-
4975-
if (cpus_have_final_cap(ARM64_HAS_HCX)) {
4976-
/*
4977-
* In general, all HCRX_EL2 bits are gated by a feature.
4978-
* The only reason we can set SMPME without checking any
4979-
* feature is that its effects are not directly observable
4980-
* from the guest.
4981-
*/
4982-
vcpu->arch.hcrx_el2 = HCRX_EL2_SMPME;
4983-
4984-
if (kvm_has_feat(kvm, ID_AA64ISAR2_EL1, MOPS, IMP))
4985-
vcpu->arch.hcrx_el2 |= (HCRX_EL2_MSCEn | HCRX_EL2_MCE2);
4986-
4987-
if (kvm_has_tcr2(kvm))
4988-
vcpu->arch.hcrx_el2 |= HCRX_EL2_TCR2En;
4989-
4990-
if (kvm_has_fpmr(kvm))
4991-
vcpu->arch.hcrx_el2 |= HCRX_EL2_EnFPM;
4992-
}
4974+
vcpu_set_hcrx(vcpu);
49934975

49944976
if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags))
49954977
goto out;

0 commit comments

Comments
 (0)