Commit 670721c7 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Peter Zijlstra

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: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210928122411.537994026@linutronix.de
parent 539fbb5b
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include <linux/rcuwait.h> #include <linux/rcuwait.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <linux/io_uring.h> #include <linux/io_uring.h>
#include <linux/kprobes.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <asm/unistd.h> #include <asm/unistd.h>
...@@ -168,6 +169,7 @@ static void delayed_put_task_struct(struct rcu_head *rhp) ...@@ -168,6 +169,7 @@ static void delayed_put_task_struct(struct rcu_head *rhp)
{ {
struct task_struct *tsk = container_of(rhp, struct task_struct, rcu); struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
kprobe_flush_task(tsk);
perf_event_delayed_put(tsk); perf_event_delayed_put(tsk);
trace_sched_process_free(tsk); trace_sched_process_free(tsk);
put_task_struct(tsk); put_task_struct(tsk);
......
...@@ -1250,10 +1250,10 @@ void kprobe_busy_end(void) ...@@ -1250,10 +1250,10 @@ void kprobe_busy_end(void)
} }
/* /*
* This function is called from finish_task_switch when task tk becomes dead, * This function is called from delayed_put_task_struct() when a task is
* so that we can recycle any function-return probe instances associated * dead and cleaned up to recycle any function-return probe instances
* with this task. These left over instances represent probed functions * associated with this task. These left over instances represent probed
* that have been called but will never return. * functions that have been called but will never return.
*/ */
void kprobe_flush_task(struct task_struct *tk) void kprobe_flush_task(struct task_struct *tk)
{ {
......
...@@ -4846,12 +4846,6 @@ static struct rq *finish_task_switch(struct task_struct *prev) ...@@ -4846,12 +4846,6 @@ static struct rq *finish_task_switch(struct task_struct *prev)
if (prev->sched_class->task_dead) if (prev->sched_class->task_dead)
prev->sched_class->task_dead(prev); prev->sched_class->task_dead(prev);
/*
* Remove function-return probe instances associated with this
* task and put them back on the free list.
*/
kprobe_flush_task(prev);
/* Task is done with its stack. */ /* Task is done with its stack. */
put_task_stack(prev); put_task_stack(prev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment