implement CLONE_KERNEL_THREAD flag
Subsystems (4)
RFC PATCH 2/3 implement CLONE_KERNEL_THREAD flag
For review only.
We have some problems with the kernel threads parented to /sbin/init, see
http://marc.info/?t=117580282200003&r=1 http://marc.info/?t=95299284800003&r=1
A task created with CLONE_KERNEL_THREAD will have swapper as its parent. Note that this is only the first step, we can extend the meaning of this flag to also use init_task for copy_mm/copy_files/etc.
arch/sparc/kernel/process.c arch/sparc64/kernel/process.c arch/m68knommu/kernel/process.c arch/m68k/kernel/process.c arch/alpha/kernel/entry.S arch/h8300/kernel/process.c arch/v850/kernel/process.c arch/frv/kernel/kernel_thread.S arch/frv/kernel/kernel_thread.S arch/powerpc/kernel/misc_32.S arch/powerpc/kernel/misc_64.S
implement kthread_create() via sys_clone(). This means that these arches can't take advantage of CLONE_KERNEL_THREAD, it will be filtered out by sys_clone().
This patch breaks arch/ia64/, its sys_clone() was not converted by the previous patch, so user-space can do sys_clone(CLONE_KERNEL_THREAD).
Signed-off-by Oleg Nesterov <[email protected]>
include/linux/sched.h | 5 ++++- kernel/fork.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/sched.h renamed from include/linux/sched.h~2_IMPL +4 -1
@@ -28,7 +28,10 @@#define CLONE_NEWIPC 0x08000000/* New ipcs */ /* user-space visible */ -#define SYS_CLONE_MASK (~0x0) +#define SYS_CLONE_MASK (~(CLONE_KERNEL_THREAD)) + +/* for in kernel use only */ +#define CLONE_KERNEL_THREAD 0x20000000/* hide from init */ /* * Scheduling policies
kernel/fork.c renamed from kernel/fork.c~2_IMPL +4 -1
@@ -1159,7 +1159,8 @@ static struct task_struct *copy_process( p->parent_exec_id = p->self_exec_id;/* ok, now we should be set up.. */ - p->exit_signal = (clone_flags &CLONE_THREAD ) ?-1 : (clone_flags &CSIGNAL ); + p->exit_signal = (clone_flags & (CLONE_THREAD |CLONE_KERNEL_THREAD )) + ?-1 : (clone_flags &CSIGNAL ); p->pdeath_signal =0 ; p->exit_state =0 ;
@@ -1196,6 +1197,8 @@ static struct task_struct *copy_process(/* CLONE_PARENT re-uses the old parent */ if (clone_flags & (CLONE_PARENT |CLONE_THREAD )) p->parent = current->parent; +else if (unlikely (clone_flags &CLONE_KERNEL_THREAD )) + p->parent = &init_task;else p->parent = current;