Patch "sched: Fix race between yield_to() and try_to_wake_up()" has been added to the 6.13-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    sched: Fix race between yield_to() and try_to_wake_up()

to the 6.13-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     sched-fix-race-between-yield_to-and-try_to_wake_up.patch
and it can be found in the queue-6.13 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 31df1c57e02aea3a17d8ce88345cf5d4de1545be
Author: Tianchen Ding <dtcccc@xxxxxxxxxxxxxxxxx>
Date:   Tue Dec 31 13:50:20 2024 +0800

    sched: Fix race between yield_to() and try_to_wake_up()
    
    [ Upstream commit 5d808c78d97251af1d3a3e4f253e7d6c39fd871e ]
    
    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 correct
    lock. Fix this by taking task pi_lock first.
    
    Fixes: d95f41220065 ("sched: Add yield_to(task, preempt) functionality")
    Signed-off-by: Tianchen Ding <dtcccc@xxxxxxxxxxxxxxxxx>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
    Link: https://lkml.kernel.org/r/20241231055020.6521-1-dtcccc@xxxxxxxxxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index ff0e5ab4e37cb..943406c4ee865 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -1433,7 +1433,7 @@ int __sched yield_to(struct task_struct *p, bool preempt)
 	struct rq *rq, *p_rq;
 	int yielded = 0;
 
-	scoped_guard (irqsave) {
+	scoped_guard (raw_spinlock_irqsave, &p->pi_lock) {
 		rq = this_rq();
 
 again:




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux