From: Boqun Feng <boqun.feng@gmail.com>
To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org
Cc: Frederic Weisbecker <frederic@kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 3/8] hrtimer: Report offline hrtimer enqueue
Date: Mon, 29 Jan 2024 15:56:36 -0800 [thread overview]
Message-ID: <20240129235646.3171983-4-boqun.feng@gmail.com> (raw)
In-Reply-To: <20240129235646.3171983-1-boqun.feng@gmail.com>
From: Frederic Weisbecker <frederic@kernel.org>
The hrtimers migration on CPU-down hotplug process has been moved
earlier, before the CPU actually goes to die. This leaves a small window
of opportunity to queue an hrtimer in a blind spot, leaving it ignored.
For example a practical case has been reported with RCU waking up a
SCHED_FIFO task right before the CPUHP_AP_IDLE_DEAD stage, queuing that
way a sched/rt timer to the local offline CPU.
Make sure such situations never go unnoticed and warn when that happens.
Reported-by: Paul E. McKenney <paulmck@kernel.org>
Fixes: 5c0930ccaad5 ("hrtimers: Push pending hrtimers away from outgoing CPU earlier")
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
include/linux/hrtimer.h | 3 ++-
kernel/time/hrtimer.c | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 87e3bedf8eb0..4f2cf7309486 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -179,7 +179,8 @@ struct hrtimer_cpu_base {
unsigned int hres_active : 1,
in_hrtirq : 1,
hang_detected : 1,
- softirq_activated : 1;
+ softirq_activated : 1,
+ online : 1;
#ifdef CONFIG_HIGH_RES_TIMERS
unsigned int nr_events;
unsigned short nr_retries;
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 760793998cdd..edb0f821dcea 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1085,6 +1085,7 @@ static int enqueue_hrtimer(struct hrtimer *timer,
enum hrtimer_mode mode)
{
debug_activate(timer, mode);
+ WARN_ON_ONCE(!base->cpu_base->online);
base->cpu_base->active_bases |= 1 << base->index;
@@ -2183,6 +2184,7 @@ int hrtimers_prepare_cpu(unsigned int cpu)
cpu_base->softirq_next_timer = NULL;
cpu_base->expires_next = KTIME_MAX;
cpu_base->softirq_expires_next = KTIME_MAX;
+ cpu_base->online = 1;
hrtimer_cpu_base_init_expiry_lock(cpu_base);
return 0;
}
@@ -2250,6 +2252,7 @@ int hrtimers_cpu_dying(unsigned int dying_cpu)
smp_call_function_single(ncpu, retrigger_next_event, NULL, 0);
raw_spin_unlock(&new_base->lock);
+ old_base->online = 0;
raw_spin_unlock(&old_base->lock);
return 0;
--
2.43.0
next prev parent reply other threads:[~2024-01-29 23:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-29 23:56 [PATCH 0/8] Misc RCU update for v6.9 Boqun Feng
2024-01-29 23:56 ` [PATCH 1/8] rcu: Rename jiffies_till_flush to jiffies_lazy_flush Boqun Feng
2024-01-29 23:56 ` [PATCH 2/8] rcu: Provide a boot time parameter to control lazy RCU Boqun Feng
2024-01-29 23:56 ` Boqun Feng [this message]
2024-01-29 23:56 ` [PATCH 4/8] srcu: Improve comments about acceleration leak Boqun Feng
2024-01-29 23:56 ` [PATCH 5/8] tsc: Check for sockets instead of CPUs to make code match comment Boqun Feng
2024-02-05 20:03 ` Paul E. McKenney
2024-02-05 21:09 ` Boqun Feng
2024-01-29 23:56 ` [PATCH 6/8] rcutorture: Suppress rtort_pipe_count warnings until after stalls Boqun Feng
2024-01-29 23:56 ` [PATCH 7/8] clocksource: Skip watchdog check for large watchdog intervals Boqun Feng
2024-01-29 23:56 ` [PATCH 8/8] rcu/sync: remove un-used rcu_sync_enter_start function Boqun Feng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240129235646.3171983-4-boqun.feng@gmail.com \
--to=boqun.feng@gmail.com \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox