From mboxrd@z Thu Jan 1 00:00:00 1970 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 7C839C433F5 for ; Tue, 1 Mar 2022 02:12:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB2F98D0002; Mon, 28 Feb 2022 21:12:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3C3C8D0001; Mon, 28 Feb 2022 21:12:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB5128D0002; Mon, 28 Feb 2022 21:12:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id A8F388D0001 for ; Mon, 28 Feb 2022 21:12:52 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 622CB181C9D29 for ; Tue, 1 Mar 2022 02:12:52 +0000 (UTC) X-FDA: 79194194184.17.EAFE336 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf27.hostedemail.com (Postfix) with ESMTP id D3F1F40004 for ; Tue, 1 Mar 2022 02:12:51 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id 27so13163022pgk.10 for ; Mon, 28 Feb 2022 18:12:51 -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=VqwKZSmUCQfMvGMcajV4YWfTIzz3lVqIZVMkUskoDd0=; b=L2RIdggPBz3kNS4Fh9HORTyRoN6vqkFQOJZikLYgVJtQGutU4yZx/SS1mYey8fHQjf Q7RYQyga0OpDiVARh8K+/L/mw61bs6pI8sxDCuyUGbinePN8+J9ktmmDR+5I4HfCZLTc 4njttVqgCL3dm5iAWIbmhHV05thRj2dPa33d5kBYbToes7azrNyGnDAQ4nw1PhK09v2M xN5fxPZ2XkF4IL1aYB9KZvPE3ZO4WhlRWAKalK76KyjdJBQfIxBUAW8jAFwcFShyGjBp FWuVPf4fhQPIS9yGPM8YMOib6tYlcAJxgz6w3hO7DYe3IiStuboYpfC6FLNOsd7YwmJp Oo8A== 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=VqwKZSmUCQfMvGMcajV4YWfTIzz3lVqIZVMkUskoDd0=; b=Kv9doxQp8DJGU2XnYSe8UAvbgcOtjSQegyI/Rrwbn+KXw53hOQtQIUbTDXolZIHOja lLfJ4HRf5ntK2cYuoZ403IS1poMPX6z7MCj0wto3CM4gLwpxZNs5i8iMD3uOaA8CkAnf 63ULmnnfik6+Qd/Gl470Qk/FjqyC98jVGKiIldadRw4wVa968afEcp2c/RKq8WVukZB/ fprvGPoMScZPNOsZYEfq7z3bp7QWV1P+AUPG9rp0AbDVO8joljC6ZolFfUJlqdoz3U9Y 0H+JRdwj8ZtCulmPHZ3uHYU3D59Ha0KFbQjGLqfjK/61lzl/G6RYxkfu+ctfTP7Rat5u 3pJw== X-Gm-Message-State: AOAM532ZmpKvGzVyv9ssGeHoNB3iiXnx67151TjyEHsfKw0Eghbzro4/ pmpdpreBWCm5cYgD1PzPCpI= X-Google-Smtp-Source: ABdhPJxyCa36UIZKtFnjuddlsFNOGwSj5AlDJ2lllpJIIfwD3NMbWOqLhVwU8DTnhh27GWymwQuXnQ== X-Received: by 2002:a63:5110:0:b0:374:2312:1860 with SMTP id f16-20020a635110000000b0037423121860mr19736943pgb.146.1646100770710; Mon, 28 Feb 2022 18:12:50 -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 17-20020a056a00071100b004f0f941d1e8sm14108030pfl.24.2022.02.28.18.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 18:12:50 -0800 (PST) Date: Tue, 1 Mar 2022 02:12:43 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Marco Elver Cc: Vlastimil Babka , 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 , Andrey Konovalov , Imran Khan , Zqiang Subject: Re: [PATCH] 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-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: 7zx7dj8p15dxbxay9qpyrcyib13zjbqu Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=L2RIdggP; spf=pass (imf27.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: D3F1F40004 X-HE-Tag: 1646100771-631644 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: On Mon, Feb 28, 2022 at 05:28:17PM +0100, Marco Elver wrote: > On Mon, Feb 28, 2022 at 03:09PM +0000, Hyeonggon Yoo wrote: > > commit ba10d4b46655 ("mm/slub: use stackdepot to save stack trace in > > objects") initializes stack depot while creating cache if SLAB_STORE_USER > > flag is set. > > > > This can make kernel crash because a cache can be created 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 to at least one cache. > > > > [ elver@google.com: initialize stack depot depending on slub_debug > > parameter instead of allowing stack_depot_init() can be called > > in kmem_cache_init() for simplicity. ] > > > > Link: https://lkml.org/lkml/2022/2/28/238 > > This would be a better permalink: > https://lore.kernel.org/all/YhyeaP8lrzKgKm5A@ip-172-31-19-208.ap-northeast-1.compute.internal/ > Agreed. > > Fixes: ba10d4b46655 ("mm/slub: use stackdepot to save stack trace in objects") > > This commit does not exist in -next. > It did not land -next yet. > I assume you intend that "lib/stackdepot: Use page allocator if both > slab and memblock is unavailable" should be dropped now. > I did not intend that, but I agree the patch you mentioned should be dropped now. > > Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > > --- > > include/linux/slab.h | 1 + > > init/main.c | 1 + > > mm/slab.c | 4 ++++ > > mm/slob.c | 4 ++++ > > mm/slub.c | 28 +++++++++++++++++++++++++--- > > 5 files changed, 35 insertions(+), 3 deletions(-) > [...] > > > > +/* Initialize stack depot if needed */ > > +void __init kmem_cache_init_early(void) > > +{ > > +#ifdef CONFIG_STACKDEPOT > > + slab_flags_t block_flags; > > + char *next_block; > > + char *slab_list; > > + > > + if (slub_debug & SLAB_STORE_USER) > > + goto init_stack_depot; > > + > > + next_block = slub_debug_string; > > + while (next_block) { > > + next_block = parse_slub_debug_flags(next_block, &block_flags, &slab_list, false); > > + if (block_flags & SLAB_STORE_USER) > > + goto init_stack_depot; > > + } > > + > > + return; > > + > > +init_stack_depot: > > + stack_depot_init(); > > +#endif > > +} > > You can simplify this function to avoid the goto: > > /* Initialize stack depot if needed */ > void __init kmem_cache_init_early(void) > { > #ifdef CONFIG_STACKDEPOT > slab_flags_t flags = slub_debug; > char *next_block = slub_debug_string; > char *slab_list; > > for (;;) { > if (flags & SLAB_STORE_USER) { > stack_depot_init(); > break; > } > if (!next_block) > break; > next_block = parse_slub_debug_flags(next_block, &flags, &slab_list, false); > } > #endif > } > > ^^ with this version, it'd also be much easier and less confusing to add > other initialization logic unrelated to stackdepot later after the loop > (should it ever be required). Thank you for nice suggestion, but I want to try it in setup_slub_debug() as Vlastimil said! Thanks. -- Thank you, You are awesome! Hyeonggon :-)