Skip to content

Commit bb85d20

Browse files
Chenghao Duanchenhuacai
authored andcommitted
samples/ftrace: Adjust LoongArch register restore order in direct calls
Ensure that in the ftrace direct call logic, the CPU register state (with ra = parent return address) is restored to the correct state after the execution of the custom trampoline function and before returning to the traced function. Additionally, guarantee the correctness of the jump logic for jr t0 (traced function address). Cc: stable@vger.kernel.org Fixes: 9cdc3b6 ("LoongArch: ftrace: Add direct call support") Reported-by: Youling Tang <tangyouling@kylinos.cn> Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Chenghao Duan <duanchenghao@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 73721d8 commit bb85d20

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

samples/ftrace/ftrace-direct-modify.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ asm (
176176
" st.d $t0, $sp, 0\n"
177177
" st.d $ra, $sp, 8\n"
178178
" bl my_direct_func1\n"
179-
" ld.d $t0, $sp, 0\n"
180-
" ld.d $ra, $sp, 8\n"
179+
" ld.d $ra, $sp, 0\n"
180+
" ld.d $t0, $sp, 8\n"
181181
" addi.d $sp, $sp, 16\n"
182182
" jr $t0\n"
183183
" .size my_tramp1, .-my_tramp1\n"
@@ -189,8 +189,8 @@ asm (
189189
" st.d $t0, $sp, 0\n"
190190
" st.d $ra, $sp, 8\n"
191191
" bl my_direct_func2\n"
192-
" ld.d $t0, $sp, 0\n"
193-
" ld.d $ra, $sp, 8\n"
192+
" ld.d $ra, $sp, 0\n"
193+
" ld.d $t0, $sp, 8\n"
194194
" addi.d $sp, $sp, 16\n"
195195
" jr $t0\n"
196196
" .size my_tramp2, .-my_tramp2\n"

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ asm (
199199
" move $a0, $t0\n"
200200
" bl my_direct_func1\n"
201201
" ld.d $a0, $sp, 0\n"
202-
" ld.d $t0, $sp, 8\n"
203-
" ld.d $ra, $sp, 16\n"
202+
" ld.d $ra, $sp, 8\n"
203+
" ld.d $t0, $sp, 16\n"
204204
" addi.d $sp, $sp, 32\n"
205205
" jr $t0\n"
206206
" .size my_tramp1, .-my_tramp1\n"
@@ -215,8 +215,8 @@ asm (
215215
" move $a0, $t0\n"
216216
" bl my_direct_func2\n"
217217
" ld.d $a0, $sp, 0\n"
218-
" ld.d $t0, $sp, 8\n"
219-
" ld.d $ra, $sp, 16\n"
218+
" ld.d $ra, $sp, 8\n"
219+
" ld.d $t0, $sp, 16\n"
220220
" addi.d $sp, $sp, 32\n"
221221
" jr $t0\n"
222222
" .size my_tramp2, .-my_tramp2\n"

samples/ftrace/ftrace-direct-multi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ asm (
131131
" move $a0, $t0\n"
132132
" bl my_direct_func\n"
133133
" ld.d $a0, $sp, 0\n"
134-
" ld.d $t0, $sp, 8\n"
135-
" ld.d $ra, $sp, 16\n"
134+
" ld.d $ra, $sp, 8\n"
135+
" ld.d $t0, $sp, 16\n"
136136
" addi.d $sp, $sp, 32\n"
137137
" jr $t0\n"
138138
" .size my_tramp, .-my_tramp\n"

samples/ftrace/ftrace-direct-too.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ asm (
143143
" ld.d $a0, $sp, 0\n"
144144
" ld.d $a1, $sp, 8\n"
145145
" ld.d $a2, $sp, 16\n"
146-
" ld.d $t0, $sp, 24\n"
147-
" ld.d $ra, $sp, 32\n"
146+
" ld.d $ra, $sp, 24\n"
147+
" ld.d $t0, $sp, 32\n"
148148
" addi.d $sp, $sp, 48\n"
149149
" jr $t0\n"
150150
" .size my_tramp, .-my_tramp\n"

samples/ftrace/ftrace-direct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ asm (
124124
" st.d $ra, $sp, 16\n"
125125
" bl my_direct_func\n"
126126
" ld.d $a0, $sp, 0\n"
127-
" ld.d $t0, $sp, 8\n"
128-
" ld.d $ra, $sp, 16\n"
127+
" ld.d $ra, $sp, 8\n"
128+
" ld.d $t0, $sp, 16\n"
129129
" addi.d $sp, $sp, 32\n"
130130
" jr $t0\n"
131131
" .size my_tramp, .-my_tramp\n"

0 commit comments

Comments
 (0)