* @kr_cur:      When KRETPROBES is selected, holds the kretprobe instance
  *               associated with the most recently encountered replacement lr
  *               value.
+ *
+ * @task:        The task being unwound.
  */
 struct unwind_state {
        unsigned long fp;
 #ifdef CONFIG_KRETPROBES
        struct llist_node *kr_cur;
 #endif
+       struct task_struct *task;
 };
 
-static void unwind_init_common(struct unwind_state *state)
+static void unwind_init_common(struct unwind_state *state,
+                              struct task_struct *task)
 {
+       state->task = task;
 #ifdef CONFIG_KRETPROBES
        state->kr_cur = NULL;
 #endif
 static inline void unwind_init_from_regs(struct unwind_state *state,
                                         struct pt_regs *regs)
 {
-       unwind_init_common(state);
+       unwind_init_common(state, current);
 
        state->fp = regs->regs[29];
        state->pc = regs->pc;
  */
 static __always_inline void unwind_init_from_caller(struct unwind_state *state)
 {
-       unwind_init_common(state);
+       unwind_init_common(state, current);
 
        state->fp = (unsigned long)__builtin_frame_address(1);
        state->pc = (unsigned long)__builtin_return_address(0);
 static inline void unwind_init_from_task(struct unwind_state *state,
                                         struct task_struct *task)
 {
-       unwind_init_common(state);
+       unwind_init_common(state, task);
 
        state->fp = thread_saved_fp(task);
        state->pc = thread_saved_pc(task);
  * records (e.g. a cycle), determined based on the location and fp value of A
  * and the location (but not the fp value) of B.
  */
-static int notrace unwind_next(struct task_struct *tsk,
-                              struct unwind_state *state)
+static int notrace unwind_next(struct unwind_state *state)
 {
+       struct task_struct *tsk = state->task;
        unsigned long fp = state->fp;
        struct stack_info info;
 
 }
 NOKPROBE_SYMBOL(unwind_next);
 
-static void notrace unwind(struct task_struct *tsk,
-                          struct unwind_state *state,
+static void notrace unwind(struct unwind_state *state,
                           stack_trace_consume_fn consume_entry, void *cookie)
 {
        while (1) {
 
                if (!consume_entry(cookie, state->pc))
                        break;
-               ret = unwind_next(tsk, state);
+               ret = unwind_next(state);
                if (ret < 0)
                        break;
        }
 {
        struct unwind_state state;
 
-       if (regs)
+       if (regs) {
+               if (task != current)
+                       return;
                unwind_init_from_regs(&state, regs);
-       else if (task == current)
+       } else if (task == current) {
                unwind_init_from_caller(&state);
-       else
+       } else {
                unwind_init_from_task(&state, task);
+       }
 
-       unwind(task, &state, consume_entry, cookie);
+       unwind(&state, consume_entry, cookie);
 }