Skip to content

Commit dad6a09

Browse files
Frederic WeisbeckerKAGA-KOKO
Frederic Weisbecker
authored andcommitted
hrtimer: Report offline hrtimer enqueue
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. Fixes: 5c0930c ("hrtimers: Push pending hrtimers away from outgoing CPU earlier") Reported-by: Paul E. McKenney <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 54be6c6 commit dad6a09

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

include/linux/hrtimer.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ enum hrtimer_base_type {
157157
* @max_hang_time: Maximum time spent in hrtimer_interrupt
158158
* @softirq_expiry_lock: Lock which is taken while softirq based hrtimer are
159159
* expired
160+
* @online: CPU is online from an hrtimers point of view
160161
* @timer_waiters: A hrtimer_cancel() invocation waits for the timer
161162
* callback to finish.
162163
* @expires_next: absolute time of the next event, is required for remote
@@ -179,7 +180,8 @@ struct hrtimer_cpu_base {
179180
unsigned int hres_active : 1,
180181
in_hrtirq : 1,
181182
hang_detected : 1,
182-
softirq_activated : 1;
183+
softirq_activated : 1,
184+
online : 1;
183185
#ifdef CONFIG_HIGH_RES_TIMERS
184186
unsigned int nr_events;
185187
unsigned short nr_retries;

kernel/time/hrtimer.c

+3
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ static int enqueue_hrtimer(struct hrtimer *timer,
10851085
enum hrtimer_mode mode)
10861086
{
10871087
debug_activate(timer, mode);
1088+
WARN_ON_ONCE(!base->cpu_base->online);
10881089

10891090
base->cpu_base->active_bases |= 1 << base->index;
10901091

@@ -2183,6 +2184,7 @@ int hrtimers_prepare_cpu(unsigned int cpu)
21832184
cpu_base->softirq_next_timer = NULL;
21842185
cpu_base->expires_next = KTIME_MAX;
21852186
cpu_base->softirq_expires_next = KTIME_MAX;
2187+
cpu_base->online = 1;
21862188
hrtimer_cpu_base_init_expiry_lock(cpu_base);
21872189
return 0;
21882190
}
@@ -2250,6 +2252,7 @@ int hrtimers_cpu_dying(unsigned int dying_cpu)
22502252
smp_call_function_single(ncpu, retrigger_next_event, NULL, 0);
22512253

22522254
raw_spin_unlock(&new_base->lock);
2255+
old_base->online = 0;
22532256
raw_spin_unlock(&old_base->lock);
22542257

22552258
return 0;

0 commit comments

Comments
 (0)