Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: Move kvm_get_hyp_vector() out of header file

kvm_get_hyp_vector() has only one caller, so move it out of kvm_mmu.h
and inline it into a new function, cpu_set_hyp_vector(), for setting
the vector.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20201113113847.21619-4-will@kernel.org

authored by

Will Deacon and committed by
Marc Zyngier
042c76a9 de5bcdb4

+44 -45
-43
arch/arm64/include/asm/kvm_mmu.h
··· 208 208 return ret; 209 209 } 210 210 211 - /* 212 - * EL2 vectors can be mapped and rerouted in a number of ways, 213 - * depending on the kernel configuration and CPU present: 214 - * 215 - * - If the CPU is affected by Spectre-v2, the hardening sequence is 216 - * placed in one of the vector slots, which is executed before jumping 217 - * to the real vectors. 218 - * 219 - * - If the CPU also has the ARM64_HARDEN_EL2_VECTORS cap, the slot 220 - * containing the hardening sequence is mapped next to the idmap page, 221 - * and executed before jumping to the real vectors. 222 - * 223 - * - If the CPU only has the ARM64_HARDEN_EL2_VECTORS cap, then an 224 - * empty slot is selected, mapped next to the idmap page, and 225 - * executed before jumping to the real vectors. 226 - * 227 - * Note that ARM64_HARDEN_EL2_VECTORS is somewhat incompatible with 228 - * VHE, as we don't have hypervisor-specific mappings. If the system 229 - * is VHE and yet selects this capability, it will be ignored. 230 - */ 231 211 extern void *__kvm_bp_vect_base; 232 212 extern int __kvm_harden_el2_vector_slot; 233 - 234 - static inline void *kvm_get_hyp_vector(void) 235 - { 236 - struct bp_hardening_data *data = arm64_get_bp_hardening_data(); 237 - void *vect = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector)); 238 - int slot = -1; 239 - 240 - if (cpus_have_const_cap(ARM64_SPECTRE_V2) && data->fn) { 241 - vect = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs)); 242 - slot = data->hyp_vectors_slot; 243 - } 244 - 245 - if (this_cpu_has_cap(ARM64_HARDEN_EL2_VECTORS) && !has_vhe()) { 246 - vect = __kvm_bp_vect_base; 247 - if (slot == -1) 248 - slot = __kvm_harden_el2_vector_slot; 249 - } 250 - 251 - if (slot != -1) 252 - vect += slot * SZ_2K; 253 - 254 - return vect; 255 - } 256 213 257 214 #define kvm_phys_to_vttbr(addr) phys_to_ttbr(addr) 258 215
+44 -2
arch/arm64/kvm/arm.c
··· 1375 1375 __hyp_reset_vectors(); 1376 1376 } 1377 1377 1378 + /* 1379 + * EL2 vectors can be mapped and rerouted in a number of ways, 1380 + * depending on the kernel configuration and CPU present: 1381 + * 1382 + * - If the CPU is affected by Spectre-v2, the hardening sequence is 1383 + * placed in one of the vector slots, which is executed before jumping 1384 + * to the real vectors. 1385 + * 1386 + * - If the CPU also has the ARM64_HARDEN_EL2_VECTORS cap, the slot 1387 + * containing the hardening sequence is mapped next to the idmap page, 1388 + * and executed before jumping to the real vectors. 1389 + * 1390 + * - If the CPU only has the ARM64_HARDEN_EL2_VECTORS cap, then an 1391 + * empty slot is selected, mapped next to the idmap page, and 1392 + * executed before jumping to the real vectors. 1393 + * 1394 + * Note that ARM64_HARDEN_EL2_VECTORS is somewhat incompatible with 1395 + * VHE, as we don't have hypervisor-specific mappings. If the system 1396 + * is VHE and yet selects this capability, it will be ignored. 1397 + */ 1398 + static void cpu_set_hyp_vector(void) 1399 + { 1400 + struct bp_hardening_data *data = arm64_get_bp_hardening_data(); 1401 + void *vect = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector)); 1402 + int slot = -1; 1403 + 1404 + if (cpus_have_const_cap(ARM64_SPECTRE_V2) && data->fn) { 1405 + vect = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs)); 1406 + slot = data->hyp_vectors_slot; 1407 + } 1408 + 1409 + if (this_cpu_has_cap(ARM64_HARDEN_EL2_VECTORS) && !has_vhe()) { 1410 + vect = __kvm_bp_vect_base; 1411 + if (slot == -1) 1412 + slot = __kvm_harden_el2_vector_slot; 1413 + } 1414 + 1415 + if (slot != -1) 1416 + vect += slot * SZ_2K; 1417 + 1418 + *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)vect; 1419 + } 1420 + 1378 1421 static void cpu_hyp_reinit(void) 1379 1422 { 1380 1423 kvm_init_host_cpu_context(&this_cpu_ptr_hyp_sym(kvm_host_data)->host_ctxt); 1381 1424 1382 1425 cpu_hyp_reset(); 1383 - 1384 - *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)kvm_get_hyp_vector(); 1426 + cpu_set_hyp_vector(); 1385 1427 1386 1428 if (is_kernel_in_hyp_mode()) 1387 1429 kvm_timer_init_vhe();