On Thu, Sep 04, 2025 at 11:43:27AM -1000, Tejun Heo wrote: > Hello, Peter. > > On Thu, Sep 04, 2025 at 10:28:58PM +0200, Peter Zijlstra wrote: > ... > > RUNNABLE: > > 1) hold both source and target rq->lock. > ... > > Now, assuming you have a locking order like: > > > > p->pi_lock > > rq->lock > > dsq->lock > > > > When you do something like: > > > > __schedule() > > raw_spin_lock(rq->lock); > > next = pick_next_task() -> pick_task_scx() > > raw_spin_lock(dsq->lock); > > > > Then you are, in effect, in the RUNNABLE 1) case above. You hold both > > locks. Nothing is going to move your task around while you hold that > > dsq->lock. That task is on the dsq, anybody else wanting to also do > > anything with that task, will have to first take dsq->lock. > > > > Therefore, at this point, it is perfectly fine to do: > > > > set_task_cpu(cpu_of(rq)); // move task here > > > > There is no actual concurrency. The only thing there is is > > set_task_cpu() complaining you're not following the rules -- but you > > are, it just doesn't know -- and we can fix that. > > I can't convince myself this is safe. For example, when task_rq_lock() > returns, it should guarantee that the rq that the task is currently > associated with is locked and the task can't go anywhere. However, as > task_rq_lock() isn't interlocked with dsq lock, this won't hold true. I > think this will break multiple things subtly - e.g. the assumptions that > task_call_func() makes in the comment wouldn't hold anymore, > task_sched_runtime()'s test of task_on_rq_queued() would be racy, and so on. > > ie. Operations protected by deq/enq pair would be fine but anything which is > protected only by task_rq_lock/unlock() would become racy, right? So task_sched_runtime() only cares about 'current' tasks, those will never be on a dsq. But yes, things like task_call_func() and sched_setaffinity() will have subtle race conditions :/ Still, this seems fixable, and fixing this should get rid of a lot of current and proposed ugly. ( while poking at all this, I noticed that I forgot to apply this: https://lkml.kernel.org/r/20241030151255.300069509@xxxxxxxxxxxxx so I've rebased that and included it in the tree) /me removes most of the babbling and redirects to the just posted series: https://lkml.kernel.org/r/20250910154409.446470175@xxxxxxxxxxxxx