forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/arch/x86/kernel/relocate_kernel_32.S
....@@ -1,18 +1,18 @@
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-2004 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>
108 #include <asm/page_types.h>
119 #include <asm/kexec.h>
10
+#include <asm/nospec-branch.h>
1211 #include <asm/processor-flags.h>
1312
1413 /*
15
- * Must be relocatable PIC code callable as a C function
14
+ * Must be relocatable PIC code callable as a C function, in particular
15
+ * there must be a plain RET and not jump to return thunk.
1616 */
1717
1818 #define PTR(x) (x << 2)
....@@ -37,8 +37,7 @@
3737 #define CP_PA_BACKUP_PAGES_MAP DATA(0x1c)
3838
3939 .text
40
- .globl relocate_kernel
41
-relocate_kernel:
40
+SYM_CODE_START_NOALIGN(relocate_kernel)
4241 /* Save the CPU context, used for jumping back */
4342
4443 pushl %ebx
....@@ -94,9 +93,12 @@
9493 movl %edi, %eax
9594 addl $(identity_mapped - relocate_kernel), %eax
9695 pushl %eax
96
+ ANNOTATE_UNRET_SAFE
9797 ret
98
+ int3
99
+SYM_CODE_END(relocate_kernel)
98100
99
-identity_mapped:
101
+SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
100102 /* set return address to 0 if not preserving context */
101103 pushl $0
102104 /* store the start address on the stack */
....@@ -161,12 +163,15 @@
161163 xorl %edx, %edx
162164 xorl %esi, %esi
163165 xorl %ebp, %ebp
166
+ ANNOTATE_UNRET_SAFE
164167 ret
168
+ int3
165169 1:
166170 popl %edx
167171 movl CP_PA_SWAP_PAGE(%edi), %esp
168172 addl $PAGE_SIZE, %esp
169173 2:
174
+ ANNOTATE_RETPOLINE_SAFE
170175 call *%edx
171176
172177 /* get the re-entry point of the peer system */
....@@ -192,9 +197,12 @@
192197 movl %edi, %eax
193198 addl $(virtual_mapped - relocate_kernel), %eax
194199 pushl %eax
200
+ ANNOTATE_UNRET_SAFE
195201 ret
202
+ int3
203
+SYM_CODE_END(identity_mapped)
196204
197
-virtual_mapped:
205
+SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
198206 movl CR4(%edi), %eax
199207 movl %eax, %cr4
200208 movl CR3(%edi), %eax
....@@ -209,10 +217,13 @@
209217 popl %edi
210218 popl %esi
211219 popl %ebx
220
+ ANNOTATE_UNRET_SAFE
212221 ret
222
+ int3
223
+SYM_CODE_END(virtual_mapped)
213224
214225 /* Do the copies */
215
-swap_pages:
226
+SYM_CODE_START_LOCAL_NOALIGN(swap_pages)
216227 movl 8(%esp), %edx
217228 movl 4(%esp), %ecx
218229 pushl %ebp
....@@ -271,7 +282,10 @@
271282 popl %edi
272283 popl %ebx
273284 popl %ebp
285
+ ANNOTATE_UNRET_SAFE
274286 ret
287
+ int3
288
+SYM_CODE_END(swap_pages)
275289
276290 .globl kexec_control_code_size
277291 .set kexec_control_code_size, . - relocate_kernel