Skip to content

Commit ffea7c7

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Properly save/restore HCRX_EL2
Rather than restoring HCRX_EL2 to a fixed value on vcpu exit, perform a full save/restore of the register, ensuring that we don't lose bits that would have been set at some point in the host kernel lifetime, such as the GCSEn bit. Fixes: ff5181d ("arm64/gcs: Provide basic EL2 setup to allow GCS usage at EL0 and EL1") Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20250430105916.3815157-2-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent b60e285 commit ffea7c7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ static inline void __deactivate_traps_mpam(void)
235235

236236
static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
237237
{
238+
struct kvm_cpu_context *hctxt = host_data_ptr(host_ctxt);
239+
238240
/* Trap on AArch32 cp15 c15 (impdef sysregs) accesses (EL1 or EL0) */
239241
write_sysreg(1 << 15, hstr_el2);
240242

@@ -245,11 +247,8 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
245247
* EL1 instead of being trapped to EL2.
246248
*/
247249
if (system_supports_pmuv3()) {
248-
struct kvm_cpu_context *hctxt;
249-
250250
write_sysreg(0, pmselr_el0);
251251

252-
hctxt = host_data_ptr(host_ctxt);
253252
ctxt_sys_reg(hctxt, PMUSERENR_EL0) = read_sysreg(pmuserenr_el0);
254253
write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0);
255254
vcpu_set_flag(vcpu, PMUSERENR_ON_CPU);
@@ -269,6 +268,7 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
269268
hcrx &= ~clr;
270269
}
271270

271+
ctxt_sys_reg(hctxt, HCRX_EL2) = read_sysreg_s(SYS_HCRX_EL2);
272272
write_sysreg_s(hcrx, SYS_HCRX_EL2);
273273
}
274274

@@ -278,19 +278,18 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
278278

279279
static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
280280
{
281+
struct kvm_cpu_context *hctxt = host_data_ptr(host_ctxt);
282+
281283
write_sysreg(*host_data_ptr(host_debug_state.mdcr_el2), mdcr_el2);
282284

283285
write_sysreg(0, hstr_el2);
284286
if (system_supports_pmuv3()) {
285-
struct kvm_cpu_context *hctxt;
286-
287-
hctxt = host_data_ptr(host_ctxt);
288287
write_sysreg(ctxt_sys_reg(hctxt, PMUSERENR_EL0), pmuserenr_el0);
289288
vcpu_clear_flag(vcpu, PMUSERENR_ON_CPU);
290289
}
291290

292291
if (cpus_have_final_cap(ARM64_HAS_HCX))
293-
write_sysreg_s(HCRX_HOST_FLAGS, SYS_HCRX_EL2);
292+
write_sysreg_s(ctxt_sys_reg(hctxt, HCRX_EL2), SYS_HCRX_EL2);
294293

295294
__deactivate_traps_hfgxtr(vcpu);
296295
__deactivate_traps_mpam();

0 commit comments

Comments
 (0)