ARC: clone syscall to setp r25 as thread pointer
authorVineet Gupta <vgupta@synopsys.com>
Fri, 5 Oct 2018 19:48:48 +0000 (12:48 -0700)
committerVineet Gupta <vgupta@synopsys.com>
Fri, 5 Oct 2018 21:33:29 +0000 (14:33 -0700)
commitc58a584f05e35d1d4342923cd7aac07d9c3d3d16
treeeab575dcb6ad79894ea9d064d7c888111e327e12
parent40660f1fcee8d524a60b5101538e42b1f39f106d
ARC: clone syscall to setp r25 as thread pointer

Per ARC TLS ABI, r25 is designated TP (thread pointer register).
However so far kernel didn't do any special treatment, like setting up
usermode r25, even for CLONE_SETTLS. We instead relied on libc runtime
to do this, in say clone libc wrapper [1]. This was deliberate to keep
kernel ABI agnostic (userspace could potentially change TP, specially
for different ARC ISA say ARCompact vs. ARCv2 with different spare
registers etc)

However userspace setting up r25, after clone syscall opens a race, if
child is not scheduled and gets a signal instead. It starts off in
userspace not in clone but in a signal handler and anything TP sepcific
there such as pthread_self() fails which showed up with uClibc
testsuite nptl/tst-kill6 [2]

Fix this by having kernel populate r25 to TP value. So this locks in
ABI, but it was not going to change anyways, and fwiw is same for both
ARCompact (arc700 core) and ARCvs (HS3x cores)

[1] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/arc/clone.S
[2] https://github.com/wbx-github/uclibc-ng-test/blob/master/test/nptl/tst-kill6.c

Fixes: ARC STAR 9001378481
Cc: stable@vger.kernel.org
Reported-by: Nikita Sobolev <sobolev@synopsys.com>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
arch/arc/kernel/process.c