From patchwork Tue Oct 24 21:46:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13435302 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16466C25B6B for ; Tue, 24 Oct 2023 21:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344474AbjJXVq4 (ORCPT ); Tue, 24 Oct 2023 17:46:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344477AbjJXVqw (ORCPT ); Tue, 24 Oct 2023 17:46:52 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C101AE8; Tue, 24 Oct 2023 14:46:49 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE75DC433C7; Tue, 24 Oct 2023 21:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698184009; bh=AqHnLeB5xem2kiRsFLowge6w/ot0AAmqtV9xGzicirc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EDaO3ZmCJO3fKoF+gIfWqQroBqbgxx5f8hX2+JrCOc4JsdJNI38tcDbzDbxDd9IiD lQQjafqLkkawzo6WRYBYq6iBDRLc6rw/K82bL4QufhCMuuMtuiIDHLj1HTZLkWwhv0 Y7mPAxMD5NRzchUhYgtYdpyVNGyV6qMUsXDOOPc0ShJDQv6YARd0YrIOFvg4uFaCm6 1ngaB9X+/AarJdFS3TRUPmWau++XTxbJE6uZMiH0YYWipraB8z3fgsqMiLJkFXYbza ZaAmHAP183sCvV3XzoyR81WsOfdotWNwXasO1UWQeKF/ElKrOC4OzjJFDnqlnpa/LJ dKFkktu+IKyVw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Boqun Feng , Joel Fernandes , Josh Triplett , Lai Jiangshan , Mathieu Desnoyers , Neeraj Upadhyay , "Paul E . McKenney" , Steven Rostedt , Uladzislau Rezki , Zqiang , rcu , "Liam R . Howlett" , Peter Zijlstra Subject: [PATCH 4/4] sched: Exclude CPU boot code from PF_IDLE area Date: Tue, 24 Oct 2023 23:46:25 +0200 Message-ID: <20231024214625.6483-5-frederic@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231024214625.6483-1-frederic@kernel.org> References: <20231024214625.6483-1-frederic@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org The commit: cff9b2332ab7 ("kernel/sched: Modify initial boot task idle setup") has changed the semantics of what is to be considered an idle task in such a way that only the actual idle loop is accounted as PF_IDLE. The intent is to exclude the CPU boot code from that coverage. However this doesn't clear the flag when the CPU goes down. Therefore when the CPU goes up again, its boot code is part of the PF_IDLE zone. Make sure this flag behave consistently and clear the flag when a CPU exits from the idle loop. If anything, RCU-tasks relies on it to exclude CPU boot code from its quiescent states. Fixes: cff9b2332ab7 ("kernel/sched: Modify initial boot task idle setup") Signed-off-by: Frederic Weisbecker --- include/linux/sched.h | 2 +- kernel/cpu.c | 4 ++++ kernel/sched/idle.c | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 8885be2c143e..ad18962b921d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1945,7 +1945,7 @@ extern struct task_struct *idle_task(int cpu); */ static __always_inline bool is_idle_task(const struct task_struct *p) { - return !!(p->flags & PF_IDLE); + return !!(READ_ONCE(p->flags) & PF_IDLE); } extern struct task_struct *curr_task(int cpu); diff --git a/kernel/cpu.c b/kernel/cpu.c index 3b9d5c7eb4a2..3a1991010f4e 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1394,7 +1394,9 @@ void cpuhp_report_idle_dead(void) { struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state); + WRITE_ONCE(current->flags, current->flags & ~PF_IDLE); BUG_ON(st->state != CPUHP_AP_OFFLINE); + rcutree_report_cpu_dead(); st->state = CPUHP_AP_IDLE_DEAD; /* @@ -1642,6 +1644,8 @@ void cpuhp_online_idle(enum cpuhp_state state) { struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state); + WRITE_ONCE(current->flags, current->flags | PF_IDLE); + /* Happens for the boot cpu */ if (state != CPUHP_AP_ONLINE_IDLE) return; diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 5007b25c5bc6..342f58a329f5 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -373,7 +373,6 @@ EXPORT_SYMBOL_GPL(play_idle_precise); void cpu_startup_entry(enum cpuhp_state state) { - current->flags |= PF_IDLE; arch_cpu_idle_prepare(); cpuhp_online_idle(state); while (1)