Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3468326pxm; Mon, 28 Feb 2022 21:37:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyL14FVKx3P/YpVlchc4hNKFNGNUzlMXQDK2JE32/IXCwvSSI1o9JepifPiAUph4hhS+fRE X-Received: by 2002:a05:6402:2694:b0:411:f0b1:7f90 with SMTP id w20-20020a056402269400b00411f0b17f90mr23130336edd.398.1646113034141; Mon, 28 Feb 2022 21:37:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646113034; cv=none; d=google.com; s=arc-20160816; b=w7kr5gOMifxiSgLoVvSSi3Bs4QbWYViAqNYB/4cwmVzC5YCou9K9jLmtgthhkltj6H +PZEafFrAtbcgtxG21Xfc0x0cLv1v6k1e2bh3jm92TUilF1zhmFf0ZX3h1iasg/IT2Vm C5dplq2OX8uH5SNS3iDRcpuA9IbFuXkY1k1++R6Far/tu50cSttEMUgjx5+W/P+LvukW GfpE4Y4veJYGsLktqB0i2QvJvhA+F4w4ez+RJhcE8sV+8fx2oxrIxuVyh62DLaEelirU MniW+ORGQHRiYo9Itt8OioPb8Fecl+bAjui0IMYtyGcTRRAT//KqTqocmGeD3YKcdrjD bkkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KOhBM55iXZYEmx9IYBkoTVCwltMj7BAc5rVJhF2Tk4Y=; b=nZ2CUb0+GfQgW8xOqirvcw98NK/rY8FSj4h2k9QZ8RPzAQMCB5uGAw4z5M4fp7lbRo 6wu518F7nKtZtFg+hodJ5GSJq5QsPhuk/wt8jzYsKrOsWv+iVhm7BC/hvhr8WbQki+yf +BMFffd0Bbv7r4GdjTPuDdff8XNlf04qcy7aKDwg108nb7WKJBn2w2FgxaGVtg+/0oio BxeKKGTj9LenUMxCl+RM95QTfj60e32WLiKXUC/tz/yu+XaV44oTPG2q4Z8ddO7FAZ3v kgng5GLYAPeN1w0by/w8sl5P/lmMv83JsqaZc8fY3Z6AtjCnFAAIVlmdfUFCyC98+aDW B4pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z3TtiMRU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a170906974300b006d0908847d4si8761087ejy.682.2022.02.28.21.36.51; Mon, 28 Feb 2022 21:37:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z3TtiMRU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232138AbiCADx7 (ORCPT + 99 others); Mon, 28 Feb 2022 22:53:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbiCADx4 (ORCPT ); Mon, 28 Feb 2022 22:53:56 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A0DD2613E for ; Mon, 28 Feb 2022 19:53:15 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id s11so2634481pfu.13 for ; Mon, 28 Feb 2022 19:53:15 -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:references:mime-version :content-disposition:in-reply-to; bh=KOhBM55iXZYEmx9IYBkoTVCwltMj7BAc5rVJhF2Tk4Y=; b=Z3TtiMRUlxmZIIYkMRiY0fzmGGMZMMk4/slyPir2Q+k5jZFaTUur95x1fkat0XMlNf rmwEhvAifEr8kst0jhTJOfAdvPh0r1IB5/oHH8IUZXySf9D71eOPH0t//b9thWAoM+PB ELjfOUbX0xpENQaoU1GRs8io+Q7owQuRppcSRcZypgz8gqwxM+tAFrQXN4KIwmovmxUd w7nWe5Xx4on4p+ilbaAbmqyTP/nUMH3zYrXKaG1UvNa0lC8NHo6PREsy5P2liiOidsZd nT7yrfmuioV19ubeVlk8/LUNOSneKdLaje97Yy7782mk2sgeNhcBwTOicS81mQ1M3jeb S5Tg== 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:references :mime-version:content-disposition:in-reply-to; bh=KOhBM55iXZYEmx9IYBkoTVCwltMj7BAc5rVJhF2Tk4Y=; b=6iST+8zCQSNe3ZdSrkKfBkejZtMev2dd4JyfMhrAEcuAJ2nLl+f+ih5NLF0KGdaOH/ sV/Hc4m4WpUFK0lQB/5DVZs3qIhf80k+XIQDZnklefD1yWC/vpqNu9Vdf86hAHZQ8DeQ OgdkTh7Tnehqe0PFW8WW8K+aberNANHRIHc8CeJ7mWIUk0+efHkR0j8eE7dBhy1YNCEt Wm6RgVKZ02uP4AMY9iRwYU5pF7FzeMh0+0XFJUgWKmu/MmbqIpzQs/OQi/Zrwxt0Dkgg 05K59tGFtSJ4Ihyyszp4du9uPLLwKECNOVi2lPhoMIeKKzefhkVj5lZKNtb0+R9RXElD YDVA== X-Gm-Message-State: AOAM531hAIKrchaHv4hfmv3CTKoxTIfnYkPsU+szlsl3CM2wYEuA1H/Q pmjZCzNHnOLnaMJfZoc6NfE= X-Received: by 2002:a05:6a00:1143:b0:4f0:e9bf:6333 with SMTP id b3-20020a056a00114300b004f0e9bf6333mr25327109pfm.29.1646106794792; Mon, 28 Feb 2022 19:53:14 -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 q24-20020aa79618000000b004e0e89985eesm14290953pfg.156.2022.02.28.19.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 19:53:14 -0800 (PST) Date: Tue, 1 Mar 2022 03:53:06 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Vlastimil Babka Cc: David Rientjes , Christoph Lameter , Joonsoo Kim , Pekka Enberg , Roman Gushchin , Andrew Morton , linux-mm@kvack.org, 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: Re: [PATCH v2] mm/slub: initialize stack depot in boot process Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > +#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/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