1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390_UNWIND_H
3 #define _ASM_S390_UNWIND_H
5 #include <linux/sched.h>
6 #include <linux/ftrace.h>
7 #include <linux/rethook.h>
8 #include <linux/llist.h>
9 #include <asm/ptrace.h>
10 #include <asm/stacktrace.h>
13 * To use the stack unwinder it has to be initialized with unwind_start.
14 * There four combinations for task and regs:
15 * 1) task==NULL, regs==NULL: the unwind starts for the task that is currently
16 * running, sp/ip picked up from the CPU registers
17 * 2) task==NULL, regs!=NULL: the unwind starts from the sp/ip found in
18 * the struct pt_regs of an interrupt frame for the current task
19 * 3) task!=NULL, regs==NULL: the unwind starts for an inactive task with
20 * the sp picked up from task->thread.ksp and the ip picked up from the
21 * return address stored by __switch_to
22 * 4) task!=NULL, regs!=NULL: the sp/ip are picked up from the interrupt
23 * frame 'regs' of a inactive task
24 * If 'first_frame' is not zero unwind_start skips unwind frames until it
25 * reaches the specified stack pointer.
26 * The end of the unwinding is indicated with unwind_done, this can be true
27 * right after unwind_start, e.g. with first_frame!=0 that can not be found.
28 * unwind_next_frame skips to the next frame.
29 * Once the unwind is completed unwind_error() can be used to check if there
30 * has been a situation where the unwinder could not correctly understand
31 * the tasks call chain.
35 struct stack_info stack_info;
36 unsigned long stack_mask;
37 struct task_struct *task;
41 struct llist_node *kr_cur;
46 /* Recover the return address modified by rethook and ftrace_graph. */
47 static inline unsigned long unwind_recover_ret_addr(struct unwind_state *state,
50 ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, ip, (void *)state->sp);
52 if (is_rethook_trampoline(ip))
53 ip = rethook_find_ret_addr(state->task, state->sp, &state->kr_cur);
58 void __unwind_start(struct unwind_state *state, struct task_struct *task,
59 struct pt_regs *regs, unsigned long first_frame);
60 bool unwind_next_frame(struct unwind_state *state);
61 unsigned long unwind_get_return_address(struct unwind_state *state);
63 static inline bool unwind_done(struct unwind_state *state)
65 return state->stack_info.type == STACK_TYPE_UNKNOWN;
68 static inline bool unwind_error(struct unwind_state *state)
73 static __always_inline void unwind_start(struct unwind_state *state,
74 struct task_struct *task,
76 unsigned long first_frame)
78 task = task ?: current;
79 first_frame = first_frame ?: get_stack_pointer(task, regs);
80 __unwind_start(state, task, regs, first_frame);
83 static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
85 return unwind_done(state) ? NULL : state->regs;
88 #define unwind_for_each_frame(state, task, regs, first_frame) \
89 for (unwind_start(state, task, regs, first_frame); \
90 !unwind_done(state); \
91 unwind_next_frame(state))
93 static inline void unwind_init(void) {}
94 static inline void unwind_module_init(struct module *mod, void *orc_ip,
95 size_t orc_ip_size, void *orc,
98 #endif /* _ASM_S390_UNWIND_H */