From patchwork Tue Mar 1 08:51:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12764361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E38FC433F5 for ; Tue, 1 Mar 2022 08:52:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BDE98D0002; Tue, 1 Mar 2022 03:52:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 86DCC8D0001; Tue, 1 Mar 2022 03:52:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7365D8D0002; Tue, 1 Mar 2022 03:52:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 672548D0001 for ; Tue, 1 Mar 2022 03:52:06 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2A90921A07 for ; Tue, 1 Mar 2022 08:52:06 +0000 (UTC) X-FDA: 79195200252.11.DA624CA Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf08.hostedemail.com (Postfix) with ESMTP id AFCA5160008 for ; Tue, 1 Mar 2022 08:52:05 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id bc27so4982061pgb.4 for ; Tue, 01 Mar 2022 00:52:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to; bh=X+CELJ7rEgmBMwuKX3QnxNunnNgyBQv4GScNFZ71SB0=; b=KwqZjC+TAY7yWZaiJPe0/5cQbVUsJm4BVqQGXKKDx26ptfR4w5H4zNTfiTpyaFtkmB +W5TytA2dylB07CeWLQuxbQWEPAGeLV89hEFLJ/MIamYquQ8KQO4III05jixVjhu545v jkL0Ua1N11cP7USZt+IU/3AjYRNKUmNtbl/8jCbTTRQ3nMDP2CYgbaPTxfhBQMLb94UT nfFyYee1BRqI/zDHFOrMZFP2d2oWxLhg89c0MP7tioNASOMIcpkiz9W298B0bRLKcr+W SoHvrpjQuJshP4oRvo0+79s/eau8VJxniJaG8VdfzBRaCXgiCC1BSS7pQZShTczThqVD lGug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to; bh=X+CELJ7rEgmBMwuKX3QnxNunnNgyBQv4GScNFZ71SB0=; b=RA6VET+34kQwRrn0W44lsjwUfot4Q5cbo4y3aDvfHpafzvHFPeJgTx69p8dyG2zSdA MrzCCakQyjDaKMFHTGfCemsD1Lgi1PEt1CFrYeaF6bd+ImjjHg/agCbnoAZx/zpCKTK2 IsShQuukmEElGgqFSBUv6pfXlTqEaqTnRYLCwvr2fe1IBpGB1Ybl4eK0gbdutpruZhiR Zy2VLyyRJ3i3MfIsbMWO3A/61vQGzKWvivS7BGJ53t8ePZkYw0XqcD7pceDQJt/BsyLx nXbdo4LFO42U3k4jupBlFuug2El9elQEaFlncWTwkOSSKQGksID4bDNbeEENx97XY8Vh wFrg== X-Gm-Message-State: AOAM531c+ka/aaG2ObuxwhzAMS+Zaz+COyx1r3B7ER42/NW+zXv2q744 s7zJPlAq6IbQcTv9kZnOwFw= X-Google-Smtp-Source: ABdhPJz+fO4CUS/yMIGn/QrRS/NMKXCeSG9j218AJLbx2wIEG3bt8mJAh6hrbPF00rlmtIW3daVe0g== X-Received: by 2002:a62:7e06:0:b0:4e0:f0f8:9b86 with SMTP id z6-20020a627e06000000b004e0f0f89b86mr26732203pfc.26.1646124724549; Tue, 01 Mar 2022 00:52:04 -0800 (PST) Received: from ip-172-31-19-208.ap-northeast-1.compute.internal (ec2-18-181-137-102.ap-northeast-1.compute.amazonaws.com. [18.181.137.102]) by smtp.gmail.com with ESMTPSA id o3-20020a056a0015c300b004e17afd9af9sm16979963pfu.92.2022.03.01.00.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Mar 2022 00:52:04 -0800 (PST) Date: Tue, 1 Mar 2022 08:51:56 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: kernel test robot Cc: Vlastimil Babka , kbuild-all@lists.01.org, David Rientjes , Christoph Lameter , Joonsoo Kim , Pekka Enberg , Roman Gushchin , Andrew Morton , Linux Memory Management List , patches@lists.linux.dev, linux-kernel@vger.kernel.org, Oliver Glitta , Faiyaz Mohammed , Dmitry Vyukov , Eric Dumazet , Jarkko Sakkinen , Johannes Berg , Yury Norov , Arnd Bergmann , James Bottomley , Matteo Croce , Marco Elver , Andrey Konovalov , Imran Khan , Zqiang Subject: [PATCH v3] mm/slub: initialize stack depot in boot process Message-ID: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <202203011512.U0o5cAx4-lkp@intel.com> X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: nrserj3wcmng7hpfy4x7q1atk1rjbgd3 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KwqZjC+T; spf=pass (imf08.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: AFCA5160008 X-HE-Tag: 1646124725-665969 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. [ 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(). ] [ lkp@intel.com: Fix build error. ] 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 | 1 + include/linux/stackdepot.h | 3 ++- mm/slab.c | 5 +++++ mm/slob.c | 5 +++++ mm/slub.c | 19 ++++++++++++++++--- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 37bde99b74af..d2b0f8f9e5e6 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -762,6 +762,7 @@ 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); +int __init slab_stack_depot_init(void); #if defined(CONFIG_SMP) && defined(CONFIG_SLAB) int slab_prepare_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 +#include 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/slab.c b/mm/slab.c index ddf5737c63d9..c7f929665fbe 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -1196,6 +1196,11 @@ static void __init set_up_node(struct kmem_cache *cachep, int index) } } +int __init slab_stack_depot_init(void) +{ + return 0; +} + /* * Initialisation. Called after the page allocator have been initialised and * before smp_init(). diff --git a/mm/slob.c b/mm/slob.c index 60c5842215f1..7597c219f061 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -725,3 +725,8 @@ void __init kmem_cache_init_late(void) { slab_state = FULL; } + +int __init slab_stack_depot_init(void) +{ + return 0; +} diff --git a/mm/slub.c b/mm/slub.c index a74afe59a403..8f130f917977 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -646,6 +646,16 @@ static slab_flags_t slub_debug; static char *slub_debug_string; static int disable_higher_order_debug; +static bool __initdata init_stack_depot; + +int __init slab_stack_depot_init(void) +{ +#ifdef CONFIG_STACKDEPOT + if (init_stack_depot) + stack_depot_init(); +#endif + return 0; +} /* * slub is about to manipulate internal object metadata. This memory lies @@ -1531,6 +1541,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 +1558,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) @@ -4221,9 +4237,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))