linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 1/4] rcu: Detect uses of rcu read side in extended quiescent states
Date: Mon,  6 Jun 2011 05:10:55 +0200	[thread overview]
Message-ID: <1307329858-14999-3-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1307329858-14999-1-git-send-email-fweisbec@gmail.com>

Detect uses of rcu that are not supposed to happen when we
are in an extended quiescent state.

This can happen for example if we use rcu between the time we
stop the tick and the time we restart it. Or inside an irq that
didn't use rcu_irq_enter,exit() or other possible kind of rcu API
misuse.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/lockdep.h  |    8 +++++++-
 include/linux/rcupdate.h |   20 ++++++++++++++------
 kernel/lockdep.c         |   12 +++++++++---
 kernel/pid.c             |    2 +-
 kernel/rcutree.c         |   14 ++++++++++++++
 5 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index ef820a3..452d547 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -547,8 +547,14 @@ do {									\
 # define might_lock_read(lock) do { } while (0)
 #endif
 
+enum rcu_warn {
+	RCU_WARN_UNPROTECTED,
+	RCU_WARN_EXT_QS
+};
+
 #ifdef CONFIG_PROVE_RCU
-extern void lockdep_rcu_dereference(const char *file, const int line);
+extern void
+lockdep_rcu_dereference(const char *file, const int line, enum rcu_warn type);
 #endif
 
 #endif /* __LINUX_LOCKDEP_H */
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 99f9aa7..651d90b 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -297,22 +297,29 @@ extern int rcu_my_thread_group_empty(void);
 /**
  * rcu_lockdep_assert - emit lockdep splat if specified condition not met
  * @c: condition to check
+ * @t: type of the rcu problem detected
  */
-#define rcu_lockdep_assert(c)						\
+#define rcu_lockdep_assert(c, t)					\
 	do {								\
 		static bool __warned;					\
 		if (debug_lockdep_rcu_enabled() && !__warned && !(c)) {	\
 			__warned = true;				\
-			lockdep_rcu_dereference(__FILE__, __LINE__);	\
+			lockdep_rcu_dereference(__FILE__, __LINE__, t);	\
 		}							\
 	} while (0)
 
 #else /* #ifdef CONFIG_PROVE_RCU */
 
-#define rcu_lockdep_assert(c) do { } while (0)
+#define rcu_lockdep_assert(c, t) do { } while (0)
 
 #endif /* #else #ifdef CONFIG_PROVE_RCU */
 
+#if defined(CONFIG_PROVE_RCU) && defined(CONFIG_NO_HZ)
+extern bool rcu_check_extended_qs(void);
+#else
+static inline bool rcu_check_extended_qs(void) { return false; }
+#endif
+
 /*
  * Helper functions for rcu_dereference_check(), rcu_dereference_protected()
  * and rcu_assign_pointer().  Some of these could be folded into their
@@ -338,14 +345,15 @@ extern int rcu_my_thread_group_empty(void);
 #define __rcu_dereference_check(p, c, space) \
 	({ \
 		typeof(*p) *_________p1 = (typeof(*p)*__force )ACCESS_ONCE(p); \
-		rcu_lockdep_assert(c); \
+		rcu_lockdep_assert(c, RCU_WARN_UNPROTECTED); \
+		rcu_lockdep_assert(!rcu_check_extended_qs(), RCU_WARN_EXT_QS); \
 		rcu_dereference_sparse(p, space); \
 		smp_read_barrier_depends(); \
 		((typeof(*p) __force __kernel *)(_________p1)); \
 	})
 #define __rcu_dereference_protected(p, c, space) \
 	({ \
-		rcu_lockdep_assert(c); \
+		rcu_lockdep_assert(c, RCU_WARN_UNPROTECTED); \
 		rcu_dereference_sparse(p, space); \
 		((typeof(*p) __force __kernel *)(p)); \
 	})
@@ -359,7 +367,7 @@ extern int rcu_my_thread_group_empty(void);
 #define __rcu_dereference_index_check(p, c) \
 	({ \
 		typeof(p) _________p1 = ACCESS_ONCE(p); \
-		rcu_lockdep_assert(c); \
+		rcu_lockdep_assert(c, RCU_WARN_UNPROTECTED); \
 		smp_read_barrier_depends(); \
 		(_________p1); \
 	})
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 63437d0..eccfede 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -3982,7 +3982,8 @@ void lockdep_sys_exit(void)
 	}
 }
 
-void lockdep_rcu_dereference(const char *file, const int line)
+void lockdep_rcu_dereference(const char *file, const int line,
+			     enum rcu_warn type)
 {
 	struct task_struct *curr = current;
 
@@ -3994,8 +3995,13 @@ void lockdep_rcu_dereference(const char *file, const int line)
 	printk("\n===================================================\n");
 	printk(  "[ INFO: suspicious rcu_dereference_check() usage. ]\n");
 	printk(  "---------------------------------------------------\n");
-	printk("%s:%d invoked rcu_dereference_check() without protection!\n",
-			file, line);
+	printk("%s:%d invoked rcu_dereference_check() ", file, line);
+
+	if (type == RCU_WARN_UNPROTECTED)
+		printk("without protection!\n");
+	else if (type == RCU_WARN_EXT_QS)
+		printk("while in RCU extended quiescent state!\n");
+
 	printk("\nother info that might help us debug this:\n\n");
 	printk("\nrcu_scheduler_active = %d, debug_locks = %d\n", rcu_scheduler_active, debug_locks);
 	lockdep_print_held_locks(curr);
diff --git a/kernel/pid.c b/kernel/pid.c
index 57a8346..87dd3c5 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -419,7 +419,7 @@ EXPORT_SYMBOL(pid_task);
  */
 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
 {
-	rcu_lockdep_assert(rcu_read_lock_held());
+	rcu_lockdep_assert(rcu_read_lock_held(), RCU_WARN_UNPROTECTED);
 	return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
 }
 
diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index 89419ff..992ec56 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -433,6 +433,20 @@ void rcu_irq_exit(void)
 	rcu_enter_nohz();
 }
 
+#ifdef CONFIG_PROVE_RCU
+
+bool rcu_check_extended_qs(void)
+{
+	struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
+
+	if (atomic_read(&rdtp->dynticks) & 0x1)
+		return false;
+
+	return true;
+}
+
+#endif /* CONFIG_PROVE_RCU */
+
 #ifdef CONFIG_SMP
 
 /*
-- 
1.7.5.2


  parent reply	other threads:[~2011-06-06  3:12 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-06  3:10 [PATCH 0/4] rcu: Detect rcu uses under extended quiescent state, and fix some Frederic Weisbecker
2011-06-06  3:10 ` Frederic Weisbecker
2011-06-06  3:10 ` Frederic Weisbecker [this message]
2011-06-06  3:44   ` [1/4] rcu: Detect uses of rcu read side in extended quiescent states Milton Miller
2011-06-06 18:10     ` Paul E. McKenney
2011-06-06 18:20       ` Frederic Weisbecker
2011-06-06 18:37         ` Paul E. McKenney
2011-06-07  0:19       ` Frederic Weisbecker
2011-06-07  0:42         ` Paul E. McKenney
2011-06-07  1:36           ` Frederic Weisbecker
2011-06-07  4:40             ` Paul E. McKenney
2011-06-07 12:58               ` Frederic Weisbecker
2011-06-07 18:34                 ` Paul E. McKenney
2011-06-07 18:49                   ` Frederic Weisbecker
2011-06-07 19:22                     ` Paul E. McKenney
2011-06-10  8:58             ` Michel Lespinasse
2011-06-06  3:10 ` [PATCH 2/4] nohz: Split extended quiescent state handling from nohz switch Frederic Weisbecker
2011-06-06  3:20   ` [PATCH 2/4 v2] " Frederic Weisbecker
2011-06-06  3:20     ` [PATCH 2/4] " Frederic Weisbecker
2011-06-08  1:15       ` Guan Xuetao
2011-06-06 15:16     ` [PATCH 2/4 v2] " Hans-Christian Egtvedt
2011-06-06 15:24     ` Ralf Baechle
2011-06-06 18:43     ` Mike Frysinger
2011-06-06 20:30     ` Chris Metcalf
2011-06-06  3:58   ` [PATCH 2/4] " David Miller
2011-06-09 23:08   ` Frederic Weisbecker
2011-06-06  3:10 ` [PATCH 3/4] x86: Don't call idle notifier inside rcu extended QS Frederic Weisbecker
2011-06-06  3:10 ` [PATCH 4/4] x86: Call idle_exit() after irq_enter() Frederic Weisbecker
2011-06-06 18:12 ` [PATCH 0/4] rcu: Detect rcu uses under extended quiescent state, and fix some Paul E. McKenney
  -- strict thread matches above, loose matches on Subject: below --
2011-06-09 23:47 [PATCH 0/4 v2] " Frederic Weisbecker
2011-06-09 23:47 ` [PATCH 1/4] rcu: Detect uses of rcu read side in extended quiescent states Frederic Weisbecker
2011-06-10  0:23   ` Paul E. McKenney
2011-06-10  0:50     ` Frederic Weisbecker
2011-06-17 23:19       ` Paul E. McKenney
2011-06-18 14:23         ` Frederic Weisbecker
2011-06-18 16:04           ` Paul E. McKenney
2011-06-18 16:10             ` Frederic Weisbecker
2011-06-18 16:36               ` 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=1307329858-14999-3-git-send-email-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --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).