[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bd82855d-4a80-58fb-c949-b968569ef1e2@kernel.org>
Date: Tue, 18 Nov 2025 13:21:50 -0700 (MST)
From: Paul Walmsley <pjw@...nel.org>
To: Jiakai Xu <xujiakai2025@...as.ac.cn>
cc: Paul Walmsley <pjw@...nel.org>, Nathan Chancellor <nathan@...nel.org>,
linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>, namcao@...utronix.de
Subject: Re: Re: [PATCH] riscv: fix KUnit test_kprobes crash when building
with Clang
Hi,
On Mon, 17 Nov 2025, Jiakai Xu wrote:
> Thank you very much for reviewing my patch; your feedback was very helpful.
Great. Here's one more request:
> > Thanks for the patch. Have you reported this difference in behavior to
Looks like you're using a mail client that sends HTML in what should be a
plain-text E-mail; please fix that.
> I have reported this issue to the LLVM community:
> https://github.com/llvm/llvm-project/issues/168308
> We now need to wait for feedback from the LLVM community.
Thank you.
> Below, I include the narrative from my readme for reference:
[ ... ]
> I would like to ask whether it is appropriate to include all this detail
> directly in the patch description and email, or if it would be better to
> submit it as a PATCH v1.
Not all of it, but some edited summary is appropriate. I've queued the
following revision for v6.18-rc fixes, under the theory that it would be
good to get the test working for Clang users while the LLVM folks
investigate. Please let us know ASAP if you think anything in it should
be changed. I plan to send a PR out later this week.
thanks,
- Paul
From: =?UTF-8?q?=E8=AE=B8=E4=BD=B3=E5=87=AF?= <xujiakai2025@...as.ac.cn>
Date: Thu, 13 Nov 2025 18:51:42 +0800
Subject: [PATCH] riscv: fix KUnit test_kprobes crash when building with Clang
Clang misaligns the test_kprobes_addresses and test_kprobes_functions
arrays, or does not export local labels by default. Both can cause
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.
- Adding .align 3 to align arrays to 8 bytes.
- Adding .globl to probe labels to ensure symbols are visible.
For detailed debug and analysis, see:
https://github.com/j1akai/temp/blob/main/20251113/readme.md
Signed-off-by: Jiakai Xu <xujiakai2025@...as.ac.cn>
Link: https://patch.msgid.link/738dd4e2.ff73.19a7cd7b4d5.Coremail.xujiakai2025@iscas.ac.cn
Link: https://github.com/llvm/llvm-project/issues/168308
Cc: Nam Cao <namcao@...utronix.de>
[pjw@...nel.org: added additional context to the patch description]
Signed-off-by: Paul Walmsley <pjw@...nel.org>
---
.../kernel/tests/kprobes/test-kprobes-asm.S | 29 +++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
index b951d0f12482..ac5ce305b1bd 100644
--- a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
+++ b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
@@ -7,8 +7,10 @@
SYM_FUNC_START(test_kprobes_add)
li a1, KPROBE_TEST_MAGIC_UPPER
li a2, KPROBE_TEST_MAGIC_LOWER
+.globl test_kprobes_add_addr1
test_kprobes_add_addr1:
add a1, a1, a2
+.globl test_kprobes_add_addr2
test_kprobes_add_addr2:
add a0, a1, x0
ret
@@ -19,6 +21,7 @@ SYM_FUNC_START(test_kprobes_jal)
mv a1, ra
.option push
.option norvc
+.globl test_kprobes_jal_addr1
test_kprobes_jal_addr1:
jal x0, 2f
ret
@@ -27,6 +30,7 @@ test_kprobes_jal_addr1:
ret
.option push
.option norvc
+.globl test_kprobes_jal_addr2
test_kprobes_jal_addr2:
2: jal 1b
.option pop
@@ -40,6 +44,7 @@ SYM_FUNC_START(test_kprobes_jalr)
mv a1, ra
.option push
.option norvc
+.globl test_kprobes_jalr_addr
test_kprobes_jalr_addr:
jalr a0
.option pop
@@ -51,6 +56,7 @@ test_kprobes_jalr_addr:
SYM_FUNC_END(test_kprobes_jalr)
SYM_FUNC_START(test_kprobes_auipc)
+.globl test_kprobes_auipc_addr
test_kprobes_auipc_addr:
auipc a0, KPROBE_TEST_MAGIC_LOWER
la a1, test_kprobes_auipc_addr
@@ -67,20 +73,26 @@ SYM_FUNC_START(test_kprobes_branch)
li a0, 0
li a1, 1
li a2, 2
+.globl test_kprobes_branch_addr1
test_kprobes_branch_addr1:
beqz a0, 1f
ret
1:
+.globl test_kprobes_branch_addr2
test_kprobes_branch_addr2:
beqz a1, 3f
+.globl test_kprobes_branch_addr3
test_kprobes_branch_addr3:
bnez a0, 3f
+.globl test_kprobes_branch_addr4
test_kprobes_branch_addr4:
bnez a2, 1f
ret
1:
+.globl test_kprobes_branch_addr5
test_kprobes_branch_addr5:
bge a1, a2, 3f
+.globl test_kprobes_branch_addr6
test_kprobes_branch_addr6:
bge a2, a1, 2f
ret
@@ -89,9 +101,11 @@ test_kprobes_branch_addr6:
add a0, a0, t0
ret
2:
+.globl test_kprobes_branch_addr7
test_kprobes_branch_addr7:
blt a2, a1, 3f
li a0, KPROBE_TEST_MAGIC_LOWER
+.globl test_kprobes_branch_addr8
test_kprobes_branch_addr8:
blt a1, a2, 1b
3:
@@ -104,6 +118,7 @@ SYM_FUNC_END(test_kprobes_branch)
SYM_FUNC_START(test_kprobes_c_j)
li a0, 0
+.globl test_kprobes_branch_c_j_addr1
test_kprobes_branch_c_j_addr1:
c.j 2f
1:
@@ -111,12 +126,14 @@ test_kprobes_branch_c_j_addr1:
add a0, a0, a1
ret
2: li a0, KPROBE_TEST_MAGIC_LOWER
+.globl test_kprobes_branch_c_j_addr2
test_kprobes_branch_c_j_addr2:
c.j 1b
SYM_FUNC_END(test_kprobes_c_j)
SYM_FUNC_START(test_kprobes_c_jr)
la a0, 2f
+.globl test_kprobes_c_jr_addr1
test_kprobes_c_jr_addr1:
c.jr a0
ret
@@ -126,6 +143,7 @@ test_kprobes_c_jr_addr1:
2:
li a0, KPROBE_TEST_MAGIC_UPPER
la a1, 1b
+.globl test_kprobes_c_jr_addr2
test_kprobes_c_jr_addr2:
c.jr a1
SYM_FUNC_END(test_kprobes_c_jr)
@@ -133,6 +151,7 @@ SYM_FUNC_END(test_kprobes_c_jr)
SYM_FUNC_START(test_kprobes_c_jalr)
mv a1, ra
la a0, 1f
+.globl test_kprobes_c_jalr_addr
test_kprobes_c_jalr_addr:
c.jalr a0
li a2, KPROBE_TEST_MAGIC_UPPER
@@ -145,16 +164,19 @@ SYM_FUNC_END(test_kprobes_c_jalr)
SYM_FUNC_START(test_kprobes_c_beqz)
li a0, 0
li a1, 1
+.globl test_kprobes_c_beqz_addr1
test_kprobes_c_beqz_addr1:
c.beqz a0, 2f
ret
1: li a1, KPROBE_TEST_MAGIC_UPPER
add a0, a0, a1
ret
+.globl test_kprobes_c_beqz_addr2
test_kprobes_c_beqz_addr2:
2: c.beqz a1, 3f
li a0, KPROBE_TEST_MAGIC_LOWER
mv a1, x0
+.globl test_kprobes_c_beqz_addr3
test_kprobes_c_beqz_addr3:
c.beqz a1, 1b
3: li a0, 0
@@ -164,15 +186,18 @@ SYM_FUNC_END(test_kprobes_c_beqz)
SYM_FUNC_START(test_kprobes_c_bnez)
li a0, 0
li a1, 1
+.globl test_kprobes_c_bnez_addr1
test_kprobes_c_bnez_addr1:
c.bnez a1, 2f
ret
1: li a1, KPROBE_TEST_MAGIC_UPPER
add a0, a0, a1
ret
+.globl test_kprobes_c_bnez_addr2
test_kprobes_c_bnez_addr2:
2: c.bnez a0, 3f
li a0, KPROBE_TEST_MAGIC_LOWER
+.globl test_kprobes_c_bnez_addr3
test_kprobes_c_bnez_addr3:
c.bnez a0, 1b
3: li a0, 0
@@ -181,6 +206,8 @@ SYM_FUNC_END(test_kprobes_c_bnez)
#endif /* CONFIG_RISCV_ISA_C */
+.section .rodata
+.align 3
SYM_DATA_START(test_kprobes_addresses)
RISCV_PTR test_kprobes_add_addr1
RISCV_PTR test_kprobes_add_addr2
@@ -212,6 +239,8 @@ SYM_DATA_START(test_kprobes_addresses)
RISCV_PTR 0
SYM_DATA_END(test_kprobes_addresses)
+.section .rodata
+.align 3
SYM_DATA_START(test_kprobes_functions)
RISCV_PTR test_kprobes_add
RISCV_PTR test_kprobes_jal
--
2.48.1
Powered by blists - more mailing lists