[RFC, PATCH 2/3] implement CLONE_KERNEL_THREAD flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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(-)

--- 2.6.21-rc5-mm4/include/linux/sched.h~2_IMPL	2007-04-07 22:07:50.000000000 +0400
+++ 2.6.21-rc5-mm4/include/linux/sched.h	2007-04-08 18:53:51.000000000 +0400
@@ -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
--- 2.6.21-rc5-mm4/kernel/fork.c~2_IMPL	2007-04-07 23:56:08.000000000 +0400
+++ 2.6.21-rc5-mm4/kernel/fork.c	2007-04-08 18:55:42.000000000 +0400
@@ -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;
 

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux