Re: [PATCH RFC 4/4] mm/slab: serialize defer_free_barrier()
From: Harry Yoo
Date: Tue Nov 03 2026 - 13:01:07 EST
On Fri, Jun 26, 2026 at 05:00:51PM +0200, Vlastimil Babka (SUSE) wrote:
> On 6/24/26 15:11, Harry Yoo (Oracle) wrote:
> > irq_work_sync() uses rcuwait instead of busy waiting in two cases:
> >
> > 1. The kernel is using PREEMPT_RT and the irq work does not run in a
> > hardirq context.
> >
> > 2. The architecture cannot send inter-processor interrupts to make
> > busy waiting reasonably short.
> >
> > However, rcuwait.h says:
> >> The caller is responsible for locking around rcuwait_wait_event(),
> >> and [prepare_to/finish]_rcuwait() such that writes to @task are
> >> properly serialized.
> >
> > Since defer_free_barrier() calls irq_work_sync() without any locks,
> > it can potentially cause a hang as writes to @task are not serialized.
> >
> > Fix this by calling defer_free_barrier() under slab_mutex and
> > cpus_read_lock() and add lockdep asserts.
> >
> > Now that defer_free_barrier() is called inside cpus_read_lock(), iterate
> > over online cpus instead of possible cpus.
> >
> > Reported-by: Sashiko <sashiko+bot@xxxxxxxxxx>
> > Closes: https://sashiko.dev/#/patchset/20260615-kfree_rcu_nolock-v3-0-70a54f3775bb%40kernel.org?part=5
> > Fixes: af92793e52c3 ("slab: Introduce kmalloc_nolock() and kfree_nolock().")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Harry Yoo (Oracle) <harry@xxxxxxxxxx>
>
> Acked-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
It was dropped as it now introduces a mutex.
(codetag_unload_module() invokes kvfree_rcu_barrier() ->
deferred_work_barrier() but doesn't have access to slab_mutex
so we can't reuse it.)
--
Cheers,
Harry / Hyeonggon