Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751908AbaKWRee (ORCPT ); Sun, 23 Nov 2014 12:34:34 -0500 Received: from mail-ig0-f170.google.com ([209.85.213.170]:51057 "EHLO mail-ig0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751273AbaKWRec (ORCPT ); Sun, 23 Nov 2014 12:34:32 -0500 Message-ID: <1416764069.17888.36.camel@edumazet-glaptop2.roam.corp.google.com> Subject: [PATCH v2] drivers/md: use proper rcu accessor From: Eric Dumazet To: Pranith Kumar , Mike Snitzer , dm-devel@redhat.com Cc: "Kirill A. Shutemov" , "Paul E. McKenney" , LKML , Ingo Molnar , Lai Jiangshan , Dipankar Sarma , Andrew Morton , Mathieu Desnoyers , Josh Triplett , Thomas Gleixner , Peter Zijlstra , Steven Rostedt , David Howells , Eric Dumazet , dvhart@linux.intel.com, =?ISO-8859-1?Q?Fr=E9d=E9ric?= Weisbecker , Oleg Nesterov Date: Sun, 23 Nov 2014 09:34:29 -0800 In-Reply-To: <1416760829.17888.19.camel@edumazet-glaptop2.roam.corp.google.com> References: <20141028220944.GA26114@linux.vnet.ibm.com> <1414534202-27312-1-git-send-email-paulmck@linux.vnet.ibm.com> <1414534202-27312-3-git-send-email-paulmck@linux.vnet.ibm.com> <20141121133145.GA17245@node.dhcp.inet.fi> <546F4C8C.4040904@gmail.com> <20141121145817.GA17710@node.dhcp.inet.fi> <1416760829.17888.19.camel@edumazet-glaptop2.roam.corp.google.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet rcu_dereference() should be used in sections protected by rcu_read_lock. For writers, holding some kind of mutex or lock, rcu_dereference_protected() is the way to go, adding explicit lockdep bits. In __unbind(), we are the last user of this mapped device, so can use the constant '1' instead of a lockdep_is_held(), not consistent with other uses of rcu_dereference_protected() which use md->suspend_lock mutex. Reported-by: Kirill A. Shutemov Signed-off-by: Eric Dumazet Fixes: 33423974bfc1 ("dm: Use rcu_dereference() for accessing rcu pointer") Cc: Pranith Kumar Cc: Mike Snitzer --- v2: changed all buggy rcu_dereference() BTW, having a mutex named suspend_lock is ugly, IMO. drivers/md/dm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index a0ece87ad426..5919d933bce9 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2335,7 +2335,8 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, merge_is_optional = dm_table_merge_is_optional(t); - old_map = rcu_dereference(md->map); + old_map = rcu_dereference_protected(md->map, + lockdep_is_held(&md->suspend_lock)); rcu_assign_pointer(md->map, t); md->immutable_target_type = dm_table_get_immutable_target_type(t); @@ -2355,7 +2356,7 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, */ static struct dm_table *__unbind(struct mapped_device *md) { - struct dm_table *map = rcu_dereference(md->map); + struct dm_table *map = rcu_dereference_protected(md->map, 1); if (!map) return NULL; @@ -2850,7 +2851,8 @@ retry: goto retry; } - map = rcu_dereference(md->map); + map = rcu_dereference_protected(md->map, + lockdep_is_held(&md->suspend_lock)); r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE); if (r) @@ -2908,7 +2910,8 @@ retry: goto retry; } - map = rcu_dereference(md->map); + map = rcu_dereference_protected(md->map, + lockdep_is_held(&md->suspend_lock)); if (!map || !dm_table_get_size(map)) goto out; @@ -2943,7 +2946,8 @@ static void __dm_internal_suspend(struct mapped_device *md, unsigned suspend_fla return; /* nest suspend */ } - map = rcu_dereference(md->map); + map = rcu_dereference_protected(md->map, + lockdep_is_held(&md->suspend_lock)); /* * Using TASK_UNINTERRUPTIBLE because only NOFLUSH internal suspend is -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/