GNU Linux-libre 4.19.286-gnu1
[releases.git] / arch / arm64 / include / asm / vectors.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2022 ARM Ltd.
4  */
5 #ifndef __ASM_VECTORS_H
6 #define __ASM_VECTORS_H
7
8 #include <linux/bug.h>
9 #include <linux/percpu.h>
10
11 #include <asm/fixmap.h>
12 #include <asm/mmu.h>
13
14 extern char vectors[];
15 extern char tramp_vectors[];
16 extern char __bp_harden_el1_vectors[];
17
18 /*
19  * Note: the order of this enum corresponds to two arrays in entry.S:
20  * tramp_vecs and __bp_harden_el1_vectors. By default the canonical
21  * 'full fat' vectors are used directly.
22  */
23 enum arm64_bp_harden_el1_vectors {
24 #ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
25         /*
26          * Perform the BHB loop mitigation, before branching to the canonical
27          * vectors.
28          */
29         EL1_VECTOR_BHB_LOOP,
30
31         /*
32          * Make the SMC call for firmware mitigation, before branching to the
33          * canonical vectors.
34          */
35         EL1_VECTOR_BHB_FW,
36
37         /*
38          * Use the ClearBHB instruction, before branching to the canonical
39          * vectors.
40          */
41         EL1_VECTOR_BHB_CLEAR_INSN,
42 #endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
43
44         /*
45          * Remap the kernel before branching to the canonical vectors.
46          */
47         EL1_VECTOR_KPTI,
48 };
49
50 #ifndef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
51 #define EL1_VECTOR_BHB_LOOP             -1
52 #define EL1_VECTOR_BHB_FW               -1
53 #define EL1_VECTOR_BHB_CLEAR_INSN       -1
54 #endif /* !CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
55
56 /* The vectors to use on return from EL0. e.g. to remap the kernel */
57 DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);
58
59 #ifndef CONFIG_UNMAP_KERNEL_AT_EL0
60 #define TRAMP_VALIAS    0
61 #endif
62
63 static inline const char *
64 arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
65 {
66         if (arm64_kernel_unmapped_at_el0())
67                 return (char *)TRAMP_VALIAS + SZ_2K * slot;
68
69         WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
70
71         return __bp_harden_el1_vectors + SZ_2K * slot;
72 }
73
74 #endif /* __ASM_VECTORS_H */