All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harry Yoo <harry@kernel.org>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	 Roman Gushchin <roman.gushchin@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	 Muchun Song <muchun.song@linux.dev>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
	 David Rientjes <rientjes@google.com>,
	Alexei Starovoitov <ast@kernel.org>,
	 Pedro Falcato <pfalcato@suse.de>,
	cgroups@vger.kernel.org, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH RFC 2/4] mm/slab: handle allow_spin in slab_free_hook() instead of open coding
Date: Tue, 3 Nov 2026 14:58:25 +0000	[thread overview]
Message-ID: <aun1uxYrS0imczik@thinkstation> (raw)
In-Reply-To: <91776136-ecaf-4687-be63-a2c074435462@kernel.org>

Apologies for the late reply...

On Fri, Jun 26, 2026 at 04:41:22PM +0200, Vlastimil Babka (SUSE) wrote:
> On 6/24/26 15:11, Harry Yoo (Oracle) wrote:
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 32672a92581b..85760c8ff2e2 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -2611,41 +2611,52 @@ struct rcu_delayed_free {
> >   * - memcg_slab_post_alloc_hook()
> >   * - alloc_tagging_slab_alloc_hook()
> >   *
> > + * slab_free_hook() assumes that memcg_slab_free_hook() and
> > + * alloc_tagging_slab_free_hook() are already invoked.
> > + *
> >   * Free hooks that must handle missing corresponding alloc hooks:
> >   * - kmemleak_free_recursive()
> >   * - kfence_free()
> >   *
> > - * Free hooks that have no alloc hook counterpart, and thus safe to call:
> > + * Free hooks that have no alloc hook counterpart, and thus safe to call
> > + * when spinning is allowed:
> >   * - debug_check_no_locks_freed()
> >   * - debug_check_no_obj_freed()
> >   * - __kcsan_check_access()
> >   */
> >  static __always_inline
> >  bool slab_free_hook(struct kmem_cache *s, void *x, bool init,
> > -		    bool after_rcu_delay)
> > +		    bool after_rcu_delay, bool allow_spin)
> >  {
> >  	/* Are the object contents still accessible? */
> >  	bool still_accessible = (s->flags & SLAB_TYPESAFE_BY_RCU) && !after_rcu_delay;
> >  
> > -	kmemleak_free_recursive(x, s->flags);
> >  	kmsan_slab_free(s, x);
> >  
> > -	debug_check_no_locks_freed(x, s->object_size);
> > -
> > -	if (!(s->flags & SLAB_DEBUG_OBJECTS))
> > -		debug_check_no_obj_freed(x, s->object_size);
> > -
> > -	/* Use KCSAN to help debug racy use-after-free. */
> > -	if (!still_accessible)
> > -		__kcsan_check_access(x, s->object_size,
> > -				     KCSAN_ACCESS_WRITE | KCSAN_ACCESS_ASSERT);
> > -
> > -	if (kfence_free(x))
> > -		return false;
> > +	if (likely(allow_spin)) {
> > +		/* These hooks acquire spinlocks */
> > +		kmemleak_free_recursive(x, s->flags);
> > +		debug_check_no_locks_freed(x, s->object_size);
> 
> This line shouldn't be here?

You mean because debug_check_no_locks_freed() doesn't acquire a lock
when there is no bug to report?

That's fair, but I didn't want to introduce functional changes
in this patch as kfree_nolock() hasn't been calling it anyway.

So separated this (and KCSAN checks) to patch 3 in v2 as they only
acquire locks when reporting a bug. (Taking risk of deadlock for bug
reporting just like KASAN).

> > +		if (!(s->flags & SLAB_DEBUG_OBJECTS))
> > +			debug_check_no_obj_freed(x, s->object_size);
> > +		/* Use KCSAN to help debug racy use-after-free. */
> > +		if (!still_accessible)
> > +			__kcsan_check_access(x, s->object_size,
> > +					     KCSAN_ACCESS_WRITE | KCSAN_ACCESS_ASSERT);
> > +		if (kfence_free(x))
> > +			return false;
> 
> The whole block now misses free space lines that it had.

Adjusted in v2, thanks!

-- 
Cheers,
Harry / Hyeonggon

  reply	other threads:[~2026-11-03 14:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24 13:11 [PATCH RFC 0/4] memcg,slab: kmalloc_nolock() fixes Harry Yoo (Oracle)
2026-06-24 13:11 ` [PATCH RFC 1/4] mm/memcontrol: do not drain objcg stock when spinning is not allowed Harry Yoo (Oracle)
2026-06-24 13:28   ` sashiko-bot
2026-06-26 14:30   ` Vlastimil Babka (SUSE)
2026-11-03 14:54     ` Harry Yoo
2026-06-24 13:11 ` [PATCH RFC 2/4] mm/slab: handle allow_spin in slab_free_hook() instead of open coding Harry Yoo (Oracle)
2026-06-24 13:24   ` sashiko-bot
2026-06-26 14:41   ` Vlastimil Babka (SUSE)
2026-11-03 14:58     ` Harry Yoo [this message]
2026-06-24 13:11 ` [PATCH RFC 3/4] mm/slab: fix a deadlock in memcg_alloc_abort_single() Harry Yoo (Oracle)
2026-06-26 14:57   ` Vlastimil Babka (SUSE)
2026-06-24 13:11 ` [PATCH RFC 4/4] mm/slab: serialize defer_free_barrier() Harry Yoo (Oracle)
2026-06-24 13:25   ` sashiko-bot
2026-06-26 15:00   ` Vlastimil Babka (SUSE)
2026-11-03 14:51     ` Harry Yoo
2026-06-24 16:30 ` [PATCH RFC 0/4] memcg,slab: kmalloc_nolock() fixes Alexei Starovoitov
2026-06-24 20:19   ` Harry Yoo
2026-06-26 15:09     ` Vlastimil Babka (SUSE)
2026-06-26  6:04 ` Harry Yoo
2026-06-26 15:10   ` 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=aun1uxYrS0imczik@thinkstation \
    --to=harry@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=cl@gentwo.org \
    --cc=hannes@cmpxchg.org \
    --cc=hao.li@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=pfalcato@suse.de \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.