Skip to content

Commit e609b4f

Browse files
samitolvanenpalmer-dabbelt
authored andcommitted
riscv: Move global pointer loading to a macro
In Clang 17, -fsanitize=shadow-call-stack uses the newly declared platform register gp for storing shadow call stack pointers. As this is obviously incompatible with gp relaxation, in preparation for CONFIG_SHADOW_CALL_STACK support, move global pointer loading to a single macro, which we can cleanly disable when SCS is used instead. Link: https://reviews.llvm.org/rGaa1d2693c256 Link: riscv-non-isa/riscv-elf-psabi-doc@a484e84 Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Tested-by: Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20230927224757.1154247-11-samitolvanen@google.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 82982fd commit e609b4f

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

arch/riscv/include/asm/asm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@
109109
REG_L \dst, 0(\dst)
110110
.endm
111111

112+
/* load __global_pointer to gp */
113+
.macro load_global_pointer
114+
.option push
115+
.option norelax
116+
la gp, __global_pointer$
117+
.option pop
118+
.endm
119+
112120
/* save all GPs except x1 ~ x5 */
113121
.macro save_from_x6_to_x31
114122
REG_S x6, PT_T1(sp)

arch/riscv/kernel/entry.S

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ _save_context:
7575
csrw CSR_SCRATCH, x0
7676

7777
/* Load the global pointer */
78-
.option push
79-
.option norelax
80-
la gp, __global_pointer$
81-
.option pop
78+
load_global_pointer
79+
8280
move a0, sp /* pt_regs */
8381
la ra, ret_from_exception
8482

arch/riscv/kernel/head.S

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ relocate_enable_mmu:
110110
csrw CSR_TVEC, a0
111111

112112
/* Reload the global pointer */
113-
.option push
114-
.option norelax
115-
la gp, __global_pointer$
116-
.option pop
113+
load_global_pointer
117114

118115
/*
119116
* Switch to kernel page tables. A full fence is necessary in order to
@@ -134,10 +131,7 @@ secondary_start_sbi:
134131
csrw CSR_IP, zero
135132

136133
/* Load the global pointer */
137-
.option push
138-
.option norelax
139-
la gp, __global_pointer$
140-
.option pop
134+
load_global_pointer
141135

142136
/*
143137
* Disable FPU & VECTOR to detect illegal usage of
@@ -228,10 +222,7 @@ pmp_done:
228222
#endif /* CONFIG_RISCV_M_MODE */
229223

230224
/* Load the global pointer */
231-
.option push
232-
.option norelax
233-
la gp, __global_pointer$
234-
.option pop
225+
load_global_pointer
235226

236227
/*
237228
* Disable FPU & VECTOR to detect illegal usage of

arch/riscv/kernel/suspend_entry.S

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ END(__cpu_suspend_enter)
6161

6262
SYM_TYPED_FUNC_START(__cpu_resume_enter)
6363
/* Load the global pointer */
64-
.option push
65-
.option norelax
66-
la gp, __global_pointer$
67-
.option pop
64+
load_global_pointer
6865

6966
#ifdef CONFIG_MMU
7067
/* Save A0 and A1 */

0 commit comments

Comments
 (0)