Re: [PATCH] workqueue: Fix alignment calculation in alloc_cwqs()

From: Linus Torvalds
Date: Mon Oct 25 2010 - 17:44:28 EST


On Mon, Oct 25, 2010 at 2:27 PM, David Howells <dhowells@xxxxxxxxxx> wrote:
> In the MN10300 arch, we occasionally see an assertion being tripped in
> alloc_cwqs() at the following line:
>
>        /* just in case, make sure it's actually aligned */
>  --->  BUG_ON(!IS_ALIGNED(wq->cpu_wq.v, align));
>        return wq->cpu_wq.v ? 0 : -ENOMEM;
>
> The values are:
>
>        wa->cpu_wq.v => 0x902776e0
>        align => 0x100
>
> and align is calculated by the following:
>
>        const size_t align = max_t(size_t, 1 << WORK_STRUCT_FLAG_BITS,
>                                   __alignof__(unsigned long long));
>
> which is wrong.  __alignof__() returns its value in bytes, but:
>
>        1 << WORK_STRUCT_FLAG_BITS
>
> returns the value in bits.  It needs dividing by the number of bits in a byte.

No it doesn't. Those bits really require that many bytes of alignment.

Think about it: if the low 8 bits of the pointer are used for flags,
then the actual pointer itself needs to be aligned to a 256-byte
boundary.

So the code is right. If needs to ask for "1 << WORK_STRUCT_FLAG_BITS"
alignment, and if it doesn't get it (because the allocator is somehow
broken - percpu allocator issues?), things will break.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/