linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Harry Yoo <harry.yoo@oracle.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Kuniyuki Iwashima <kuni1840@gmail.com>,
	linux-mm <linux-mm@kvack.org>,
	syzbot+a6f4d69b9b23404bbabf@syzkaller.appspotmail.com
Subject: Re: [PATCH] slub: Don't call lockdep_unregister_key() for immature kmem_cache.
Date: Tue, 7 Oct 2025 20:07:54 +0200	[thread overview]
Message-ID: <e072aba0-6160-4485-93ed-3c3ae5abdc22@suse.cz> (raw)
In-Reply-To: <CAADnVQJ1AzEL6JD+ePBZctqmK6unYKDYKuARRwDBhNJ3CBykdw@mail.gmail.com>

On 10/7/25 18:11, Alexei Starovoitov wrote:
> On Tue, Oct 7, 2025 at 12:46 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>>
>> On 10/7/25 07:25, Kuniyuki Iwashima wrote:
>> > syzbot reported the lockdep splat below in __kmem_cache_release(). [0]
>> >
>> > The problem is that __kmem_cache_release() could be called from
>> > do_kmem_cache_create() before init_kmem_cache_cpus() registers
>> > the lockdep key.
> 
> Hmm. If that's the case then alloc_kmem_cache_cpus() wasn't called yet
> and s->cpu_slab == NULL, so any kmalloc/kmem_cache_alloc from
> that slub will crash. The above sounds like it's a race condition,
> but it's not. It's a weird error path in do_kmem_cache_create()

Indeed.

> due to syzbot pressure.
> So the fix isn't quite right.
> There is no need to sprinkle #ifdef all over the code.
> 
>> >
>> > Let's move lockdep_unregister_key() from __kmem_cache_release()
>> > to slab_kmem_cache_release() and do_kmem_cache_create().
> 
> I wouldn't.
> 
>> Thanks, added to slab/for-next-fixes
> 
> The following is imo much cleaner fix:

Yes much better, I'm changing it. Thanks!
> diff --git a/mm/slub.c b/mm/slub.c
> index 584a5ff1828b..0a1fbddb77f8 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -7693,7 +7693,8 @@ void __kmem_cache_release(struct kmem_cache *s)
>                 pcs_destroy(s);
>  #ifndef CONFIG_SLUB_TINY
>  #ifdef CONFIG_PREEMPT_RT
> -       lockdep_unregister_key(&s->lock_key);
> +       if (s->cpu_slab)
> +               lockdep_unregister_key(&s->lock_key);
>  #endif
>         free_percpu(s->cpu_slab);
>  #endif
> 
> compile tested only...



  reply	other threads:[~2025-10-07 18:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  5:25 Kuniyuki Iwashima
2025-10-07  7:46 ` Vlastimil Babka
2025-10-07 16:11   ` Alexei Starovoitov
2025-10-07 18:07     ` Vlastimil Babka [this message]
2025-10-13  0:21       ` Harry Yoo

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=e072aba0-6160-4485-93ed-3c3ae5abdc22@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=cl@gentwo.org \
    --cc=harry.yoo@oracle.com \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@google.com \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=syzbot+a6f4d69b9b23404bbabf@syzkaller.appspotmail.com \
    /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