Skip to content
This repository was archived by the owner on Oct 30, 2021. It is now read-only.

Commit 4794604

Browse files
dennisszhougregkh
authored andcommitted
percpu: do not search past bitmap when allocating an area
[ Upstream commit 8c43004af01635cc9fbb11031d070e5e0d327ef2 ] pcpu_find_block_fit() guarantees that a fit is found within PCPU_BITMAP_BLOCK_BITS. Iteration is used to determine the first fit as it compares against the block's contig_hint. This can lead to incorrectly scanning past the end of the bitmap. The behavior was okay given the check after for bit_off >= end and the correctness of the hints from pcpu_find_block_fit(). This patch fixes this by bounding the end offset by the number of bits in a chunk. Signed-off-by: Dennis Zhou <dennis@kernel.org> Reviewed-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3e729a2 commit 4794604

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/percpu.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,8 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits,
984984
/*
985985
* Search to find a fit.
986986
*/
987-
end = start + alloc_bits + PCPU_BITMAP_BLOCK_BITS;
987+
end = min_t(int, start + alloc_bits + PCPU_BITMAP_BLOCK_BITS,
988+
pcpu_chunk_map_bits(chunk));
988989
bit_off = bitmap_find_next_zero_area(chunk->alloc_map, end, start,
989990
alloc_bits, align_mask);
990991
if (bit_off >= end)

0 commit comments

Comments
 (0)