summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Zhou <dennis@kernel.org>2019-02-21 15:54:11 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-06-15 11:54:59 +0200
commit4794604a68922b179c334a7a2e6942ffa2e6b893 (patch)
tree335f1c51844db49480d5bcd7f7ddb9f0596d396f
parent3e729a2c5a465fb3f295137020570269d96ee0d2 (diff)
downloadlinux-stable-4794604a68922b179c334a7a2e6942ffa2e6b893.tar.gz
linux-stable-4794604a68922b179c334a7a2e6942ffa2e6b893.tar.bz2
linux-stable-4794604a68922b179c334a7a2e6942ffa2e6b893.zip
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>
-rw-r--r--mm/percpu.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/mm/percpu.c b/mm/percpu.c
index bc58bcbe4b60..9beb84800d8d 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -984,7 +984,8 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits,
/*
* Search to find a fit.
*/
- end = start + alloc_bits + PCPU_BITMAP_BLOCK_BITS;
+ end = min_t(int, start + alloc_bits + PCPU_BITMAP_BLOCK_BITS,
+ pcpu_chunk_map_bits(chunk));
bit_off = bitmap_find_next_zero_area(chunk->alloc_map, end, start,
alloc_bits, align_mask);
if (bit_off >= end)