mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC, PATCH 2/3] implement CLONE_KERNEL_THREAD flag
@ 2007-04-08 15:55 Oleg Nesterov
  0 siblings, 0 replies; only message in thread
From: Oleg Nesterov @ 2007-04-08 15:55 UTC (permalink / raw)
  To: Andrew Morton, Eric W. Biederman, Davide Libenzi, Ingo Molnar,
	Linus Torvalds, Robin Holt, Roland McGrath
  Cc: linux-kernel, linux-arch

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 <oleg@tv-sign.ru>

 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;
 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-04-08 15:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-08 15:55 [RFC, PATCH 2/3] implement CLONE_KERNEL_THREAD flag Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®