blob: 1ab798d5b60a922707fb6a8deb8d69308633258f [file] [log] [blame]
From 8b328b2ae781885843e697cc191c923dbabebf7f Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Mon, 21 Nov 2016 19:31:08 +0100
Subject: [PATCH] kernel/sched: move stack + kprobe clean up to
__put_task_struct()
There is no need to free the stack before the task struct. This also
comes handy on -RT because we can't free memory in preempt disabled
region.
Cc: stable-rt@vger.kernel.org #for kprobe_flush_task()
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
diff --git a/kernel/fork.c b/kernel/fork.c
index 03ce033ddf30..ef8ec1221828 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -88,6 +88,7 @@
#include <linux/sysctl.h>
#include <linux/kcov.h>
#include <linux/livepatch.h>
+#include <linux/kprobes.h>
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -399,6 +400,15 @@ void __put_task_struct(struct task_struct *tsk)
WARN_ON(atomic_read(&tsk->usage));
WARN_ON(tsk == current);
+ /*
+ * Remove function-return probe instances associated with this
+ * task and put them back on the free list.
+ */
+ kprobe_flush_task(tsk);
+
+ /* Task is done with its stack. */
+ put_task_stack(tsk);
+
cgroup_free(tsk);
task_numa_free(tsk);
security_task_free(tsk);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 59474843ece9..ac441093d1ca 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2795,15 +2795,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);
-
put_task_struct(prev);
}
--
2.1.4