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

KVM: arm64: Tidy up kvm_map_vector()

The bulk of the work in kvm_map_vector() is conditional on the
ARM64_HARDEN_EL2_VECTORS capability, so return early if that is not set
and make the code a bit easier to read.

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-3-will@kernel.org

authored by

Will Deacon and committed by
Marc Zyngier
de5bcdb4 8934c845

+14 -14
+14 -14
arch/arm64/kvm/arm.c
··· 1297 1297 1298 1298 static int kvm_map_vectors(void) 1299 1299 { 1300 + int slot; 1301 + 1300 1302 /* 1301 1303 * SV2 = ARM64_SPECTRE_V2 1302 1304 * HEL2 = ARM64_HARDEN_EL2_VECTORS ··· 1308 1306 * !SV2 + HEL2 -> allocate one vector slot and use exec mapping 1309 1307 * SV2 + HEL2 -> use hardened vectors and use exec mapping 1310 1308 */ 1311 - if (cpus_have_const_cap(ARM64_HARDEN_EL2_VECTORS)) { 1312 - phys_addr_t vect_pa = __pa_symbol(__bp_harden_hyp_vecs); 1313 - unsigned long size = __BP_HARDEN_HYP_VECS_SZ; 1309 + if (!cpus_have_const_cap(ARM64_HARDEN_EL2_VECTORS)) 1310 + return 0; 1314 1311 1315 - /* 1316 - * Always allocate a spare vector slot, as we don't 1317 - * know yet which CPUs have a BP hardening slot that 1318 - * we can reuse. 1319 - */ 1320 - __kvm_harden_el2_vector_slot = atomic_inc_return(&arm64_el2_vector_last_slot); 1321 - BUG_ON(__kvm_harden_el2_vector_slot >= BP_HARDEN_EL2_SLOTS); 1322 - return create_hyp_exec_mappings(vect_pa, size, 1323 - &__kvm_bp_vect_base); 1324 - } 1312 + /* 1313 + * Always allocate a spare vector slot, as we don't know yet which CPUs 1314 + * have a BP hardening slot that we can reuse. 1315 + */ 1316 + slot = atomic_inc_return(&arm64_el2_vector_last_slot); 1317 + BUG_ON(slot >= BP_HARDEN_EL2_SLOTS); 1318 + __kvm_harden_el2_vector_slot = slot; 1325 1319 1326 - return 0; 1320 + return create_hyp_exec_mappings(__pa_symbol(__bp_harden_hyp_vecs), 1321 + __BP_HARDEN_HYP_VECS_SZ, 1322 + &__kvm_bp_vect_base); 1327 1323 } 1328 1324 1329 1325 static void cpu_init_hyp_mode(void)