Skip to content

Commit 9ba2741

Browse files
committed
Merge tag 'fork-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux
Pull fork cleanups from Christian Brauner: "This is cleanup series from when we reworked a chunk of the process creation paths in the kernel and switched to struct {kernel_}clone_args. High-level this does two main things: - Remove the double export of both do_fork() and _do_fork() where do_fork() used the incosistent legacy clone calling convention. Now we only export _do_fork() which is based on struct kernel_clone_args. - Remove the copy_thread_tls()/copy_thread() split making the architecture specific HAVE_COYP_THREAD_TLS config option obsolete. This switches all remaining architectures to select HAVE_COPY_THREAD_TLS and thus to the copy_thread_tls() calling convention. The current split makes the process creation codepaths more convoluted than they need to be. Each architecture has their own copy_thread() function unless it selects HAVE_COPY_THREAD_TLS then it has a copy_thread_tls() function. The split is not needed anymore nowadays, all architectures support CLONE_SETTLS but quite a few of them never bothered to select HAVE_COPY_THREAD_TLS and instead simply continued to use copy_thread() and use the old calling convention. Removing this split cleans up the process creation codepaths and paves the way for implementing clone3() on such architectures since it requires the copy_thread_tls() calling convention. After having made each architectures support copy_thread_tls() this series simply renames that function back to copy_thread(). It also switches all architectures that call do_fork() directly over to _do_fork() and the struct kernel_clone_args calling convention. This is a corollary of switching the architectures that did not yet support it over to copy_thread_tls() since do_fork() is conditional on not supporting copy_thread_tls() (Mostly because it lacks a separate argument for tls which is trivial to fix but there's no need for this function to exist.). The do_fork() removal is in itself already useful as it allows to to remove the export of both do_fork() and _do_fork() we currently have in favor of only _do_fork(). This has already been discussed back when we added clone3(). The legacy clone() calling convention is - as is probably well-known - somewhat odd: # # ABI hall of shame # config CLONE_BACKWARDS config CLONE_BACKWARDS2 config CLONE_BACKWARDS3 that is aggravated by the fact that some architectures such as sparc follow the CLONE_BACKWARDSx calling convention but don't really select the corresponding config option since they call do_fork() directly. So do_fork() enforces a somewhat arbitrary calling convention in the first place that doesn't really help the individual architectures that deviate from it. They can thus simply be switched to _do_fork() enforcing a single calling convention. (I really hope that any new architectures will __not__ try to implement their own calling conventions...) Most architectures already have made a similar switch (m68k comes to mind). Overall this removes more code than it adds even with a good portion of added comments. It simplifies a chunk of arch specific assembly either by moving the code into C or by simply rewriting the assembly. Architectures that have been touched in non-trivial ways have all been actually boot and stress tested: sparc and ia64 have been tested with Debian 9 images. They are the two architectures which have been touched the most. All non-trivial changes to architectures have seen acks from the relevant maintainers. nios2 with a custom built buildroot image. h8300 I couldn't get something bootable to test on but the changes have been fairly automatic and I'm sure we'll hear people yell if I broke something there. All other architectures that have been touched in trivial ways have been compile tested for each single patch of the series via git rebase -x "make ..." v5.8-rc2. arm{64} and x86{_64} have been boot tested even though they have just been trivially touched (removal of the HAVE_COPY_THREAD_TLS macro from their Kconfig) because well they are basically "core architectures" and since it is trivial to get your hands on a useable image" * tag 'fork-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux: arch: rename copy_thread_tls() back to copy_thread() arch: remove HAVE_COPY_THREAD_TLS unicore: switch to copy_thread_tls() sh: switch to copy_thread_tls() nds32: switch to copy_thread_tls() microblaze: switch to copy_thread_tls() hexagon: switch to copy_thread_tls() c6x: switch to copy_thread_tls() alpha: switch to copy_thread_tls() fork: remove do_fork() h8300: select HAVE_COPY_THREAD_TLS, switch to kernel_clone_args nios2: enable HAVE_COPY_THREAD_TLS, switch to kernel_clone_args ia64: enable HAVE_COPY_THREAD_TLS, switch to kernel_clone_args sparc: unconditionally enable HAVE_COPY_THREAD_TLS sparc: share process creation helpers between sparc and sparc64 sparc64: enable HAVE_COPY_THREAD_TLS fork: fold legacy_clone_args_valid() into _do_fork()
2 parents 0a72761 + 714acdb commit 9ba2741

File tree

52 files changed

+274
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+274
-286
lines changed

arch/Kconfig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,6 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
754754
depends on MMU
755755
select ARCH_HAS_ELF_RANDOMIZE
756756

757-
config HAVE_COPY_THREAD_TLS
758-
bool
759-
help
760-
Architecture provides copy_thread_tls to accept tls argument via
761-
normal C parameter passing, rather than extracting the syscall
762-
argument from pt_regs.
763-
764757
config HAVE_STACK_VALIDATION
765758
bool
766759
help

arch/alpha/kernel/process.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,9 @@ release_thread(struct task_struct *dead_task)
233233
/*
234234
* Copy architecture-specific thread state
235235
*/
236-
int
237-
copy_thread(unsigned long clone_flags, unsigned long usp,
238-
unsigned long kthread_arg,
239-
struct task_struct *p)
236+
int copy_thread(unsigned long clone_flags, unsigned long usp,
237+
unsigned long kthread_arg, struct task_struct *p,
238+
unsigned long tls)
240239
{
241240
extern void ret_from_fork(void);
242241
extern void ret_from_kernel_thread(void);
@@ -267,7 +266,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
267266
required for proper operation in the case of a threaded
268267
application calling fork. */
269268
if (clone_flags & CLONE_SETTLS)
270-
childti->pcb.unique = regs->r20;
269+
childti->pcb.unique = tls;
271270
else
272271
regs->r20 = 0; /* OSF/1 has some strange fork() semantics. */
273272
childti->pcb.usp = usp ?: rdusp();

arch/arc/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ config ARC
2929
select GENERIC_SMP_IDLE_THREAD
3030
select HAVE_ARCH_KGDB
3131
select HAVE_ARCH_TRACEHOOK
32-
select HAVE_COPY_THREAD_TLS
3332
select HAVE_DEBUG_STACKOVERFLOW
3433
select HAVE_DEBUG_KMEMLEAK
3534
select HAVE_FUTEX_CMPXCHG if FUTEX

arch/arc/kernel/process.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ asmlinkage void ret_from_fork(void);
173173
* | user_r25 |
174174
* ------------------ <===== END of PAGE
175175
*/
176-
int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
177-
unsigned long kthread_arg, struct task_struct *p, unsigned long tls)
176+
int copy_thread(unsigned long clone_flags, unsigned long usp,
177+
unsigned long kthread_arg, struct task_struct *p,
178+
unsigned long tls)
178179
{
179180
struct pt_regs *c_regs; /* child's pt_regs */
180181
unsigned long *childksp; /* to unwind out of __switch_to() */

arch/arm/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ config ARM
7272
select HAVE_ARM_SMCCC if CPU_V7
7373
select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32
7474
select HAVE_CONTEXT_TRACKING
75-
select HAVE_COPY_THREAD_TLS
7675
select HAVE_C_RECORDMCOUNT
7776
select HAVE_DEBUG_KMEMLEAK if !XIP_KERNEL
7877
select HAVE_DMA_CONTIGUOUS if MMU

arch/arm/kernel/process.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ void release_thread(struct task_struct *dead_task)
225225

226226
asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
227227

228-
int
229-
copy_thread_tls(unsigned long clone_flags, unsigned long stack_start,
230-
unsigned long stk_sz, struct task_struct *p, unsigned long tls)
228+
int copy_thread(unsigned long clone_flags, unsigned long stack_start,
229+
unsigned long stk_sz, struct task_struct *p, unsigned long tls)
231230
{
232231
struct thread_info *thread = task_thread_info(p);
233232
struct pt_regs *childregs = task_pt_regs(p);

arch/arm64/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ config ARM64
149149
select HAVE_CMPXCHG_DOUBLE
150150
select HAVE_CMPXCHG_LOCAL
151151
select HAVE_CONTEXT_TRACKING
152-
select HAVE_COPY_THREAD_TLS
153152
select HAVE_DEBUG_BUGVERBOSE
154153
select HAVE_DEBUG_KMEMLEAK
155154
select HAVE_DMA_CONTIGUOUS

arch/arm64/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
375375

376376
asmlinkage void ret_from_fork(void) asm("ret_from_fork");
377377

378-
int copy_thread_tls(unsigned long clone_flags, unsigned long stack_start,
378+
int copy_thread(unsigned long clone_flags, unsigned long stack_start,
379379
unsigned long stk_sz, struct task_struct *p, unsigned long tls)
380380
{
381381
struct pt_regs *childregs = task_pt_regs(p);

arch/c6x/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ void start_thread(struct pt_regs *regs, unsigned int pc, unsigned long usp)
105105
* Copy a new thread context in its stack.
106106
*/
107107
int copy_thread(unsigned long clone_flags, unsigned long usp,
108-
unsigned long ustk_size,
109-
struct task_struct *p)
108+
unsigned long ustk_size, struct task_struct *p,
109+
unsigned long tls)
110110
{
111111
struct pt_regs *childregs;
112112

arch/csky/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ config CSKY
3838
select GX6605S_TIMER if CPU_CK610
3939
select HAVE_ARCH_TRACEHOOK
4040
select HAVE_ARCH_AUDITSYSCALL
41-
select HAVE_COPY_THREAD_TLS
4241
select HAVE_DEBUG_BUGVERBOSE
4342
select HAVE_DYNAMIC_FTRACE
4443
select HAVE_DYNAMIC_FTRACE_WITH_REGS

0 commit comments

Comments
 (0)