1
0
Fork 0
alistair23-linux/kernel/sched
Boqun Feng 35a2897c2a sched/wait: Remove the lockless swait_active() check in swake_up*()
Steven Rostedt reported a potential race in RCU core because of
swake_up():

        CPU0                            CPU1
        ----                            ----
                                __call_rcu_core() {

                                 spin_lock(rnp_root)
                                 need_wake = __rcu_start_gp() {
                                  rcu_start_gp_advanced() {
                                   gp_flags = FLAG_INIT
                                  }
                                 }

 rcu_gp_kthread() {
   swait_event_interruptible(wq,
        gp_flags & FLAG_INIT) {
   spin_lock(q->lock)

                                *fetch wq->task_list here! *

   list_add(wq->task_list, q->task_list)
   spin_unlock(q->lock);

   *fetch old value of gp_flags here *

                                 spin_unlock(rnp_root)

                                 rcu_gp_kthread_wake() {
                                  swake_up(wq) {
                                   swait_active(wq) {
                                    list_empty(wq->task_list)

                                   } * return false *

  if (condition) * false *
    schedule();

In this case, a wakeup is missed, which could cause the rcu_gp_kthread
waits for a long time.

The reason of this is that we do a lockless swait_active() check in
swake_up(). To fix this, we can either 1) add a smp_mb() in swake_up()
before swait_active() to provide the proper order or 2) simply remove
the swait_active() in swake_up().

The solution 2 not only fixes this problem but also keeps the swait and
wait API as close as possible, as wake_up() doesn't provide a full
barrier and doesn't do a lockless check of the wait queue either.
Moreover, there are users already using swait_active() to do their quick
checks for the wait queues, so it make less sense that swake_up() and
swake_up_all() do this on their own.

This patch then removes the lockless swait_active() check in swake_up()
and swake_up_all().

Reported-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Krister Johansen <kjlx@templeofstupid.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20170615041828.zk3a3sfyudm5p6nl@tardis
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-08-10 12:28:53 +02:00
..
Makefile Merge branch 'WIP.sched/core' into sched/core 2017-06-20 12:28:21 +02:00
autogroup.c sched/autogroup: Rename auto_group.[ch] to autogroup.[ch] 2017-02-08 09:01:11 +01:00
autogroup.h sched/headers: Prepare for new header dependencies before moving code to <linux/sched/autogroup.h> 2017-03-02 08:42:28 +01:00
clock.c sched/clock: Fix early boot preempt assumption in __set_sched_clock_stable() 2017-05-24 09:10:00 +02:00
completion.c sched/wait: Rename wait_queue_t => wait_queue_entry_t 2017-06-20 12:18:27 +02:00
core.c sched/core: Fix some documentation build warnings 2017-07-25 11:17:02 +02:00
cpuacct.c sched/cputime: Convert kcpustat to nsecs 2017-02-01 09:13:47 +01:00
cpuacct.h sched/cpuacct: Simplify the cpuacct code 2016-03-21 11:00:28 +01:00
cpudeadline.c sched/core: Remove the tsk_cpus_allowed() wrapper 2017-03-02 08:42:24 +01:00
cpudeadline.h sched/deadline: Split cpudl_set() into cpudl_set() and cpudl_clear() 2016-09-05 13:29:43 +02:00
cpufreq.c cpufreq / sched: Pass flags to cpufreq_update_util() 2016-08-16 22:14:55 +02:00
cpufreq_schedutil.c cpufreq: schedutil: Fix sugov_start() versus sugov_update_shared() race 2017-07-12 14:47:48 +02:00
cpupri.c sched/core: Remove the tsk_cpus_allowed() wrapper 2017-03-02 08:42:24 +01:00
cpupri.h sched/cpupri: Remove unnecessary definitions in cpupri.h 2014-11-16 10:58:59 +01:00
cputime.c sched/cputime: Don't use smp_processor_id() in preemptible context 2017-07-14 10:27:15 +02:00
deadline.c sched/deadline: Fix confusing comments about selection of top pi-waiter 2017-07-14 10:35:16 +02:00
debug.c sched/debug: Expose the number of RT/DL tasks that can migrate 2017-06-30 09:32:07 +02:00
fair.c sched/fair: Fix load_balance() affinity redo path 2017-07-05 16:28:48 +02:00
features.h sched/core: Implement new approach to scale select_idle_cpu() 2017-06-08 10:25:17 +02:00
idle.c sched/idle: Add deferrable vmstat_updater back 2017-06-08 10:32:09 +02:00
idle_task.c sched/core: Add wrappers for lockdep_(un)pin_lock() 2017-01-14 11:29:30 +01:00
loadavg.c sched/loadavg: Generalize "_idle" naming to "_nohz" 2017-06-22 11:30:01 +02:00
rt.c sched/rt: Move RT related code from sched/core.c to sched/rt.c 2017-06-23 10:46:45 +02:00
sched-pelt.h sched/fair: Move the PELT constants into a generated header 2017-04-14 10:26:37 +02:00
sched.h sched/rt: Move RT related code from sched/core.c to sched/rt.c 2017-06-23 10:46:45 +02:00
stats.c sched: use %*pb[l] to print bitmaps including cpumasks and nodemasks 2015-02-13 21:21:37 -08:00
stats.h sched/headers: Move cputime functionality from <linux/sched.h> and <linux/cputime.h> into <linux/sched/cputime.h> 2017-03-03 01:45:22 +01:00
stop_task.c sched/core: Add wrappers for lockdep_(un)pin_lock() 2017-01-14 11:29:30 +01:00
swait.c sched/wait: Remove the lockless swait_active() check in swake_up*() 2017-08-10 12:28:53 +02:00
topology.c sched/topology: Rename sched_group_cpus() 2017-05-15 10:15:34 +02:00
wait.c sched/wait: Disambiguate wq_entry->task_list and wq_head->task_list naming 2017-06-20 12:19:14 +02:00
wait_bit.c sched/wait: Disambiguate wq_entry->task_list and wq_head->task_list naming 2017-06-20 12:19:14 +02:00