From: Harry Yoo <harry.yoo@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
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>,
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: Mon, 13 Oct 2025 09:21:24 +0900 [thread overview]
Message-ID: <aOxGBD1W23t4otkT@hyeyoo> (raw)
In-Reply-To: <e072aba0-6160-4485-93ed-3c3ae5abdc22@suse.cz>
On Tue, Oct 07, 2025 at 08:07:54PM +0200, Vlastimil Babka wrote:
> 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...
Looks good to me,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
--
Cheers,
Harry / Hyeonggon
prev parent reply other threads:[~2025-10-13 0:21 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
2025-10-13 0:21 ` Harry Yoo [this message]
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=aOxGBD1W23t4otkT@hyeyoo \
--to=harry.yoo@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=cl@gentwo.org \
--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 \
--cc=vbabka@suse.cz \
/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