Skip to content

Commit 09cf57e

Browse files
David BrazdilMarc Zyngier
authored andcommitted
KVM: arm64: Split hyp/switch.c to VHE/nVHE
switch.c implements context-switching for KVM, with large parts shared between VHE/nVHE. These common routines are moved to a header file, VHE-specific code is moved to vhe/switch.c and nVHE-specific code is moved to nvhe/switch.c. Previously __kvm_vcpu_run needed a different symbol name for VHE/nVHE. This is cleaned up and the caller in arm.c simplified. Signed-off-by: David Brazdil <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e03fa29 commit 09cf57e

File tree

13 files changed

+1048
-952
lines changed

13 files changed

+1048
-952
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ extern void __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu);
9696

9797
extern void __kvm_timer_set_cntvoff(u64 cntvoff);
9898

99-
extern int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu);
100-
101-
extern int __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu);
99+
extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu);
102100

103101
extern void __kvm_enable_ssbs(void);
104102

arch/arm64/include/asm/kvm_hyp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ void __debug_switch_to_host(struct kvm_vcpu *vcpu);
8181
void __fpsimd_save_state(struct user_fpsimd_state *fp_regs);
8282
void __fpsimd_restore_state(struct user_fpsimd_state *fp_regs);
8383

84+
#ifndef __KVM_NVHE_HYPERVISOR__
8485
void activate_traps_vhe_load(struct kvm_vcpu *vcpu);
8586
void deactivate_traps_vhe_put(void);
87+
#endif
8688

8789
u64 __guest_enter(struct kvm_vcpu *vcpu, struct kvm_cpu_context *host_ctxt);
90+
91+
void __noreturn hyp_panic(struct kvm_cpu_context *host_ctxt);
92+
#ifdef __KVM_NVHE_HYPERVISOR__
8893
void __noreturn __hyp_do_panic(unsigned long, ...);
94+
#endif
8995

9096
#endif /* __ARM64_KVM_HYP_H__ */
9197

arch/arm64/kernel/image-vars.h

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,50 @@ __efistub__ctype = _ctype;
6363

6464
#define KVM_NVHE_ALIAS(sym) __kvm_nvhe_##sym = sym;
6565

66+
/* Symbols defined in aarch32.c (not yet compiled with nVHE build rules). */
67+
KVM_NVHE_ALIAS(kvm_skip_instr32);
68+
6669
/* Symbols defined in debug-sr.c (not yet compiled with nVHE build rules). */
70+
KVM_NVHE_ALIAS(__debug_switch_to_guest);
71+
KVM_NVHE_ALIAS(__debug_switch_to_host);
6772
KVM_NVHE_ALIAS(__kvm_get_mdcr_el2);
6873

6974
/* Symbols defined in entry.S (not yet compiled with nVHE build rules). */
75+
KVM_NVHE_ALIAS(__guest_enter);
7076
KVM_NVHE_ALIAS(__guest_exit);
7177
KVM_NVHE_ALIAS(abort_guest_exit_end);
7278
KVM_NVHE_ALIAS(abort_guest_exit_start);
7379

74-
/* Symbols defined in switch.c (not yet compiled with nVHE build rules). */
75-
KVM_NVHE_ALIAS(__kvm_vcpu_run_nvhe);
76-
KVM_NVHE_ALIAS(hyp_panic);
80+
/* Symbols defined in fpsimd.S (not yet compiled with nVHE build rules). */
81+
KVM_NVHE_ALIAS(__fpsimd_restore_state);
82+
KVM_NVHE_ALIAS(__fpsimd_save_state);
7783

7884
/* Symbols defined in sysreg-sr.c (not yet compiled with nVHE build rules). */
7985
KVM_NVHE_ALIAS(__kvm_enable_ssbs);
86+
KVM_NVHE_ALIAS(__sysreg32_restore_state);
87+
KVM_NVHE_ALIAS(__sysreg32_save_state);
88+
KVM_NVHE_ALIAS(__sysreg_restore_state_nvhe);
89+
KVM_NVHE_ALIAS(__sysreg_save_state_nvhe);
8090

8191
/* Symbols defined in timer-sr.c (not yet compiled with nVHE build rules). */
8292
KVM_NVHE_ALIAS(__kvm_timer_set_cntvoff);
93+
KVM_NVHE_ALIAS(__timer_disable_traps);
94+
KVM_NVHE_ALIAS(__timer_enable_traps);
95+
96+
/* Symbols defined in vgic-v2-cpuif-proxy.c (not yet compiled with nVHE build rules). */
97+
KVM_NVHE_ALIAS(__vgic_v2_perform_cpuif_access);
8398

8499
/* Symbols defined in vgic-v3-sr.c (not yet compiled with nVHE build rules). */
100+
KVM_NVHE_ALIAS(__vgic_v3_activate_traps);
101+
KVM_NVHE_ALIAS(__vgic_v3_deactivate_traps);
85102
KVM_NVHE_ALIAS(__vgic_v3_get_ich_vtr_el2);
86103
KVM_NVHE_ALIAS(__vgic_v3_init_lrs);
104+
KVM_NVHE_ALIAS(__vgic_v3_perform_cpuif_access);
87105
KVM_NVHE_ALIAS(__vgic_v3_read_vmcr);
88106
KVM_NVHE_ALIAS(__vgic_v3_restore_aprs);
107+
KVM_NVHE_ALIAS(__vgic_v3_restore_state);
89108
KVM_NVHE_ALIAS(__vgic_v3_save_aprs);
109+
KVM_NVHE_ALIAS(__vgic_v3_save_state);
90110
KVM_NVHE_ALIAS(__vgic_v3_write_vmcr);
91111

92112
/* Alternative callbacks for init-time patching of nVHE hyp code. */
@@ -97,11 +117,13 @@ KVM_NVHE_ALIAS(kvm_update_va_mask);
97117
/* Global kernel state accessed by nVHE hyp code. */
98118
KVM_NVHE_ALIAS(arm64_ssbd_callback_required);
99119
KVM_NVHE_ALIAS(kvm_host_data);
120+
KVM_NVHE_ALIAS(kvm_vgic_global_state);
100121

101122
/* Kernel constant needed to compute idmap addresses. */
102123
KVM_NVHE_ALIAS(kimage_voffset);
103124

104125
/* Kernel symbols used to call panic() from nVHE hyp code (via ERET). */
126+
KVM_NVHE_ALIAS(__hyp_panic_string);
105127
KVM_NVHE_ALIAS(panic);
106128

107129
/* Vectors installed by hyp-init on reset HVC. */
@@ -118,6 +140,15 @@ KVM_NVHE_ALIAS(arm64_const_caps_ready);
118140
KVM_NVHE_ALIAS(cpu_hwcap_keys);
119141
KVM_NVHE_ALIAS(cpu_hwcaps);
120142

143+
/* Static keys which are set if a vGIC trap should be handled in hyp. */
144+
KVM_NVHE_ALIAS(vgic_v2_cpuif_trap);
145+
KVM_NVHE_ALIAS(vgic_v3_cpuif_trap);
146+
147+
/* Static key checked in pmr_sync(). */
148+
#ifdef CONFIG_ARM64_PSEUDO_NMI
149+
KVM_NVHE_ALIAS(gic_pmr_sync);
150+
#endif
151+
121152
#endif /* CONFIG_KVM */
122153

123154
#endif /* __ARM64_KERNEL_IMAGE_VARS_H */

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
748748
trace_kvm_entry(*vcpu_pc(vcpu));
749749
guest_enter_irqoff();
750750

751-
if (has_vhe()) {
752-
ret = kvm_vcpu_run_vhe(vcpu);
753-
} else {
754-
ret = kvm_call_hyp_ret(__kvm_vcpu_run_nvhe, vcpu);
755-
}
751+
ret = kvm_call_hyp_ret(__kvm_vcpu_run, vcpu);
756752

757753
vcpu->mode = OUTSIDE_GUEST_MODE;
758754
vcpu->stat.exits++;

arch/arm64/kvm/hyp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ obj-$(CONFIG_KVM) += hyp.o vhe/ nvhe/
1414
obj-$(CONFIG_KVM_INDIRECT_VECTORS) += smccc_wa.o
1515

1616
hyp-y := vgic-v3-sr.o timer-sr.o aarch32.o vgic-v2-cpuif-proxy.o sysreg-sr.o \
17-
debug-sr.o entry.o switch.o fpsimd.o
17+
debug-sr.o entry.o fpsimd.o
1818

1919
# KVM code is run at a different exception code with a different map, so
2020
# compiler instrumentation that inserts callbacks or checks into the code may

arch/arm64/kvm/hyp/hyp-entry.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ el2_error:
182182
eret
183183
sb
184184

185+
#ifdef __KVM_NVHE_HYPERVISOR__
185186
SYM_FUNC_START(__hyp_do_panic)
186187
mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
187188
PSR_MODE_EL1h)
@@ -191,6 +192,7 @@ SYM_FUNC_START(__hyp_do_panic)
191192
eret
192193
sb
193194
SYM_FUNC_END(__hyp_do_panic)
195+
#endif
194196

195197
SYM_CODE_START(__hyp_panic)
196198
get_host_ctxt x0, x1

0 commit comments

Comments
 (0)