KVM: arm64: Move kvm_get_hyp_vector() out of header file
authorWill Deacon <will@kernel.org>
Fri, 13 Nov 2020 11:38:40 +0000 (11:38 +0000)
committerMarc Zyngier <maz@kernel.org>
Mon, 16 Nov 2020 10:40:17 +0000 (10:40 +0000)
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
arch/arm64/include/asm/kvm_mmu.h
arch/arm64/kvm/arm.c

index 331394306ccee34633d178dbec9c1800612ac910..23182e7d941344e2ca47f17efb9435f5acf391cc 100644 (file)
@@ -208,52 +208,9 @@ static inline int kvm_write_guest_lock(struct kvm *kvm, gpa_t gpa,
        return ret;
 }
 
-/*
- * EL2 vectors can be mapped and rerouted in a number of ways,
- * depending on the kernel configuration and CPU present:
- *
- * - If the CPU is affected by Spectre-v2, the hardening sequence is
- *   placed in one of the vector slots, which is executed before jumping
- *   to the real vectors.
- *
- * - If the CPU also has the ARM64_HARDEN_EL2_VECTORS cap, the slot
- *   containing the hardening sequence is mapped next to the idmap page,
- *   and executed before jumping to the real vectors.
- *
- * - If the CPU only has the ARM64_HARDEN_EL2_VECTORS cap, then an
- *   empty slot is selected, mapped next to the idmap page, and
- *   executed before jumping to the real vectors.
- *
- * Note that ARM64_HARDEN_EL2_VECTORS is somewhat incompatible with
- * VHE, as we don't have hypervisor-specific mappings. If the system
- * is VHE and yet selects this capability, it will be ignored.
- */
 extern void *__kvm_bp_vect_base;
 extern int __kvm_harden_el2_vector_slot;
 
-static inline void *kvm_get_hyp_vector(void)
-{
-       struct bp_hardening_data *data = arm64_get_bp_hardening_data();
-       void *vect = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector));
-       int slot = -1;
-
-       if (cpus_have_const_cap(ARM64_SPECTRE_V2) && data->fn) {
-               vect = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs));
-               slot = data->hyp_vectors_slot;
-       }
-
-       if (this_cpu_has_cap(ARM64_HARDEN_EL2_VECTORS) && !has_vhe()) {
-               vect = __kvm_bp_vect_base;
-               if (slot == -1)
-                       slot = __kvm_harden_el2_vector_slot;
-       }
-
-       if (slot != -1)
-               vect += slot * SZ_2K;
-
-       return vect;
-}
-
 #define kvm_phys_to_vttbr(addr)                phys_to_ttbr(addr)
 
 static __always_inline u64 kvm_get_vttbr(struct kvm_s2_mmu *mmu)
index 476bc613d0e6592eeb913abb00252a2df7a1f1f6..c63c0b3c9b17ba6d26488814f57d2368fa05eacf 100644 (file)
@@ -1375,13 +1375,55 @@ static void cpu_hyp_reset(void)
                __hyp_reset_vectors();
 }
 
+/*
+ * EL2 vectors can be mapped and rerouted in a number of ways,
+ * depending on the kernel configuration and CPU present:
+ *
+ * - If the CPU is affected by Spectre-v2, the hardening sequence is
+ *   placed in one of the vector slots, which is executed before jumping
+ *   to the real vectors.
+ *
+ * - If the CPU also has the ARM64_HARDEN_EL2_VECTORS cap, the slot
+ *   containing the hardening sequence is mapped next to the idmap page,
+ *   and executed before jumping to the real vectors.
+ *
+ * - If the CPU only has the ARM64_HARDEN_EL2_VECTORS cap, then an
+ *   empty slot is selected, mapped next to the idmap page, and
+ *   executed before jumping to the real vectors.
+ *
+ * Note that ARM64_HARDEN_EL2_VECTORS is somewhat incompatible with
+ * VHE, as we don't have hypervisor-specific mappings. If the system
+ * is VHE and yet selects this capability, it will be ignored.
+ */
+static void cpu_set_hyp_vector(void)
+{
+       struct bp_hardening_data *data = arm64_get_bp_hardening_data();
+       void *vect = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector));
+       int slot = -1;
+
+       if (cpus_have_const_cap(ARM64_SPECTRE_V2) && data->fn) {
+               vect = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs));
+               slot = data->hyp_vectors_slot;
+       }
+
+       if (this_cpu_has_cap(ARM64_HARDEN_EL2_VECTORS) && !has_vhe()) {
+               vect = __kvm_bp_vect_base;
+               if (slot == -1)
+                       slot = __kvm_harden_el2_vector_slot;
+       }
+
+       if (slot != -1)
+               vect += slot * SZ_2K;
+
+       *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)vect;
+}
+
 static void cpu_hyp_reinit(void)
 {
        kvm_init_host_cpu_context(&this_cpu_ptr_hyp_sym(kvm_host_data)->host_ctxt);
 
        cpu_hyp_reset();
-
-       *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)kvm_get_hyp_vector();
+       cpu_set_hyp_vector();
 
        if (is_kernel_in_hyp_mode())
                kvm_timer_init_vhe();