Skip to content

Commit 07c54cc

Browse files
oleg-nesterovKAGA-KOKO
authored andcommitted
tick/nohz_full: Don't abuse smp_call_function_single() in tick_setup_device()
After the recent commit 5097cbc ("sched/isolation: Prevent boot crash when the boot CPU is nohz_full") the kernel no longer crashes, but there is another problem. In this case tick_setup_device() calls tick_take_do_timer_from_boot() to update tick_do_timer_cpu and this triggers the WARN_ON_ONCE(irqs_disabled) in smp_call_function_single(). Kill tick_take_do_timer_from_boot() and just use WRITE_ONCE(), the new comment explains why this is safe (thanks Thomas!). Fixes: 08ae95f ("nohz_full: Allow the boot CPU to be nohz_full") Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240528122019.GA28794@redhat.com Link: https://lore.kernel.org/all/20240522151742.GA10400@redhat.com
1 parent 83a7eef commit 07c54cc

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

kernel/time/tick-common.c

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,6 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast)
178178
}
179179
}
180180

181-
#ifdef CONFIG_NO_HZ_FULL
182-
static void giveup_do_timer(void *info)
183-
{
184-
int cpu = *(unsigned int *)info;
185-
186-
WARN_ON(tick_do_timer_cpu != smp_processor_id());
187-
188-
tick_do_timer_cpu = cpu;
189-
}
190-
191-
static void tick_take_do_timer_from_boot(void)
192-
{
193-
int cpu = smp_processor_id();
194-
int from = tick_do_timer_boot_cpu;
195-
196-
if (from >= 0 && from != cpu)
197-
smp_call_function_single(from, giveup_do_timer, &cpu, 1);
198-
}
199-
#endif
200-
201181
/*
202182
* Setup the tick device
203183
*/
@@ -221,19 +201,25 @@ static void tick_setup_device(struct tick_device *td,
221201
tick_next_period = ktime_get();
222202
#ifdef CONFIG_NO_HZ_FULL
223203
/*
224-
* The boot CPU may be nohz_full, in which case set
225-
* tick_do_timer_boot_cpu so the first housekeeping
226-
* secondary that comes up will take do_timer from
227-
* us.
204+
* The boot CPU may be nohz_full, in which case the
205+
* first housekeeping secondary will take do_timer()
206+
* from it.
228207
*/
229208
if (tick_nohz_full_cpu(cpu))
230209
tick_do_timer_boot_cpu = cpu;
231210

232-
} else if (tick_do_timer_boot_cpu != -1 &&
233-
!tick_nohz_full_cpu(cpu)) {
234-
tick_take_do_timer_from_boot();
211+
} else if (tick_do_timer_boot_cpu != -1 && !tick_nohz_full_cpu(cpu)) {
235212
tick_do_timer_boot_cpu = -1;
236-
WARN_ON(READ_ONCE(tick_do_timer_cpu) != cpu);
213+
/*
214+
* The boot CPU will stay in periodic (NOHZ disabled)
215+
* mode until clocksource_done_booting() called after
216+
* smp_init() selects a high resolution clocksource and
217+
* timekeeping_notify() kicks the NOHZ stuff alive.
218+
*
219+
* So this WRITE_ONCE can only race with the READ_ONCE
220+
* check in tick_periodic() but this race is harmless.
221+
*/
222+
WRITE_ONCE(tick_do_timer_cpu, cpu);
237223
#endif
238224
}
239225

0 commit comments

Comments
 (0)