]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
sched: Move kprobes cleanup out of finish_task_switch()
authorThomas Gleixner <tglx@linutronix.de>
Tue, 28 Sep 2021 12:24:28 +0000 (14:24 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 5 Oct 2021 13:52:14 +0000 (15:52 +0200)
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 <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210928122411.537994026@linutronix.de
kernel/exit.c
kernel/kprobes.c
kernel/sched/core.c

index 91a43e57a32ebbf155287f580094e3c0f66e1188..63851320ae734f2f8941fee0db3b913e83283c22 100644 (file)
@@ -64,6 +64,7 @@
 #include <linux/rcuwait.h>
 #include <linux/compat.h>
 #include <linux/io_uring.h>
+#include <linux/kprobes.h>
 
 #include <linux/uaccess.h>
 #include <asm/unistd.h>
@@ -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);
 
+       kprobe_flush_task(tsk);
        perf_event_delayed_put(tsk);
        trace_sched_process_free(tsk);
        put_task_struct(tsk);
index 790a573bbe00c6f6b2afd27dc8fac862d222ec9b..9a38e7581a5ce53ed0080b6053cb3c68b9367891 100644 (file)
@@ -1250,10 +1250,10 @@ void kprobe_busy_end(void)
 }
 
 /*
- * This function is called from finish_task_switch when task tk becomes dead,
- * so that we can recycle any function-return probe instances associated
- * with this task. These left over instances represent probed functions
- * that have been called but will never return.
+ * This function is called from delayed_put_task_struct() when a task is
+ * dead and cleaned up to recycle any function-return probe instances
+ * associated with this task. These left over instances represent probed
+ * functions that have been called but will never return.
  */
 void kprobe_flush_task(struct task_struct *tk)
 {
index 749284fc3c1fc2af469653c18a29bd80946e1228..e33b03c2bb9a83cca553c97f05ad006826f2f87d 100644 (file)
@@ -4846,12 +4846,6 @@ static struct rq *finish_task_switch(struct task_struct *prev)
                if (prev->sched_class->task_dead)
                        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. */
                put_task_stack(prev);