From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: David Rientjes <rientjes@google.com>,
Christoph Lameter <cl@linux.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Pekka Enberg <penberg@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, patches@lists.linux.dev,
linux-kernel@vger.kernel.org, Oliver Glitta <glittao@gmail.com>,
Faiyaz Mohammed <faiyazm@codeaurora.org>,
Dmitry Vyukov <dvyukov@google.com>,
Eric Dumazet <edumazet@google.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
Johannes Berg <johannes.berg@intel.com>,
Yury Norov <yury.norov@gmail.com>, Arnd Bergmann <arnd@arndb.de>,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Matteo Croce <mcroce@microsoft.com>,
Marco Elver <elver@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Imran Khan <imran.f.khan@oracle.com>,
Zqiang <qiang.zhang@windriver.com>
Subject: Re: [PATCH v2] mm/slub: initialize stack depot in boot process
Date: Tue, 1 Mar 2022 03:53:06 +0000 [thread overview]
Message-ID: <Yh2YoqGwfwwpiFOJ@ip-172-31-19-208.ap-northeast-1.compute.internal> (raw)
In-Reply-To: <Yh2Uxh9DMndwjGcb@ip-172-31-19-208.ap-northeast-1.compute.internal>
On Tue, Mar 01, 2022 at 03:36:38AM +0000, Hyeonggon Yoo wrote:
> commit ba10d4b46655 ("mm/slub: use stackdepot to save stack trace in
> objects") initializes stack depot in cache creation if SLAB_STORE_USER
> flag is set.
>
> This can make kernel crash because a cache can be crashed in various
> contexts. For example if user sets slub_debug=U, kernel crashes
> because create_boot_cache() calls stack_depot_init(), which tries to
> allocate hash table using memblock_alloc() if slab is not available.
> But memblock is also not available at that time.
>
> This patch solves the problem by initializing stack depot early
> in boot process if SLAB_STORE_USER debug flag is set globally
> or the flag is set for at least one cache.
>
Hello Vlastimil, would you pick this up into slub-stackdepot-v1,
or fold it into original patch (2/5)?
Thanks!
--
Thank you, You are awesome!
Hyeonggon :-)
> [ elver@google.com: initialize stack depot depending on slub_debug
> parameter instead of allowing stack_depot_init() to be called
> during kmem_cache_init() for simplicity. ]
>
> [ vbabka@suse.cz: parse slub_debug parameter in setup_slub_debug()
> and initialize stack depot in stack_depot_early_init(). ]
>
> Link: https://lore.kernel.org/all/YhyeaP8lrzKgKm5A@ip-172-31-19-208.ap-northeast-1.compute.internal/
> Fixes: ba10d4b46655 ("mm/slub: use stackdepot to save stack trace in objects")
> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> ---
> include/linux/slab.h | 6 ++++++
> include/linux/stackdepot.h | 3 ++-
> mm/slub.c | 18 +++++++++++++++---
> 3 files changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 37bde99b74af..062128e0db10 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -763,6 +763,12 @@ extern void kvfree_sensitive(const void *addr, size_t len);
> unsigned int kmem_cache_size(struct kmem_cache *s);
> void __init kmem_cache_init_late(void);
>
> +#if defined(CONFIG_SLUB_DEBUG) && defined(CONFIG_STACKDEPOT)
> +int slab_stack_depot_init(void);
> +#else
> +int slab_stack_depot_init(void) { return 0; }
> +#endif
> +
> #if defined(CONFIG_SMP) && defined(CONFIG_SLAB)
> int slab_prepare_cpu(unsigned int cpu);
> int slab_dead_cpu(unsigned int cpu);
> diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h
> index 17f992fe6355..a813a2673c48 100644
> --- a/include/linux/stackdepot.h
> +++ b/include/linux/stackdepot.h
> @@ -12,6 +12,7 @@
> #define _LINUX_STACKDEPOT_H
>
> #include <linux/gfp.h>
> +#include <linux/slab.h>
>
> typedef u32 depot_stack_handle_t;
>
> @@ -32,7 +33,7 @@ int stack_depot_init(void);
> #ifdef CONFIG_STACKDEPOT_ALWAYS_INIT
> static inline int stack_depot_early_init(void) { return stack_depot_init(); }
> #else
> -static inline int stack_depot_early_init(void) { return 0; }
> +static inline int stack_depot_early_init(void) { return slab_stack_depot_init(); }
> #endif
>
> depot_stack_handle_t stack_depot_save(unsigned long *entries,
> diff --git a/mm/slub.c b/mm/slub.c
> index a74afe59a403..2419fc3cc9f3 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -646,6 +646,14 @@ static slab_flags_t slub_debug;
>
> static char *slub_debug_string;
> static int disable_higher_order_debug;
> +static bool init_stack_depot;
> +
> +int slab_stack_depot_init(void)
> +{
> + if (init_stack_depot)
> + stack_depot_init();
> + return 0;
> +}
>
> /*
> * slub is about to manipulate internal object metadata. This memory lies
> @@ -1531,6 +1539,8 @@ static int __init setup_slub_debug(char *str)
> global_slub_debug_changed = true;
> } else {
> slab_list_specified = true;
> + if (flags & SLAB_STORE_USER)
> + init_stack_depot = true;
> }
> }
>
> @@ -1546,6 +1556,10 @@ static int __init setup_slub_debug(char *str)
> global_flags = slub_debug;
> slub_debug_string = saved_str;
> }
> +
> + if (global_flags & SLAB_STORE_USER)
> + init_stack_depot = true;
> +
> out:
> slub_debug = global_flags;
> if (slub_debug != 0 || slub_debug_string)
> @@ -1556,6 +1570,7 @@ static int __init setup_slub_debug(char *str)
> static_branch_unlikely(&init_on_free)) &&
> (slub_debug & SLAB_POISON))
> pr_info("mem auto-init: SLAB_POISON will take precedence over init_on_alloc/init_on_free\n");
> +
> return 1;
> }
>
> @@ -4221,9 +4236,6 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
> s->remote_node_defrag_ratio = 1000;
> #endif
>
> - if (s->flags & SLAB_STORE_USER && IS_ENABLED(CONFIG_STACKDEPOT))
> - stack_depot_init();
> -
> /* Initialize the pre-computed randomized freelist if slab is up */
> if (slab_state >= UP) {
> if (init_cache_random_seq(s))
> --
> 2.33.1
next prev parent reply other threads:[~2022-03-01 3:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 3:36 Hyeonggon Yoo
2022-03-01 3:53 ` Hyeonggon Yoo [this message]
2022-03-01 7:00 ` kernel test robot
2022-03-01 7:11 ` kernel test robot
2022-03-01 8:51 ` [PATCH v3] " Hyeonggon Yoo
2022-03-01 9:14 ` Vlastimil Babka
2022-03-01 9:29 ` Hyeonggon Yoo
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=Yh2YoqGwfwwpiFOJ@ip-172-31-19-208.ap-northeast-1.compute.internal \
--to=42.hyeyoo@gmail.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=arnd@arndb.de \
--cc=cl@linux.com \
--cc=dvyukov@google.com \
--cc=edumazet@google.com \
--cc=elver@google.com \
--cc=faiyazm@codeaurora.org \
--cc=glittao@gmail.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=imran.f.khan@oracle.com \
--cc=jarkko@kernel.org \
--cc=johannes.berg@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mcroce@microsoft.com \
--cc=patches@lists.linux.dev \
--cc=penberg@kernel.org \
--cc=qiang.zhang@windriver.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@suse.cz \
--cc=yury.norov@gmail.com \
/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