mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] riscv: fix KUnit test_kprobes crash when building with Clang
@ 2025-12-26  3:23 Jiakai Xu
  2025-12-31  3:15 ` Paul Walmsley
  0 siblings, 1 reply; 3+ messages in thread
From: Jiakai Xu @ 2025-12-26  3:23 UTC (permalink / raw)
  To: linux-kernel, linux-riscv
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Nam Cao,
	Alexandre Ghiti, Jiakai Xu, Jiakai Xu

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

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: https://github.com/llvm/llvm-project/issues/168308

v1 -> v2:
- Drop changes to .align, and .globl.

---
 arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S | 2 ++
 1 file changed, 2 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..f16deee9e091 100644
--- a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
+++ b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
@@ -181,6 +181,7 @@ SYM_FUNC_END(test_kprobes_c_bnez)
 
 #endif /* CONFIG_RISCV_ISA_C */
 
+.section .rodata
 SYM_DATA_START(test_kprobes_addresses)
 	RISCV_PTR test_kprobes_add_addr1
 	RISCV_PTR test_kprobes_add_addr2
@@ -212,6 +213,7 @@ SYM_DATA_START(test_kprobes_addresses)
 	RISCV_PTR 0
 SYM_DATA_END(test_kprobes_addresses)
 
+.section .rodata
 SYM_DATA_START(test_kprobes_functions)
 	RISCV_PTR test_kprobes_add
 	RISCV_PTR test_kprobes_jal
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] riscv: fix KUnit test_kprobes crash when building with Clang
  2025-12-26  3:23 [PATCH v2] riscv: fix KUnit test_kprobes crash when building with Clang Jiakai Xu
@ 2025-12-31  3:15 ` Paul Walmsley
  2026-01-04  0:53   ` Jiakai Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Walmsley @ 2025-12-31  3:15 UTC (permalink / raw)
  To: Jiakai Xu
  Cc: linux-kernel, linux-riscv, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Nam Cao, Alexandre Ghiti, Jiakai Xu

[-- Attachment #1: Type: text/plain, Size: 2649 bytes --]

Hi Jiakai Xu,

thanks for updating this patch -

On Fri, 26 Dec 2025, Jiakai Xu wrote:

> 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
> 
> 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: https://github.com/llvm/llvm-project/issues/168308
> 
> v1 -> v2:
> - Drop changes to .align, and .globl.

This should go below the --- line (or above the Signed-off-by:, Link: 
lines).  There shouldn't be anything between the Signed-off-by:, Link: 
trailers and the ---.

I've fixed this up locally, and queued for v6.19-rc.

> 
> ---
>  arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S | 2 ++
>  1 file changed, 2 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..f16deee9e091 100644
> --- a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
> +++ b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
> @@ -181,6 +181,7 @@ SYM_FUNC_END(test_kprobes_c_bnez)
>  
>  #endif /* CONFIG_RISCV_ISA_C */
>  
> +.section .rodata
>  SYM_DATA_START(test_kprobes_addresses)
>  	RISCV_PTR test_kprobes_add_addr1
>  	RISCV_PTR test_kprobes_add_addr2
> @@ -212,6 +213,7 @@ SYM_DATA_START(test_kprobes_addresses)
>  	RISCV_PTR 0
>  SYM_DATA_END(test_kprobes_addresses)
>  
> +.section .rodata
>  SYM_DATA_START(test_kprobes_functions)
>  	RISCV_PTR test_kprobes_add
>  	RISCV_PTR test_kprobes_jal
> -- 
> 2.34.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [PATCH v2] riscv: fix KUnit test_kprobes crash when building with Clang
  2025-12-31  3:15 ` Paul Walmsley
@ 2026-01-04  0:53   ` Jiakai Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Jiakai Xu @ 2026-01-04  0:53 UTC (permalink / raw)
  To: Paul Walmsley
  Cc: Jiakai Xu, linux-kernel, linux-riscv, Palmer Dabbelt, Albert Ou,
	Nam Cao, Alexandre Ghiti

Hi Paul,

Thanks for for fixing the formatting.

Best regards,
Jiakai

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-04  1:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-26  3:23 [PATCH v2] riscv: fix KUnit test_kprobes crash when building with Clang Jiakai Xu
2025-12-31  3:15 ` Paul Walmsley
2026-01-04  0:53   ` Jiakai Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®