alistair23-linux/kernel/sched
Mathieu Desnoyers ce3614daab sched: Fix unreliable rseq cpu_id for new tasks
While integrating rseq into glibc and replacing glibc's sched_getcpu
implementation with rseq, glibc's tests discovered an issue with
incorrect __rseq_abi.cpu_id field value right after the first time
a newly created process issues sched_setaffinity.

For the records, it triggers after building glibc and running tests, and
then issuing:

  for x in {1..2000} ; do posix/tst-affinity-static  & done

and shows up as:

error: Unexpected CPU 2, expected 0
error: Unexpected CPU 2, expected 0
error: Unexpected CPU 2, expected 0
error: Unexpected CPU 2, expected 0
error: Unexpected CPU 138, expected 0
error: Unexpected CPU 138, expected 0
error: Unexpected CPU 138, expected 0
error: Unexpected CPU 138, expected 0

This is caused by the scheduler invoking __set_task_cpu() directly from
sched_fork() and wake_up_new_task(), thus bypassing rseq_migrate() which
is done by set_task_cpu().

Add the missing rseq_migrate() to both functions. The only other direct
use of __set_task_cpu() is done by init_idle(), which does not involve a
user-space task.

Based on my testing with the glibc test-case, just adding rseq_migrate()
to wake_up_new_task() is sufficient to fix the observed issue. Also add
it to sched_fork() to keep things consistent.

The reason why this never triggered so far with the rseq/basic_test
selftest is unclear.

The current use of sched_getcpu(3) does not typically require it to be
always accurate. However, use of the __rseq_abi.cpu_id field within rseq
critical sections requires it to be accurate. If it is not accurate, it
can cause corruption in the per-cpu data targeted by rseq critical
sections in user-space.

Reported-By: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-By: Florian Weimer <fweimer@redhat.com>
Cc: stable@vger.kernel.org # v4.18+
Link: https://lkml.kernel.org/r/20200707201505.2632-1-mathieu.desnoyers@efficios.com
2020-07-08 11:38:50 +02:00
..
autogroup.c
autogroup.h
clock.c
completion.c
core.c sched: Fix unreliable rseq cpu_id for new tasks 2020-07-08 11:38:50 +02:00
cpuacct.c sched/cpuacct: Fix charge cpuacct.usage_sys 2020-05-19 20:34:14 +02:00
cpudeadline.c
cpudeadline.h
cpufreq.c
cpufreq_schedutil.c
cpupri.c
cpupri.h
cputime.c sched/vtime: Work around an unitialized variable warning 2020-04-15 11:06:50 +02:00
deadline.c sched/deadline: Initialize ->dl_boosted 2020-06-28 17:01:20 +02:00
debug.c sched: Add rq::ttwu_pending 2020-05-28 10:54:16 +02:00
fair.c sched/cfs: change initial value of runnable_avg 2020-06-28 17:01:20 +02:00
features.h
idle.c cpuidle: Rearrange s2idle-specific idle state entry code 2020-06-25 13:52:53 +02:00
isolation.c sched/isolation: Allow "isolcpus=" to skip unknown sub-parameters 2020-04-15 10:38:26 +02:00
loadavg.c
Makefile
membarrier.c
pelt.c sched/pelt: Sync util/runnable_sum with PELT window when propagating 2020-05-19 20:34:14 +02:00
pelt.h
psi.c
rt.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-06-03 16:27:18 -07:00
sched-pelt.h
sched.h sched/core: s/WF_ON_RQ/WQ_ON_CPU/ 2020-06-28 17:01:20 +02:00
smp.h sched/headers: Split out open-coded prototypes into kernel/sched/smp.h 2020-05-28 11:03:20 +02:00
stats.c
stats.h
stop_task.c
swait.c
topology.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-06-03 16:27:18 -07:00
wait.c
wait_bit.c