Re: [PATCH 1/1] kthread: break dependency between worker->lock and task_struct->pi_lock

From: Peter Zijlstra
Date: Tue Apr 28 2020 - 12:32:20 EST


On Mon, Apr 27, 2020 at 11:43:58AM -0700, Suren Baghdasaryan wrote:
> A number of kthread-related functions indirectly take task_struct->pi_lock
> while holding worker->lock in the call chain like this:
> spin_lock(&worker->lock)
> kthread_insert_work
> wake_up_process
> try_to_wake_up
> raw_spin_lock_irqsave(&p->pi_lock, flags)
>
> This lock dependency exists whenever kthread_insert_work is called either
> directly or indirectly via __kthread_queue_delayed_work in the following
> functions:
> kthread_queue_work
> kthread_delayed_work_timer_fn
> kthread_queue_delayed_work
> kthread_flush_work
> kthread_mod_delayed_work
>
> This creates possibilities for circular dependencies like the one reported
> at: https://lkml.org/lkml/2020/4/24/954

Please, do not use lkml.org links.

Also, ideally, we'd pull that kthread_queue_delayed_work() out from
under rq->lock.

In fact, looking at it, WTH is the delayed branch of
kthread_queue_delayed_work() under that lock? That whole
delayed_work_list thing smells like bong-hits.