Skip to content

Commit 04c5355

Browse files
mrutland-armMarc Zyngier
authored andcommitted
KVM: arm64: VHE: Centralize ISBs when returning to host
The VHE hyp code has recently gained a few ISBs. Simplify this to one unconditional ISB in __kvm_vcpu_run_vhe(), and remove the unnecessary ISB from the kvm_call_hyp_ret() macro. While kvm_call_hyp_ret() is also used to invoke __vgic_v3_get_gic_config(), but no ISB is necessary in that case either. For the moment, an ISB is left in kvm_call_hyp(), as there are many more users, and removing the ISB would require a more thorough audit. Suggested-by: Marc Zyngier <[email protected]> Signed-off-by: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Fuad Tabba <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Brown <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 3a300a3 commit 04c5355

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,8 @@ void kvm_arm_resume_guest(struct kvm *kvm);
12891289
})
12901290

12911291
/*
1292-
* The couple of isb() below are there to guarantee the same behaviour
1293-
* on VHE as on !VHE, where the eret to EL1 acts as a context
1294-
* synchronization event.
1292+
* The isb() below is there to guarantee the same behaviour on VHE as on !VHE,
1293+
* where the eret to EL1 acts as a context synchronization event.
12951294
*/
12961295
#define kvm_call_hyp(f, ...) \
12971296
do { \
@@ -1309,7 +1308,6 @@ void kvm_arm_resume_guest(struct kvm *kvm);
13091308
\
13101309
if (has_vhe()) { \
13111310
ret = f(__VA_ARGS__); \
1312-
isb(); \
13131311
} else { \
13141312
ret = kvm_call_hyp_nvhe(f, ##__VA_ARGS__); \
13151313
} \

arch/arm64/kvm/hyp/include/hyp/debug-sr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ static inline void __debug_switch_to_host_common(struct kvm_vcpu *vcpu)
167167

168168
__debug_save_state(guest_dbg, guest_ctxt);
169169
__debug_restore_state(host_dbg, host_ctxt);
170-
171-
if (has_vhe())
172-
isb();
173170
}
174171

175172
#endif /* __ARM64_KVM_HYP_DEBUG_SR_H__ */

arch/arm64/kvm/hyp/vhe/switch.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
558558
host_ctxt = host_data_ptr(host_ctxt);
559559
guest_ctxt = &vcpu->arch.ctxt;
560560

561-
sysreg_save_host_state_vhe(host_ctxt);
562-
563561
fpsimd_lazy_switch_to_guest(vcpu);
564562

563+
sysreg_save_host_state_vhe(host_ctxt);
564+
565565
/*
566566
* Note that ARM erratum 1165522 requires us to configure both stage 1
567567
* and stage 2 translation for the guest context before we clear
@@ -586,18 +586,23 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
586586

587587
__deactivate_traps(vcpu);
588588

589-
/* Ensure CPTR trap deactivation has taken effect */
589+
sysreg_restore_host_state_vhe(host_ctxt);
590+
591+
__debug_switch_to_host(vcpu);
592+
593+
/*
594+
* Ensure that all system register writes above have taken effect
595+
* before returning to the host. In VHE mode, CPTR traps for
596+
* FPSIMD/SVE/SME also apply to EL2, so FPSIMD/SVE/SME state must be
597+
* manipulated after the ISB.
598+
*/
590599
isb();
591600

592601
fpsimd_lazy_switch_to_host(vcpu);
593602

594-
sysreg_restore_host_state_vhe(host_ctxt);
595-
596603
if (guest_owns_fp_regs())
597604
__fpsimd_save_fpexc32(vcpu);
598605

599-
__debug_switch_to_host(vcpu);
600-
601606
return exit_code;
602607
}
603608
NOKPROBE_SYMBOL(__kvm_vcpu_run_vhe);
@@ -627,12 +632,6 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
627632
*/
628633
local_daif_restore(DAIF_PROCCTX_NOIRQ);
629634

630-
/*
631-
* When we exit from the guest we change a number of CPU configuration
632-
* parameters, such as traps. We rely on the isb() in kvm_call_hyp*()
633-
* to make sure these changes take effect before running the host or
634-
* additional guests.
635-
*/
636635
return ret;
637636
}
638637

0 commit comments

Comments
 (0)