percpu: pcpu_embed_first_chunk() should free unused parts after all allocs are complete
authorTejun Heo <tj@kernel.org>
Fri, 27 Apr 2012 15:42:53 +0000 (08:42 -0700)
committerTejun Heo <tj@kernel.org>
Wed, 9 May 2012 17:08:16 +0000 (10:08 -0700)
commit42b64281453249dac52861f9b97d18552a7ec62b
tree1a9ca6f44ee7834c5b0a9757631534452b0fc3bd
parent789505b05752239d957dbfa84b183e0d7a641952
percpu: pcpu_embed_first_chunk() should free unused parts after all allocs are complete

pcpu_embed_first_chunk() allocates memory for each node, copies percpu
data and frees unused portions of it before proceeding to the next
group.  This assumes that allocations for different nodes doesn't
overlap; however, depending on memory topology, the bootmem allocator
may end up allocating memory from a different node than the requested
one which may overlap with the portion freed from one of the previous
percpu areas.  This leads to percpu groups for different nodes
overlapping which is a serious bug.

This patch separates out copy & partial free from the allocation loop
such that all allocations are complete before partial frees happen.

This also fixes overlapping frees which could happen on allocation
failure path - out_free_areas path frees whole groups but the groups
could have portions freed at that point.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org
Reported-by: "Pavel V. Panteleev" <pp_84@mail.ru>
Tested-by: "Pavel V. Panteleev" <pp_84@mail.ru>
LKML-Reference: <E1SNhwY-0007ui-V7.pp_84-mail-ru@f220.mail.ru>
mm/percpu.c