From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965250AbbEMNRw (ORCPT ); Wed, 13 May 2015 09:17:52 -0400 Received: from e38.co.us.ibm.com ([32.97.110.159]:53369 "EHLO e38.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965205AbbEMNRp (ORCPT ); Wed, 13 May 2015 09:17:45 -0400 Date: Wed, 13 May 2015 06:17:37 -0700 From: "Paul E. McKenney" To: NeilBrown Cc: Steven Rostedt , 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: <20150513131737.GZ6776@linux.vnet.ibm.com> Reply-To: paulmck@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150513125839.371ef677@notabene.brown> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15051313-0029-0000-0000-000009BDDBFC Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 13, 2015 at 12:58:39PM +1000, NeilBrown wrote: > On Tue, 12 May 2015 22:38:53 -0400 Steven Rostedt wrote: > > > On Tue, 12 May 2015 15:46:26 -0700 > > "Paul E. McKenney" wrote: > > > > > From: Patrick Marlier > > > > > > Signed-off-by: Patrick Marlier > > > Signed-off-by: Paul E. McKenney > > > --- > > > drivers/md/bitmap.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > 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_rdev *rdev, struct mddev *mdde > > > rcu_read_lock(); > > > if (rdev == NULL) > > > /* start at the beginning */ > > > - rdev = list_entry_rcu(&mddev->disks, struct md_rdev, same_set); > > > + rdev = list_entry_rcu(mddev->disks.next, struct md_rdev, same_set); > > > > Hmm, this changes the semantics. > > > > 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 == NULL) > rdev = list_entry_rcu(mddev->disks.next, struct md_rdev, same_set); > else { > rdev_dec_pending(rdev, mddev); > rdev = 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".... Patrick, this one is for you. As are all of the questions from Steven. > Also, it would have been polity to at least 'cc' them Maintainer of this code > in the original patch - no? Rest assured that this set is not going to -tip without at least an Acked-by from at least one of the maintainers. In some cases, I will interpret silence as assent, but this is not one of those cases. ;-) Thanx, Paul > Thanks, > NeilBrown > > > > > > else { > > > /* release the previous rdev and start from there. */ > > > rdev_dec_pending(rdev, mddev); > > > > > > What comes after this is: > > > > list_for_each_entry_continue_rcu(rdev, &mddev->disks, same_set) { > > if (rdev->raid_disk >= 0 && > > > > Now the original code had: > > > > rdev = list_entry_rcu(&mddev->disks, struct md_rdev, same_set); > > > > 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: > > > > #define list_for_each_entry_continue_rcu(pos, head, member) \ > > for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \ > > &pos->member != (head); \ > > pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) > > > > Thus the first use of pos is pos->member.next or: > > > > mddev->disks.next > > > > But now you converted it to rdev = mddev->disks.next, which means the > > first use is: > > > > pos = mddev->disks.next->next > > > > I think you are skipping the first element here. > > > > -- Steve >