All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Paul Walmsley <pjw@kernel.org>, Jiakai Xu <xujiakai2025@iscas.ac.cn>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	namcao@linutronix.de
Subject: Re: Re: [PATCH] riscv: fix KUnit test_kprobes crash when building with Clang
Date: Tue, 18 Nov 2025 18:38:08 -0700	[thread overview]
Message-ID: <20251119013808.GA1264583@ax162> (raw)
In-Reply-To: <bd82855d-4a80-58fb-c949-b968569ef1e2@kernel.org>

Hi Paul and Jiakai,

On Tue, Nov 18, 2025 at 01:21:50PM -0700, Paul Walmsley wrote:
> 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.

I spent some time today trying to minimize a small set of configurations
that triggers this issue on top of defconfig since that occasionally
reveals a path to head down for triage and I landed on:

  $ cat arch/riscv/configs/repro.config
  CONFIG_KPROBES=y
  CONFIG_KUNIT=y
  CONFIG_RELOCATABLE=y
  CONFIG_RISCV_KPROBES_KUNIT=y

  $ make -skj"$(nproc)" ARCH=riscv LLVM=1 clean defconfig repro.config Image

  $ curl -LSs https://github.com/ClangBuiltLinux/boot-utils/releases/download/20241120-044434/riscv-rootfs.cpio.zst | zstd -d >rootfs.cpio

  $ qemu-system-riscv64 \
      -display none \
      -nodefaults \
      -bios default \
      -M virt \
      -append earlycon \
      -kernel arch/riscv/boot/Image \
      -initrd rootfs.cpio \
      -m 512m \
      -serial mon:stdio
  ...
  [    0.000000] Booting Linux on hartid 0
  [    0.000000] Linux version 6.18.0-rc6-dirty (nathan@ax162) (ClangBuiltLinux clang version 21.1.5 (https://github.com/llvm/llvm-project.git 8e2cd28cd4ba46613a46467b0c91b1cabead26cd), ClangBuiltLinux LLD 21.1.5 (https://github.com/llvm/llvm-project.git 8e2cd28cd4ba46613a46467b0c91b1cabead26cd)) #1 SMP Tue Nov 18 17:58:23 MST 2025
  ...
  [    1.041311] KTAP version 1
  [    1.041433] 1..1
  [    1.042111]     KTAP version 1
  [    1.042310]     # Subtest: kprobes_riscv
  [    1.042610]     # module: kprobes_riscv_kunit
  [    1.042732]     1..1
  [    1.047104] ------------[ cut here ]------------
  [    1.047293] WARNING: CPU: 0 PID: 45 at mm/page_alloc.c:5159 __alloc_frozen_pages_noprof+0x160/0x228
  [    1.047602] Modules linked in:
  [    1.047851] CPU: 0 UID: 0 PID: 45 Comm: kunit_try_catch Tainted: G                 N  6.18.0-rc6-dirty #1 NONE
  [    1.047933] Tainted: [N]=TEST
  [    1.047948] Hardware name: riscv-virtio,qemu (DT)
  [    1.048024] epc : __alloc_frozen_pages_noprof+0x160/0x228
  [    1.048057]  ra : ___kmalloc_large_node+0x52/0x1a0
  [    1.048073] epc : ffffffff8023e2e8 ra : ffffffff80247c26 sp : ff200000001f3c10
  [    1.048086]  gp : ffffffff81a25900 tp : ff600000023924c0 t0 : 00000000264163d0
  [    1.048097]  t1 : 00000000264163d0 t2 : 00000000000aae60 s0 : ff200000001f3c90
  [    1.048108]  s1 : 000000000a83ca20 a0 : 0000000000000001 a1 : ffffffff819e71ba
  [    1.048119]  a2 : 0000000000000000 a3 : 0000000000000000 a4 : 000000003b9aca00
  [    1.048130]  a5 : 0000000000016698 a6 : ff600000021480d0 a7 : 00000000000aae60
  [    1.048140]  s2 : 0000000000000010 s3 : ffffffff8024857a s4 : 0000000000000dc0
  [    1.048151]  s5 : ffffffff80018e20 s6 : ff2000000000bb40 s7 : 0000000000000000
  [    1.048161]  s8 : 0000000000000000 s9 : 0000000000166e7c s10: 0000000000000000
  [    1.048171]  s11: 0000000000000000 t3 : 0000000000000000 t4 : 0000000000000002
  [    1.048181]  t5 : ff60000002392580 t6 : 0000000000000001
  [    1.048191] status: 0000000200000120 badaddr: ffffffff8023e2e8 cause: 0000000000000003
  [    1.048281] [<ffffffff8023e2e8>] __alloc_frozen_pages_noprof+0x160/0x228
  [    1.048362] [<ffffffff80247c26>] ___kmalloc_large_node+0x52/0x1a0
  [    1.048374] [<ffffffff80247dd8>] __kmalloc_large_node_noprof+0x1c/0x114
  [    1.048384] [<ffffffff8024857a>] __kmalloc_noprof+0x252/0x450
  [    1.048393] [<ffffffff80018ae6>] test_kprobe_riscv+0x5a/0x210
  [    1.048406] [<ffffffff8050d6a6>] kunit_try_run_case+0x5a/0x15c
  [    1.048417] [<ffffffff8050f69a>] kunit_generic_run_threadfn_adapter+0x1a/0x34
  [    1.048439] [<ffffffff8004fa88>] kthread+0x178/0x1a0
  [    1.048450] [<ffffffff8001311a>] ret_from_fork_kernel+0xe/0x48
  [    1.048464] [<ffffffff80b500f2>] ret_from_fork_kernel_asm+0x16/0x1c
  [    1.048513] ---[ end trace 0000000000000000 ]---
  [    1.056832]     # test_kprobe_riscv: EXPECTATION FAILED at arch/riscv/kernel/tests/kprobes/test-kprobes.c:24
  [    1.056832]     Expected kp to be true, but is false
  [    1.058370]     not ok 1 test_kprobe_riscv
  [    1.058484] not ok 1 kprobes_riscv
  ...

This appears to happen back to LLVM 15 so I am not sure it is a recent
recent regression on the toolchain side.

Without CONFIG_RELOCATABLE enabled, the test passes:

  [    1.049384] KTAP version 1
  [    1.049656] 1..1
  [    1.050246]     KTAP version 1
  [    1.050447]     # Subtest: kprobes_riscv
  [    1.050760]     # module: kprobes_riscv_kunit
  [    1.050867]     1..1
  [    1.061790]     ok 1 test_kprobe_riscv
  [    1.061929] ok 1 kprobes_riscv

Interestingly, if I enable CONFIG_RISCV_KPROBES_KUNIT as a module, I get
a failure when trying to load it in QEMU:

  ~ # modprobe kprobes_riscv_kunit
  [   42.214642] kprobes_riscv_kunit: The unexpected relocation type 'R_RISCV_ALIGN' from PC = 00000000abb84ce7
  [   42.222778] kprobes_riscv_kunit: The unexpected relocation type 'R_RISCV_ALIGN' from PC = 00000000abb84ce7
  modprobe: can't load module kprobes_riscv_kunit (kernel/arch/riscv/kernel/tests/kprobes/kprobes_riscv_kunit.ko): Invalid argument

which is probably unrelated but I figured it was worth mentioning, as it
does not allow me to see if this has something to do with the flags
added to LDFLAGS_vmlinux.

Maybe this is useful for the upstream report and further triage.

Cheers,
Nathan

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: Nathan Chancellor <nathan@kernel.org>
To: Paul Walmsley <pjw@kernel.org>, Jiakai Xu <xujiakai2025@iscas.ac.cn>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	namcao@linutronix.de
Subject: Re: Re: [PATCH] riscv: fix KUnit test_kprobes crash when building with Clang
Date: Tue, 18 Nov 2025 18:38:08 -0700	[thread overview]
Message-ID: <20251119013808.GA1264583@ax162> (raw)
In-Reply-To: <bd82855d-4a80-58fb-c949-b968569ef1e2@kernel.org>

Hi Paul and Jiakai,

On Tue, Nov 18, 2025 at 01:21:50PM -0700, Paul Walmsley wrote:
> 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.

I spent some time today trying to minimize a small set of configurations
that triggers this issue on top of defconfig since that occasionally
reveals a path to head down for triage and I landed on:

  $ cat arch/riscv/configs/repro.config
  CONFIG_KPROBES=y
  CONFIG_KUNIT=y
  CONFIG_RELOCATABLE=y
  CONFIG_RISCV_KPROBES_KUNIT=y

  $ make -skj"$(nproc)" ARCH=riscv LLVM=1 clean defconfig repro.config Image

  $ curl -LSs https://github.com/ClangBuiltLinux/boot-utils/releases/download/20241120-044434/riscv-rootfs.cpio.zst | zstd -d >rootfs.cpio

  $ qemu-system-riscv64 \
      -display none \
      -nodefaults \
      -bios default \
      -M virt \
      -append earlycon \
      -kernel arch/riscv/boot/Image \
      -initrd rootfs.cpio \
      -m 512m \
      -serial mon:stdio
  ...
  [    0.000000] Booting Linux on hartid 0
  [    0.000000] Linux version 6.18.0-rc6-dirty (nathan@ax162) (ClangBuiltLinux clang version 21.1.5 (https://github.com/llvm/llvm-project.git 8e2cd28cd4ba46613a46467b0c91b1cabead26cd), ClangBuiltLinux LLD 21.1.5 (https://github.com/llvm/llvm-project.git 8e2cd28cd4ba46613a46467b0c91b1cabead26cd)) #1 SMP Tue Nov 18 17:58:23 MST 2025
  ...
  [    1.041311] KTAP version 1
  [    1.041433] 1..1
  [    1.042111]     KTAP version 1
  [    1.042310]     # Subtest: kprobes_riscv
  [    1.042610]     # module: kprobes_riscv_kunit
  [    1.042732]     1..1
  [    1.047104] ------------[ cut here ]------------
  [    1.047293] WARNING: CPU: 0 PID: 45 at mm/page_alloc.c:5159 __alloc_frozen_pages_noprof+0x160/0x228
  [    1.047602] Modules linked in:
  [    1.047851] CPU: 0 UID: 0 PID: 45 Comm: kunit_try_catch Tainted: G                 N  6.18.0-rc6-dirty #1 NONE
  [    1.047933] Tainted: [N]=TEST
  [    1.047948] Hardware name: riscv-virtio,qemu (DT)
  [    1.048024] epc : __alloc_frozen_pages_noprof+0x160/0x228
  [    1.048057]  ra : ___kmalloc_large_node+0x52/0x1a0
  [    1.048073] epc : ffffffff8023e2e8 ra : ffffffff80247c26 sp : ff200000001f3c10
  [    1.048086]  gp : ffffffff81a25900 tp : ff600000023924c0 t0 : 00000000264163d0
  [    1.048097]  t1 : 00000000264163d0 t2 : 00000000000aae60 s0 : ff200000001f3c90
  [    1.048108]  s1 : 000000000a83ca20 a0 : 0000000000000001 a1 : ffffffff819e71ba
  [    1.048119]  a2 : 0000000000000000 a3 : 0000000000000000 a4 : 000000003b9aca00
  [    1.048130]  a5 : 0000000000016698 a6 : ff600000021480d0 a7 : 00000000000aae60
  [    1.048140]  s2 : 0000000000000010 s3 : ffffffff8024857a s4 : 0000000000000dc0
  [    1.048151]  s5 : ffffffff80018e20 s6 : ff2000000000bb40 s7 : 0000000000000000
  [    1.048161]  s8 : 0000000000000000 s9 : 0000000000166e7c s10: 0000000000000000
  [    1.048171]  s11: 0000000000000000 t3 : 0000000000000000 t4 : 0000000000000002
  [    1.048181]  t5 : ff60000002392580 t6 : 0000000000000001
  [    1.048191] status: 0000000200000120 badaddr: ffffffff8023e2e8 cause: 0000000000000003
  [    1.048281] [<ffffffff8023e2e8>] __alloc_frozen_pages_noprof+0x160/0x228
  [    1.048362] [<ffffffff80247c26>] ___kmalloc_large_node+0x52/0x1a0
  [    1.048374] [<ffffffff80247dd8>] __kmalloc_large_node_noprof+0x1c/0x114
  [    1.048384] [<ffffffff8024857a>] __kmalloc_noprof+0x252/0x450
  [    1.048393] [<ffffffff80018ae6>] test_kprobe_riscv+0x5a/0x210
  [    1.048406] [<ffffffff8050d6a6>] kunit_try_run_case+0x5a/0x15c
  [    1.048417] [<ffffffff8050f69a>] kunit_generic_run_threadfn_adapter+0x1a/0x34
  [    1.048439] [<ffffffff8004fa88>] kthread+0x178/0x1a0
  [    1.048450] [<ffffffff8001311a>] ret_from_fork_kernel+0xe/0x48
  [    1.048464] [<ffffffff80b500f2>] ret_from_fork_kernel_asm+0x16/0x1c
  [    1.048513] ---[ end trace 0000000000000000 ]---
  [    1.056832]     # test_kprobe_riscv: EXPECTATION FAILED at arch/riscv/kernel/tests/kprobes/test-kprobes.c:24
  [    1.056832]     Expected kp to be true, but is false
  [    1.058370]     not ok 1 test_kprobe_riscv
  [    1.058484] not ok 1 kprobes_riscv
  ...

This appears to happen back to LLVM 15 so I am not sure it is a recent
recent regression on the toolchain side.

Without CONFIG_RELOCATABLE enabled, the test passes:

  [    1.049384] KTAP version 1
  [    1.049656] 1..1
  [    1.050246]     KTAP version 1
  [    1.050447]     # Subtest: kprobes_riscv
  [    1.050760]     # module: kprobes_riscv_kunit
  [    1.050867]     1..1
  [    1.061790]     ok 1 test_kprobe_riscv
  [    1.061929] ok 1 kprobes_riscv

Interestingly, if I enable CONFIG_RISCV_KPROBES_KUNIT as a module, I get
a failure when trying to load it in QEMU:

  ~ # modprobe kprobes_riscv_kunit
  [   42.214642] kprobes_riscv_kunit: The unexpected relocation type 'R_RISCV_ALIGN' from PC = 00000000abb84ce7
  [   42.222778] kprobes_riscv_kunit: The unexpected relocation type 'R_RISCV_ALIGN' from PC = 00000000abb84ce7
  modprobe: can't load module kprobes_riscv_kunit (kernel/arch/riscv/kernel/tests/kprobes/kprobes_riscv_kunit.ko): Invalid argument

which is probably unrelated but I figured it was worth mentioning, as it
does not allow me to see if this has something to do with the flags
added to LDFLAGS_vmlinux.

Maybe this is useful for the upstream report and further triage.

Cheers,
Nathan

  reply	other threads:[~2025-11-19  1:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 10:51 [PATCH] riscv: fix KUnit test_kprobes crash when building with Clang 许佳凯
2025-11-13 10:51 ` 许佳凯
2025-11-16  5:15 ` Paul Walmsley
2025-11-16  5:15   ` Paul Walmsley
2025-11-17  3:03   ` Jiakai Xu
2025-11-17  3:03     ` Jiakai Xu
2025-11-18 20:21     ` Paul Walmsley
2025-11-18 20:21       ` Paul Walmsley
2025-11-19  1:38       ` Nathan Chancellor [this message]
2025-11-19  1:38         ` Nathan Chancellor
2025-11-19  3:33         ` Jiakai Xu
2025-11-19  3:33           ` Jiakai Xu
2025-11-19  3:01       ` Jiakai Xu
2025-11-19  3:01         ` Jiakai Xu
2025-11-22  1:10         ` Paul Walmsley
2025-11-22  1:10           ` Paul Walmsley
2025-12-26  3:31           ` Jiakai Xu
2025-12-26  3:31             ` Jiakai Xu
2025-11-18 21:10 ` patchwork-bot+linux-riscv
2025-11-18 21:10   ` patchwork-bot+linux-riscv
2025-11-26  9:23 ` Nam Cao
2025-11-26  9:23   ` Nam Cao
2025-11-26 18:08   ` Nam Cao
2025-11-26 18:08     ` Nam Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251119013808.GA1264583@ax162 \
    --to=nathan@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=namcao@linutronix.de \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=xujiakai2025@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.