All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: kprobes: Add test case for c.jal instruction simulation
@ 2026-06-27 11:50 ` Nam Cao
  0 siblings, 0 replies; 4+ messages in thread
From: Nam Cao @ 2026-06-27 11:50 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	linux-riscv, linux-kernel
  Cc: Nam Cao

Add test validating that kprobes correctly simulate the c.jal
instruction.

Signed-off-by: Nam Cao <namcao@linutronix.de>
---
the test fails without c.jal simulation patch:
https://lore.kernel.org/linux-riscv/20260627001939.3847-1-xiaofengmian@163.com/
---
 .../kernel/tests/kprobes/test-kprobes-asm.S   | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
index f16deee9e091..15e50934bbd7 100644
--- a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
+++ b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
@@ -179,6 +179,23 @@ test_kprobes_c_bnez_addr3:
 	ret
 SYM_FUNC_END(test_kprobes_c_bnez)
 
+#ifdef CONFIG_32BIT
+SYM_FUNC_START(test_kprobes_c_jal)
+	li a0, 0
+	mv a1, ra
+test_kprobes_c_jal_addr1:
+	c.jal 2f
+	ret
+1:	li a0, KPROBE_TEST_MAGIC_UPPER
+	ret
+test_kprobes_c_jal_addr2:
+2:	c.jal 1b
+	li a2, KPROBE_TEST_MAGIC_LOWER
+	add a0, a0, a2
+	jr a1
+SYM_FUNC_END(test_kprobes_c_jal)
+#endif
+
 #endif /* CONFIG_RISCV_ISA_C */
 
 .section .rodata
@@ -209,6 +226,10 @@ SYM_DATA_START(test_kprobes_addresses)
 	RISCV_PTR test_kprobes_c_bnez_addr1
 	RISCV_PTR test_kprobes_c_bnez_addr2
 	RISCV_PTR test_kprobes_c_bnez_addr3
+#ifdef CONFIG_32BIT
+	RISCV_PTR test_kprobes_c_jal_addr1
+	RISCV_PTR test_kprobes_c_jal_addr2
+#endif
 #endif /* CONFIG_RISCV_ISA_C */
 	RISCV_PTR 0
 SYM_DATA_END(test_kprobes_addresses)
@@ -226,6 +247,9 @@ SYM_DATA_START(test_kprobes_functions)
 	RISCV_PTR test_kprobes_c_jalr
 	RISCV_PTR test_kprobes_c_beqz
 	RISCV_PTR test_kprobes_c_bnez
+#ifdef CONFIG_32BIT
+	RISCV_PTR test_kprobes_c_jal
+#endif
 #endif /* CONFIG_RISCV_ISA_C */
 	RISCV_PTR 0
 SYM_DATA_END(test_kprobes_functions)
-- 
2.47.3


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

* [PATCH] riscv: kprobes: Add test case for c.jal instruction simulation
@ 2026-06-27 11:50 ` Nam Cao
  0 siblings, 0 replies; 4+ messages in thread
From: Nam Cao @ 2026-06-27 11:50 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	linux-riscv, linux-kernel
  Cc: Nam Cao

Add test validating that kprobes correctly simulate the c.jal
instruction.

Signed-off-by: Nam Cao <namcao@linutronix.de>
---
the test fails without c.jal simulation patch:
https://lore.kernel.org/linux-riscv/20260627001939.3847-1-xiaofengmian@163.com/
---
 .../kernel/tests/kprobes/test-kprobes-asm.S   | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
index f16deee9e091..15e50934bbd7 100644
--- a/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
+++ b/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S
@@ -179,6 +179,23 @@ test_kprobes_c_bnez_addr3:
 	ret
 SYM_FUNC_END(test_kprobes_c_bnez)
 
+#ifdef CONFIG_32BIT
+SYM_FUNC_START(test_kprobes_c_jal)
+	li a0, 0
+	mv a1, ra
+test_kprobes_c_jal_addr1:
+	c.jal 2f
+	ret
+1:	li a0, KPROBE_TEST_MAGIC_UPPER
+	ret
+test_kprobes_c_jal_addr2:
+2:	c.jal 1b
+	li a2, KPROBE_TEST_MAGIC_LOWER
+	add a0, a0, a2
+	jr a1
+SYM_FUNC_END(test_kprobes_c_jal)
+#endif
+
 #endif /* CONFIG_RISCV_ISA_C */
 
 .section .rodata
@@ -209,6 +226,10 @@ SYM_DATA_START(test_kprobes_addresses)
 	RISCV_PTR test_kprobes_c_bnez_addr1
 	RISCV_PTR test_kprobes_c_bnez_addr2
 	RISCV_PTR test_kprobes_c_bnez_addr3
+#ifdef CONFIG_32BIT
+	RISCV_PTR test_kprobes_c_jal_addr1
+	RISCV_PTR test_kprobes_c_jal_addr2
+#endif
 #endif /* CONFIG_RISCV_ISA_C */
 	RISCV_PTR 0
 SYM_DATA_END(test_kprobes_addresses)
@@ -226,6 +247,9 @@ SYM_DATA_START(test_kprobes_functions)
 	RISCV_PTR test_kprobes_c_jalr
 	RISCV_PTR test_kprobes_c_beqz
 	RISCV_PTR test_kprobes_c_bnez
+#ifdef CONFIG_32BIT
+	RISCV_PTR test_kprobes_c_jal
+#endif
 #endif /* CONFIG_RISCV_ISA_C */
 	RISCV_PTR 0
 SYM_DATA_END(test_kprobes_functions)
-- 
2.47.3


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

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

* Re: [PATCH] riscv: kprobes: Add test case for c.jal instruction simulation
  2026-06-27 11:50 ` Nam Cao
  (?)
@ 2026-06-27 12:58 ` Xiaofeng Yuan
  2026-06-27 13:25   ` Nam Cao
  -1 siblings, 1 reply; 4+ messages in thread
From: Xiaofeng Yuan @ 2026-06-27 12:58 UTC (permalink / raw)
  To: namcao; +Cc: charlie, linux-riscv

Hi Nam,

Thanks for the test case. Since c.jal is RV32-only, I haven't been able
to run it on real hardware. I tried running the full kprobes KUNIT test
suite under QEMU riscv32, but the test appears to hang before
completing -- even without the c.jal test case included.

I suspect this may be a QEMU emulation speed issue or a pre-existing
limitation of the test framework in an emulated environment.

Did you run this test on real hardware or in QEMU? If QEMU, any tips
on how to get it to complete?

Best regards,
Xiaofeng


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

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

* Re: [PATCH] riscv: kprobes: Add test case for c.jal instruction simulation
  2026-06-27 12:58 ` Xiaofeng Yuan
@ 2026-06-27 13:25   ` Nam Cao
  0 siblings, 0 replies; 4+ messages in thread
From: Nam Cao @ 2026-06-27 13:25 UTC (permalink / raw)
  To: Xiaofeng Yuan; +Cc: charlie, linux-riscv

Xiaofeng Yuan <xiaofengmian@163.com> writes:
> Thanks for the test case. Since c.jal is RV32-only, I haven't been able
> to run it on real hardware. I tried running the full kprobes KUNIT test
> suite under QEMU riscv32, but the test appears to hang before
> completing -- even without the c.jal test case included.

That is not supposed to happen.

> I suspect this may be a QEMU emulation speed issue or a pre-existing
> limitation of the test framework in an emulated environment.
>
> Did you run this test on real hardware or in QEMU? If QEMU, any tips
> on how to get it to complete?

I mostly run on QEMU, but I did run on real hardware a few times. I
never observed a problem.

If you want me to look into it, please share your qemu command and
kernel config file.

Nam

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

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

end of thread, other threads:[~2026-06-27 13:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-27 11:50 [PATCH] riscv: kprobes: Add test case for c.jal instruction simulation Nam Cao
2026-06-27 11:50 ` Nam Cao
2026-06-27 12:58 ` Xiaofeng Yuan
2026-06-27 13:25   ` Nam Cao

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.