From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@kernel.org, laijs@cn.fujitsu.com, dipankar@in.ibm.com,
akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
dvhart@linux.intel.com, fweisbec@gmail.com, oleg@redhat.com,
bobby.prani@gmail.com,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH v5 tip/core/rcu 04/16] rcu: Make TASKS_RCU handle tasks that are almost done exiting
Date: Mon, 11 Aug 2014 15:48:53 -0700 [thread overview]
Message-ID: <1407797345-28227-4-git-send-email-paulmck@linux.vnet.ibm.com> (raw)
In-Reply-To: <1407797345-28227-1-git-send-email-paulmck@linux.vnet.ibm.com>
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Once a task has passed exit_notify() in the do_exit() code path, it
is no longer on the task lists, and is therefore no longer visible
to rcu_tasks_kthread(). This means that an almost-exited task might
be preempted while within a trampoline, and this task won't be waited
on by rcu_tasks_kthread(). This commit fixes this bug by adding an
srcu_struct. An exiting task does srcu_read_lock() just before calling
exit_notify(), and does the corresponding srcu_read_unlock() after
doing the final preempt_disable(). This means that rcu_tasks_kthread()
can do synchronize_srcu() to wait for all mostly-exited tasks to reach
their final preempt_disable() region, and then use synchronize_sched()
to wait for those tasks to finish exiting.
Reported-by: Oleg Nesterov <oleg@redhat.com>
Suggested-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
include/linux/rcupdate.h | 3 +++
kernel/exit.c | 3 +++
kernel/rcu/update.c | 21 +++++++++++++++++++++
3 files changed, 27 insertions(+)
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 1f073af940a5..e6aea256ad39 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -321,6 +321,8 @@ static inline void rcu_user_hooks_switch(struct task_struct *prev,
* macro rather than an inline function to avoid #include hell.
*/
#ifdef CONFIG_TASKS_RCU
+#define TASKS_RCU(x) x
+extern struct srcu_struct tasks_rcu_exit_srcu;
#define rcu_note_voluntary_context_switch(t) \
do { \
preempt_disable(); /* Exclude synchronize_sched(); */ \
@@ -329,6 +331,7 @@ static inline void rcu_user_hooks_switch(struct task_struct *prev,
preempt_enable(); \
} while (0)
#else /* #ifdef CONFIG_TASKS_RCU */
+#define TASKS_RCU(x) do { } while (0)
#define rcu_note_voluntary_context_switch(t) do { } while (0)
#endif /* #else #ifdef CONFIG_TASKS_RCU */
diff --git a/kernel/exit.c b/kernel/exit.c
index e5c4668f1799..b63823876afc 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -663,6 +663,7 @@ void do_exit(long code)
{
struct task_struct *tsk = current;
int group_dead;
+ TASKS_RCU(int tasks_rcu_i);
profile_task_exit(tsk);
@@ -772,6 +773,7 @@ void do_exit(long code)
*/
flush_ptrace_hw_breakpoint(tsk);
+ TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
exit_notify(tsk, group_dead);
proc_exit_connector(tsk);
#ifdef CONFIG_NUMA
@@ -811,6 +813,7 @@ void do_exit(long code)
if (tsk->nr_dirtied)
__this_cpu_add(dirty_throttle_leaks, tsk->nr_dirtied);
exit_rcu();
+ TASKS_RCU(__srcu_read_unlock(&tasks_rcu_exit_srcu, tasks_rcu_i));
/*
* The setting of TASK_RUNNING by try_to_wake_up() may be delayed
diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
index d6fa54befa22..4cece6e886ee 100644
--- a/kernel/rcu/update.c
+++ b/kernel/rcu/update.c
@@ -370,6 +370,13 @@ static struct rcu_head *rcu_tasks_cbs_head;
static struct rcu_head **rcu_tasks_cbs_tail = &rcu_tasks_cbs_head;
static DEFINE_RAW_SPINLOCK(rcu_tasks_cbs_lock);
+/* Track exiting tasks in order to allow them to be waited for. */
+DEFINE_SRCU(tasks_rcu_exit_srcu);
+
+/* Control stall timeouts. Disable with <= 0, otherwise jiffies till stall. */
+static int rcu_task_stall_timeout __read_mostly = HZ * 60 * 3;
+module_param(rcu_task_stall_timeout, int, 0644);
+
/* Post an RCU-tasks callback. */
void call_rcu_tasks(struct rcu_head *rhp, void (*func)(struct rcu_head *rhp))
{
@@ -521,6 +528,15 @@ static int __noreturn rcu_tasks_kthread(void *arg)
rcu_read_unlock();
/*
+ * Wait for tasks that are in the process of exiting.
+ * This does only part of the job, ensuring that all
+ * tasks that were previously exiting reach the point
+ * where they have disabled preemption, allowing the
+ * later synchronize_sched() to finish the job.
+ */
+ synchronize_srcu(&tasks_rcu_exit_srcu);
+
+ /*
* Each pass through the following loop scans the list
* of holdout tasks, removing any that are no longer
* holdouts. When the list is empty, we are done.
@@ -549,6 +565,11 @@ static int __noreturn rcu_tasks_kthread(void *arg)
* ->rcu_tasks_holdout accesses to be within the grace
* period, avoiding the need for memory barriers for
* ->rcu_tasks_holdout accesses.
+ *
+ * In addition, this synchronize_sched() waits for exiting
+ * tasks to complete their final preempt_disable() region
+ * of execution, cleaning up after the synchronize_srcu()
+ * above.
*/
synchronize_sched();
--
1.8.1.5
next prev parent reply other threads:[~2014-08-11 22:50 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-11 22:48 [PATCH tip/core/rcu 0/16] RCU-tasks implementation Paul E. McKenney
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 01/16] rcu: Add call_rcu_tasks() Paul E. McKenney
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 02/16] rcu: Provide cond_resched_rcu_qs() to force quiescent states in long loops Paul E. McKenney
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 03/16] rcu: Add synchronous grace-period waiting for RCU-tasks Paul E. McKenney
2014-08-11 22:48 ` Paul E. McKenney [this message]
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 05/16] rcu: Export RCU-tasks APIs to GPL modules Paul E. McKenney
2014-08-14 19:08 ` Pranith Kumar
2014-08-14 21:29 ` Paul E. McKenney
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 06/16] rcutorture: Add torture tests for RCU-tasks Paul E. McKenney
2014-08-14 21:34 ` Pranith Kumar
2014-08-14 21:44 ` Paul E. McKenney
2014-08-14 21:49 ` Paul E. McKenney
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 07/16] rcutorture: Add RCU-tasks test cases Paul E. McKenney
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 08/16] rcu: Add stall-warning checks for RCU-tasks Paul E. McKenney
2014-08-14 21:39 ` Pranith Kumar
2014-08-14 21:59 ` Paul E. McKenney
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 09/16] rcu: Improve RCU-tasks energy efficiency Paul E. McKenney
2014-08-14 21:42 ` Pranith Kumar
2014-08-14 21:55 ` Paul E. McKenney
2014-08-14 22:00 ` Pranith Kumar
2014-08-11 22:48 ` [PATCH v5 tip/core/rcu 10/16] documentation: Add verbiage on RCU-tasks stall warning messages Paul E. McKenney
2014-08-11 22:49 ` [PATCH v5 tip/core/rcu 11/16] rcu: Defer rcu_tasks_kthread() creation till first call_rcu_tasks() Paul E. McKenney
2014-08-14 22:28 ` Pranith Kumar
2014-08-14 22:53 ` Paul E. McKenney
2014-08-11 22:49 ` [PATCH v5 tip/core/rcu 12/16] rcu: Make TASKS_RCU handle nohz_full= CPUs Paul E. McKenney
2014-08-14 22:55 ` Pranith Kumar
2014-08-14 23:16 ` Paul E. McKenney
2014-08-11 22:49 ` [PATCH v5 tip/core/rcu 13/16] rcu: Make rcu_tasks_kthread()'s GP-wait loop allow preemption Paul E. McKenney
2014-08-11 22:49 ` [PATCH v5 tip/core/rcu 14/16] rcu: Remove redundant preempt_disable() from rcu_note_voluntary_context_switch() Paul E. McKenney
2014-08-13 10:56 ` Peter Zijlstra
2014-08-13 14:07 ` Paul E. McKenney
2014-08-13 14:33 ` Peter Zijlstra
2014-08-13 20:06 ` Paul E. McKenney
2014-08-11 22:49 ` [PATCH v5 tip/core/rcu 15/16] rcu: Make RCU-tasks wait for idle tasks Paul E. McKenney
2014-08-13 8:12 ` Peter Zijlstra
2014-08-13 12:48 ` Paul E. McKenney
2014-08-13 13:40 ` Peter Zijlstra
2014-08-13 13:51 ` Steven Rostedt
2014-08-13 14:07 ` Peter Zijlstra
2014-08-13 14:13 ` Steven Rostedt
2014-08-13 14:43 ` Paul E. McKenney
2014-08-13 16:30 ` Peter Zijlstra
2014-08-13 16:43 ` Jacob Pan
2014-08-13 18:24 ` Paul E. McKenney
2014-08-13 16:35 ` Peter Zijlstra
2014-08-13 18:25 ` Paul E. McKenney
2014-08-13 14:43 ` Peter Zijlstra
2014-08-13 20:56 ` Paul E. McKenney
2014-08-13 14:12 ` Paul E. McKenney
2014-08-13 14:42 ` Peter Zijlstra
2014-08-13 17:24 ` Peter Zijlstra
2014-08-13 17:30 ` Peter Zijlstra
2014-08-13 18:16 ` Peter Zijlstra
2014-08-13 18:20 ` Paul E. McKenney
2014-08-13 18:55 ` Peter Zijlstra
2014-08-13 19:54 ` Paul E. McKenney
2014-08-11 22:49 ` [PATCH v5 tip/core/rcu 16/16] rcu: Additional information on RCU-tasks stall-warning messages Paul E. McKenney
2014-08-14 20:46 ` [PATCH v5 tip/core/rcu 01/16] rcu: Add call_rcu_tasks() Pranith Kumar
2014-08-14 21:22 ` Paul E. McKenney
2014-08-12 23:57 ` [PATCH tip/core/rcu 0/16] RCU-tasks implementation Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1407797345-28227-4-git-send-email-paulmck@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=bobby.prani@gmail.com \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=dvhart@linux.intel.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=josh@joshtriplett.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).