From patchwork Tue Oct 24 21:46:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13435299 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 E9DDDC25B47 for ; Tue, 24 Oct 2023 21:46:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234942AbjJXVql (ORCPT ); Tue, 24 Oct 2023 17:46:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344454AbjJXVqk (ORCPT ); Tue, 24 Oct 2023 17:46:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17440E8; Tue, 24 Oct 2023 14:46:38 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D70CC433CA; Tue, 24 Oct 2023 21:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698183997; bh=55r/JWo6Uc73yf5DqaZWWtL9jn0mpU9zwuvJddzRrBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJwBiK2zpYQrDryXd6sMwPwBHy1iWVHeuLLm1/SKdspkdlBLaYb177rzprEGFzQFC d/2ylslU8EmC2+4Sxk4BW38uhxydzZeW+CDALQ60QUQXXXMYjKOENLFfZDMsQ7glEN 8TPMKcAiWCjVXy86PTUMPR4BEzvx+20j7GxF0ihu6H1skiQnZQQdkTR+l8JG5Oe8yb qTLqfRwx7ExEu1za8vQIQvLUB4dJIgVHGysKG9CVdjrd+GFhiUBp0cCxXA3ht+hfqb Yy0yzvn+ueDYrOWnH1UYuicR+p70IkpRclVnhpdORftbhzg+rh52jd3Uz8zDi6+0G/ yVG9Kidh8eqhw== 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 1/4] rcu: Introduce rcu_cpu_online() Date: Tue, 24 Oct 2023 23:46:22 +0200 Message-ID: <20231024214625.6483-2-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 Export the RCU point of view as to when a CPU is considered offline (ie: when does RCU consider that a CPU is sufficiently down in the hotplug process to not feature any possible read side). This will be used by RCU-tasks whose vision of an offline CPU should reasonably match the one of RCU core. Fixes: cff9b2332ab7 ("kernel/sched: Modify initial boot task idle setup") Signed-off-by: Frederic Weisbecker --- kernel/rcu/rcu.h | 2 ++ kernel/rcu/tree.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h index 0d866eaa4cc8..b531c33e9545 100644 --- a/kernel/rcu/rcu.h +++ b/kernel/rcu/rcu.h @@ -500,6 +500,7 @@ static inline void rcu_expedite_gp(void) { } static inline void rcu_unexpedite_gp(void) { } static inline void rcu_async_hurry(void) { } static inline void rcu_async_relax(void) { } +static inline bool rcu_cpu_online(int cpu) { return true; } #else /* #ifdef CONFIG_TINY_RCU */ bool rcu_gp_is_normal(void); /* Internal RCU use. */ bool rcu_gp_is_expedited(void); /* Internal RCU use. */ @@ -509,6 +510,7 @@ void rcu_unexpedite_gp(void); void rcu_async_hurry(void); void rcu_async_relax(void); void rcupdate_announce_bootup_oddness(void); +bool rcu_cpu_online(int cpu); #ifdef CONFIG_TASKS_RCU_GENERIC void show_rcu_tasks_gp_kthreads(void); #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */ diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 700524726079..fd21c1506092 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -4202,6 +4202,13 @@ static bool rcu_rdp_cpu_online(struct rcu_data *rdp) return !!(rdp->grpmask & rcu_rnp_online_cpus(rdp->mynode)); } +bool rcu_cpu_online(int cpu) +{ + struct rcu_data *rdp = this_cpu_ptr(&rcu_data); + + return rcu_rdp_cpu_online(rdp); +} + #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU) /* From patchwork Tue Oct 24 21:46:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13435300 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 396C7C25B47 for ; Tue, 24 Oct 2023 21:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344464AbjJXVqs (ORCPT ); Tue, 24 Oct 2023 17:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234973AbjJXVqq (ORCPT ); Tue, 24 Oct 2023 17:46:46 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A75410D7; Tue, 24 Oct 2023 14:46:42 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F750C433C9; Tue, 24 Oct 2023 21:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698184001; bh=VF4rwPu4+YtRb7YG4mHtznxP8H/nXqrrus0i9svAMXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=au3/YmnrmAJQJG631/cxb4ORAO9pRQTWXnK7H6KnQmVugQQJmTa3DGjZcpQw9ePHJ VdX4Ifg7c8hlUO3kYIPVedfUuNpoouQDRjZIwigFJ5/PmE7rSzXFb9v8iDKOJcliSR HgWUCmh1iEQyjGwkEZxVBM6mSAlAQmfGiMlCD5A/OtOAJPxJyw+h+ApaZRgo0tcomy WmAMclPVf8javsIc5NZGs+kYXXeO8I0+YOzKenD/QkuKkpVtgeK7ciGyjzLbweSBWv 4lZLEwd3THfxpNQ7GMPc5W8yr/npFOeo0iM66/n73ymQi9DO+Zs85gzU/c+TmxleVd 5PiXlKNNqLlqw== 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 2/4] rcu/tasks: Handle new PF_IDLE semantics Date: Tue, 24 Oct 2023 23:46:23 +0200 Message-ID: <20231024214625.6483-3-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 CPU boot code preceding the actual idle loop is excluded from it. This has however introduced new potential RCU-tasks stalls when either: 1) Grace period is started before init/0 had a chance to set PF_IDLE, keeping it stuck in the holdout list until idle ever schedules. 2) Grace period is started when some possible CPUs have never been online, keeping their idle tasks stuck in the holdout list until the CPU ever boots up. 3) Similar to 1) but with secondary CPUs: Grace period is started concurrently with secondary CPU booting, putting its idle task in the holdout list because PF_IDLE isn't yet observed on it. It stays then stuck in the holdout list until that CPU ever schedules. The effect is mitigated here by the hotplug AP thread that must run to bring the CPU up. Fix this with handling the new semantics of PF_IDLE, keeping in mind that it may or may not be set on an idle task. Take advantage of that to strengthen the coverage of an RCU-tasks quiescent state within an idle task, excluding the CPU boot code from it. Only the code running within the idle loop is now a quiescent state, along with offline CPUs. Fixes: cff9b2332ab7 ("kernel/sched: Modify initial boot task idle setup") Suggested-by: Joel Fernandes Suggested-by: Paul E . McKenney" Signed-off-by: Frederic Weisbecker --- kernel/rcu/tasks.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h index bf5f178fe723..acf81efe5eff 100644 --- a/kernel/rcu/tasks.h +++ b/kernel/rcu/tasks.h @@ -895,10 +895,37 @@ static void rcu_tasks_pregp_step(struct list_head *hop) synchronize_rcu(); } +/* Check for quiescent states since the pregp's synchronize_rcu() */ +static bool rcu_tasks_is_holdout(struct task_struct *t) +{ + int cpu; + + /* Has the task been seen voluntarily sleeping? */ + if (!READ_ONCE(t->on_rq)) + return false; + + cpu = task_cpu(t); + + /* + * Idle tasks within the idle loop or offline CPUs are RCU-tasks + * quiescent states. But CPU boot code performed by the idle task + * isn't a quiescent state. + */ + if (t == idle_task(cpu)) { + if (is_idle_task(t)) + return false; + + if (!rcu_cpu_online(cpu)) + return false; + } + + return true; +} + /* Per-task initial processing. */ static void rcu_tasks_pertask(struct task_struct *t, struct list_head *hop) { - if (t != current && READ_ONCE(t->on_rq) && !is_idle_task(t)) { + if (t != current && rcu_tasks_is_holdout(t)) { get_task_struct(t); t->rcu_tasks_nvcsw = READ_ONCE(t->nvcsw); WRITE_ONCE(t->rcu_tasks_holdout, true); @@ -947,7 +974,7 @@ static void check_holdout_task(struct task_struct *t, if (!READ_ONCE(t->rcu_tasks_holdout) || t->rcu_tasks_nvcsw != READ_ONCE(t->nvcsw) || - !READ_ONCE(t->on_rq) || + !rcu_tasks_is_holdout(t) || (IS_ENABLED(CONFIG_NO_HZ_FULL) && !is_idle_task(t) && READ_ONCE(t->rcu_tasks_idle_cpu) >= 0)) { WRITE_ONCE(t->rcu_tasks_holdout, false); From patchwork Tue Oct 24 21:46:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13435301 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 BB5C1C25B6B for ; Tue, 24 Oct 2023 21:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234975AbjJXVqt (ORCPT ); Tue, 24 Oct 2023 17:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234984AbjJXVqs (ORCPT ); Tue, 24 Oct 2023 17:46:48 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F73D7F; Tue, 24 Oct 2023 14:46:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FE7FC433C8; Tue, 24 Oct 2023 21:46:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698184005; bh=SWH3H5Xdn3J5BOiYP+tbzdRJbhkTqpBLrBJhKbzm4Fo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=usKGKhB8JfO8caii44hKkyfsLAu0qLEivqPpVb5HoIyzboKeu0t9NOqlr5pq7VhBt QA6eSDiSI63VG1CG6dLZo9glJsKFKPHBIK1xN/syP7JfBPcjUxlBYf1rMg/r+u788I gP/+BztEMPJ5FUutfZ6KmeUL3wrg42cVHmg0igQIQMnK0sI04vsAiAmmnvmziFhbEM zh4nYA71JTFaW6qLDN/S7uwATgtoGBwyhJuex65txdCp8/8IWlstvWppT4gc+fJyB4 gcZ1zbzHYqU7Wy+743hSyHh2TLnFRa0PSdwqvwWaxOwLyC8AK3Db0MGYsps52afPoQ rn+mH6j3kFvkQ== 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 , Naresh Kamboju Subject: [PATCH 3/4] rcu/tasks-trace: Handle new PF_IDLE semantics Date: Tue, 24 Oct 2023 23:46:24 +0200 Message-ID: <20231024214625.6483-4-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 the idle task of an offline CPU may not carry the PF_IDLE flag anymore. However RCU-tasks-trace tests the opposite assertion, still assuming that idle tasks carry the PF_IDLE flag during their whole lifecycle. Remove this assumption to avoid spurious warnings but keep the initial test verifying that the idle task is the current task on any offline CPU. Reported-by: Naresh Kamboju Fixes: cff9b2332ab7 ("kernel/sched: Modify initial boot task idle setup") Suggested-by: Joel Fernandes Suggested-by: Paul E . McKenney" Signed-off-by: Frederic Weisbecker --- kernel/rcu/tasks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h index acf81efe5eff..4dd70f2af4af 100644 --- a/kernel/rcu/tasks.h +++ b/kernel/rcu/tasks.h @@ -1552,7 +1552,7 @@ static int trc_inspect_reader(struct task_struct *t, void *bhp_in) } else { // The task is not running, so C-language access is safe. nesting = t->trc_reader_nesting; - WARN_ON_ONCE(ofl && task_curr(t) && !is_idle_task(t)); + WARN_ON_ONCE(ofl && task_curr(t) && (t != idle_task(task_cpu(t)))); if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB) && ofl) n_heavy_reader_ofl_updates++; } 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)