From: Harry Yoo <harry.yoo@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 5/6] slab: validate slab before using it in alloc_single_from_partial()
Date: Mon, 15 Sep 2025 23:25:11 +0900 [thread overview]
Message-ID: <aMghx7WTJP9NHoNe@hyeyoo> (raw)
In-Reply-To: <20250915-slub-slab-validation-v2-5-314690fc1532@suse.cz>
On Mon, Sep 15, 2025 at 03:55:12PM +0200, Vlastimil Babka wrote:
> We touch slab->freelist and slab->inuse before checking the slab pointer
> is actually sane. Do that validation first, which will be safer. We can
> thus also remove the check from alloc_debug_processing().
>
> This adds a new "s->flags & SLAB_CONSISTENCY_CHECKS" test but
> alloc_single_from_partial() is only called for caches with debugging
> enabled so it's acceptable.
>
> In alloc_single_from_new_slab() we just created the struct slab and call
> alloc_debug_processing() to mainly set up redzones, tracking etc, while
> not really expecting the consistency checks to fail. Thus don't validate
> it there.
>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/slub.c | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 12ad42f3d2e066b02340f2c30a85422583af3c5d..e5b53d1debddd3fe0f941f579a1043a5b976e50b 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -821,6 +821,8 @@ static inline unsigned int get_orig_size(struct kmem_cache *s, void *object)
> return *(unsigned int *)p;
> }
>
> +#ifdef CONFIG_SLUB_DEBUG
> +
> /*
> * For debugging context when we want to check if the struct slab pointer
> * appears to be valid.
> @@ -830,7 +832,6 @@ static inline bool validate_slab_ptr(struct slab *slab)
> return PageSlab(slab_page(slab));
> }
>
> -#ifdef CONFIG_SLUB_DEBUG
> static unsigned long object_map[BITS_TO_LONGS(MAX_OBJS_PER_PAGE)];
> static DEFINE_SPINLOCK(object_map_lock);
>
> @@ -1651,11 +1652,6 @@ static noinline bool alloc_debug_processing(struct kmem_cache *s,
> struct slab *slab, void *object, int orig_size)
> {
> if (s->flags & SLAB_CONSISTENCY_CHECKS) {
> - if (!validate_slab_ptr(slab)) {
> - slab_err(s, slab, "Not a valid slab page");
> - return false;
> - }
> -
> if (!alloc_consistency_checks(s, slab, object))
> goto bad;
> }
> @@ -2825,13 +2821,21 @@ static void *alloc_single_from_partial(struct kmem_cache *s,
>
> lockdep_assert_held(&n->list_lock);
>
> +#ifdef SLUB_DEBUG
I'm sure you meant CONFIG_SLUB_DEBUG ;)
With that adjusted, looks good to me,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
> + if (s->flags & SLAB_CONSISTENCY_CHECKS) {
> + if (!validate_slab_ptr(slab)) {
> + slab_err(s, slab, "Not a valid slab page");
> + return NULL;
> + }
> + }
> +#endif
> +
> object = slab->freelist;
> slab->freelist = get_freepointer(s, object);
> slab->inuse++;
>
> if (!alloc_debug_processing(s, slab, object, orig_size)) {
> - if (validate_slab_ptr(slab))
> - remove_partial(n, slab);
> + remove_partial(n, slab);
> return NULL;
> }
--
Cheers,
Harry / Hyeonggon
next prev parent reply other threads:[~2025-09-15 14:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 13:55 [PATCH v2 0/6] slab: struct slab pointer validation improvements Vlastimil Babka
2025-09-15 13:55 ` [PATCH v2 1/6] slab: Remove dead code in free_consistency_checks() Vlastimil Babka
2025-09-15 13:55 ` [PATCH v2 2/6] slab: wrap debug slab validation in validate_slab_ptr() Vlastimil Babka
2025-09-15 13:55 ` [PATCH v2 3/6] slab: move validate_slab_ptr() from check_slab() to its callers Vlastimil Babka
2025-09-15 13:55 ` [PATCH v2 4/6] slab: move validate_slab_ptr() from alloc_consistency_checks() to its caller Vlastimil Babka
2025-09-15 13:55 ` [PATCH v2 5/6] slab: validate slab before using it in alloc_single_from_partial() Vlastimil Babka
2025-09-15 14:25 ` Harry Yoo [this message]
2025-09-15 14:48 ` Vlastimil Babka
2025-09-15 13:55 ` [PATCH v2 6/6] slab: don't validate slab pointer in free_debug_processing() 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=aMghx7WTJP9NHoNe@hyeyoo \
--to=harry.yoo@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@suse.cz \
--cc=willy@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox