GNU Linux-libre 4.14.332-gnu1
[releases.git] / arch / arm64 / kernel / bpi.S
1 /*
2  * Contains CPU specific branch predictor invalidation sequences
3  *
4  * Copyright (C) 2018 ARM Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <linux/linkage.h>
20 #include <linux/arm-smccc.h>
21
22 .macro ventry target
23         .rept 31
24         nop
25         .endr
26         b       \target
27 .endm
28
29 .macro vectors target
30         ventry \target + 0x000
31         ventry \target + 0x080
32         ventry \target + 0x100
33         ventry \target + 0x180
34
35         ventry \target + 0x200
36         ventry \target + 0x280
37         ventry \target + 0x300
38         ventry \target + 0x380
39
40         ventry \target + 0x400
41         ventry \target + 0x480
42         ventry \target + 0x500
43         ventry \target + 0x580
44
45         ventry \target + 0x600
46         ventry \target + 0x680
47         ventry \target + 0x700
48         ventry \target + 0x780
49 .endm
50
51         .align  11
52 ENTRY(__bp_harden_hyp_vecs_start)
53         .rept 4
54         vectors __kvm_hyp_vector
55         .endr
56 ENTRY(__bp_harden_hyp_vecs_end)
57
58
59 ENTRY(__smccc_workaround_1_smc_start)
60         sub     sp, sp, #(8 * 4)
61         stp     x2, x3, [sp, #(8 * 0)]
62         stp     x0, x1, [sp, #(8 * 2)]
63         mov     w0, #ARM_SMCCC_ARCH_WORKAROUND_1
64         smc     #0
65         ldp     x2, x3, [sp, #(8 * 0)]
66         ldp     x0, x1, [sp, #(8 * 2)]
67         add     sp, sp, #(8 * 4)
68 ENTRY(__smccc_workaround_1_smc_end)
69
70 ENTRY(__smccc_workaround_3_smc_start)
71         sub     sp, sp, #(8 * 4)
72         stp     x2, x3, [sp, #(8 * 0)]
73         stp     x0, x1, [sp, #(8 * 2)]
74         mov     w0, #ARM_SMCCC_ARCH_WORKAROUND_3
75         smc     #0
76         ldp     x2, x3, [sp, #(8 * 0)]
77         ldp     x0, x1, [sp, #(8 * 2)]
78         add     sp, sp, #(8 * 4)
79 ENTRY(__smccc_workaround_3_smc_end)
80
81 ENTRY(__spectre_bhb_loop_k8_start)
82         sub     sp, sp, #(8 * 2)
83         stp     x0, x1, [sp, #(8 * 0)]
84         mov     x0, #8
85 2:      b       . + 4
86         subs    x0, x0, #1
87         b.ne    2b
88         dsb     nsh
89         isb
90         ldp     x0, x1, [sp, #(8 * 0)]
91         add     sp, sp, #(8 * 2)
92 ENTRY(__spectre_bhb_loop_k8_end)
93
94 ENTRY(__spectre_bhb_loop_k24_start)
95         sub     sp, sp, #(8 * 2)
96         stp     x0, x1, [sp, #(8 * 0)]
97         mov     x0, #24
98 2:      b       . + 4
99         subs    x0, x0, #1
100         b.ne    2b
101         dsb     nsh
102         isb
103         ldp     x0, x1, [sp, #(8 * 0)]
104         add     sp, sp, #(8 * 2)
105 ENTRY(__spectre_bhb_loop_k24_end)
106
107 ENTRY(__spectre_bhb_loop_k32_start)
108         sub     sp, sp, #(8 * 2)
109         stp     x0, x1, [sp, #(8 * 0)]
110         mov     x0, #32
111 2:      b       . + 4
112         subs    x0, x0, #1
113         b.ne    2b
114         dsb     nsh
115         isb
116         ldp     x0, x1, [sp, #(8 * 0)]
117         add     sp, sp, #(8 * 2)
118 ENTRY(__spectre_bhb_loop_k32_end)
119
120 ENTRY(__spectre_bhb_clearbhb_start)
121         hint    #22     /* aka clearbhb */
122         isb
123 ENTRY(__spectre_bhb_clearbhb_end)