[PATCH v6 2/2] riscv: kprobes: add test case for c.jal instruction simulation

Charlie Jenkins thecharlesjenkins at gmail.com
Thu Jul 9 00:19:40 PDT 2026


# Add your code comments below. There is no need to trim or delete
# any existing content -- just insert your comments under the relevant
# lines of code. Lines starting with "> " are quoted diff context and
# lines starting with "| " are comments from other reviewers.
# The final email will be reformatted automatically to include only
# the sections that have your comments.
#
> Add a test case validating that kprobes correctly simulates the
> c.jal instruction on RV32.
> 
> The test uses two probe points: a forward c.jal and a backward
> c.jal, and verifies that the containing function returns the
> expected magic value KPROBE_TEST_MAGIC after kprobe interception.
> 
> Co-developed-by: Xiaofeng Yuan <xiaofengmian at 163.com>
> Signed-off-by: Nam Cao <namcao at linutronix.de>
> Signed-off-by: Xiaofeng Yuan <xiaofengmian at 163.com>


>
> 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)

Reviewed-by: Charlie Jenkins <thecharlesjenkins at gmail.com>
Tested-by: Charlie Jenkins <thecharlesjenkins at gmail.com>

-- 
- Charlie




More information about the linux-riscv mailing list