Re: [PATCH] sched: Fix race between yield_to() and try_to_wake_up()

From: Tianchen Ding
Date: Tue Dec 31 2024 - 01:01:45 EST


On 2024/12/31 13:50, Tianchen Ding wrote:
We met a SCHED_WARN in set_next_buddy():
__warn_printk
set_next_buddy
yield_to_task_fair
yield_to
kvm_vcpu_yield_to [kvm]
...

After a short dig, we found the rq_lock held by yield_to() may not
be exactly the rq that the target task belongs to. There is a race
window against try_to_wake_up().

CPU0 target_task

blocking on CPU1
lock rq0 & rq1
double check task_rq == p_rq, ok
woken to CPU2 (lock task_pi & rq2)
task_rq = rq2
yield_to_task_fair (w/o lock rq2)

In this race window, yield_to() is operating the task w/o the currect
Sorry... a typo for "correct"