Re: [PATCH v5 3/8] mm/slab: use call_rcu() in unknown context if irqs are enabled

From: Harry Yoo

Date: Mon Aug 03 2026 - 03:19:44 EST


On Thu, Jul 30, 2026 at 07:21:19PM +0800, hu.shengming@xxxxxxxxxx wrote:
> Harry wrote:
> > call_rcu() disables IRQs with local_irq_save() to protect its per-cpu
> > data structures. Therefore, if IRQs are not disabled, they cannot be
> > corrupted by reentrance into call_rcu(). So fall back to the deferred
> > path only when !allow_spin && irqs_disabled().
> >
> > The RCU subsystem does not guarantee this contractually, and this
> > optimization relies on RCU's implementation details. Ideally, it should
> > be removed once call_rcu_nolock() is supported by the RCU subsystem.
> >
> > Link: https://lore.kernel.org/linux-mm/CAADnVQKRVD5ZSnEKbZZU7w86gHbGHUug2pvzpgZTngNS+fg4rw@xxxxxxxxxxxxxx
> > Suggested-by: Alexei Starovoitov <ast@xxxxxxxxxx>
> > Signed-off-by: Harry Yoo (Oracle) <harry@xxxxxxxxxx>
> > ---
> > mm/slub.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 2c5ba8c326e7..bb0f2975c95b 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -6157,8 +6157,12 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)
> > if (likely(rcu_sheaf->size < s->sheaf_capacity)) {
> > rcu_sheaf = NULL;
> > } else {
> > - if (unlikely(!allow_spin)) {
> > - /* call_rcu() cannot be called in an unknown context */
> > + /*
> > + * With !allow_spin, we might have interrupted call_rcu()'s
> > + * IRQ-disabled critical section. If IRQs are not disabled,
> > + * we know that's not the case.
> > + */
> > + if (unlikely(!allow_spin && irqs_disabled())) {
>
> LGTM!
> Reviewed-by: Shengming Hu <hu.shengming@xxxxxxxxxx>

Thanks a lot, Shengming!

> I initially wondered whether in_nmi() should also be checked here.
> However, irqs_disabled() already covers the relevant reentrancy case,
> since call_rcu() disables IRQs while modifying its per-CPU data.

Exactly, that was my reasoning ;)

As a side note there is an attempt to do this in call_rcu() instead of
slab:

https://lore.kernel.org/all/20260729162207.1567770-1-puranjay@xxxxxxxxxx

Just FYI.

--
Cheers,
Harry / Hyeonggon