Re: [PATCH v5 2/8] mm/slab: handle the !allow_spin case in kfree_rcu_sheaf()
[email protected] Wed, 29 Jul 2026 08:44:34 +0000
| Newsgroups | dev.linux.lists.linux-rt-devel,org.kernel.vger.bpf,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your contribution! Sashiko AI review found 2 potential issue(= s) to consider: New issues: - [High] Kmemleak symmetry violation when a sheaf allocated with SLAB_ALLOC= _NOLOCK is freed with standard kfree(). Pre-existing issues: - [High] Lock recursion deadlock via kswapd wakeup from raw spinlock contex= t due to GFP_NOWAIT usage. -- --- Patch [2]: [PATCH v5 2/8] mm/slab: handle the !allow_spin case in kfree= _rcu_sheaf() --- commit 10fcb5282968708fbb08270a6618140198eda999 Author: Harry Yoo (Oracle) <[email protected]> mm/slab: handle the !allow_spin case in kfree_rcu_sheaf() This patch teaches kfree_rcu_sheaf() how to handle the !allow_spin case by introducing free_flags. It attempts to get an empty sheaf even when spinning is not allowed, translating free_flags to alloc_flags during allocation. It also ensures kfree_rcu_sheaf() fails when the RCU sheaf becomes full in an unknown context. Link: https://lore.kernel.org/linux-mm/872bd673-3d45-4111-8a41-31185db3ece5= @kernel.org > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 1e1d3feec3535..42db62f3e801a 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -1638,7 +1638,7 @@ static bool kfree_rcu_sheaf(void *obj) > =20 > s =3D slab->slab_cache; > if (likely(!IS_ENABLED(CONFIG_NUMA) || slab_nid(slab) =3D=3D numa_mem_i= d())) > - return __kfree_rcu_sheaf(s, obj); > + return __kfree_rcu_sheaf(s, obj, SLAB_FREE_DEFAULT); [Severity: High] This isn't a bug introduced by this patch, but does this unconditional use = of SLAB_FREE_DEFAULT here cause a lock recursion deadlock? Because SLAB_FREE_DEFAULT evaluates allow_spin to true, __kfree_rcu_sheaf() will use GFP_NOWAIT. GFP_NOWAIT includes __GFP_KSWAPD_RECLAIM, which can trigger wakeup_kswapd(). Since kfree_rcu() (via kvfree_call_rcu()) can be called while holding scheduler internal raw spinlocks like pi_lock, waking kswapd enters try_to_wake_up() which attempts to acquire pi_lock again, deadlocking the system. > =20 > return false; > } > diff --git a/mm/slub.c b/mm/slub.c > index d14226ad09822..2c5ba8c326e73 100644 > --- a/mm/slub.c > +++ b/mm/slub.c [ ... ] > -static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sh= eaf) > +static void __free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *= sheaf, > + unsigned int free_flags) > { [ ... ] > + if (unlikely(free_flags & SLAB_FREE_NOLOCK)) > + kfree_nolock(sheaf); > + else > + kfree(sheaf); > =20 > stat(s, SHEAF_FREE); > } > =20 > +static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sh= eaf) > +{ > + __free_empty_sheaf(s, sheaf, SLAB_FREE_DEFAULT); > +} [Severity: High] Does this wrapper cause a kmemleak symmetry violation? When __kfree_rcu_sheaf() is called with SLAB_FREE_NOLOCK, it allocates the sheaf using SLAB_ALLOC_NOLOCK, which skips kmemleak registration. However, the allocated sheaf struct does not track its allocation flags. Later, when this sheaf is flushed or processed for freeing (e.g., via rcu_free_sheaf()), free_empty_sheaf() is called unconditionally. Because free_empty_sheaf() hardcodes SLAB_FREE_DEFAULT, it will call kfree() instead of kfree_nolock() on an unregistered memory block. Could this lead to kmemleak warnings and false positive memory leaks due to freeing an unknown object? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260729-kfree_rcu_= [email protected]?part=3D2