Skip to content

Commit ea266c7

Browse files
mrutland-armMarc Zyngier
authored andcommitted
KVM: arm64: Unconditionally configure fine-grain traps
... otherwise we can inherit the host configuration if this differs from the KVM configuration. Signed-off-by: Mark Rutland <mark.rutland@arm.com> [maz: simplified a couple of things] Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 7ed43d8 commit ea266c7

1 file changed

Lines changed: 15 additions & 24 deletions

File tree

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

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,19 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
107107

108108
#define update_fgt_traps_cs(hctxt, vcpu, kvm, reg, clr, set) \
109109
do { \
110-
u64 c = 0, s = 0; \
110+
u64 c = clr, s = set; \
111+
u64 val; \
111112
\
112113
ctxt_sys_reg(hctxt, reg) = read_sysreg_s(SYS_ ## reg); \
113114
if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) \
114115
compute_clr_set(vcpu, reg, c, s); \
115116
\
116117
compute_undef_clr_set(vcpu, kvm, reg, c, s); \
117118
\
118-
s |= set; \
119-
c |= clr; \
120-
if (c || s) { \
121-
u64 val = __ ## reg ## _nMASK; \
122-
val |= s; \
123-
val &= ~c; \
124-
write_sysreg_s(val, SYS_ ## reg); \
125-
} \
119+
val = __ ## reg ## _nMASK; \
120+
val |= s; \
121+
val &= ~c; \
122+
write_sysreg_s(val, SYS_ ## reg); \
126123
} while(0)
127124

128125
#define update_fgt_traps(hctxt, vcpu, kvm, reg) \
@@ -175,33 +172,27 @@ static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu)
175172
update_fgt_traps(hctxt, vcpu, kvm, HAFGRTR_EL2);
176173
}
177174

178-
#define __deactivate_fgt(htcxt, vcpu, kvm, reg) \
175+
#define __deactivate_fgt(htcxt, vcpu, reg) \
179176
do { \
180-
if ((vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) || \
181-
kvm->arch.fgu[reg_to_fgt_group_id(reg)]) \
182-
write_sysreg_s(ctxt_sys_reg(hctxt, reg), \
183-
SYS_ ## reg); \
177+
write_sysreg_s(ctxt_sys_reg(hctxt, reg), \
178+
SYS_ ## reg); \
184179
} while(0)
185180

186181
static inline void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu)
187182
{
188183
struct kvm_cpu_context *hctxt = host_data_ptr(host_ctxt);
189-
struct kvm *kvm = kern_hyp_va(vcpu->kvm);
190184

191185
if (!cpus_have_final_cap(ARM64_HAS_FGT))
192186
return;
193187

194-
__deactivate_fgt(hctxt, vcpu, kvm, HFGRTR_EL2);
195-
if (cpus_have_final_cap(ARM64_WORKAROUND_AMPERE_AC03_CPU_38))
196-
write_sysreg_s(ctxt_sys_reg(hctxt, HFGWTR_EL2), SYS_HFGWTR_EL2);
197-
else
198-
__deactivate_fgt(hctxt, vcpu, kvm, HFGWTR_EL2);
199-
__deactivate_fgt(hctxt, vcpu, kvm, HFGITR_EL2);
200-
__deactivate_fgt(hctxt, vcpu, kvm, HDFGRTR_EL2);
201-
__deactivate_fgt(hctxt, vcpu, kvm, HDFGWTR_EL2);
188+
__deactivate_fgt(hctxt, vcpu, HFGRTR_EL2);
189+
__deactivate_fgt(hctxt, vcpu, HFGWTR_EL2);
190+
__deactivate_fgt(hctxt, vcpu, HFGITR_EL2);
191+
__deactivate_fgt(hctxt, vcpu, HDFGRTR_EL2);
192+
__deactivate_fgt(hctxt, vcpu, HDFGWTR_EL2);
202193

203194
if (cpu_has_amu())
204-
__deactivate_fgt(hctxt, vcpu, kvm, HAFGRTR_EL2);
195+
__deactivate_fgt(hctxt, vcpu, HAFGRTR_EL2);
205196
}
206197

207198
static inline void __activate_traps_mpam(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)