From: Harry Yoo <harry@kernel.org>
To: hu.shengming@zte.com.cn
Cc: vbabka@kernel.org, akpm@linux-foundation.org, hao.li@linux.dev,
cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev,
ast@kernel.org, andrii@kernel.org, puranjay@kernel.org,
ameryhung@gmail.com, bigeasy@linutronix.de,
clrkwllms@kernel.org, rostedt@goodmis.org, paulmck@kernel.org,
frederic@kernel.org, neeraj.upadhyay@kernel.org,
joelagnelf@nvidia.com, josh@joshtriplett.org, boqun@kernel.org,
urezki@gmail.com, mathieu.desnoyers@efficios.com,
jiangshanlai@gmail.com, qiang.zhang@linux.dev, pfalcato@suse.de,
surenb@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev,
rcu@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v5 3/8] mm/slab: use call_rcu() in unknown context if irqs are enabled
Date: Mon, 3 Aug 2026 07:19:32 +0000 [thread overview]
Message-ID: <anBAiTl_16H7NqEr@dev> (raw)
In-Reply-To: <20260730192119586UvhYMv4xrNqaZLKIJH9X0@zte.com.cn>
On Thu, Jul 30, 2026 at 07:21:19PM +0800, hu.shengming@zte.com.cn 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@mail.gmail.com
> > Suggested-by: Alexei Starovoitov <ast@kernel.org>
> > Signed-off-by: Harry Yoo (Oracle) <harry@kernel.org>
> > ---
> > 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@zte.com.cn>
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@kernel.org
Just FYI.
--
Cheers,
Harry / Hyeonggon
next prev parent reply other threads:[~2026-08-03 7:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 8:20 [PATCH v5 0/8] mm/slab: introduce kfree_rcu_nolock() and improve slub_kunit coverage Harry Yoo (Oracle)
2026-07-29 8:20 ` [PATCH v5 1/8] mm/slab, slub_kunit: register kprobe to trigger _nolock APIs Harry Yoo (Oracle)
2026-07-29 8:20 ` [PATCH v5 2/8] mm/slab: handle the !allow_spin case in kfree_rcu_sheaf() Harry Yoo (Oracle)
2026-07-30 11:10 ` hu.shengming
2026-07-29 8:20 ` [PATCH v5 3/8] mm/slab: use call_rcu() in unknown context if irqs are enabled Harry Yoo (Oracle)
2026-07-30 11:21 ` hu.shengming
2026-08-03 7:19 ` Harry Yoo [this message]
2026-08-03 8:41 ` hu.shengming
2026-08-03 15:30 ` Paul E. McKenney
2026-07-29 8:20 ` [PATCH v5 4/8] mm/slab: extend deferred free mechanism to handle rcu sheaves Harry Yoo (Oracle)
2026-07-29 8:20 ` [PATCH v5 5/8] mm/slab: allow kfree_rcu_sheaf() on PREEMPT_RT Harry Yoo (Oracle)
2026-07-29 8:20 ` [PATCH v5 6/8] mm/slab: introduce struct kvfree_rcu_head for kvfree_rcu batching Harry Yoo (Oracle)
2026-07-29 8:20 ` [PATCH v5 7/8] mm/slab: introduce kfree_rcu_nolock() Harry Yoo (Oracle)
2026-07-29 8:20 ` [PATCH v5 8/8] slub_kunit: extend the test for kfree_rcu_nolock() Harry Yoo (Oracle)
2026-07-29 14:14 ` [PATCH v5 0/8] mm/slab: introduce kfree_rcu_nolock() and improve slub_kunit coverage Vlastimil Babka (SUSE)
2026-07-30 3:08 ` Harry Yoo
2026-07-30 9:01 ` Vlastimil Babka (SUSE)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=anBAiTl_16H7NqEr@dev \
--to=harry@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cl@gentwo.org \
--cc=clrkwllms@kernel.org \
--cc=frederic@kernel.org \
--cc=hao.li@linux.dev \
--cc=hu.shengming@zte.com.cn \
--cc=jiangshanlai@gmail.com \
--cc=joelagnelf@nvidia.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=pfalcato@suse.de \
--cc=puranjay@kernel.org \
--cc=qiang.zhang@linux.dev \
--cc=rcu@vger.kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=surenb@google.com \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox