From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Christoph Lameter <cl@linux.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
David Rientjes <rientjes@google.com>,
Pekka Enberg <penberg@kernel.org>,
Joel Fernandes <joel@joelfernandes.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
linux-mm@kvack.org, Matthew Wilcox <willy@infradead.org>,
paulmck@kernel.org, rcu@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] mm/slub: perform free consistency checks before call_rcu
Date: Mon, 29 Aug 2022 11:50:37 +0900 [thread overview]
Message-ID: <YwwpfVvsqEGUW96P@hyeyoo> (raw)
In-Reply-To: <20220826090912.11292-1-vbabka@suse.cz>
On Fri, Aug 26, 2022 at 11:09:11AM +0200, Vlastimil Babka wrote:
> For SLAB_TYPESAFE_BY_RCU caches we use call_rcu to perform empty slab
> freeing. The rcu callback rcu_free_slab() calls __free_slab() that
> currently includes checking the slab consistency for caches with
> SLAB_CONSISTENCY_CHECKS flags. This check needs the slab->objects field
> to be intact.
>
> Because in the next patch we want to allow rcu_head in struct slab to
> become larger in debug configurations and thus potentially overwrite
> more fields through a union than slab_list, we want to limit the fields
> used in rcu_free_slab(). Thus move the consistency checks to
> free_slab() before call_rcu(). This can be done safely even for
> SLAB_TYPESAFE_BY_RCU caches where accesses to the objects can still
> occur after freeing them.
>
> As a result, only the slab->slab_cache field has to be physically
> separate from rcu_head for the freeing callback to work. We also save
> some cycles in the rcu callback for caches with consistency checks
> enabled.
>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/slub.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 862dbd9af4f5..d86be1b0d09f 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2036,14 +2036,6 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
> int order = folio_order(folio);
> int pages = 1 << order;
>
> - if (kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS)) {
> - void *p;
> -
> - slab_pad_check(s, slab);
> - for_each_object(p, s, slab_address(slab), slab->objects)
> - check_object(s, slab, p, SLUB_RED_INACTIVE);
> - }
> -
> __slab_clear_pfmemalloc(slab);
> __folio_clear_slab(folio);
> folio->mapping = NULL;
> @@ -2062,9 +2054,17 @@ static void rcu_free_slab(struct rcu_head *h)
>
> static void free_slab(struct kmem_cache *s, struct slab *slab)
> {
> - if (unlikely(s->flags & SLAB_TYPESAFE_BY_RCU)) {
> + if (kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS)) {
> + void *p;
> +
> + slab_pad_check(s, slab);
> + for_each_object(p, s, slab_address(slab), slab->objects)
> + check_object(s, slab, p, SLUB_RED_INACTIVE);
> + }
> +
> + if (unlikely(s->flags & SLAB_TYPESAFE_BY_RCU))
> call_rcu(&slab->rcu_head, rcu_free_slab);
> - } else
> + else
> __free_slab(s, slab);
> }
So this allows corrupting 'counters' with patch 2.
The code looks still safe to me as we do only
redzone checking for SLAB_TYPESAFE_RCU caches.
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> --
> 2.37.2
>
--
Thanks,
Hyeonggon
prev parent reply other threads:[~2022-08-29 2:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 9:09 [RFC PATCH 1/2] mm/slub: perform free consistency checks before call_rcu Vlastimil Babka
2022-08-26 9:09 ` [RFC PATCH 2/2] mm/sl[au]b: rearrange struct slab fields to allow larger rcu_head Vlastimil Babka
2022-08-29 2:54 ` Hyeonggon Yoo
2022-09-01 9:55 ` Vlastimil Babka
2022-08-29 2:50 ` Hyeonggon Yoo [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=YwwpfVvsqEGUW96P@hyeyoo \
--to=42.hyeyoo@gmail.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=joel@joelfernandes.org \
--cc=linux-mm@kvack.org \
--cc=paulmck@kernel.org \
--cc=penberg@kernel.org \
--cc=rcu@vger.kernel.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 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.