linux/drivers
Josh Triplett 3033f14ab7 clone: support passing tls argument via C rather than pt_regs magic
clone has some of the quirkiest syscall handling in the kernel, with a
pile of special cases, historical curiosities, and architecture-specific
calling conventions.  In particular, clone with CLONE_SETTLS accepts a
parameter "tls" that the C entry point completely ignores and some
assembly entry points overwrite; instead, the low-level arch-specific
code pulls the tls parameter out of the arch-specific register captured
as part of pt_regs on entry to the kernel.  That's a massive hack, and
it makes the arch-specific code only work when called via the specific
existing syscall entry points; because of this hack, any new clone-like
system call would have to accept an identical tls argument in exactly
the same arch-specific position, rather than providing a unified system
call entry point across architectures.

The first patch allows architectures to handle the tls argument via
normal C parameter passing, if they opt in by selecting
HAVE_COPY_THREAD_TLS.  The second patch makes 32-bit and 64-bit x86 opt
into this.

These two patches came out of the clone4 series, which isn't ready for
this merge window, but these first two cleanup patches were entirely
uncontroversial and have acks.  I'd like to go ahead and submit these
two so that other architectures can begin building on top of this and
opting into HAVE_COPY_THREAD_TLS.  However, I'm also happy to wait and
send these through the next merge window (along with v3 of clone4) if
anyone would prefer that.

This patch (of 2):

clone with CLONE_SETTLS accepts an argument to set the thread-local
storage area for the new thread.  sys_clone declares an int argument
tls_val in the appropriate point in the argument list (based on the
various CLONE_BACKWARDS variants), but doesn't actually use or pass along
that argument.  Instead, sys_clone calls do_fork, which calls
copy_process, which calls the arch-specific copy_thread, and copy_thread
pulls the corresponding syscall argument out of the pt_regs captured at
kernel entry (knowing what argument of clone that architecture passes tls
in).

Apart from being awful and inscrutable, that also only works because only
one code path into copy_thread can pass the CLONE_SETTLS flag, and that
code path comes from sys_clone with its architecture-specific
argument-passing order.  This prevents introducing a new version of the
clone system call without propagating the same architecture-specific
position of the tls argument.

However, there's no reason to pull the argument out of pt_regs when
sys_clone could just pass it down via C function call arguments.

Introduce a new CONFIG_HAVE_COPY_THREAD_TLS for architectures to opt into,
and a new copy_thread_tls that accepts the tls parameter as an additional
unsigned long (syscall-argument-sized) argument.  Change sys_clone's tls
argument to an unsigned long (which does not change the ABI), and pass
that down to copy_thread_tls.

Architectures that don't opt into copy_thread_tls will continue to ignore
the C argument to sys_clone in favor of the pt_regs captured at kernel
entry, and thus will be unable to introduce new versions of the clone
syscall.

Patch co-authored by Josh Triplett and Thiago Macieira.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Acked-by: Andy Lutomirski <luto@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thiago Macieira <thiago.macieira@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-06-25 17:00:38 -07:00
..
accessibility
acpi Power management and ACPI material for v4.2-rc1 2015-06-23 14:18:07 -07:00
amba
android
ata
atm
auxdisplay
base regmap: Fixes for v4.2 2015-06-23 17:25:32 -07:00
bcma
block zram: check comp algorithm availability earlier 2015-06-25 17:00:37 -07:00
bluetooth Bluetooth: ath3k: Add support of 04ca:300d AR3012 device 2015-06-18 21:00:06 +03:00
bus Power management and ACPI material for v4.2-rc1 2015-06-23 14:18:07 -07:00
cdrom
char powerpc updates for 4.2 2015-06-24 08:46:32 -07:00
clk Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
clocksource clocksource: Increase dependencies of timer-stm32 to limit build wreckage 2015-06-21 20:01:48 +02:00
connector
cpufreq Power management and ACPI material for v4.2-rc1 2015-06-23 14:18:07 -07:00
cpuidle Merge branch 'pm-cpuidle' 2015-06-22 15:15:36 +02:00
crypto Power management and ACPI material for v4.2-rc1 2015-06-23 14:18:07 -07:00
dca
devfreq
dio
dma Merge branch 'x86-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2015-06-22 17:59:09 -07:00
dma-buf
edac EDAC, mce_amd_inj: Set MISCV on injection 2015-06-24 18:17:38 +02:00
eisa
extcon
firewire
firmware Merge branch 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2015-06-22 17:10:44 -07:00
fmc
gpio Here is the bulk of pin control changes for the v4.2 series: 2015-06-24 19:21:02 -07:00
gpu Power management and ACPI material for v4.2-rc1 2015-06-23 14:18:07 -07:00
hid Merge branches 'for-4.2/i2c-hid', 'for-4.2/lenovo', 'for-4.2/plantronics', 'for-4.2/rmi', 'for-4.2/sensor-hub', 'for-4.2/sjoy', 'for-4.2/sony' and 'for-4.2/wacom' into for-linus 2015-06-22 16:23:43 +02:00
hsi HSI: nokia-modem: use flags argument of devm_gpiod_get to set direction 2015-06-23 02:40:03 +02:00
hv
hwmon hwmon changes for v4.2 2015-06-23 13:39:56 -07:00
hwspinlock
hwtracing/coresight
i2c == Changes to existing drivers == 2015-06-23 17:31:27 -07:00
ide
idle
iio
infiniband Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
input Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2015-06-24 19:56:58 -07:00
iommu IOMMU Updates for Linux v4.2 2015-06-23 18:27:19 -07:00
ipack
irqchip Merge branch 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2015-06-22 19:42:56 -07:00
isdn Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
leds Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2015-06-24 19:56:58 -07:00
lguest Merge branch 'x86-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2015-06-22 17:59:09 -07:00
macintosh
mailbox
mcb
md
media Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2015-06-23 14:08:54 -07:00
memory
memstick
message
mfd Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
misc clone: support passing tls argument via C rather than pt_regs magic 2015-06-25 17:00:38 -07:00
mmc mmc: queue: prevent soft lockups on PREEMPT=n 2015-06-18 09:21:04 +02:00
mtd powerpc updates for 4.2 2015-06-24 08:46:32 -07:00
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
nfc
ntb PCI changes for the v4.2 merge window: 2015-06-23 13:41:24 -07:00
nubus
of Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
oprofile
parisc
parport
pci Mohit Kumar has moved 2015-06-25 17:00:38 -07:00
pcmcia pcmcia: do not break rsrc_nonstatic when handling anonymous cards 2015-06-16 07:29:39 +02:00
phy Mohit Kumar has moved 2015-06-25 17:00:38 -07:00
pinctrl Here is the bulk of pin control changes for the v4.2 series: 2015-06-24 19:21:02 -07:00
platform == Changes to existing drivers == 2015-06-23 17:31:27 -07:00
pnp Merge branches 'pnp' and 'pm-tools' 2015-06-19 01:18:43 +02:00
power power supply and reset changes for the v4.2 series 2015-06-23 16:10:27 -07:00
powercap
pps
ps3
ptp
pwm pwm: Changes for v4.2-rc1 2015-06-23 13:32:38 -07:00
rapidio Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2015-06-23 14:08:54 -07:00
ras
regulator == Changes to existing drivers == 2015-06-23 17:31:27 -07:00
remoteproc
reset
rpmsg
rtc == Changes to existing drivers == 2015-06-23 17:31:27 -07:00
s390 Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
sbus
scsi Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
sfi
sh
sn
soc
spi Merge remote-tracking branches 'spi/topic/sirf', 'spi/topic/spidev' and 'spi/topic/zynq' into spi-next 2015-06-18 00:19:56 +01:00
spmi
ssb
staging Merge branch 'akpm' (patches from Andrew) 2015-06-24 20:47:21 -07:00
target Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
tc
thermal
thunderbolt
tty Merge branch 'akpm' (patches from Andrew) 2015-06-24 20:47:21 -07:00
uio
usb Pratyush Anand has moved 2015-06-25 17:00:38 -07:00
uwb
vfio powerpc updates for 4.2 2015-06-24 08:46:32 -07:00
vhost Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2015-06-24 16:49:49 -07:00
video == Changes to existing drivers == 2015-06-24 18:57:00 -07:00
virt
virtio PCI changes for the v4.2 merge window: 2015-06-23 13:41:24 -07:00
vlynq
vme
w1
watchdog
xen frontswap: allow multiple backends 2015-06-24 17:49:45 -07:00
zorro
Kconfig
Makefile