1 From 98506788746933b7d1212684fc42e9798651d943 Mon Sep 17 00:00:00 2001
2 From: Dennis Zhou <dennis@kernel.org>
3 Date: Thu, 21 Feb 2019 15:54:11 -0800
4 Subject: percpu: do not search past bitmap when allocating an area
6 [ Upstream commit 8c43004af01635cc9fbb11031d070e5e0d327ef2 ]
8 pcpu_find_block_fit() guarantees that a fit is found within
9 PCPU_BITMAP_BLOCK_BITS. Iteration is used to determine the first fit as
10 it compares against the block's contig_hint. This can lead to
11 incorrectly scanning past the end of the bitmap. The behavior was okay
12 given the check after for bit_off >= end and the correctness of the
13 hints from pcpu_find_block_fit().
15 This patch fixes this by bounding the end offset by the number of bits
18 Signed-off-by: Dennis Zhou <dennis@kernel.org>
19 Reviewed-by: Peng Fan <peng.fan@nxp.com>
20 Signed-off-by: Sasha Levin <sashal@kernel.org>
23 1 file changed, 2 insertions(+), 1 deletion(-)
25 diff --git a/mm/percpu.c b/mm/percpu.c
26 index c66149ce1fe6..ff76fa0b7528 100644
29 @@ -988,7 +988,8 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits,
31 * Search to find a fit.
33 - end = start + alloc_bits + PCPU_BITMAP_BLOCK_BITS;
34 + end = min_t(int, start + alloc_bits + PCPU_BITMAP_BLOCK_BITS,
35 + pcpu_chunk_map_bits(chunk));
36 bit_off = bitmap_find_next_zero_area(chunk->alloc_map, end, start,
37 alloc_bits, align_mask);