linux-stable/kernel
Peter Zijlstra 0b0c518c17 sched/wake_q: Fix wakeup ordering for wake_q
commit 4c4e373156 upstream.

Notable cmpxchg() does not provide ordering when it fails, however
wake_q_add() requires ordering in this specific case too. Without this
it would be possible for the concurrent wakeup to not observe our
prior state.

Andrea Parri provided:

  C wake_up_q-wake_q_add

  {
	int next = 0;
	int y = 0;
  }

  P0(int *next, int *y)
  {
	int r0;

	/* in wake_up_q() */

	WRITE_ONCE(*next, 1);   /* node->next = NULL */
	smp_mb();               /* implied by wake_up_process() */
	r0 = READ_ONCE(*y);
  }

  P1(int *next, int *y)
  {
	int r1;

	/* in wake_q_add() */

	WRITE_ONCE(*y, 1);      /* wake_cond = true */
	smp_mb__before_atomic();
	r1 = cmpxchg_relaxed(next, 1, 2);
  }

  exists (0:r0=0 /\ 1:r1=0)

  This "exists" clause cannot be satisfied according to the LKMM:

  Test wake_up_q-wake_q_add Allowed
  States 3
  0:r0=0; 1:r1=1;
  0:r0=1; 1:r1=0;
  0:r0=1; 1:r1=1;
  No
  Witnesses
  Positive: 0 Negative: 3
  Condition exists (0:r0=0 /\ 1:r1=0)
  Observation wake_up_q-wake_q_add Never 0 3

Reported-by: Yongji Xie <elohimes@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-11-10 11:25:38 +01:00
..
bpf bpf: fix use after free in prog symbol exposure 2019-10-07 18:55:15 +02:00
cgroup cgroup: Fix css_task_iter_advance_css_set() cset skip condition 2019-08-09 17:53:37 +02:00
configs
debug kdb: Don't back trace on a cpu that didn't round up 2019-02-12 19:46:09 +01:00
events perf/core: Fix creating kernel counters for PMUs that override event->cpu 2019-08-16 10:13:55 +02:00
gcov
irq genirq: Prevent NULL pointer dereference in resend_irqs() 2019-09-19 09:08:04 +02:00
livepatch livepatch: Nullify obj->mod in klp_module_coming()'s error path 2019-10-07 18:55:09 +02:00
locking Revert "locking/pvqspinlock: Don't wait if vCPU is preempted" 2019-10-11 18:18:36 +02:00
power x86/power: Fix 'nosmt' vs hibernation triple fault during resume 2019-06-11 12:21:48 +02:00
printk printk: Do not lose last line in kmsg buffer dump 2019-10-05 12:48:04 +02:00
rcu rcuperf: Fix cleanup path for invalid perf_type strings 2019-05-31 06:47:33 -07:00
sched sched/wake_q: Fix wakeup ordering for wake_q 2019-11-10 11:25:38 +01:00
time tick: broadcast-hrtimer: Fix a race in bc_set_next 2019-10-11 18:18:46 +02:00
trace tracing: Initialize iter->seq after zeroing in tracing_read_pipe() 2019-11-06 12:43:20 +01:00
.gitignore
acct.c
async.c
audit.c
audit.h
audit_fsnotify.c
audit_tree.c
audit_watch.c audit: fix use-after-free in audit_add_watch 2018-09-26 08:38:09 +02:00
auditfilter.c audit: fix a memory leak bug 2019-05-31 06:47:25 -07:00
auditsc.c
backtracetest.c
bounds.c kbuild: fix kernel/bounds.c 'W=1' warning 2018-11-13 11:15:08 -08:00
capability.c
compat.c
configs.c
context_tracking.c
cpu.c cpu/hotplug: Fix out-of-bounds read when setting fail state 2019-07-21 09:04:40 +02:00
cpu_pm.c
crash_core.c
crash_dump.c
cred.c access: avoid the RCU grace period for the temporary subjective credentials 2019-07-31 07:28:58 +02:00
delayacct.c
dma.c
elfcore.c kernel/elfcore.c: include proper prototypes 2019-10-11 18:18:42 +02:00
exec_domain.c
exit.c cgroup: Call cgroup_release() before __exit_signal() 2019-08-09 17:53:36 +02:00
extable.c
fork.c kernel/sysctl.c: do not override max_threads provided by userspace 2019-10-17 13:43:45 -07:00
freezer.c
futex.c locking/futex: Allow low-level atomic operations to return -EAGAIN 2019-05-10 17:53:15 +02:00
futex_compat.c
groups.c
hung_task.c kernel: hung_task.c: disable on suspend 2019-04-20 09:15:05 +02:00
irq_work.c
jump_label.c sched/core: Fix cpu.max vs. cpuhotplug deadlock 2018-12-05 19:41:17 +01:00
kallsyms.c kallsyms: Don't let kallsyms_lookup_size_offset() fail on retrieving the first symbol 2019-09-21 07:15:38 +02:00
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
kcov.c
kexec.c
kexec_core.c kexec: bail out upon SIGKILL when allocating memory. 2019-10-07 18:55:23 +02:00
kexec_file.c
kexec_internal.h
kmod.c
kprobes.c kprobes: Prohibit probing on BUG() and WARN() address 2019-10-05 12:48:01 +02:00
ksysfs.c
kthread.c
latencytop.c
Makefile x86/uaccess, kcov: Disable stack protector 2019-06-19 08:20:56 +02:00
memremap.c mm, devm_memremap_pages: kill mapping "System RAM" support 2019-01-13 10:01:02 +01:00
module-internal.h
module.c kernel/module: Fix mem leak in module_add_modinfo_attrs 2019-09-16 08:20:46 +02:00
module_signing.c
notifier.c
nsproxy.c
padata.c padata: use smp_mb in padata_reorder to avoid orphaned padata jobs 2019-07-31 07:28:39 +02:00
panic.c panic: ensure preemption is disabled during panic() 2019-10-17 13:43:19 -07:00
params.c
pid.c
pid_namespace.c signal/pid_namespace: Fix reboot_pid_ns to use send_sig not force_sig 2019-07-31 07:28:21 +02:00
profile.c
ptrace.c ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME 2019-07-10 09:54:38 +02:00
range.c
reboot.c
relay.c relay: check return of create_buf_file() properly 2019-03-13 14:03:20 -07:00
resource.c
seccomp.c
signal.c kernel/signal.c: trace_signal_deliver when signal_group_exit 2019-06-09 09:18:17 +02:00
smp.c cpu/hotplug: Fix "SMT disabled by BIOS" detection for KVM 2019-02-12 19:46:13 +01:00
smpboot.c
smpboot.h
softirq.c
stacktrace.c
stop_machine.c stop_machine: Atomically queue and wake stopper threads 2018-09-05 09:26:36 +02:00
sys.c kernel/sys.c: prctl: fix false positive in validate_prctl_map() 2019-06-15 11:54:52 +02:00
sys_ni.c
sysctl.c sysctl: return -EINVAL if val violates minmax 2019-06-15 11:54:51 +02:00
sysctl_binary.c
task_work.c
taskstats.c
test_kprobes.c
torture.c
tracepoint.c
tsacct.c
ucount.c
uid16.c
umh.c
up.c
user-return-notifier.c
user.c
user_namespace.c userns: move user access out of the mutex 2018-09-09 19:56:00 +02:00
utsname.c
utsname_sysctl.c sys: don't hold uts_sem while accessing userspace memory 2018-09-09 19:56:00 +02:00
watchdog.c watchdog: Mark watchdog touch functions as notrace 2018-09-05 09:26:42 +02:00
watchdog_hld.c watchdog: Mark watchdog touch functions as notrace 2018-09-05 09:26:42 +02:00
workqueue.c watchdog: Mark watchdog touch functions as notrace 2018-09-05 09:26:42 +02:00
workqueue_internal.h