Skip to content

Commit 629291d

Browse files
Song Shuaipalmer-dabbelt
authored andcommitted
samples: ftrace: Add RISC-V support for SAMPLE_FTRACE_DIRECT[_MULTI]
Add RISC-V variants of the ftrace-direct* samples. Tested-by: Evgenii Shatokhin <e.shatokhin@yadro.com> Signed-off-by: Song Shuai <suagrfillet@gmail.com> Tested-by: Guo Ren <guoren@kernel.org> Signed-off-by: Guo Ren <guoren@kernel.org> Acked-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20231130121531.1178502-5-bjorn@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 196c79f commit 629291d

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed

arch/riscv/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ config RISCV
142142
select HAVE_REGS_AND_STACK_ACCESS_API
143143
select HAVE_RETHOOK if !XIP_KERNEL
144144
select HAVE_RSEQ
145+
select HAVE_SAMPLE_FTRACE_DIRECT
146+
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
145147
select HAVE_STACKPROTECTOR
146148
select HAVE_SYSCALL_TRACEPOINTS
147149
select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU

samples/ftrace/ftrace-direct-modify.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,41 @@ extern void my_tramp2(void *);
2424

2525
static unsigned long my_ip = (unsigned long)schedule;
2626

27+
#ifdef CONFIG_RISCV
28+
#include <asm/asm.h>
29+
30+
asm (
31+
" .pushsection .text, \"ax\", @progbits\n"
32+
" .type my_tramp1, @function\n"
33+
" .globl my_tramp1\n"
34+
" my_tramp1:\n"
35+
" addi sp,sp,-2*"SZREG"\n"
36+
" "REG_S" t0,0*"SZREG"(sp)\n"
37+
" "REG_S" ra,1*"SZREG"(sp)\n"
38+
" call my_direct_func1\n"
39+
" "REG_L" t0,0*"SZREG"(sp)\n"
40+
" "REG_L" ra,1*"SZREG"(sp)\n"
41+
" addi sp,sp,2*"SZREG"\n"
42+
" jr t0\n"
43+
" .size my_tramp1, .-my_tramp1\n"
44+
" .type my_tramp2, @function\n"
45+
" .globl my_tramp2\n"
46+
47+
" my_tramp2:\n"
48+
" addi sp,sp,-2*"SZREG"\n"
49+
" "REG_S" t0,0*"SZREG"(sp)\n"
50+
" "REG_S" ra,1*"SZREG"(sp)\n"
51+
" call my_direct_func2\n"
52+
" "REG_L" t0,0*"SZREG"(sp)\n"
53+
" "REG_L" ra,1*"SZREG"(sp)\n"
54+
" addi sp,sp,2*"SZREG"\n"
55+
" jr t0\n"
56+
" .size my_tramp2, .-my_tramp2\n"
57+
" .popsection\n"
58+
);
59+
60+
#endif /* CONFIG_RISCV */
61+
2762
#ifdef CONFIG_X86_64
2863

2964
#include <asm/ibt.h>

samples/ftrace/ftrace-direct-multi-modify.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,47 @@ void my_direct_func2(unsigned long ip)
2222
extern void my_tramp1(void *);
2323
extern void my_tramp2(void *);
2424

25+
#ifdef CONFIG_RISCV
26+
#include <asm/asm.h>
27+
28+
asm (
29+
" .pushsection .text, \"ax\", @progbits\n"
30+
" .type my_tramp1, @function\n"
31+
" .globl my_tramp1\n"
32+
" my_tramp1:\n"
33+
" addi sp,sp,-3*"SZREG"\n"
34+
" "REG_S" a0,0*"SZREG"(sp)\n"
35+
" "REG_S" t0,1*"SZREG"(sp)\n"
36+
" "REG_S" ra,2*"SZREG"(sp)\n"
37+
" mv a0,t0\n"
38+
" call my_direct_func1\n"
39+
" "REG_L" a0,0*"SZREG"(sp)\n"
40+
" "REG_L" t0,1*"SZREG"(sp)\n"
41+
" "REG_L" ra,2*"SZREG"(sp)\n"
42+
" addi sp,sp,3*"SZREG"\n"
43+
" jr t0\n"
44+
" .size my_tramp1, .-my_tramp1\n"
45+
46+
" .type my_tramp2, @function\n"
47+
" .globl my_tramp2\n"
48+
" my_tramp2:\n"
49+
" addi sp,sp,-3*"SZREG"\n"
50+
" "REG_S" a0,0*"SZREG"(sp)\n"
51+
" "REG_S" t0,1*"SZREG"(sp)\n"
52+
" "REG_S" ra,2*"SZREG"(sp)\n"
53+
" mv a0,t0\n"
54+
" call my_direct_func2\n"
55+
" "REG_L" a0,0*"SZREG"(sp)\n"
56+
" "REG_L" t0,1*"SZREG"(sp)\n"
57+
" "REG_L" ra,2*"SZREG"(sp)\n"
58+
" addi sp,sp,3*"SZREG"\n"
59+
" jr t0\n"
60+
" .size my_tramp2, .-my_tramp2\n"
61+
" .popsection\n"
62+
);
63+
64+
#endif /* CONFIG_RISCV */
65+
2566
#ifdef CONFIG_X86_64
2667

2768
#include <asm/ibt.h>

samples/ftrace/ftrace-direct-multi.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ void my_direct_func(unsigned long ip)
1717

1818
extern void my_tramp(void *);
1919

20+
#ifdef CONFIG_RISCV
21+
#include <asm/asm.h>
22+
23+
asm (
24+
" .pushsection .text, \"ax\", @progbits\n"
25+
" .type my_tramp, @function\n"
26+
" .globl my_tramp\n"
27+
" my_tramp:\n"
28+
" addi sp,sp,-3*"SZREG"\n"
29+
" "REG_S" a0,0*"SZREG"(sp)\n"
30+
" "REG_S" t0,1*"SZREG"(sp)\n"
31+
" "REG_S" ra,2*"SZREG"(sp)\n"
32+
" mv a0,t0\n"
33+
" call my_direct_func\n"
34+
" "REG_L" a0,0*"SZREG"(sp)\n"
35+
" "REG_L" t0,1*"SZREG"(sp)\n"
36+
" "REG_L" ra,2*"SZREG"(sp)\n"
37+
" addi sp,sp,3*"SZREG"\n"
38+
" jr t0\n"
39+
" .size my_tramp, .-my_tramp\n"
40+
" .popsection\n"
41+
);
42+
43+
#endif /* CONFIG_RISCV */
44+
2045
#ifdef CONFIG_X86_64
2146

2247
#include <asm/ibt.h>

samples/ftrace/ftrace-direct-too.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ void my_direct_func(struct vm_area_struct *vma, unsigned long address,
1919

2020
extern void my_tramp(void *);
2121

22+
#ifdef CONFIG_RISCV
23+
#include <asm/asm.h>
24+
25+
asm (
26+
" .pushsection .text, \"ax\", @progbits\n"
27+
" .type my_tramp, @function\n"
28+
" .globl my_tramp\n"
29+
" my_tramp:\n"
30+
" addi sp,sp,-5*"SZREG"\n"
31+
" "REG_S" a0,0*"SZREG"(sp)\n"
32+
" "REG_S" a1,1*"SZREG"(sp)\n"
33+
" "REG_S" a2,2*"SZREG"(sp)\n"
34+
" "REG_S" t0,3*"SZREG"(sp)\n"
35+
" "REG_S" ra,4*"SZREG"(sp)\n"
36+
" call my_direct_func\n"
37+
" "REG_L" a0,0*"SZREG"(sp)\n"
38+
" "REG_L" a1,1*"SZREG"(sp)\n"
39+
" "REG_L" a2,2*"SZREG"(sp)\n"
40+
" "REG_L" t0,3*"SZREG"(sp)\n"
41+
" "REG_L" ra,4*"SZREG"(sp)\n"
42+
" addi sp,sp,5*"SZREG"\n"
43+
" jr t0\n"
44+
" .size my_tramp, .-my_tramp\n"
45+
" .popsection\n"
46+
);
47+
48+
#endif /* CONFIG_RISCV */
49+
2250
#ifdef CONFIG_X86_64
2351

2452
#include <asm/ibt.h>

samples/ftrace/ftrace-direct.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ void my_direct_func(struct task_struct *p)
1616

1717
extern void my_tramp(void *);
1818

19+
#ifdef CONFIG_RISCV
20+
#include <asm/asm.h>
21+
22+
asm (
23+
" .pushsection .text, \"ax\", @progbits\n"
24+
" .type my_tramp, @function\n"
25+
" .globl my_tramp\n"
26+
" my_tramp:\n"
27+
" addi sp,sp,-3*"SZREG"\n"
28+
" "REG_S" a0,0*"SZREG"(sp)\n"
29+
" "REG_S" t0,1*"SZREG"(sp)\n"
30+
" "REG_S" ra,2*"SZREG"(sp)\n"
31+
" call my_direct_func\n"
32+
" "REG_L" a0,0*"SZREG"(sp)\n"
33+
" "REG_L" t0,1*"SZREG"(sp)\n"
34+
" "REG_L" ra,2*"SZREG"(sp)\n"
35+
" addi sp,sp,3*"SZREG"\n"
36+
" jr t0\n"
37+
" .size my_tramp, .-my_tramp\n"
38+
" .popsection\n"
39+
);
40+
41+
#endif /* CONFIG_RISCV */
42+
1943
#ifdef CONFIG_X86_64
2044

2145
#include <asm/ibt.h>

0 commit comments

Comments
 (0)