Skip to content

Commit 641ecc8

Browse files
6eanutPaul Walmsley
authored andcommitted
riscv: fix KUnit test_kprobes crash when building with Clang
Clang misinterprets the placement of test_kprobes_addresses and test_kprobes_functions arrays when they are not explicitly assigned to a data section. This can lead to kmalloc_array() allocation errors and KUnit failures. When testing the Clang-compiled code in QEMU, this warning was emitted: WARNING: CPU: 1 PID: 3000 at mm/page_alloc.c:5159 __alloc_frozen_pages_noprof+0xe6/0x2fc mm/page_alloc.c:5159 Further investigation revealed that the test_kprobes_addresses array appeared to have over 100,000 elements, including invalid addresses; whereas, according to test-kprobes-asm.S, test_kprobes_addresses should only have 25 elements. When compiling the kernel with GCC, the kernel boots correctly. This patch fixes the issue by adding .section .rodata to explicitly place arrays in the read-only data segment. For detailed debug and analysis, see: https://github.com/j1akai/temp/blob/main/20251113/readme.md v1 -> v2: - Drop changes to .align, and .globl. Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Link: https://patch.msgid.link/738dd4e2.ff73.19a7cd7b4d5.Coremail.xujiakai2025@iscas.ac.cn Link: llvm/llvm-project#168308 Link: https://patch.msgid.link/20251226032317.1523764-1-jiakaiPeanut@gmail.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent 25fd7ee commit 641ecc8

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ SYM_FUNC_END(test_kprobes_c_bnez)
181181

182182
#endif /* CONFIG_RISCV_ISA_C */
183183

184+
.section .rodata
184185
SYM_DATA_START(test_kprobes_addresses)
185186
RISCV_PTR test_kprobes_add_addr1
186187
RISCV_PTR test_kprobes_add_addr2
@@ -212,6 +213,7 @@ SYM_DATA_START(test_kprobes_addresses)
212213
RISCV_PTR 0
213214
SYM_DATA_END(test_kprobes_addresses)
214215

216+
.section .rodata
215217
SYM_DATA_START(test_kprobes_functions)
216218
RISCV_PTR test_kprobes_add
217219
RISCV_PTR test_kprobes_jal

0 commit comments

Comments
 (0)