Skip to content

Commit

Permalink
percpu: allocation size should be even
Browse files Browse the repository at this point in the history
723ad1d ("percpu: store offsets instead of lengths in ->map[]")
updated percpu area allocator to use the lowest bit, instead of sign,
to signify whether the area is occupied and forced min align to 2;
unfortunately, it forgot to force the allocation size to be even
causing malfunctions for the very rare odd-sized allocations.

Always force the allocations to be even sized.

tj: Wrote patch description.

Original-patch-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Viro authored and htejun committed Mar 17, 2014
1 parent 3d331ad commit 2f69fa8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mm/percpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,14 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved)

/*
* We want the lowest bit of offset available for in-use/free
* indicator.
* indicator, so force >= 16bit alignment and make size even.
*/
if (unlikely(align < 2))
align = 2;

if (unlikely(size & 1))
size++;

if (unlikely(!size || size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE)) {
WARN(true, "illegal size (%zu) or align (%zu) for "
"percpu allocation\n", size, align);
Expand Down

0 comments on commit 2f69fa8

Please sign in to comment.