mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harry Yoo <harry@kernel.org>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org, linux-rt-devel@lists.linux.dev,
	linux-kernel@vger.kernel.org, hao.li@linux.dev
Subject: Re: [PATCH slab/for-next v4 5/8] mm/slab: allow kfree_rcu_sheaf() on PREEMPT_RT
Date: Thu, 23 Jul 2026 19:02:40 +0900	[thread overview]
Message-ID: <60c1dbf3-3212-40f9-90c9-56aefdea5f1a@kernel.org> (raw)
In-Reply-To: <a8dc9a6b-a08c-426a-9a92-30a4014e2446@kernel.org>



On 7/23/26 6:46 PM, Vlastimil Babka (SUSE) wrote:
> On 7/23/26 07:39, Harry Yoo wrote:
>> On 7/20/26 9:56 PM, sashiko-bot@kernel.org wrote:
>>>
>>>> diff --git a/mm/slub.c b/mm/slub.c
>>>> index 8afa6b47b1f2b..deac315d0f23e 100644
>>>> --- a/mm/slub.c
>>>> +++ b/mm/slub.c
>>> [ ... ]
>>>> @@ -6080,10 +6081,10 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)
>>>>  	struct slab_sheaf *rcu_sheaf;
>>>>  	bool allow_spin = free_flags_allow_spinning(free_flags);
>>>>  
>>>> -	if (WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT)))
>>>> -		return false;
>>>> +	VM_WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT) && allow_spin);
>>>>  
>>>> -	lock_map_acquire_try(&kfree_rcu_sheaf_map);
>>>> +	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
>>>> +		lock_map_acquire_try(&kfree_rcu_sheaf_map);
>>>>  
>>>>  	if (!local_trylock(&s->cpu_sheaves->lock))
>>>              ^^^^^^^^^^^^^
>>> [Severity: High]
>>> This is a pre-existing issue, but since we are enabling this path for
>>> PREEMPT_RT, does the use of GFP_NOWAIT later in this function cause
>>> lock recursion deadlocks?
>>>
>>> When the fast path fails, __kfree_rcu_sheaf() calls:
>>>
>>>     empty = alloc_empty_sheaf(s, GFP_NOWAIT, alloc_flags);
>>>
>>> GFP_NOWAIT includes __GFP_KSWAPD_RECLAIM, which invokes wakeup_kswapd().
>>> The wake-up path enters the scheduler via try_to_wake_up() and attempts to
>>> acquire scheduler locks like pi_lock and the runqueue lock.
>>
>> This indeed looks like a real issue as kfree_rcu() can be called under
>> scheduler locks,
> 
> Are there any paths that actually do that?

in kernel/sched/core.c:

	/*
	 * Because this is called with p->pi_lock held, it is not possible
	 * to use kfree() here (when PREEMPT_RT=y), therefore punt to using
	 * kfree_rcu().
	 */
	kfree_rcu((union cpumask_rcuhead *)ac.user_mask, rcu);

...and try_to_wake_up acquires pi_lock.

So I'm bit puzzled :)

>> but not sure how it's been undiscovered for this long?
> 
> With kfree_rcu_sheaf_map we prevent the raw spinlock nesting detection in
> general.

Yeah. It only overrides wait type (and tell lockdep
that it is okay to acquire a spinlock, although we're holding a raw
spinlock).

> But I guess if there was an actual kfree_rcu() call under any
> scheduler lock involved in wakeup_kswapd(), lockdep would still trigger, right?

I was assuming so, but there is one!

...I guess we should look at when the path is executed.

>>> If kvfree_call_rcu() was called while the CPU already holds these scheduler
>>> locks, will this wake-up attempt cause a lock recursion self-deadlock?

-- 
Cheers,
Harry / Hyeonggon

  reply	other threads:[~2026-07-23 10:02 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 12:44 [PATCH slab/for-next v4 0/8] mm/slab: introduce kfree_rcu_nolock() and improve slub_kunit coverage Harry Yoo (Oracle)
2026-07-20 12:44 ` [PATCH slab/for-next v4 1/8] mm/slab, slub_kunit: register kprobe to trigger _nolock APIs Harry Yoo (Oracle)
2026-07-20 12:56   ` sashiko-bot
2026-07-22  3:27   ` hu.shengming
2026-07-22  7:16     ` Harry Yoo
2026-07-22  8:32       ` hu.shengming
2026-07-20 12:44 ` [PATCH slab/for-next v4 2/8] mm/slab: handle the !allow_spin case in kfree_rcu_sheaf() Harry Yoo (Oracle)
2026-07-20 13:11   ` sashiko-bot
2026-07-21 10:07   ` Vlastimil Babka (SUSE)
2026-07-22  7:28     ` Harry Yoo
2026-07-22  7:37       ` Vlastimil Babka (SUSE)
2026-07-22  7:39         ` Harry Yoo
2026-07-20 12:44 ` [PATCH slab/for-next v4 3/8] mm/slab: use call_rcu() in unknown context if irqs are enabled Harry Yoo (Oracle)
2026-07-20 13:01   ` sashiko-bot
2026-07-20 12:44 ` [PATCH slab/for-next v4 4/8] mm/slab: extend deferred free mechanism to handle rcu sheaves Harry Yoo (Oracle)
2026-07-20 13:03   ` sashiko-bot
2026-07-23 10:27   ` hu.shengming
2026-07-24 11:42     ` Harry Yoo
2026-07-24 14:10       ` hu.shengming
2026-07-20 12:44 ` [PATCH slab/for-next v4 5/8] mm/slab: allow kfree_rcu_sheaf() on PREEMPT_RT Harry Yoo (Oracle)
2026-07-20 12:56   ` sashiko-bot
2026-07-23  5:39     ` Harry Yoo
2026-07-23  9:46       ` Vlastimil Babka (SUSE)
2026-07-23 10:02         ` Harry Yoo [this message]
2026-07-21 10:46   ` Vlastimil Babka (SUSE)
2026-07-22  7:41     ` Harry Yoo
2026-07-20 12:44 ` [PATCH slab/for-next v4 6/8] mm/slab: introduce struct kvfree_rcu_head for kvfree_rcu batching Harry Yoo (Oracle)
2026-07-20 13:09   ` sashiko-bot
2026-07-21 11:06   ` Vlastimil Babka (SUSE)
2026-07-22  7:42     ` Harry Yoo
2026-07-20 12:44 ` [PATCH slab/for-next v4 7/8] mm/slab: introduce kfree_rcu_nolock() Harry Yoo (Oracle)
2026-07-20 13:07   ` sashiko-bot
2026-07-21 13:09   ` Vlastimil Babka (SUSE)
2026-07-22  8:15     ` Harry Yoo
2026-07-22 10:05       ` Vlastimil Babka (SUSE)
2026-07-22 13:03         ` Harry Yoo
2026-07-20 12:44 ` [PATCH slab/for-next v4 8/8] slub_kunit: extend the test for kfree_rcu_nolock() Harry Yoo (Oracle)

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=60c1dbf3-3212-40f9-90c9-56aefdea5f1a@kernel.org \
    --to=harry@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hao.li@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --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

all inboxes | Powered by JetHome®