linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hao Li <hao.li@linux.dev>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Harry Yoo <harry.yoo@oracle.com>,
	Eric Dumazet <edumazet@google.com>,
	 Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	 Roman Gushchin <roman.gushchin@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 llvm@lists.linux.dev
Subject: Re: [PATCH] slab: replace cache_from_obj() with inline checks
Date: Tue, 20 Jan 2026 23:39:19 +0800	[thread overview]
Message-ID: <obrup5ejxuy42fpwmzczvo5ubyv62tocoqooqpxg3u5eq2i2sg@qpcialjznogf> (raw)
In-Reply-To: <efd02f1f-b09b-4786-aa55-aa366f58442f@suse.cz>

On Tue, Jan 20, 2026 at 03:01:23PM +0100, Vlastimil Babka wrote:
> On 1/20/26 14:56, Hao Li wrote:
> > On Tue, Jan 20, 2026 at 01:55:09PM +0100, Vlastimil Babka wrote:
> >> On 1/20/26 12:57, Hao Li wrote:
> >> 
> >> >> @@ -6774,11 +6770,21 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
> >> >>   */
> >> >>  void kmem_cache_free(struct kmem_cache *s, void *x)
> >> >>  {
> >> >> -	s = cache_from_obj(s, x);
> >> >> -	if (!s)
> >> >> -		return;
> >> >> +	struct slab *slab;
> >> >> +
> >> >> +	slab = virt_to_slab(x);
> >> >> +
> >> >> +	if (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) ||
> >> >> +	    kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS)) {
> >> >> +
> >> >> +		if (unlikely(!slab || (slab->slab_cache != s))) {
> >> >> +			warn_free_bad_obj(s, x);
> >> > 
> >> > Just to make sure I'm understanding correctly, are we intentionally not
> >> > releasing the object x in this case? Thanks.
> >> 
> >> Yes, it means something went wrong so it's better not to do anything.
> > 
> > Got it, that makes sense - thanks!
> > 
> >> That was true before this patch as well.
> > 
> > I'm still not entirely sure I follow. I read the original code, and it seems
> > like it retrieved the real cache from the object and released the object into
> > that correct cache. Did I misunderstand something?
> 
> You're right, I misread it as returning NULL, but that was only on
> virt_to_slab() failure. So that's a change, but I believe a proper one.

Yes, I agree - the current handling looks good to me.

> But I'll mention it in the changelog and the comment. Thanks!

Sounds great, thanks for taking care of that.

Reviewed-by: Hao Li <hao.li@linux.dev>

-- 
Thanks,
Hao


      reply	other threads:[~2026-01-20 15:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20  9:35 Vlastimil Babka
2026-01-20 11:05 ` Harry Yoo
2026-01-20 11:57 ` Hao Li
2026-01-20 12:55   ` Vlastimil Babka
2026-01-20 13:56     ` Hao Li
2026-01-20 14:01       ` Vlastimil Babka
2026-01-20 15:39         ` Hao Li [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=obrup5ejxuy42fpwmzczvo5ubyv62tocoqooqpxg3u5eq2i2sg@qpcialjznogf \
    --to=hao.li@linux.dev \
    --cc=cl@gentwo.org \
    --cc=edumazet@google.com \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=llvm@lists.linux.dev \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --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