linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
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 09:11:06 -0700	[thread overview]
Message-ID: <CAADnVQJ1AzEL6JD+ePBZctqmK6unYKDYKuARRwDBhNJ3CBykdw@mail.gmail.com> (raw)
In-Reply-To: <10d6dec4-665d-493f-97a9-2982dfbc1afe@suse.cz>

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()
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:

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 16:11 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 [this message]
2025-10-07 18:07     ` Vlastimil Babka
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=CAADnVQJ1AzEL6JD+ePBZctqmK6unYKDYKuARRwDBhNJ3CBykdw@mail.gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --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 \
    --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