Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754066AbbEUAIB (ORCPT ); Wed, 20 May 2015 20:08:01 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58735 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbbEUAH6 (ORCPT ); Wed, 20 May 2015 20:07:58 -0400 Date: Thu, 21 May 2015 10:07:35 +1000 From: NeilBrown To: "Paul E. McKenney" Cc: Steven Rostedt , Patrick Marlier , linux-kernel@vger.kernel.org, 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, dhowells@redhat.com, edumazet@google.com, dvhart@linux.intel.com, fweisbec@gmail.com, oleg@redhat.com, bobby.prani@gmail.com, wangyun@linux.vnet.ibm.com Subject: Re: [PATCH tip/core/rcu 3/4] md/bitmap: Fix list_entry_rcu usage Message-ID: <20150521100735.4ad0b5ae@notabene.brown> In-Reply-To: <20150520132835.GJ6776@linux.vnet.ibm.com> References: <20150512224603.GA4531@linux.vnet.ibm.com> <1431470787-4702-1-git-send-email-paulmck@linux.vnet.ibm.com> <1431470787-4702-3-git-send-email-paulmck@linux.vnet.ibm.com> <20150512223853.55e0ed90@grimm.local.home> <20150513125839.371ef677@notabene.brown> <5557819E.1060001@gmail.com> <20150518120647.0c3cecd8@notabene.brown> <20150518094321.2012a66a@gandalf.local.home> <20150519220725.GA6776@linux.vnet.ibm.com> <20150520150919.7f5aa0e9@notabene.brown> <20150520132835.GJ6776@linux.vnet.ibm.com> X-Mailer: Claws Mail 3.10.1-162-g4d0ed6 (GTK+ 2.24.25; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/1Dc3yytY9Fp60TVlBNYNz2P"; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5070 Lines: 143 --Sig_/1Dc3yytY9Fp60TVlBNYNz2P Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Wed, 20 May 2015 06:28:35 -0700 "Paul E. McKenney" wrote: > On Wed, May 20, 2015 at 03:09:19PM +1000, NeilBrown wrote: > > On Tue, 19 May 2015 15:07:25 -0700 "Paul E. McKenney" > > wrote: > >=20 > >=20 > > > The code in md probably needs to change in any case, as otherwise we = are > > > invoking rcu_dereference_whatever() on a full struct list_head rather > > > than on a single pointer. Or am I missing something here? > >=20 > > I think it would be > > rcu_dereference_whatever(&mddev->disks) > >=20 > > I don't know what you mean by "on a full struct list_head", but there is > > nothing actually being dereferenced here - right? Just pointer arithme= tic on > > 'mddev'. >=20 > It really does dereference. Strange but true. Well... your the expert. But without an lvalue, I can't see it. >=20 > > I should probably just > >=20 > > diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > > index 2bc56e2a3526..b1d237bf8b3b 100644 > > --- a/drivers/md/bitmap.c > > +++ b/drivers/md/bitmap.c > > @@ -181,7 +181,7 @@ static struct md_rdev *next_active_rdev(struct md_r= dev *rdev, struct mddev *mdde > > rcu_read_lock(); > > if (rdev =3D=3D NULL) > > /* start at the beginning */ > > - rdev =3D list_entry_rcu(&mddev->disks, struct md_rdev, same_set); > > + rdev =3D list_entry(&mddev->disks, struct md_rdev, same_set); > > else { > > /* release the previous rdev and start from there. */ > > rdev_dec_pending(rdev, mddev); > >=20 > > as there really are no RCU issues with getting that address. Maybe I s= hould > > move it outside the rcu_read_lock() just to be blatant.... but that wou= ld > > make the code a lot more clumsy as the rdev_dec_pending must be inside = the > > rcu_read_lock.. > >=20 > > So this. >=20 > Fair enough -- if you aren't using RCU, there is really no point in using > the RCU API. I will drop this patch from my tree. You are pushing yours, > I am guessing? Excellent guess :-) Hopefully for the next -rc. Thanks, NeilBrown >=20 > Thanx, Paul >=20 > > Thanks, > > NeilBrown > >=20 > > From: NeilBrown > > Date: Wed, 20 May 2015 15:05:09 +1000 > > Subject: [PATCH] md/bitmap: remove rcu annotation from pointer arithmet= ic. > >=20 > > Evaluating "&mddev->disks" is simple pointer arithmetic, so > > it does not need 'rcu' annotations - no dereferencing is happening. > >=20 > > Also enhance the comment to explain that 'rdev' in that case > > is not actually a pointer to an rdev. > >=20 > > Reported-by: Patrick Marlier > > Signed-off-by: NeilBrown > >=20 > > diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > > index 2bc56e2a3526..135a0907e9de 100644 > > --- a/drivers/md/bitmap.c > > +++ b/drivers/md/bitmap.c > > @@ -177,11 +177,16 @@ static struct md_rdev *next_active_rdev(struct md= _rdev *rdev, struct mddev *mdde > > * nr_pending is 0 and In_sync is clear, the entries we return will > > * still be in the same position on the list when we re-enter > > * list_for_each_entry_continue_rcu. > > + * > > + * Note that if entered with 'rdev =3D=3D NULL' to start at the > > + * beginning, we temporarily assign 'rdev' to an address which > > + * isn't really an rdev, but which can be used by > > + * list_for_each_entry_continue_rcu() to find the first entry. > > */ > > rcu_read_lock(); > > if (rdev =3D=3D NULL) > > /* start at the beginning */ > > - rdev =3D list_entry_rcu(&mddev->disks, struct md_rdev, same_set); > > + rdev =3D list_entry(&mddev->disks, struct md_rdev, same_set); > > else { > > /* release the previous rdev and start from there. */ > > rdev_dec_pending(rdev, mddev); >=20 --Sig_/1Dc3yytY9Fp60TVlBNYNz2P Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIVAwUBVV0hzTnsnt1WYoG5AQLkJBAAt8ov0dfFLs4w48OiPyHJq4xxiW3lWlBE C45SdmFNWgmAyt2Q7C91fx0RJxWL2+i33UiKo+2nBoX3OjLjOX06fBiYJvf7UULV ofq+3oxzz0Zze22PO8EoxFOgmPGPl/RU6X80BggW0n6pEK+uGfS1Sq9X1kftS8wn SiNlHIGMt6iwCfNNPrQCI/9BPeaXUXrX2Rgj3YIYNBklRUz+IiqHrUMTdCDu54VB rLlupWpxniWi5UR/CixXjw5htPqfJBzO4l8E08drJLCm2JNpyDVjzpnP+1lQfEAs GtjcJI8gTY0sPgqmC6t19h5vi8QISTF6kRu6uhC0dshR/k20+wFlaJIKrFzY1wnJ iviu3TzD3Ve7ZAWx4v6TcHVuZ9dP4yAl5itbDLbM/GUPT5FhZhrQ63Opdr5d1yNU e2y3+15foB0WH6Cw1GIJyb0ThQSTpjeh7Lqr3MQ1O9Rgtmq5k7ED9bPirfzNYBFQ bkVhswF/qll49sWy4jnPT+MwrAs+hTVuzjN2FmSboqWPr1gslliUS2tdXCV43/XI n/FuxMfsgJZi3Lap54GmyD20cm7eyxz2dfVOGaSf6jGPBUE20OIOXwewRi36syM5 10VhZg3OWW99bnXV6GNyQHYCC3u9MWzWOOvyNc3yLkz2JZD0+U9YTGQBozikexyY KVZahOxCeWg= =kGHa -----END PGP SIGNATURE----- --Sig_/1Dc3yytY9Fp60TVlBNYNz2P-- -- 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/