Skip to content

Commit a63cf31

Browse files
author
Marc Zyngier
committed
KVM: arm64: Move HCRX_EL2 switch to load/put on VHE systems
Although the nVHE behaviour requires HCRX_EL2 to be switched on each switch between host and guest, there is nothing in this register that would affect a VHE host. It is thus possible to save/restore this register on load/put on VHE systems, avoiding unnecessary sysreg access on the hot path. Additionally, it avoids unnecessary traps when running with NV. To achieve this, simply move the read/writes to the *_common() helpers, which are called on load/put on VHE, and more eagerly on nVHE. Reviewed-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Jing Zhang <jingzhangos@google.com> Link: https://lore.kernel.org/r/20230815183903.2735724-28-maz@kernel.org
1 parent 0a5d284 commit a63cf31

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
197197
vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2);
198198
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
199199

200+
if (cpus_have_final_cap(ARM64_HAS_HCX))
201+
write_sysreg_s(HCRX_GUEST_FLAGS, SYS_HCRX_EL2);
202+
200203
__activate_traps_hfgxtr(vcpu);
201204
}
202205

@@ -213,6 +216,9 @@ static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
213216
vcpu_clear_flag(vcpu, PMUSERENR_ON_CPU);
214217
}
215218

219+
if (cpus_have_final_cap(ARM64_HAS_HCX))
220+
write_sysreg_s(HCRX_HOST_FLAGS, SYS_HCRX_EL2);
221+
216222
__deactivate_traps_hfgxtr(vcpu);
217223
}
218224

@@ -227,9 +233,6 @@ static inline void ___activate_traps(struct kvm_vcpu *vcpu)
227233

228234
if (cpus_have_final_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE))
229235
write_sysreg_s(vcpu->arch.vsesr_el2, SYS_VSESR_EL2);
230-
231-
if (cpus_have_final_cap(ARM64_HAS_HCX))
232-
write_sysreg_s(HCRX_GUEST_FLAGS, SYS_HCRX_EL2);
233236
}
234237

235238
static inline void ___deactivate_traps(struct kvm_vcpu *vcpu)
@@ -244,9 +247,6 @@ static inline void ___deactivate_traps(struct kvm_vcpu *vcpu)
244247
vcpu->arch.hcr_el2 &= ~HCR_VSE;
245248
vcpu->arch.hcr_el2 |= read_sysreg(hcr_el2) & HCR_VSE;
246249
}
247-
248-
if (cpus_have_final_cap(ARM64_HAS_HCX))
249-
write_sysreg_s(HCRX_HOST_FLAGS, SYS_HCRX_EL2);
250250
}
251251

252252
static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)