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 B236DC433EF for ; Wed, 2 Mar 2022 17:47:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23C6A8D0003; Wed, 2 Mar 2022 12:47:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EA6A8D0001; Wed, 2 Mar 2022 12:47:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B4138D0003; Wed, 2 Mar 2022 12:47:13 -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 F18748D0001 for ; Wed, 2 Mar 2022 12:47:12 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id CD3BA62007 for ; Wed, 2 Mar 2022 17:47:12 +0000 (UTC) X-FDA: 79200177504.08.8820FC1 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by imf03.hostedemail.com (Postfix) with ESMTP id 4791020006 for ; Wed, 2 Mar 2022 17:47:12 +0000 (UTC) Received: by mail-wr1-f46.google.com with SMTP id u1so3953815wrg.11 for ; Wed, 02 Mar 2022 09:47:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=babB7lz53+t2z0xMSNGpVBWnIE028PwCS5tlqxlaCt4=; b=iQHkTcjGH932p2hqrL2Znc97cS2n8fBFEDQZZyTnQUOd57pWEttKWiYBxiBdN+x0g8 FbCvxQ0nbcty/dtamxohDvRjFqFzpQQB+ZkEoJ7SMXASfKPiK6KFUyIWEcsvcTpS4M0n gBOJcg4ph/jAxQei3OeKzwxCNpi3udAmQI3wGq7KmqTVIQSDCA/O+JVOEJIZwL/nG2zO Jl+6hzOml42W6qkYYgiGhkQlzSiRh5u8QJhfYrqgwbWosVSh1c3gJ8PeACJTOstvwLUk 5f52K09Cuc1Ada/scL/yUCPfMnbrm6j2mAKupizg6tPxKb1z2DNn5yF/K1U0yqLAqrxt pyZA== 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:user-agent; bh=babB7lz53+t2z0xMSNGpVBWnIE028PwCS5tlqxlaCt4=; b=BQCcMRs7JKjIdDYTYKzQaZcsyoI2kOngES8xj+8sNPZd3H2SDeLqdyR7akOz/TprMZ N7L9927r8/GUvdZmoj5wCYn/Bsx0heCGARYYK79hZKbzzLahuE66ln0xxxHP/uN9LCvO anPOTaBjCcFI4O3RanJavC9U4o1tV4CC1+/A5OktQ6W1ShRGWh6+lPDq5WuAIXKxX1Rt hGVj8VaZJyVv4/oZe/MHHiyTiV7rFQwKCXmNtNpjxIpfr1/I5FyG03VfZ+Ur0qC3ILrO 5/Lmuad48LvKZMJLbliumF8e/RW3KnYo2N1vGoumx+xmn5a7GY2lwZf9mwaCalKVUo3g hiPA== X-Gm-Message-State: AOAM533UDLkehNhT0UkdG5vROUyAsfUu9pU5LJ2BD2RNmFbeIQdDUFV7 E3/cqqtvqP6AE78l+mfgInAxFw== X-Google-Smtp-Source: ABdhPJzUUEWMcnms/5qjdNhJPBP5UEjbNdvLuLz4bPej2xsS5DQyaFuN1zOPIFK2ogEEOKhkCPI2tQ== X-Received: by 2002:a5d:47a1:0:b0:1f0:3440:2d04 with SMTP id 1-20020a5d47a1000000b001f034402d04mr2801204wrb.357.1646243230762; Wed, 02 Mar 2022 09:47:10 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:2ddb:aa6:c006:df16]) by smtp.gmail.com with ESMTPSA id 2-20020a1c1902000000b00380d3873d6asm6525416wmz.43.2022.03.02.09.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 09:47:10 -0800 (PST) Date: Wed, 2 Mar 2022 18:47:04 +0100 From: Marco Elver 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 , Mike Rapoport , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Imran Khan Subject: Re: [PATCH v2 1/6] lib/stackdepot: allow requesting early initialization dynamically Message-ID: References: <20220302173122.11939-1-vbabka@suse.cz> <20220302173122.11939-2-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220302173122.11939-2-vbabka@suse.cz> User-Agent: Mutt/2.1.4 (2021-12-11) X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4791020006 X-Stat-Signature: cwcfdhyps3gryzb5aao8reabzhbtjc6b Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=iQHkTcjG; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of elver@google.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=elver@google.com X-HE-Tag: 1646243232-669476 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 Wed, Mar 02, 2022 at 06:31PM +0100, Vlastimil Babka wrote: > In a later patch we want to add stackdepot support for object owner > tracking in slub caches, which is enabled by slub_debug boot parameter. > This creates a bootstrap problem as some caches are created early in > boot when slab_is_available() is false and thus stack_depot_init() > tries to use memblock. But, as reported by Hyeonggon Yoo [1] we are > already beyond memblock_free_all(). Ideally memblock allocation should > fail, yet it succeeds, but later the system crashes, which is a > separately handled issue. > > To resolve this boostrap issue in a robust way, this patch adds another > way to request stack_depot_early_init(), which happens at a well-defined > point of time. In addition to build-time CONFIG_STACKDEPOT_ALWAYS_INIT, > code that's e.g. processing boot parmeters (which happens early enough) > can set a new variable stack_depot_want_early_init as true. Agree, I think this is the best solution. > In this patch we also convert page_owner to this approach. While it > doesn't have the bootstrap issue as slub, it's also a functionality > enabled by a boot param and can thus request stack_depot_early_init() > with memblock allocation instead of later initialization with > kvmalloc(). > > [1] https://lore.kernel.org/all/YhnUcqyeMgCrWZbd@ip-172-31-19-208.ap-northeast-1.compute.internal/ > > Reported-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > Signed-off-by: Vlastimil Babka > --- > include/linux/stackdepot.h | 16 ++++++++++++++-- > lib/stackdepot.c | 2 ++ > mm/page_owner.c | 9 ++++++--- > 3 files changed, 22 insertions(+), 5 deletions(-) > > diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h > index 17f992fe6355..1217ba2b636e 100644 > --- a/include/linux/stackdepot.h > +++ b/include/linux/stackdepot.h > @@ -15,6 +15,8 @@ > > typedef u32 depot_stack_handle_t; > > +extern bool stack_depot_want_early_init; > + > depot_stack_handle_t __stack_depot_save(unsigned long *entries, > unsigned int nr_entries, > gfp_t gfp_flags, bool can_alloc); > @@ -26,11 +28,21 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, > * The alternative is to select STACKDEPOT_ALWAYS_INIT to have stack depot > * enabled as part of mm_init(), for subsystems where it's known at compile time > * that stack depot will be used. > + * > + * Another alternative is to set stack_depot_want_early_init as true, when the > + * decision to use stack depot is taken e.g. when evaluating kernel boot > + * parameters, which precedes the call to stack_depot_want_early_init(). > */ > int stack_depot_init(void); I think for stack_depot_init() it might now be convenient to provide a no-op version automatically if !STACKDEPOT, which would avoid some 'if (.. && IS_ENABLED(CONFIG_STACKDEPOT))' in a later patch. Similarly, for stack_depot_want_early_init, where instead you could simply provide stack_depot_want_early_init() as a function, which simply sets a boolean __stack_depot_want_early_init. If !STACKDEPOT, it'll also just be a no-op function. > > -#ifdef CONFIG_STACKDEPOT_ALWAYS_INIT > -static inline int stack_depot_early_init(void) { return stack_depot_init(); } > +#ifdef CONFIG_STACKDEPOT > +static inline int stack_depot_early_init(void) > +{ > + if (IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT) > + || stack_depot_want_early_init) > + return stack_depot_init(); > + return 0; > +} > #else > static inline int stack_depot_early_init(void) { return 0; } > #endif > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index bf5ba9af0500..02e2b5fcbf3b 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -66,6 +66,8 @@ struct stack_record { > unsigned long entries[]; /* Variable-sized array of entries. */ > }; > > +bool stack_depot_want_early_init = false; > + This can be __initdata, right? > static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; > > static int depot_index; > diff --git a/mm/page_owner.c b/mm/page_owner.c > index 99e360df9465..40dce2b81d13 100644 > --- a/mm/page_owner.c > +++ b/mm/page_owner.c > @@ -42,7 +42,12 @@ static void init_early_allocated_pages(void); > > static int __init early_page_owner_param(char *buf) > { > - return kstrtobool(buf, &page_owner_enabled); > + int ret = kstrtobool(buf, &page_owner_enabled); > + > + if (page_owner_enabled) > + stack_depot_want_early_init = true; > + > + return ret; > } > early_param("page_owner", early_page_owner_param); > > @@ -80,8 +85,6 @@ static __init void init_page_owner(void) > if (!page_owner_enabled) > return; > > - stack_depot_init(); > - > register_dummy_stack(); > register_failure_stack(); > register_early_stack(); > -- > 2.35.1 >