Patch "sched/core: Mitigate race cpus_share_cache()/update_top_cache_domain()" has been added to the 5.4-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/core: Mitigate race cpus_share_cache()/update_top_cache_domain()

to the 5.4-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-core-mitigate-race-cpus_share_cache-update_top.patch
and it can be found in the queue-5.4 subdirectory.

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



commit d7fd604052b2e8817592daae67a460fee0ddefa6
Author: Vincent Donnefort <vincent.donnefort@xxxxxxx>
Date:   Thu Nov 4 17:51:20 2021 +0000

    sched/core: Mitigate race cpus_share_cache()/update_top_cache_domain()
    
    [ Upstream commit 42dc938a590c96eeb429e1830123fef2366d9c80 ]
    
    Nothing protects the access to the per_cpu variable sd_llc_id. When testing
    the same CPU (i.e. this_cpu == that_cpu), a race condition exists with
    update_top_cache_domain(). One scenario being:
    
                  CPU1                            CPU2
      ==================================================================
    
      per_cpu(sd_llc_id, CPUX) => 0
                                        partition_sched_domains_locked()
                                          detach_destroy_domains()
      cpus_share_cache(CPUX, CPUX)          update_top_cache_domain(CPUX)
        per_cpu(sd_llc_id, CPUX) => 0
                                              per_cpu(sd_llc_id, CPUX) = CPUX
        per_cpu(sd_llc_id, CPUX) => CPUX
        return false
    
    ttwu_queue_cond() wouldn't catch smp_processor_id() == cpu and the result
    is a warning triggered from ttwu_queue_wakelist().
    
    Avoid a such race in cpus_share_cache() by always returning true when
    this_cpu == that_cpu.
    
    Fixes: 518cd6234178 ("sched: Only queue remote wakeups when crossing cache boundaries")
    Reported-by: Jing-Ting Wu <jing-ting.wu@xxxxxxxxxxxx>
    Signed-off-by: Vincent Donnefort <vincent.donnefort@xxxxxxx>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
    Reviewed-by: Valentin Schneider <valentin.schneider@xxxxxxx>
    Reviewed-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20211104175120.857087-1-vincent.donnefort@xxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5dc43d37e6a2b..f8ca0738d729e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2482,6 +2482,9 @@ void wake_up_if_idle(int cpu)
 
 bool cpus_share_cache(int this_cpu, int that_cpu)
 {
+	if (this_cpu == that_cpu)
+		return true;
+
 	return per_cpu(sd_llc_id, this_cpu) == per_cpu(sd_llc_id, that_cpu);
 }
 #endif /* CONFIG_SMP */



[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