softirq: Provide a handshake for canceling tasklets via polling
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 4 Sep 2025 14:25:24 +0000 (16:25 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 17 Sep 2025 14:25:41 +0000 (16:25 +0200)
commitfd4e876f59b7e70283b4025c717cad8948397be1
tree8360a0d374552df4836015e4bcb2bce5caa181b9
parent8ad25ebfa70e86860559b306bbc923c7db4fcac6
softirq: Provide a handshake for canceling tasklets via polling

The tasklet_unlock_spin_wait() via tasklet_disable_in_atomic() is
provided for a few legacy tasklet users. The interface is used from
atomic context (which is either softirq or disabled preemption) on
non-PREEMPT_RT and relies on spinning until the tasklet callback
completes.

On PREEMPT_RT the context is never atomic but the busy polling logic
remains. It is possible that the thread invoking tasklet_unlock_spin_wait()
has higher priority than the tasklet. If both run on the same CPU the the
tasklet makes no progress and the thread trying to cancel the tasklet will
live-lock the system.

To avoid the lockup tasklet_unlock_spin_wait() uses local_bh_disable()/
enable() which utilizes the local_lock_t for synchronisation. This lock is
a central per-CPU BKL and about to be removed.

Solve this by acquire a lock in tasklet_action_common() which is held while
the tasklet's callback is invoked. This lock will be acquired from
tasklet_unlock_spin_wait() via tasklet_callback_cancel_wait_running().

After the tasklet completed tasklet_callback_sync_wait_running() drops the
lock and acquires it again. In order to avoid unlocking the lock even if
there is no cancel request, there is a cb_waiters counter which is
incremented during a cancel request.  Blocking on the lock will PI-boost
the tasklet if needed, ensuring progress is made.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
kernel/softirq.c