* [PATCH] workqueue: Fix alignment calculation in alloc_cwqs()
@ 2010-10-25 21:27 David Howells
2010-10-25 21:38 ` [Linux-am33-list] " David Howells
2010-10-25 21:43 ` Linus Torvalds
0 siblings, 2 replies; 4+ messages in thread
From: David Howells @ 2010-10-25 21:27 UTC (permalink / raw)
To: torvalds, akpm
Cc: Tejun Heo, linux-am33-list, linux-kernel, Akira Takeuchi,
Mark Salter
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.
Reported-by: Akira Takeuchi <takeuchi.akr@jp.panasonic.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Mark Salter <msalter@redhat.com>
cc: Tejun Heo <tj@kernel.org>
---
kernel/workqueue.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 30acdb7..e29ebd4 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2766,8 +2766,9 @@ static int alloc_cwqs(struct workqueue_struct *wq)
* unsigned long long.
*/
const size_t size = sizeof(struct cpu_workqueue_struct);
- const size_t align = max_t(size_t, 1 << WORK_STRUCT_FLAG_BITS,
- __alignof__(unsigned long long));
+ const size_t align =
+ max_t(size_t, 1 << (WORK_STRUCT_FLAG_BITS - BITS_PER_BYTE),
+ __alignof__(unsigned long long));
#ifdef CONFIG_SMP
bool percpu = !(wq->flags & WQ_UNBOUND);
#else
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Linux-am33-list] [PATCH] workqueue: Fix alignment calculation in alloc_cwqs()
2010-10-25 21:27 [PATCH] workqueue: Fix alignment calculation in alloc_cwqs() David Howells
@ 2010-10-25 21:38 ` David Howells
2010-10-25 21:43 ` Linus Torvalds
1 sibling, 0 replies; 4+ messages in thread
From: David Howells @ 2010-10-25 21:38 UTC (permalink / raw)
To: torvalds, akpm
Cc: dhowells, Tejun Heo, linux-am33-list, linux-kernel,
Akira Takeuchi, Mark Salter
David Howells <dhowells@redhat.com> wrote:
> + const size_t align =
> + max_t(size_t, 1 << (WORK_STRUCT_FLAG_BITS - BITS_PER_BYTE),
> + __alignof__(unsigned long long));
Actually, no, that's not right either. Need to subtract log2(BITS_PER_BYTE).
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] workqueue: Fix alignment calculation in alloc_cwqs()
2010-10-25 21:27 [PATCH] workqueue: Fix alignment calculation in alloc_cwqs() David Howells
2010-10-25 21:38 ` [Linux-am33-list] " David Howells
@ 2010-10-25 21:43 ` Linus Torvalds
2010-10-25 21:46 ` David Howells
1 sibling, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2010-10-25 21:43 UTC (permalink / raw)
To: David Howells
Cc: akpm, Tejun Heo, linux-am33-list, linux-kernel, Akira Takeuchi,
Mark Salter
On Mon, Oct 25, 2010 at 2:27 PM, David Howells <dhowells@redhat.com> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] workqueue: Fix alignment calculation in alloc_cwqs()
2010-10-25 21:43 ` Linus Torvalds
@ 2010-10-25 21:46 ` David Howells
0 siblings, 0 replies; 4+ messages in thread
From: David Howells @ 2010-10-25 21:46 UTC (permalink / raw)
To: Linus Torvalds
Cc: dhowells, akpm, Tejun Heo, linux-am33-list, linux-kernel,
Akira Takeuchi, Mark Salter
Linus Torvalds <torvalds@linux-foundation.org> wrote:
> 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.
That's a good point.
David
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-25 21:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-25 21:27 [PATCH] workqueue: Fix alignment calculation in alloc_cwqs() David Howells
2010-10-25 21:38 ` [Linux-am33-list] " David Howells
2010-10-25 21:43 ` Linus Torvalds
2010-10-25 21:46 ` David Howells
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox