Skip to content

Commit c0408f4

Browse files
committed
tick/nohz_full: Don't abuse smp_call_function_single() in tick_setup_device()
JIRA: https://issues.redhat.com/browse/RHEL-30589 commit 07c54cc Author: Oleg Nesterov <oleg@redhat.com> Date: Tue May 28 14:20:19 2024 +0200 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 Signed-off-by: Oleg Nesterov <oleg@redhat.com>
1 parent 4997440 commit c0408f4

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
@@ -179,26 +179,6 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast)
179179
}
180180
}
181181

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

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

0 commit comments

Comments
 (0)