]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
mm: mempool: fix wake-up edge case bug for zero-minimum pools
authorYadan Fan <ydfan@suse.com>
Fri, 18 Jul 2025 22:06:51 +0000 (06:06 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 25 Jul 2025 02:12:38 +0000 (19:12 -0700)
commita5867a218d7ca15359e762fa067d867d738689e2
tree64feac193f8e78baa1f3c387c93bfa97cd662725
parent5631da56c9a87ea41d69d1bbbc1cee327eb9354b
mm: mempool: fix wake-up edge case bug for zero-minimum pools

The mempool wake-up path has a edge case bug that affects pools created
with min_nr=0.  When a thread blocks waiting for memory from an empty pool
(curr_nr == 0), subsequent mempool_free() calls fail to wake the waiting
thread because the condition "curr_nr < min_nr" evaluates to "0 < 0" which
is false, this can cause threads to sleep indefinitely according to the
code logic.

There is at least 2 places where the mempool created with min_nr=0:

1. lib/btree.c:191: mempool_create(0, btree_alloc, btree_free, NULL)
2. drivers/md/dm-verity-fec.c:791:
 mempool_init_slab_pool(&f->extra_pool, 0, f->cache)

Add an explicit check in mempool_free() to handle the min_nr=0 case: when
the pool has zero minimum reserves, is currently empty, and has active
waiters, allocate the element then wake up the sleeper.

Link: https://lkml.kernel.org/r/f28a81ba-615c-481e-86fb-c0bf4115ec89@suse.com
Signed-off-by: Yadan Fan <ydfan@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mempool.c