mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hao Ge <hao.ge@linux.dev>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Harry Yoo <harry.yoo@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Suren Baghdasaryan <surenb@google.com>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Hao Ge <gehao@kylinos.cn>
Subject: Re: [PATCH v2] slab: Fix obj_ext is mistakenly considered NULL due to race condition
Date: Fri, 24 Oct 2025 18:06:09 +0800	[thread overview]
Message-ID: <123334B8-89A9-48C2-BBD9-A601E0395AB1@linux.dev> (raw)
In-Reply-To: <8b152d73-ecc4-415c-acdc-3f5105412ac0@suse.cz>

Hi Vlastimil


> On Oct 24, 2025, at 17:40, Vlastimil Babka <vbabka@suse.cz> wrote:
> 
> On 10/24/25 11:27, Hao Ge wrote:
>> Hi Harry
>> Hi Vlastimil
>> 
>> 
>> Thank you for adding V2 to your tree. Now, should I resubmit V3,
>> 
>> or can you assist with making these modifications in your tree?
> 
> Massaged it a bit more and now have this:
> 
> commit b4bdf6770cadb8bffcf3dce7ad7a346979f79ede
> Author: Hao Ge <gehao@kylinos.cn>
> Date:   Thu Oct 23 22:33:13 2025 +0800
> 
>    slab: Fix obj_ext mistakenly considered NULL due to race condition
> 
>    If two competing threads enter alloc_slab_obj_exts(), and the one that
>    allocates the vector wins the cmpxchg(), the other thread that failed
>    allocation mistakenly assumes that slab->obj_exts is still empty due to
>    its own allocation failure. This will then trigger warnings with
>    CONFIG_MEM_ALLOC_PROFILING_DEBUG checks in the subsequent free path.
> 
>    Therefore, let's check the result of cmpxchg() to see if marking the
>    allocation as failed was successful. If it wasn't, check whether the
>    winning side has succeeded its allocation (it might have been also
>    marking it as failed) and if yes, return success.
> 
>    Suggested-by: Harry Yoo <harry.yoo@oracle.com>
>    Signed-off-by: Hao Ge <gehao@kylinos.cn>
>    Link: https://patch.msgid.link/20251023143313.1327968-1-hao.ge@linux.dev
>    Reviewed-by: Suren Baghdasaryan <surenb@google.com>
>    Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
>    Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 87a1d2f9de0d..d4367f25b20d 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2052,9 +2052,9 @@ static inline void mark_objexts_empty(struct slabobj_ext *obj_exts)
>    }
> }
> 
> -static inline void mark_failed_objexts_alloc(struct slab *slab)
> +static inline bool mark_failed_objexts_alloc(struct slab *slab)
> {
> -    cmpxchg(&slab->obj_exts, 0, OBJEXTS_ALLOC_FAIL);
> +    return cmpxchg(&slab->obj_exts, 0, OBJEXTS_ALLOC_FAIL) == 0;
> }
> 
> static inline void handle_failed_objexts_alloc(unsigned long obj_exts,
> @@ -2076,7 +2076,7 @@ static inline void handle_failed_objexts_alloc(unsigned long obj_exts,
> #else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
> 
> static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) {}
> -static inline void mark_failed_objexts_alloc(struct slab *slab) {}
> +static inline bool mark_failed_objexts_alloc(struct slab *slab) { return false; }
> static inline void handle_failed_objexts_alloc(unsigned long obj_exts,
>            struct slabobj_ext *vec, unsigned int objects) {}
> 
> @@ -2124,8 +2124,14 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
>                   slab_nid(slab));
>    }
>    if (!vec) {
> -        /* Mark vectors which failed to allocate */
> -        mark_failed_objexts_alloc(slab);
> +        /*
> +         * Try to mark vectors which failed to allocate.
> +         * If this operation fails, there may be a racing process
> +         * that has already completed the allocation.
> +         */
> +        if (!mark_failed_objexts_alloc(slab) &&
> +            slab_obj_exts(slab))
> +            return 0;
> 
>        return -ENOMEM;
>    }
> 
Thank you very much for your help, 
and I sincerely apologize for the actual trouble I have caused you.

  reply	other threads:[~2025-10-24 10:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-23 14:33 Hao Ge
2025-10-23 16:33 ` Suren Baghdasaryan
2025-10-24  8:54 ` Harry Yoo
2025-10-24  9:27   ` Hao Ge
2025-10-24  9:39     ` Vlastimil Babka
2025-10-24 10:06       ` Hao Ge [this message]
2025-10-24 10:34         ` Vlastimil Babka

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=123334B8-89A9-48C2-BBD9-A601E0395AB1@linux.dev \
    --to=hao.ge@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=gehao@kylinos.cn \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.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

all inboxes | Powered by JetHome®