forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/arch/arm64/kernel/efi-rt-wrapper.S
....@@ -1,14 +1,12 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org>
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
74 */
85
96 #include <linux/linkage.h>
7
+#include <asm/assembler.h>
108
11
-ENTRY(__efi_rt_asm_wrapper)
9
+SYM_FUNC_START(__efi_rt_asm_wrapper)
1210 stp x29, x30, [sp, #-32]!
1311 mov x29, sp
1412
....@@ -18,6 +16,12 @@
1816 * (such as UEFI) should never touch it.
1917 */
2018 stp x1, x18, [sp, #16]
19
+
20
+ ldr_l x16, efi_rt_stack_top
21
+ mov sp, x16
22
+#ifdef CONFIG_SHADOW_CALL_STACK
23
+ str x18, [sp, #-16]!
24
+#endif
2125
2226 /*
2327 * We are lucky enough that no EFI runtime services take more than
....@@ -32,19 +36,24 @@
3236 mov x4, x6
3337 blr x8
3438
39
+ mov sp, x29
3540 ldp x1, x2, [sp, #16]
3641 cmp x2, x18
3742 ldp x29, x30, [sp], #32
3843 b.ne 0f
3944 ret
4045 0:
41
-#ifdef CONFIG_SHADOW_CALL_STACK
4246 /*
43
- * Restore x18 before returning to instrumented code. This is
44
- * safe because the wrapper is called with preemption disabled and
45
- * a separate shadow stack is used for interrupts.
47
+ * With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a
48
+ * shadow stack pointer, which we need to restore before returning to
49
+ * potentially instrumented code. This is safe because the wrapper is
50
+ * called with preemption disabled and a separate shadow stack is used
51
+ * for interrupts.
4652 */
47
- mov x18, x2
53
+#ifdef CONFIG_SHADOW_CALL_STACK
54
+ ldr_l x18, efi_rt_stack_top
55
+ ldr x18, [x18, #-16]
4856 #endif
57
+
4958 b efi_handle_corrupted_x18 // tail call
50
-ENDPROC(__efi_rt_asm_wrapper)
59
+SYM_FUNC_END(__efi_rt_asm_wrapper)