public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Patrick Marlier <patrick.marlier@gmail.com>
To: NeilBrown <neilb@suse.de>
Cc: "Steven Rostedt" <rostedt@goodmis.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	linux-kernel@vger.kernel.org, mingo@kernel.org,
	laijs@cn.fujitsu.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Josh Triplett" <josh@joshtriplett.org>,
	tglx@linutronix.de, peterz@infradead.org, dhowells@redhat.com,
	"Eric Dumazet" <edumazet@google.com>,
	dvhart@linux.intel.com,
	"Frédéric Weisbecker" <fweisbec@gmail.com>,
	oleg@redhat.com, "pranith kumar" <bobby.prani@gmail.com>,
	wangyun@linux.vnet.ibm.com
Subject: Re: [PATCH tip/core/rcu 3/4] md/bitmap: Fix list_entry_rcu usage
Date: Mon, 18 May 2015 21:36:25 +0200	[thread overview]
Message-ID: <555A3F39.8020907@gmail.com> (raw)
In-Reply-To: <CAKQMxzQC-pXbAjAxmKVEVHvSNtFdRpJ9YB63yhPr-PZqKJeENA@mail.gmail.com>


On 05/18/2015 03:53 PM, Patrick Marlier wrote:
> On Mon, May 18, 2015 at 4:06 AM, NeilBrown <neilb@suse.de> wrote:
>> On Sat, 16 May 2015 19:42:54 +0200 Patrick Marlier
>> <patrick.marlier@gmail.com> wrote:
>>> On 05/13/2015 04:58 AM, NeilBrown wrote:
>>>> On Tue, 12 May 2015 22:38:53 -0400 Steven Rostedt <rostedt@goodmis.org> wrote:
>>>>> On Tue, 12 May 2015 15:46:26 -0700
>>>>> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
>>>>> 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.
>>>
>>>
>>> struct mddev {
>>> ...
>>>        struct list_head                disks;
>>> ...}
>>>
>>> struct list_head {
>>>           struct list_head *next, *prev;
>>> };
>>>
>>> The tricky thing is that "list_entry_rcu" before and after the patch is
>>> reading the same thing.
>>
>> No it isn't.
>> Before the patch it is passed the address of the 'next' field.  After the
>> patch it is passed the contents of the 'next' field.
>
> Here I meant "list_entry_rcu" (in include/linux/rculist.h) not the
> change to drivers/md/bitmap.c.
>
>
>>> However in your case, the change I proposed is probably wrong I trust
>>> you on this side. :) What's your proposal to fix it with the rculist patch?
>>
>> What needs fixing?  I don't see anything broken.
>>
>> Maybe there is something in this "rculist patch" that I'm missing.  Can you
>> point me at it?
>
> Do not apply the patch on drivers/md/bitmap.c but only on
> include/linux/rculist.h and you will see that the compilation fails.

Here an example of the compilation error in drivers/md/bitmap.c

In file included from include/linux/sched.h:17:0,
                  from include/linux/blkdev.h:4,
                  from drivers/md/bitmap.c:18:
drivers/md/bitmap.c: In function ‘next_active_rdev’:
include/linux/compiler.h:469:24: error: lvalue required as unary ‘&’ operand
   (volatile typeof(x) *)&(x); })
                         ^
include/linux/kernel.h:800:49: note: in definition of macro ‘container_of’
   const typeof( ((type *)0)->member ) *__mptr = (ptr); \
                                                  ^
include/linux/compiler.h:470:26: note: in expansion of macro ‘__ACCESS_ONCE’
  #define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
                           ^
include/linux/rcupdate.h:630:26: note: in expansion of macro ‘ACCESS_ONCE’
   typeof(p) _________p1 = ACCESS_ONCE(p); \
                           ^
include/linux/rcupdate.h:587:48: note: in expansion of macro 
‘lockless_dereference’
   typeof(*p) *________p1 = (typeof(*p) *__force)lockless_dereference(p); \
                                                 ^
include/linux/rcupdate.h:723:2: note: in expansion of macro 
‘__rcu_dereference_check’
   __rcu_dereference_check((p), rcu_read_lock_held() || (c), __rcu)
   ^
include/linux/rcupdate.h:746:32: note: in expansion of macro 
‘rcu_dereference_check’
  #define rcu_dereference_raw(p) rcu_dereference_check(p, 1) /*@@@ 
needed? @@@*/
                                 ^
include/linux/rculist.h:251:28: note: in expansion of macro 
‘rcu_dereference_raw’
   container_of((typeof(ptr))rcu_dereference_raw(ptr), type, member); \
                             ^
drivers/md/bitmap.c:184:10: note: in expansion of macro ‘list_entry_rcu’
    rdev = list_entry_rcu(&mddev->disks, struct md_rdev, same_set);
           ^

Thanks.
--
Pat

  reply	other threads:[~2015-05-18 19:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-12 22:46 [PATCH tip/core/rcu 0/4] RCU-protected list updates for 4.2 Paul E. McKenney
2015-05-12 22:46 ` [PATCH tip/core/rcu 1/4] rculist: Fix another sparse warning Paul E. McKenney
2015-05-12 22:46   ` [PATCH tip/core/rcu 2/4] rculist: Fix list_entry_rcu to read ptr with rcu_dereference_raw Paul E. McKenney
2015-05-12 22:46   ` [PATCH tip/core/rcu 3/4] md/bitmap: Fix list_entry_rcu usage Paul E. McKenney
2015-05-13  2:38     ` Steven Rostedt
2015-05-13  2:58       ` NeilBrown
2015-05-13 13:17         ` Paul E. McKenney
2015-05-16 17:42         ` Patrick Marlier
2015-05-18  2:06           ` NeilBrown
2015-05-18 13:43             ` Steven Rostedt
2015-05-19 22:07               ` Paul E. McKenney
2015-05-20  5:09                 ` NeilBrown
2015-05-20 13:28                   ` Paul E. McKenney
2015-05-21  0:07                     ` NeilBrown
2015-09-11 23:05                 ` Paul E. McKenney
2015-09-13 10:06                   ` Patrick Marlier
2015-09-13 16:10                     ` Paul E. McKenney
2015-09-22 20:50                       ` Paul E. McKenney
2015-09-23 17:57                         ` Patrick Marlier
2015-09-24  4:45                           ` Paul E. McKenney
2015-05-18 13:53             ` Patrick Marlier
2015-05-18 19:36               ` Patrick Marlier [this message]
2015-05-12 22:46   ` [PATCH tip/core/rcu 4/4] netfilter: " Paul E. McKenney
2015-05-13  2:42     ` Steven Rostedt

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=555A3F39.8020907@gmail.com \
    --to=patrick.marlier@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bobby.prani@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=dvhart@linux.intel.com \
    --cc=edumazet@google.com \
    --cc=fweisbec@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=neilb@suse.de \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=wangyun@linux.vnet.ibm.com \
    /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