Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934192AbbEMC66 (ORCPT ); Tue, 12 May 2015 22:58:58 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49367 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932719AbbEMC6z (ORCPT ); Tue, 12 May 2015 22:58:55 -0400 Date: Wed, 13 May 2015 12:58:39 +1000 From: NeilBrown To: Steven Rostedt Cc: "Paul E. McKenney" , 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, Patrick Marlier , wangyun@linux.vnet.ibm.com Subject: Re: [PATCH tip/core/rcu 3/4] md/bitmap: Fix list_entry_rcu usage Message-ID: <20150513125839.371ef677@notabene.brown> In-Reply-To: <20150512223853.55e0ed90@grimm.local.home> 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> 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_/zAfA.IuM4It1x=_XR+JC=VB"; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4251 Lines: 125 --Sig_/zAfA.IuM4It1x=_XR+JC=VB Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Tue, 12 May 2015 22:38:53 -0400 Steven Rostedt wro= te: > On Tue, 12 May 2015 15:46:26 -0700 > "Paul E. McKenney" wrote: >=20 > > From: Patrick Marlier > >=20 > > Signed-off-by: Patrick Marlier > > Signed-off-by: Paul E. McKenney > > --- > > drivers/md/bitmap.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > >=20 > > diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > > index 2bc56e2a3526..32901772e4ee 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_rcu(mddev->disks.next, struct md_rdev, same_set); >=20 > Hmm, this changes the semantics. >=20 > The original code looks nasty, I first thought it was broken, but it > seems to work out of sheer luck (or clever hack) Definitely a clever hack - no question of "luck" here :-) It might makes sense to change it to use list_for_each_entry_from_rcu() if (rdev =3D=3D NULL) rdev =3D list_entry_rcu(mddev->disks.next, struct md_rdev, same_set); else { rdev_dec_pending(rdev, mddev); rdev =3D list_next_entry_rcu(rdev->same_set.next, struct md_rdev, same= _set); } list_for_each_entry_from_rcu(rdev, ....) but there isn't a "list_next_entry_rcu".... Also, it would have been polity to at least 'cc' them Maintainer of this co= de in the original patch - no? Thanks, NeilBrown >=20 > > else { > > /* release the previous rdev and start from there. */ > > rdev_dec_pending(rdev, mddev); >=20 >=20 > What comes after this is: >=20 > list_for_each_entry_continue_rcu(rdev, &mddev->disks, same_set) { > if (rdev->raid_disk >=3D 0 && >=20 > Now the original code had: >=20 > rdev =3D list_entry_rcu(&mddev->disks, struct md_rdev, same_set); >=20 > Where &mddev->disks would return the address of the disks field of > mddev which is a list head. Then it would get the 'same_set' offset, > which is 0, and rdev is pointing to a makeshift md_rdev struct. But it > isn't used, as the list_for_each_entry_continue_rcu() has: >=20 > #define list_for_each_entry_continue_rcu(pos, head, member) \ > for (pos =3D list_entry_rcu(pos->member.next, typeof(*pos), member); \ > &pos->member !=3D (head); \ > pos =3D list_entry_rcu(pos->member.next, typeof(*pos), member)) >=20 > Thus the first use of pos is pos->member.next or: >=20 > mddev->disks.next >=20 > But now you converted it to rdev =3D mddev->disks.next, which means the > first use is: >=20 > pos =3D mddev->disks.next->next >=20 > I think you are skipping the first element here. >=20 > -- Steve --Sig_/zAfA.IuM4It1x=_XR+JC=VB Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIVAwUBVVK93znsnt1WYoG5AQKXUBAAqXpjA0eQFbDRcc3tpK33c6ROCuj7Z8zb 8zTWZg3SIOoyUWAl+yT6erT6jN66q4OpvIoZyOabDYG5ntyC6hjLqJZmY70SkVUJ AdWXzA3lEeqAFX9MHmokIHUePxJob82RlIkvr4XePvzB3uNc7/pwQyNRoXd2IVzZ qSigcwMgPk2pYkEqYzmwDElmRUCwk4pa7L0FCUPsPVtAVfBXMNgqJk0fgSerQSTf E9hTYjYZViynXfWyoNlm+mobCrqGGcz+gmzTM87Vjj5+wLRdv6cduKU+j3Pxuy0d W8BtvXNasuqBIxiYgxgQnZgn1h0XAjeYm5JLyufu2GcQMuetx0wMdUOBqZJeDDgP uWZTUW1nCAWrbyCfBXDCE0Ldg6fqN6vW0MW4gs7Yh/Tvtbcb1nBwOGKhDasgmYTg eKC2OUNGREtIdjaYstgNiswTPE6x+c/ez6DryNIxP74JotKOgmHz56GGFNTgPugF h3tPrCJ8+d9+P41SPaCUxtCfBBG5EPAyCFVfH0SaGGfNamwpKC9TCTe0yH8TlQbJ TOg4pfpGFiCSZbVfmBCv1fDxFSkysEsiZpcuLFEFf8SpDXZb+lsv906mGc/Q/Wtx 9PBIZUXo5f57m6xvlkNjUPeyjXr1RGAeZbilCqVkazZb8PNsUoHldi13HEgYKuw9 QWMh7hxrK6w= =TZKp -----END PGP SIGNATURE----- --Sig_/zAfA.IuM4It1x=_XR+JC=VB-- -- 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/