Skip to content

Commit 670721c

Browse files
KAGA-KOKOPeter Zijlstra
authored andcommitted
sched: Move kprobes cleanup out of finish_task_switch()
Doing cleanups in the tail of schedule() is a latency punishment for the incoming task. The point of invoking kprobes_task_flush() for a dead task is that the instances are returned and cannot leak when __schedule() is kprobed. Move it into the delayed cleanup. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 539fbb5 commit 670721c

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

kernel/exit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include <linux/rcuwait.h>
6565
#include <linux/compat.h>
6666
#include <linux/io_uring.h>
67+
#include <linux/kprobes.h>
6768

6869
#include <linux/uaccess.h>
6970
#include <asm/unistd.h>
@@ -168,6 +169,7 @@ static void delayed_put_task_struct(struct rcu_head *rhp)
168169
{
169170
struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
170171

172+
kprobe_flush_task(tsk);
171173
perf_event_delayed_put(tsk);
172174
trace_sched_process_free(tsk);
173175
put_task_struct(tsk);

kernel/kprobes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,10 +1250,10 @@ void kprobe_busy_end(void)
12501250
}
12511251

12521252
/*
1253-
* This function is called from finish_task_switch when task tk becomes dead,
1254-
* so that we can recycle any function-return probe instances associated
1255-
* with this task. These left over instances represent probed functions
1256-
* that have been called but will never return.
1253+
* This function is called from delayed_put_task_struct() when a task is
1254+
* dead and cleaned up to recycle any function-return probe instances
1255+
* associated with this task. These left over instances represent probed
1256+
* functions that have been called but will never return.
12571257
*/
12581258
void kprobe_flush_task(struct task_struct *tk)
12591259
{

kernel/sched/core.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,12 +4846,6 @@ static struct rq *finish_task_switch(struct task_struct *prev)
48464846
if (prev->sched_class->task_dead)
48474847
prev->sched_class->task_dead(prev);
48484848

4849-
/*
4850-
* Remove function-return probe instances associated with this
4851-
* task and put them back on the free list.
4852-
*/
4853-
kprobe_flush_task(prev);
4854-
48554849
/* Task is done with its stack. */
48564850
put_task_stack(prev);
48574851

0 commit comments

Comments
 (0)