Skip to content

Commit 45cb47c

Browse files
Chenghao Duanchenhuacai
authored andcommitted
LoongArch: Refactor register restoration in ftrace_common_return
Refactor the register restoration sequence in the ftrace_common_return function to clearly distinguish between the logic of normal returns and direct call returns in function tracing scenarios. The logic is as follows: 1. In the case of a normal return, the execution flow returns to the traced function, and ftrace must ensure that the register data is consistent with the state when the function was entered. ra = parent return address; t0 = traced function return address. 2. In the case of a direct call return, the execution flow jumps to the custom trampoline function, and ftrace must ensure that the register data is consistent with the state when ftrace was entered. ra = traced function return address; t0 = parent return address. Cc: stable@vger.kernel.org Fixes: 9cdc3b6 ("LoongArch: ftrace: Add direct call support") Signed-off-by: Chenghao Duan <duanchenghao@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 9bdc1ab commit 45cb47c

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

arch/loongarch/kernel/mcount_dyn.S

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL)
9494
* at the callsite, so there is no need to restore the T series regs.
9595
*/
9696
ftrace_common_return:
97-
PTR_L ra, sp, PT_R1
9897
PTR_L a0, sp, PT_R4
9998
PTR_L a1, sp, PT_R5
10099
PTR_L a2, sp, PT_R6
@@ -104,12 +103,17 @@ ftrace_common_return:
104103
PTR_L a6, sp, PT_R10
105104
PTR_L a7, sp, PT_R11
106105
PTR_L fp, sp, PT_R22
107-
PTR_L t0, sp, PT_ERA
108106
PTR_L t1, sp, PT_R13
109-
PTR_ADDI sp, sp, PT_SIZE
110107
bnez t1, .Ldirect
108+
109+
PTR_L ra, sp, PT_R1
110+
PTR_L t0, sp, PT_ERA
111+
PTR_ADDI sp, sp, PT_SIZE
111112
jr t0
112113
.Ldirect:
114+
PTR_L t0, sp, PT_R1
115+
PTR_L ra, sp, PT_ERA
116+
PTR_ADDI sp, sp, PT_SIZE
113117
jr t1
114118
SYM_CODE_END(ftrace_common)
115119

@@ -161,6 +165,8 @@ SYM_CODE_END(return_to_handler)
161165
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
162166
SYM_CODE_START(ftrace_stub_direct_tramp)
163167
UNWIND_HINT_UNDEFINED
164-
jr t0
168+
move t1, ra
169+
move ra, t0
170+
jr t1
165171
SYM_CODE_END(ftrace_stub_direct_tramp)
166172
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */

0 commit comments

Comments
 (0)