Skip to content

Commit c725daf

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
timers: Don't block on ->expiry_lock for TIMER_IRQSAFE timers
PREEMPT_RT does not spin and wait until a running timer completes its callback but instead it blocks on a sleeping lock to prevent a livelock in the case that the task waiting for the callback completion preempted the callback. This cannot be done for timers flagged with TIMER_IRQSAFE. These timers can be canceled from an interrupt disabled context even on RT kernels. The expiry callback of such timers is invoked with interrupts disabled so there is no need to use the expiry lock mechanism because obviously the callback cannot be preempted even on RT kernels. Do not use the timer_base::expiry_lock mechanism when waiting for a running callback to complete if the timer is flagged with TIMER_IRQSAFE. Also add a lockdep assertion for RT kernels to validate that the expiry lock mechanism is always invoked in preemptible context. Reported-by: Mike Galbraith <efault@gmx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20201103190937.hga67rqhvknki3tp@linutronix.de
1 parent da88f9b commit c725daf

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎kernel/time/timer.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ static void del_timer_wait_running(struct timer_list *timer)
12881288
u32 tf;
12891289

12901290
tf = READ_ONCE(timer->flags);
1291-
if (!(tf & TIMER_MIGRATING)) {
1291+
if (!(tf & (TIMER_MIGRATING | TIMER_IRQSAFE))) {
12921292
struct timer_base *base = get_timer_base(tf);
12931293

12941294
/*
@@ -1372,6 +1372,13 @@ int del_timer_sync(struct timer_list *timer)
13721372
*/
13731373
WARN_ON(in_irq() && !(timer->flags & TIMER_IRQSAFE));
13741374

1375+
/*
1376+
* Must be able to sleep on PREEMPT_RT because of the slowpath in
1377+
* del_timer_wait_running().
1378+
*/
1379+
if (IS_ENABLED(CONFIG_PREEMPT_RT) && !(timer->flags & TIMER_IRQSAFE))
1380+
lockdep_assert_preemption_enabled();
1381+
13751382
do {
13761383
ret = try_to_del_timer_sync(timer);
13771384

0 commit comments

Comments
 (0)