public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Miles Lane <miles.lane@gmail.com>
Cc: Eric Paris <eparis@redhat.com>,
	Lai Jiangshan <laijs@cn.fujitsu.com>, Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] RCU: don't turn off lockdep when find suspicious rcu_dereference_check() usage
Date: Tue, 20 Apr 2010 06:52:27 -0700	[thread overview]
Message-ID: <20100420135227.GC2628@linux.vnet.ibm.com> (raw)
In-Reply-To: <j2ya44ae5cd1004200545q6be4ec82o18ae99d93e8c29c7@mail.gmail.com>

On Tue, Apr 20, 2010 at 08:45:28AM -0400, Miles Lane wrote:
> Is there a patch set for 2.6.34-rc5 I can test?

I will be sending a patchset out later today after testing, but
please see below for a sneak preview collapsed into a single patch.

							Thanx, Paul

> On Tue, Apr 20, 2010 at 8:31 AM, Eric Paris <eparis@redhat.com> wrote:
> 
> > On Tue, 2010-04-20 at 16:23 +0800, Lai Jiangshan wrote:
> >
> > > [PATCH] RCU: don't turn off lockdep when find suspicious
> > rcu_dereference_check() usage
> > >
> > > When suspicious rcu_dereference_check() usage is detected, lockdep is
> > still
> > > available actually, so we should not call debug_locks_off() in
> > > lockdep_rcu_dereference().
> > >
> > > For get rid of too much "suspicious rcu_dereference_check() usage"
> > > output when the "if(!debug_locks_off())" statement is removed. This patch
> > uses
> > > static variable '__warned's for very usage of "rcu_dereference*()".
> > >
> > > One variable per usage, so, Now, we can get multiple complaint
> > > when we detect multiple different suspicious rcu_dereference_check()
> > usage.
> > >
> > > Requested-by: Eric Paris <eparis@redhat.com>
> > > Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> >
> > Although mine was a linux-next kernel and it doesn't appear that I have
> > rcu_dereference_protected() at all, so I dropped that bit of the patch,
> > it worked great!  I got 4 more complaints to harass people with.  Feel
> > free to add my tested by if you care to.
> >
> > Tested-by: Eric Paris <eparis@redhat.com>

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 07db2fe..ec9ab49 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -190,6 +190,15 @@ static inline int rcu_read_lock_sched_held(void)
 
 #ifdef CONFIG_PROVE_RCU
 
+#define __do_rcu_dereference_check(c)					\
+	do {								\
+		static bool __warned;					\
+		if (debug_lockdep_rcu_enabled() && !__warned && !(c)) {	\
+			__warned = true;				\
+			lockdep_rcu_dereference(__FILE__, __LINE__);	\
+		}							\
+	} while (0)
+
 /**
  * rcu_dereference_check - rcu_dereference with debug checking
  * @p: The pointer to read, prior to dereferencing
@@ -219,8 +228,7 @@ static inline int rcu_read_lock_sched_held(void)
  */
 #define rcu_dereference_check(p, c) \
 	({ \
-		if (debug_lockdep_rcu_enabled() && !(c)) \
-			lockdep_rcu_dereference(__FILE__, __LINE__); \
+		__do_rcu_dereference_check(c); \
 		rcu_dereference_raw(p); \
 	})
 
@@ -237,8 +245,7 @@ static inline int rcu_read_lock_sched_held(void)
  */
 #define rcu_dereference_protected(p, c) \
 	({ \
-		if (debug_lockdep_rcu_enabled() && !(c)) \
-			lockdep_rcu_dereference(__FILE__, __LINE__); \
+		__do_rcu_dereference_check(c); \
 		(p); \
 	})
 
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index da5e139..e5c0244 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -205,9 +205,12 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
 	 * No lock is needed, since the task isn't on tasklist yet,
 	 * so it can't be moved to another cgroup, which means the
 	 * freezer won't be removed and will be valid during this
-	 * function call.
+	 * function call.  Nevertheless, apply RCU read-side critical
+	 * section to suppress RCU lockdep false positives.
 	 */
+	rcu_read_lock();
 	freezer = task_freezer(task);
+	rcu_read_unlock();
 
 	/*
 	 * The root cgroup is non-freezable, so we can skip the
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 2594e1c..03dd1fa 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -3801,8 +3801,6 @@ void lockdep_rcu_dereference(const char *file, const int line)
 {
 	struct task_struct *curr = current;
 
-	if (!debug_locks_off())
-		return;
 	printk("\n===================================================\n");
 	printk(  "[ INFO: suspicious rcu_dereference_check() usage. ]\n");
 	printk(  "---------------------------------------------------\n");
diff --git a/kernel/sched.c b/kernel/sched.c
index 6af210a..14c44ec 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -323,6 +323,15 @@ static inline struct task_group *task_group(struct task_struct *p)
 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
 static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
 {
+	/*
+	 * Strictly speaking this rcu_read_lock() is not needed since the
+	 * task_group is tied to the cgroup, which in turn can never go away
+	 * as long as there are tasks attached to it.
+	 *
+	 * However since task_group() uses task_subsys_state() which is an
+	 * rcu_dereference() user, this quiets CONFIG_PROVE_RCU.
+	 */
+	rcu_read_lock();
 #ifdef CONFIG_FAIR_GROUP_SCHED
 	p->se.cfs_rq = task_group(p)->cfs_rq[cpu];
 	p->se.parent = task_group(p)->se[cpu];
@@ -332,6 +341,7 @@ static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
 	p->rt.rt_rq  = task_group(p)->rt_rq[cpu];
 	p->rt.parent = task_group(p)->rt_se[cpu];
 #endif
+	rcu_read_unlock();
 }
 
 #else

  parent reply	other threads:[~2010-04-20 13:52 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-08  1:26 INFO: suspicious rcu_dereference_check() usage - include/linux/cgroup.h:492 invoked rcu_dereference_check() without protection! Miles Lane
2010-03-11  3:28 ` Paul E. McKenney
2010-04-12 18:44   ` Eric Paris
2010-04-12 18:47     ` Peter Zijlstra
2010-04-14 10:47       ` Peter Zijlstra
2010-04-15 15:47         ` Paul E. McKenney
2010-04-19  3:45           ` Lai Jiangshan
2010-04-19 18:26         ` Eric Paris
2010-04-19 23:01           ` Paul E. McKenney
2010-04-20  1:25             ` Eric Paris
2010-04-20  3:04               ` Paul E. McKenney
2010-04-20  7:21                 ` Peter Zijlstra
2010-04-20  8:23                 ` [PATCH] RCU: don't turn off lockdep when find suspicious rcu_dereference_check() usage Lai Jiangshan
2010-04-20  8:36                   ` Peter Zijlstra
2010-04-20 12:31                   ` Eric Paris
2010-04-20 13:28                     ` Paul E. McKenney
     [not found]                     ` <j2ya44ae5cd1004200545q6be4ec82o18ae99d93e8c29c7@mail.gmail.com>
2010-04-20 13:52                       ` Paul E. McKenney [this message]
2010-04-20 15:38                         ` Miles Lane
2010-04-21  6:04                           ` Borislav Petkov
2010-04-21 21:45                             ` Paul E. McKenney
2010-04-21 21:35                           ` Paul E. McKenney
2010-04-21 21:48                             ` Paul E. McKenney
2010-04-21 21:57                             ` Eric Dumazet
2010-04-21 22:14                               ` Paul E. McKenney
2010-04-21 23:26                                 ` Eric W. Biederman
2010-04-22 14:56                             ` Vivek Goyal
2010-04-22 16:01                               ` Paul E. McKenney
2010-04-23 12:50                                 ` Miles Lane
2010-04-23 19:42                                   ` Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 01/12] rcu: Fix RCU lockdep splat in set_task_cpu on fork path Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 02/12] rcu: fix RCU lockdep splat on freezer_fork path Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 03/12] rcu: leave lockdep enabled after RCU lockdep splat Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 04/12] NFSv4: Fix the locking in nfs_inode_reclaim_delegation() Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 05/12] NFS: Fix RCU issues in the NFSv4 delegation code Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 06/12] KEYS: Fix an RCU warning Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 07/12] KEYS: Fix an RCU warning in the reading of user keys Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 08/12] cgroup: Fix an RCU warning in cgroup_path() Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 09/12] cgroup: Fix an RCU warning in alloc_css_id() Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 10/12] sched: Fix an RCU warning in print_task() Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 11/12] cgroup: Check task_lock in task_subsys_state() Paul E. McKenney
2010-04-23 19:43                                     ` [PATCH v2.6.34-rc5 12/12] memcg: css_id() must be called under rcu_read_lock() Paul E. McKenney
2010-04-23 22:59                                     ` [PATCH] RCU: don't turn off lockdep when find suspicious rcu_dereference_check() usage Miles Lane
2010-04-24  5:35                                       ` Miles Lane
2010-04-25  2:36                                         ` Paul E. McKenney
2010-04-25  2:34                                       ` Paul E. McKenney
2010-04-25  7:45                                         ` Johannes Berg
2010-04-25  7:49                                           ` David Miller
2010-04-26  2:07                                             ` Paul E. McKenney
2010-04-25 15:49                                         ` Miles Lane
2010-04-25 20:20                                           ` Miles Lane
2010-04-26 16:09                                             ` Paul E. McKenney
2010-04-26 18:35                                               ` Eric W. Biederman
2010-04-27  4:27                                                 ` Paul E. McKenney
2010-04-27 16:22                                                   ` Paul E. McKenney
2010-04-27 16:33                                                     ` Eric Dumazet
2010-04-27 17:58                                                     ` Miles Lane
2010-04-27 23:31                                                       ` Paul E. McKenney
2010-04-27 23:42                                                         ` David Miller
2010-04-27 23:52                                                           ` Paul E. McKenney
     [not found]                                         ` <p2ka44ae5cd1004281358n86ce29d2tbece16b2fb974dab@mail.gmail.com>
2010-04-28 21:37                                           ` Paul E. McKenney
2010-05-01 17:26                         ` Miles Lane
2010-05-01 21:55                           ` Paul E. McKenney
2010-05-02  2:00                             ` Miles Lane
2010-05-02  4:11                               ` Paul E. McKenney
2010-04-21  1:05             ` INFO: suspicious rcu_dereference_check() usage - include/linux/cgroup.h:492 invoked rcu_dereference_check() without protection! Li Zefan
2010-04-21  3:14               ` Paul E. McKenney
2010-04-14 16:03     ` Paul E. McKenney
  -- strict thread matches above, loose matches on Subject: below --
2010-06-01 13:06 [PATCH] RCU: don't turn off lockdep when find suspicious rcu_dereference_check() usage Daniel J Blueman
2010-06-02 14:56 ` Paul E. McKenney
2010-06-02 15:24   ` Daniel J Blueman
2010-06-03  9:22   ` Li Zefan
2010-06-03 18:30     ` Paul E. McKenney
2010-06-04  2:44       ` Li Zefan
2010-06-04  4:10         ` Paul E. McKenney
2010-06-04  8:54           ` Daniel J Blueman

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=20100420135227.GC2628@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=eparis@redhat.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miles.lane@gmail.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /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