Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3398285rdb; Wed, 13 Sep 2023 10:44:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/9koPQACN6dEHycsmRA0geYGUOq6KPJdO/Uq/A1Q/mX/qavFmcDnuiw0h5XfO7PPsQh+0 X-Received: by 2002:a17:90a:4e84:b0:263:2312:60c2 with SMTP id o4-20020a17090a4e8400b00263231260c2mr2707923pjh.3.1694627088037; Wed, 13 Sep 2023 10:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694627088; cv=none; d=google.com; s=arc-20160816; b=HW0a/mvU3CXFZmB68VUqYfGzRRC2JicSLbYM+FM0jYU+UzcKVnOpZNKJ+5axLPPPfz h/QEXHfi6JjGWN873POvlpojy443fkFsrF6oVmxWswIX3/pVET2V84EjKhduEbaZ31fX Msi16agc6ihGsdaZn1yqOsfYsLuZ3daOEvH7R2MiK1VnKlrHyt9DGqeLu6/6PDg3COMK agPazNONMygcVM9AxLOKNoJcNouWgSuGN1FfNtPnU8DK7Ihbr2lKoPCWXWR2gL6ELpdB bJRUiu6Dckij79mTBKvnbmbdBYNOeCH86WpEveHUAJ+DubJP9/9wO0r08UQOXC0GO6+C T1Xg== 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=Ph6IZOjxVfNK0j0D6FBkY/k2VECArBn3iv8gnIxi7NU=; fh=ceGYfXPwvFkL/d4Z+b4U7FHqYZN/UDzYpDRZZKkR/gw=; b=ooLXzTwWDZxVSF3/yeIyUdbWaPaZ8xJ6QmQZ5ssvkXOwabZQb0EpEIUZZRIOENH9Dm z33zc0ztira8Ch4dyzSWwCiQmWwbT4J7FLJ9FxtO4MQudA6tdWNQNmjL09aGcUAYTA/E U3SaYl0uUoWps+3iOtul+J5lmAxPhM6Qx0Nx5Ao9phbISjLkEnnR3494W0gJpsp13UTC 738DqCWXNGGrH7rYJE91LB4YdKhRcG5jByvsqwcFxtOVO3KWEM0Jqf12/Q9upSBBZ8Hb xzjrJboUkzBWTlg7oA9Tw65cIpY0e0t7HulvR8UaWHS6hI/GHJbjlJviSnx0Zwym5n/6 WpOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LWgmBUtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id mm14-20020a17090b358e00b002532c9b252asi1894916pjb.73.2023.09.13.10.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 10:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LWgmBUtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 64CC980E6C7E; Wed, 13 Sep 2023 04:02:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239847AbjIMLCR (ORCPT + 99 others); Wed, 13 Sep 2023 07:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbjIMLCP (ORCPT ); Wed, 13 Sep 2023 07:02:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F41CE1726; Wed, 13 Sep 2023 04:02:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Ph6IZOjxVfNK0j0D6FBkY/k2VECArBn3iv8gnIxi7NU=; b=LWgmBUtqijN5jZg4OTh3/n7y8S CBGYD5upmZC2bNhP4tUBGRgBf/M14Iy7pfwWf1cgDMqKKCRC/khSGyEVbigMwsZOTds2JZHEEZq+b RH9NQFMYUhSy04YwqbKDJELCZDNHq6Y+rgXMaaz3bhgyQR9e/oj5CAd7cGNT66jhgBj7xdh6d3JhP xzI27FDLWkWJtkgbKZW/TMY5jFuysOyzUYOwZaEASTWhnDRlUwAe2iUrTaxapVtOQ7sv2T6fYkee1 knclwk/xz098cfRo3p/puWgRPh3Q/KNPo1bdAzBE117ZOMpSAUXMlNTVTZxZnPsZV4VjQF57m6RrP jfrJ/K+w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qgNcq-00DQqf-F2; Wed, 13 Sep 2023 11:01:40 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 1CCF4300348; Wed, 13 Sep 2023 13:01:40 +0200 (CEST) Date: Wed, 13 Sep 2023 13:01:39 +0200 From: Peter Zijlstra To: "Liam R. Howlett" Cc: Andrew Morton , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Geert Uytterhoeven , "Paul E. McKenney" , Christophe Leroy , Andreas Schwab , Matthew Wilcox , Peng Zhang , Ingo Molnar , Juri Lelli , Vincent Guittot , "Mike Rapoport (IBM)" , Vlastimil Babka Subject: Re: [PATCH] init/main: Clear boot task idle flag Message-ID: <20230913110139.GE692@noisy.programming.kicks-ass.net> References: <20230913005647.1534747-1-Liam.Howlett@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230913005647.1534747-1-Liam.Howlett@oracle.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 04:02:19 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email On Tue, Sep 12, 2023 at 08:56:47PM -0400, Liam R. Howlett wrote: > Initial booting is setting the task flag to idle (PF_IDLE) by the call > path sched_init() -> init_idle(). Having the task idle and calling > call_rcu() in kernel/rcu/tiny.c means that TIF_NEED_RESCHED will be > set. Subsequent calls to any cond_resched() will enable IRQs, > potentially earlier than the IRQ setup has completed. Recent changes > have caused just this scenario and IRQs have been enabled early. > > This causes a warning later in start_kernel() as interrupts are enabled > before they are fully set up. > > Fix this issue by clearing the PF_IDLE flag on return from sched_init() > and restore the flag in rest_init(). Although the boot task was marked > as idle since (at least) d80e4fda576d, I am not sure that it is wrong to > do so. The forced context-switch on idle task was introduced in the > tiny_rcu update, so I'm going to claim this fixes 5f6130fa52ee. > > Link: https://lore.kernel.org/linux-mm/87v8cv22jh.fsf@mail.lhotse/ > Link: https://lore.kernel.org/linux-mm/CAMuHMdWpvpWoDa=Ox-do92czYRvkok6_x6pYUH+ZouMcJbXy+Q@mail.gmail.com/ > Fixes: 5f6130fa52ee ("tiny_rcu: Directly force QS when call_rcu_[bh|sched]() on idle_task") > Cc: stable@vger.kernel.org > Cc: Geert Uytterhoeven > Cc: "Paul E. McKenney" > Cc: Christophe Leroy > Cc: Andreas Schwab > Cc: Matthew Wilcox > Cc: Peng Zhang > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Juri Lelli > Cc: Vincent Guittot > Cc: Andrew Morton > Cc: "Mike Rapoport (IBM)" > Cc: Vlastimil Babka > Signed-off-by: Liam R. Howlett > --- > init/main.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/init/main.c b/init/main.c > index ad920fac325c..f74772acf612 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -696,7 +696,7 @@ noinline void __ref __noreturn rest_init(void) > */ > rcu_read_lock(); > tsk = find_task_by_pid_ns(pid, &init_pid_ns); > - tsk->flags |= PF_NO_SETAFFINITY; > + tsk->flags |= PF_NO_SETAFFINITY | PF_IDLE; > set_cpus_allowed_ptr(tsk, cpumask_of(smp_processor_id())); > rcu_read_unlock(); > > @@ -938,6 +938,8 @@ void start_kernel(void) > * time - but meanwhile we still have a functioning scheduler. > */ > sched_init(); > + /* Avoid early context switch, rest_init() restores PF_IDLE */ > + current->flags &= ~PF_IDLE; > > if (WARN(!irqs_disabled(), > "Interrupts were enabled *very* early, fixing it\n")) Hurmph... so since this is about IRQs, would it not make sense to have the | PF_IDLE near 'early_boot_irqs_disabled = false' ? Or, alternatively, make the tinyrcu thing check that variable?