]> git.ipfire.org Git - thirdparty/linux.git/commit
mm/slab: allow freeing kmalloc_nolock()'d objects using kfree[_rcu]()
authorHarry Yoo <harry.yoo@oracle.com>
Tue, 10 Feb 2026 04:46:41 +0000 (13:46 +0900)
committerVlastimil Babka <vbabka@suse.cz>
Tue, 10 Feb 2026 10:39:30 +0000 (11:39 +0100)
commitc4d6d7829817f762dfdce829ffd0c14ea3bad7fe
treecdd24f838ce215529cebdc1f77716a1c9989bdc2
parenta1e244a9f177894969c6cd5ebbc6d72c19fc4a7a
mm/slab: allow freeing kmalloc_nolock()'d objects using kfree[_rcu]()

Slab objects that are allocated with kmalloc_nolock() must be freed
using kfree_nolock() because only a subset of alloc hooks are called,
since kmalloc_nolock() can't spin on a lock during allocation.

This imposes a limitation: such objects cannot be freed with kfree_rcu(),
forcing users to work around this limitation by calling call_rcu()
with a callback that frees the object using kfree_nolock().

Remove this limitation by teaching kmemleak to gracefully ignore cases
when kmemleak_free() or kmemleak_ignore() is called without a prior
kmemleak_alloc().

Unlike kmemleak, kfence already handles this case, because,
due to its design, only a subset of allocations are served from kfence.

With this change, kfree() and kfree_rcu() can be used to free objects
that are allocated using kmalloc_nolock().

Suggested-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
Link: https://patch.msgid.link/20260210044642.139482-2-harry.yoo@oracle.com
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
include/linux/rcupdate.h
mm/kmemleak.c
mm/slub.c