2014-06-06 18:46:12

by Paul E. McKenney

[permalink] [raw]
Subject: Re: rcu alignment warning tripping on m68k

On Fri, May 30, 2014 at 11:29:41AM +1000, Greg Ungerer wrote:
> On 29/05/14 23:11, One Thousand Gnomes wrote:
> > On Thu, 29 May 2014 12:08:32 +1000
> > Greg Ungerer <[email protected]> wrote:
> >
> >> Hi All,
> >>
> >> Inside kernel/rcy/tree.c in __call_rcu() it does an alignment check on
> >> the head pointer passed in. This trips on m68k systems, because they only
> >> need alignment of 32bit quantities to 16bit boundaries.
> >
> > __alignof perhaps ?
>
> That might do. Change then becomes something like:
>
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -2467,7 +2467,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_
> unsigned long flags;
> struct rcu_data *rdp;
>
> - WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
> + WARN_ON_ONCE((unsigned long)head & (__alignof__(head) - 1)); /* Misaligned rcu_head! */

Hmmm... The purpose of the check is to reserve the low-order bits to
allow RCU to classify callbacks as being time-critical or not. RCU
can probably live with a single bit, but if there is some architecture
out there that simply refuses to do alignment, I need to know about it.

(See "git show 0bb7b59d6e2b8" for more info.)

So how about this instead?

- WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */

(Trying to remember if I have seen Linux kernel code that uses both
the lower bits...)

Thanx, Paul

> if (debug_rcu_head_queue(head)) {
> /* Probable double call_rcu(), so leak the callback. */
> ACCESS_ONCE(head->func) = rcu_leak_callback;
>
> Thanks
> Greg
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>


2014-06-07 13:17:31

by Mikael Pettersson

[permalink] [raw]
Subject: Re: rcu alignment warning tripping on m68k

Paul E. McKenney writes:
> On Fri, May 30, 2014 at 11:29:41AM +1000, Greg Ungerer wrote:
> > On 29/05/14 23:11, One Thousand Gnomes wrote:
> > > On Thu, 29 May 2014 12:08:32 +1000
> > > Greg Ungerer <[email protected]> wrote:
> > >
> > >> Hi All,
> > >>
> > >> Inside kernel/rcy/tree.c in __call_rcu() it does an alignment check on
> > >> the head pointer passed in. This trips on m68k systems, because they only
> > >> need alignment of 32bit quantities to 16bit boundaries.
> > >
> > > __alignof perhaps ?
> >
> > That might do. Change then becomes something like:
> >
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -2467,7 +2467,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_
> > unsigned long flags;
> > struct rcu_data *rdp;
> >
> > - WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
> > + WARN_ON_ONCE((unsigned long)head & (__alignof__(head) - 1)); /* Misaligned rcu_head! */
>
> Hmmm... The purpose of the check is to reserve the low-order bits to
> allow RCU to classify callbacks as being time-critical or not. RCU
> can probably live with a single bit, but if there is some architecture
> out there that simply refuses to do alignment, I need to know about it.
>
> (See "git show 0bb7b59d6e2b8" for more info.)
>
> So how about this instead?
>
> - WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
>
> (Trying to remember if I have seen Linux kernel code that uses both
> the lower bits...)

As stated above, m68k-linux aligns to 16-bit boundaries by default, so you'd
get one bit but not necessarily more. If you want more free low bits, why
not attach an explicit attribute aligned to the rcu_head type declaration?

2014-06-09 15:24:29

by Paul E. McKenney

[permalink] [raw]
Subject: Re: rcu alignment warning tripping on m68k

On Sat, Jun 07, 2014 at 03:17:24PM +0200, Mikael Pettersson wrote:
> Paul E. McKenney writes:
> > On Fri, May 30, 2014 at 11:29:41AM +1000, Greg Ungerer wrote:
> > > On 29/05/14 23:11, One Thousand Gnomes wrote:
> > > > On Thu, 29 May 2014 12:08:32 +1000
> > > > Greg Ungerer <[email protected]> wrote:
> > > >
> > > >> Hi All,
> > > >>
> > > >> Inside kernel/rcy/tree.c in __call_rcu() it does an alignment check on
> > > >> the head pointer passed in. This trips on m68k systems, because they only
> > > >> need alignment of 32bit quantities to 16bit boundaries.
> > > >
> > > > __alignof perhaps ?
> > >
> > > That might do. Change then becomes something like:
> > >
> > > --- a/kernel/rcu/tree.c
> > > +++ b/kernel/rcu/tree.c
> > > @@ -2467,7 +2467,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_
> > > unsigned long flags;
> > > struct rcu_data *rdp;
> > >
> > > - WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
> > > + WARN_ON_ONCE((unsigned long)head & (__alignof__(head) - 1)); /* Misaligned rcu_head! */
> >
> > Hmmm... The purpose of the check is to reserve the low-order bits to
> > allow RCU to classify callbacks as being time-critical or not. RCU
> > can probably live with a single bit, but if there is some architecture
> > out there that simply refuses to do alignment, I need to know about it.
> >
> > (See "git show 0bb7b59d6e2b8" for more info.)
> >
> > So how about this instead?
> >
> > - WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
> >
> > (Trying to remember if I have seen Linux kernel code that uses both
> > the lower bits...)
>
> As stated above, m68k-linux aligns to 16-bit boundaries by default, so you'd
> get one bit but not necessarily more. If you want more free low bits, why
> not attach an explicit attribute aligned to the rcu_head type declaration?

One bit should do it for the time being, but yes, if I ever need two bits,
your suggestion of explicitly aligning the rcu_head type declaration
sounds like a very good one.

Thanx, Paul

2014-06-10 06:22:45

by Greg Ungerer

[permalink] [raw]
Subject: Re: rcu alignment warning tripping on m68k

Hi Paul,

On 07/06/14 04:46, Paul E. McKenney wrote:
> On Fri, May 30, 2014 at 11:29:41AM +1000, Greg Ungerer wrote:
>> On 29/05/14 23:11, One Thousand Gnomes wrote:
>>> On Thu, 29 May 2014 12:08:32 +1000
>>> Greg Ungerer <[email protected]> wrote:
>>>
>>>> Hi All,
>>>>
>>>> Inside kernel/rcy/tree.c in __call_rcu() it does an alignment check on
>>>> the head pointer passed in. This trips on m68k systems, because they only
>>>> need alignment of 32bit quantities to 16bit boundaries.
>>>
>>> __alignof perhaps ?
>>
>> That might do. Change then becomes something like:
>>
>> --- a/kernel/rcu/tree.c
>> +++ b/kernel/rcu/tree.c
>> @@ -2467,7 +2467,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_
>> unsigned long flags;
>> struct rcu_data *rdp;
>>
>> - WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
>> + WARN_ON_ONCE((unsigned long)head & (__alignof__(head) - 1)); /* Misaligned rcu_head! */
>
> Hmmm... The purpose of the check is to reserve the low-order bits to
> allow RCU to classify callbacks as being time-critical or not. RCU
> can probably live with a single bit, but if there is some architecture
> out there that simply refuses to do alignment, I need to know about it.

This change was prompted by this check tripping, so the alignment
issue is certainly real for m68k.

Regards
Greg


> (See "git show 0bb7b59d6e2b8" for more info.)
>
> So how about this instead?
>
> - WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
>
> (Trying to remember if I have seen Linux kernel code that uses both
> the lower bits...)
>
> Thanx, Paul
>
>> if (debug_rcu_head_queue(head)) {
>> /* Probable double call_rcu(), so leak the callback. */
>> ACCESS_ONCE(head->func) = rcu_leak_callback;
>>
>> Thanks
>> Greg
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>>
>
>