[PATCH v2 12/13] percpu: search the whole reserved chunk
From: Lorenzo Stoakes (ARM)
Date: Fri Nov 13 2026 - 16:47:56 EST
Loading a module with static percpu data can fail with -ENOMEM even
though the reserved chunk has a free area that fits the data.
pcpu_find_block_fit() does not scan the allocation bitmap, rather it
tests the request against hints, starting with the contig_hint of the
chunk, which describes its largest free area. If that area is too small
once aligned, the search gives up even if a smaller free area fits.
Consider:
request: 256 bytes, aligned to 256 bytes
contig_hint: 260 bytes, starts 4 bytes after a 256-byte boundary,
so 8 bytes remain after alignment
also free: 256 bytes, starts on a 256-byte boundary
Ordinarily this is fine as the allocator moves on to the next chunk or
creates a new one, but the static percpu data of modules can only come
from the reserved chunk.
Fix this by searching the allocation bitmap of the reserved chunk
directly rather than using hints.
Reported-by: Chris Mason <mason@xxxxxxxxxx>
Fixes: 13f966373f92 ("percpu: skip chunks if the alloc does not fit in the contig hint")
Fixes: b4c2116cfae6 ("percpu: update pcpu_find_block_fit to use an iterator")
Cc: stable@xxxxxxxxxxxxxxx
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
---
mm/percpu.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/mm/percpu.c b/mm/percpu.c
index dfd3ff0a1ac0..f87813e6ad73 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1771,8 +1771,11 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
if (reserved && pcpu_reserved_chunk) {
chunk = pcpu_reserved_chunk;
- off = pcpu_find_block_fit(chunk, bits, bit_align, is_atomic);
- if (off < 0) {
+ /* No other chunk to fall back on, so don't rely on hints. */
+ off = bitmap_find_next_zero_area(chunk->alloc_map,
+ pcpu_chunk_map_bits(chunk), 0,
+ bits, bit_align - 1);
+ if (off >= pcpu_chunk_map_bits(chunk)) {
err = "alloc from reserved chunk failed";
goto fail_unlock;
}
--
2.56.0