Skip to content

Commit ce4a362

Browse files
committed
KVM: arm64: Refactor HFGxTR configuration into separate helpers
A subsequent change will need to flip more trap bits in HFGWTR_EL2. Make room for this by factoring out the programming of the HFGxTR registers into helpers and using locals to build the set/clear masks. Link: https://lore.kernel.org/r/20230609220104.1836988-3-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 6df696c commit ce4a362

1 file changed

Lines changed: 42 additions & 18 deletions

File tree

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

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,44 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
7070
}
7171
}
7272

73+
static inline bool __hfgxtr_traps_required(void)
74+
{
75+
if (cpus_have_final_cap(ARM64_SME))
76+
return true;
77+
78+
return false;
79+
}
80+
81+
static inline void __activate_traps_hfgxtr(void)
82+
{
83+
u64 r_clr = 0, w_clr = 0, r_set = 0, w_set = 0, tmp;
84+
85+
if (cpus_have_final_cap(ARM64_SME)) {
86+
tmp = HFGxTR_EL2_nSMPRI_EL1_MASK | HFGxTR_EL2_nTPIDR2_EL0_MASK;
87+
88+
r_clr |= tmp;
89+
w_clr |= tmp;
90+
}
91+
92+
sysreg_clear_set_s(SYS_HFGRTR_EL2, r_clr, r_set);
93+
sysreg_clear_set_s(SYS_HFGWTR_EL2, w_clr, w_set);
94+
}
95+
96+
static inline void __deactivate_traps_hfgxtr(void)
97+
{
98+
u64 r_clr = 0, w_clr = 0, r_set = 0, w_set = 0, tmp;
99+
100+
if (cpus_have_final_cap(ARM64_SME)) {
101+
tmp = HFGxTR_EL2_nSMPRI_EL1_MASK | HFGxTR_EL2_nTPIDR2_EL0_MASK;
102+
103+
r_set |= tmp;
104+
w_set |= tmp;
105+
}
106+
107+
sysreg_clear_set_s(SYS_HFGRTR_EL2, r_clr, r_set);
108+
sysreg_clear_set_s(SYS_HFGWTR_EL2, w_clr, w_set);
109+
}
110+
73111
static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
74112
{
75113
/* Trap on AArch32 cp15 c15 (impdef sysregs) accesses (EL1 or EL0) */
@@ -89,16 +127,8 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
89127
vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2);
90128
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
91129

92-
if (cpus_have_final_cap(ARM64_SME)) {
93-
sysreg_clear_set_s(SYS_HFGRTR_EL2,
94-
HFGxTR_EL2_nSMPRI_EL1_MASK |
95-
HFGxTR_EL2_nTPIDR2_EL0_MASK,
96-
0);
97-
sysreg_clear_set_s(SYS_HFGWTR_EL2,
98-
HFGxTR_EL2_nSMPRI_EL1_MASK |
99-
HFGxTR_EL2_nTPIDR2_EL0_MASK,
100-
0);
101-
}
130+
if (__hfgxtr_traps_required())
131+
__activate_traps_hfgxtr();
102132
}
103133

104134
static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
@@ -109,14 +139,8 @@ static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
109139
if (kvm_arm_support_pmu_v3())
110140
write_sysreg(0, pmuserenr_el0);
111141

112-
if (cpus_have_final_cap(ARM64_SME)) {
113-
sysreg_clear_set_s(SYS_HFGRTR_EL2, 0,
114-
HFGxTR_EL2_nSMPRI_EL1_MASK |
115-
HFGxTR_EL2_nTPIDR2_EL0_MASK);
116-
sysreg_clear_set_s(SYS_HFGWTR_EL2, 0,
117-
HFGxTR_EL2_nSMPRI_EL1_MASK |
118-
HFGxTR_EL2_nTPIDR2_EL0_MASK);
119-
}
142+
if (__hfgxtr_traps_required())
143+
__deactivate_traps_hfgxtr();
120144
}
121145

122146
static inline void ___activate_traps(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)