forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/arch/x86/kernel/relocate_kernel_64.S
....@@ -1,9 +1,7 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * relocate_kernel.S - put the kernel image in place to boot
34 * Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com>
4
- *
5
- * This source code is licensed under the GNU General Public License,
6
- * Version 2. See the file COPYING for more details.
75 */
86
97 #include <linux/linkage.h>
....@@ -11,9 +9,12 @@
119 #include <asm/kexec.h>
1210 #include <asm/processor-flags.h>
1311 #include <asm/pgtable_types.h>
12
+#include <asm/nospec-branch.h>
13
+#include <asm/unwind_hints.h>
1414
1515 /*
16
- * Must be relocatable PIC code callable as a C function
16
+ * Must be relocatable PIC code callable as a C function, in particular
17
+ * there must be a plain RET and not jump to return thunk.
1718 */
1819
1920 #define PTR(x) (x << 3)
....@@ -40,8 +41,8 @@
4041 .text
4142 .align PAGE_SIZE
4243 .code64
43
- .globl relocate_kernel
44
-relocate_kernel:
44
+SYM_CODE_START_NOALIGN(relocate_kernel)
45
+ UNWIND_HINT_EMPTY
4546 /*
4647 * %rdi indirection_page
4748 * %rsi page_list
....@@ -104,9 +105,13 @@
104105 /* jump to identity mapped page */
105106 addq $(identity_mapped - relocate_kernel), %r8
106107 pushq %r8
108
+ ANNOTATE_UNRET_SAFE
107109 ret
110
+ int3
111
+SYM_CODE_END(relocate_kernel)
108112
109
-identity_mapped:
113
+SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
114
+ UNWIND_HINT_EMPTY
110115 /* set return address to 0 if not preserving context */
111116 pushq $0
112117 /* store the start address on the stack */
....@@ -189,19 +194,19 @@
189194 xorl %r14d, %r14d
190195 xorl %r15d, %r15d
191196
197
+ ANNOTATE_UNRET_SAFE
192198 ret
199
+ int3
193200
194201 1:
195202 popq %rdx
196203 leaq PAGE_SIZE(%r10), %rsp
204
+ ANNOTATE_RETPOLINE_SAFE
197205 call *%rdx
198206
199207 /* get the re-entry point of the peer system */
200208 movq 0(%rsp), %rbp
201
- call 1f
202
-1:
203
- popq %r8
204
- subq $(1b - relocate_kernel), %r8
209
+ leaq relocate_kernel(%rip), %r8
205210 movq CP_PA_SWAP_PAGE(%r8), %r10
206211 movq CP_PA_BACKUP_PAGES_MAP(%r8), %rdi
207212 movq CP_PA_TABLE_PAGE(%r8), %rax
....@@ -210,9 +215,13 @@
210215 call swap_pages
211216 movq $virtual_mapped, %rax
212217 pushq %rax
218
+ ANNOTATE_UNRET_SAFE
213219 ret
220
+ int3
221
+SYM_CODE_END(identity_mapped)
214222
215
-virtual_mapped:
223
+SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
224
+ UNWIND_HINT_EMPTY
216225 movq RSP(%r8), %rsp
217226 movq CR4(%r8), %rax
218227 movq %rax, %cr4
....@@ -229,10 +238,14 @@
229238 popq %r12
230239 popq %rbp
231240 popq %rbx
241
+ ANNOTATE_UNRET_SAFE
232242 ret
243
+ int3
244
+SYM_CODE_END(virtual_mapped)
233245
234246 /* Do the copies */
235
-swap_pages:
247
+SYM_CODE_START_LOCAL_NOALIGN(swap_pages)
248
+ UNWIND_HINT_EMPTY
236249 movq %rdi, %rcx /* Put the page_list in %rcx */
237250 xorl %edi, %edi
238251 xorl %esi, %esi
....@@ -284,7 +297,10 @@
284297 lea PAGE_SIZE(%rax), %rsi
285298 jmp 0b
286299 3:
300
+ ANNOTATE_UNRET_SAFE
287301 ret
302
+ int3
303
+SYM_CODE_END(swap_pages)
288304
289305 .globl kexec_control_code_size
290306 .set kexec_control_code_size, . - relocate_kernel