Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3170017rdb; Wed, 13 Sep 2023 04:30:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFXNW+O4Zrrm/HGXmIQrXKqmGirN3IqJEB7EfnTxds5xQ5NCBHkc+WFwKdkUTkseQNRY8w X-Received: by 2002:a05:6358:7251:b0:141:d2d:6d8f with SMTP id i17-20020a056358725100b001410d2d6d8fmr3051207rwa.17.1694604615059; Wed, 13 Sep 2023 04:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694604615; cv=none; d=google.com; s=arc-20160816; b=SiIopz0OH8SdtsrrtodQsLRmpZZYP0mlUGSsIjEzyiJ7Z7Eow0DBCj6X64I7xinhpH TxU0fahJgDO8phLPgaEOeDpaPbpmzt5OCI6Rc7J4lPrPdqcv+kp8d2o/RjlHtXN9mDG+ tGZF36KQafqpzTeLKJUkR9uLZLqHFl1hgOyFAIL+wMImv+7/1d9ryFJQPcD7oNBlLfmj zT3fhKcVy3q94S0NPMgdNFZoEQFz/8LpdGRUd8qZoEdBNqeSMPNz8V8nd10PJRypWZCg WEjI3VMyuGLv5qBXBuPkcMnOAeq7pFbZluBOk3M1s79ZuxXVvX+y4epZLNzGKJEI+4cR 6Msw== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=SkU9Bj1zhDPp8UcF63n5AW0gurq26cM2A8Td112dKhQ=; fh=lPEwZFW0YHdRt/ifvvEIfycxE0sgL2HlT8/jgMTETn0=; b=Iwgbfl97uxd7zM6AzPZtfzqUas9kxXdpFjXQWvA/THNnA9iE8bm5qhifqAAPYj5wlz wr6HB7juFCHdHQ6ImJu3+e4CJPQliRirTcPslEArN+wLHmF3EGs6dRB+yZJXlGxSgT7y OMHyzP48Us3PdBM0rBK834IsqGdsSI3+RGJfxdJhwcUnrjCn7I6okDUvwkNd7ZK1lzZz /jtP1oAmNDmKDnqCIPwtnVxjWtjr9e48hLS5B6ziDzYkITqHeF9oK7R/ZA9iYcmq15xm tEE3t6fcryWleJpbxia8ASs4WWK6W1nsRLk0q5VNTCXapjGndp8WHtqCruAqrQE5uM1Y 6lnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=scWKfvGS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id x5-20020a654145000000b00563a0c1bf06si9582584pgp.428.2023.09.13.04.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 04:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=scWKfvGS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4349E808D2AD; Wed, 13 Sep 2023 04:28:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240130AbjIML2d (ORCPT + 99 others); Wed, 13 Sep 2023 07:28:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240021AbjIML2c (ORCPT ); Wed, 13 Sep 2023 07:28:32 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C39B173E; Wed, 13 Sep 2023 04:28:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFAC0C433C7; Wed, 13 Sep 2023 11:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694604507; bh=TgkMDTSkKvv4v8TszdJrmsSFRm605JoHp3AjwV4m+9c=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=scWKfvGSzlV8VbrgFExT/iBiV7p7Hm6NS/oiTwWinIkZ9EX3STfSnMhxsJujgFxZe E37E8lYZFibj9+PWgHBsuqs2YPfibAqF3dcIgMwA+SWX1l2E3PQtcBy2C2Sfh8roFs 9wO9N/KcqF5zt3T2o8es07/Xx7Qa73nwFd+pVP1xHzcW49Wka47WiKwY2SaQsAg6Dh pvrVBbl7OS8+FepotpWFQDIW7XK3weNVf7u/gEQqUHns8UHeKFslc7zA7g/UOidjNl mDSOpKqbyPolRFeafKOAZ6tXJektNF90u43Wb4odCg/MKdf82eXVuNQwqn0tYWc1Z6 jpeowzaDppzOg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6AE58CE093C; Wed, 13 Sep 2023 04:28:27 -0700 (PDT) Date: Wed, 13 Sep 2023 04:28:27 -0700 From: "Paul E. McKenney" To: Peter Zijlstra Cc: "Liam R. Howlett" , Andrew Morton , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Geert Uytterhoeven , 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: <14620af6-7315-4de3-ac7f-5bb51f773397@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20230913005647.1534747-1-Liam.Howlett@oracle.com> <20230913110139.GE692@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230913110139.GE692@noisy.programming.kicks-ass.net> 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 (groat.vger.email [0.0.0.0]); Wed, 13 Sep 2023 04:28:34 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 groat.vger.email On Wed, Sep 13, 2023 at 01:01:39PM +0200, Peter Zijlstra wrote: > 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? We could do that, but do we really the decidedly non-idle early boot sequence designated as idle? What surprises me is that this is just now showing up. The ingredients for this one have been in place for almost 10 years. Thanx, Paul