Skip to contentSkip to conversation

Multiple instances of the process id namespace

RFC PATCH In review Eric W. Biederman 12 participants 78 messages Feb 6, 2006 – Mar 1, 2006

Subsystems (33)
Memory management VFS USB PowerPC +29 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Multiple instances of the process id namespace

There have been several discussions in the past month about how to do a good job of implementing a subset of user space that looks like it has the system to itself. Essentially making chroot everything it could be. This is my take on what the implementation of a pid namespace should look like.

What follows is a real patch set that is sufficiently complete to be used and useful in it's own right. There are a few areas of the kernel where the patchset does not reach, mostly these cause the compile to fail. In addition a good thorough review still needs to be done. This patchset does paint a picture of how I think things should look.

Quoted 1 line

From the kernel community at large I am asking:

Does the code look generally sane?

Does the use of clone to create a new namespace instance look like the sane approach?

Hopefully this code is sufficiently comprehensible to allow a good discussion to come out of this.

Thanks for your time,

Eric

p.s. My apologies at the size of the CC list. It is very hard to tell who the interested parties are, and since there is no one list we all subscribe to other than linux-kernel how to reach everyone in a timely manner. I am copying everyone who has chimed in on a previous thread on the subject. If you don't want to be copied in the future tell and I will take your name off of my list.

#1 lore raw

RFC PATCH 1/20 pid: Intoduce the concept of a wid (wait id)

The wait id is the pid returned by wait. For tasks that span 2 namespaces (i.e. the process leaders of the pid namespaces) their parent knows the task by a different PID value than the task knows itself. Having a child with PID == 1 would be confusing.

This patch introduces the wid and walks through kernel and modifies the places that observe the pid from the parent processes perspective to use the wid instead of the pid.

---

 include/linux/sched.h |    1 +
 kernel/exit.c         |   18 +++++++++---------
 kernel/fork.c         |    4 ++--
 kernel/sched.c        |    2 +-
 kernel/signal.c       |    6 +++---
 5 files changed, 16 insertions(+), 15 deletions(-)

598714d79648463ab3f2cbf6f6acd3cd6c09c87a

include/linux/sched.h +1 -0
index f368048..e8ea561 100644
@@ -740,6 +740,7 @@ struct task_struct {
 	/* ??? */
 	unsigned long personality;
 	unsigned did_exec:1;
+	pid_t wid;
 	pid_t pid;
 	pid_t tgid;
 	/* 
kernel/exit.c +9 -9
index fb4c8b1..749bc8b 100644
@@ -941,7 +941,7 @@ asmlinkage void sys_exit_group(int error
 static int eligible_child(pid_t pid, int options, task_t *p)
 {
 	if (pid > 0) {
-		if (p->pid != pid)
+		if (p->wid != pid)
 			return 0;
 	} else if (!pid) {
 		if (process_group(p) != process_group(current))
@@ -1018,7 +1018,7 @@ static int wait_task_zombie(task_t *p, i
 	int status;
 
 	if (unlikely(noreap)) {
-		pid_t pid = p->pid;
+		pid_t pid = p->wid;
 		uid_t uid = p->uid;
 		int exit_code = p->exit_code;
 		int why, status;
@@ -1130,7 +1130,7 @@ static int wait_task_zombie(task_t *p, i
 			retval = put_user(status, &infop->si_status);
 	}
 	if (!retval && infop)
-		retval = put_user(p->pid, &infop->si_pid);
+		retval = put_user(p->wid, &infop->si_pid);
 	if (!retval && infop)
 		retval = put_user(p->uid, &infop->si_uid);
 	if (retval) {
@@ -1138,7 +1138,7 @@ static int wait_task_zombie(task_t *p, i
 		p->exit_state = EXIT_ZOMBIE;
 		return retval;
 	}
-	retval = p->pid;
+	retval = p->wid;
 	if (p->real_parent != p->parent) {
 		write_lock_irq(&tasklist_lock);
 		/* Double-check with lock held.  */
@@ -1198,7 +1198,7 @@ static int wait_task_stopped(task_t *p, 
 	read_unlock(&tasklist_lock);
 
 	if (unlikely(noreap)) {
-		pid_t pid = p->pid;
+		pid_t pid = p->wid;
 		uid_t uid = p->uid;
 		int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
 
@@ -1269,11 +1269,11 @@ bail_ref:
 	if (!retval && infop)
 		retval = put_user(exit_code, &infop->si_status);
 	if (!retval && infop)
-		retval = put_user(p->pid, &infop->si_pid);
+		retval = put_user(p->wid, &infop->si_pid);
 	if (!retval && infop)
 		retval = put_user(p->uid, &infop->si_uid);
 	if (!retval)
-		retval = p->pid;
+		retval = p->wid;
 	put_task_struct(p);
 
 	BUG_ON(!retval);
@@ -1310,7 +1310,7 @@ static int wait_task_continued(task_t *p
 		p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
 	spin_unlock_irq(&p->sighand->siglock);
 
-	pid = p->pid;
+	pid = p->wid;
 	uid = p->uid;
 	get_task_struct(p);
 	read_unlock(&tasklist_lock);
@@ -1321,7 +1321,7 @@ static int wait_task_continued(task_t *p
 		if (!retval && stat_addr)
 			retval = put_user(0xffff, stat_addr);
 		if (!retval)
-			retval = p->pid;
+			retval = pid;
 	} else {
 		retval = wait_noreap_copyout(p, pid, uid,
 					     CLD_CONTINUED, SIGCONT,
kernel/fork.c +2 -2
index f4a7281..743d46c 100644
@@ -931,10 +931,10 @@ static task_t *copy_process(unsigned lon
 
 	p->did_exec = 0;
 	copy_flags(clone_flags, p);
-	p->pid = pid;
+	p->wid = p->pid = pid;
 	retval = -EFAULT;
 	if (clone_flags & CLONE_PARENT_SETTID)
-		if (put_user(p->pid, parent_tidptr))
+		if (put_user(p->wid, parent_tidptr))
 			goto bad_fork_cleanup;
 
 	p->proc_dentry = NULL;
kernel/sched.c +1 -1
index f77f23f..6579d49 100644
@@ -1674,7 +1674,7 @@ asmlinkage void schedule_tail(task_t *pr
 	preempt_enable();
 #endif
 	if (current->set_child_tid)
-		put_user(current->pid, current->set_child_tid);
+		put_user(current->wid, current->set_child_tid);
 }
 
 /*
kernel/signal.c +3 -3
index 1f54ed7..70c226c 100644
@@ -1564,7 +1564,7 @@ void do_notify_parent(struct task_struct
 
 	info.si_signo = sig;
 	info.si_errno = 0;
-	info.si_pid = tsk->pid;
+	info.si_pid = tsk->wid;
 	info.si_uid = tsk->uid;
 
 	/* FIXME: find out whether or not this is supposed to be c*time. */
@@ -1629,7 +1629,7 @@ static void do_notify_parent_cldstop(str
 
 	info.si_signo = SIGCHLD;
 	info.si_errno = 0;
-	info.si_pid = tsk->pid;
+	info.si_pid = tsk->wid;
 	info.si_uid = tsk->uid;
 
 	/* FIXME: find out whether or not this is supposed to be c*time. */
@@ -1732,7 +1732,7 @@ void ptrace_notify(int exit_code)
 	memset(&info, 0, sizeof info);
 	info.si_signo = SIGTRAP;
 	info.si_code = exit_code;
-	info.si_pid = current->pid;
+	info.si_pid = current->wid;
 	info.si_uid = current->uid;
 
 	/* Let the debugger run.  */
Signature · 1 line
1.1.5.g3480
#2 lore raw

RFC PATCH 2/20 pspace: The parent process id of pid 1 is always 0.

Force the parent process id of pid == 1 to always be 0. Force this for nested pspaces.

---

 arch/alpha/kernel/entry.S |    3 +++
 kernel/timer.c            |    2 ++
 2 files changed, 5 insertions(+), 0 deletions(-)

bec203c8a3e7bec5e3bee8086361caffa71ad685

arch/alpha/kernel/entry.S +3 -0
index 7af15bf..38996ab 100644
@@ -891,6 +891,9 @@ sys_getxpid:
 	cmpeq	$4, $5, $5
 	beq	$5, 1b
 #endif
+	cmpeq	$0, 1, $5
+	cmoveq	$5, 0, $1
+	
 	stq	$1, 80($sp)
 	ret
 .end sys_getxpid
kernel/timer.c +2 -0
index 4f1cb0a..bae17fb 100644
@@ -987,6 +987,8 @@ asmlinkage long sys_getppid(void)
 #endif
 		break;
 	}
+	if (current->tgid == 1)
+		pid = 0;
 	return pid;
 }
 
Signature · 1 line
1.1.5.g3480
#3 lore raw

RFC PATCH 3/20 pid: Introduce a generic helper to test for init.

There are a lot of places in the kernel where we test for init because we give it special properties. Most significantly init must not die. This results in code all over the kernel test ->pid == 1.

Introduce is_init to capture this case.

With multiple pid spaces for all of the cases affected we are looking for only the first process on the system, not some other process that has pid == 1.

---

 arch/alpha/mm/fault.c                |    2 +-
 arch/i386/lib/usercopy.c             |    2 +-
 arch/i386/mm/fault.c                 |    2 +-
 arch/ia64/mm/fault.c                 |    2 +-
 arch/m32r/mm/fault.c                 |    2 +-
 arch/m68k/mm/fault.c                 |    2 +-
 arch/mips/mm/fault.c                 |    2 +-
 arch/powerpc/mm/fault.c              |    2 +-
 arch/powerpc/platforms/pseries/ras.c |    2 +-
 arch/s390/mm/fault.c                 |    2 +-
 arch/sh/mm/fault.c                   |    2 +-
 arch/sh64/mm/fault.c                 |    6 +++---
 arch/um/kernel/trap_kern.c           |    2 +-
 arch/x86_64/mm/fault.c               |    2 +-
 arch/xtensa/mm/fault.c               |    2 +-
 drivers/char/snsc_event.c            |    2 +-
 include/linux/sched.h                |   13 +++++++++++++
 kernel/exit.c                        |    2 +-
 kernel/kexec.c                       |    2 +-
 kernel/sysctl.c                      |    2 +-
 mm/oom_kill.c                        |    6 +++---
 security/seclvl.c                    |    4 ++--
 22 files changed, 39 insertions(+), 26 deletions(-)

26458ca5ad0bf86dde7bbe914e0f475f11945f44

arch/alpha/mm/fault.c +1 -1
index 64ace5a..36284e7 100644
@@ -194,7 +194,7 @@ do_page_fault(unsigned long address, uns
 	/* We ran out of memory, or some other thing happened to us that
 	   made us unable to handle the page fault gracefully.  */
  out_of_memory:
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/i386/lib/usercopy.c +1 -1
index 4cf981d..ae9b319 100644
@@ -543,7 +543,7 @@ survive:
 			retval = get_user_pages(current, current->mm,
 					(unsigned long )to, 1, 1, 0, &pg, NULL);
 
-			if (retval == -ENOMEM && current->pid == 1) {
+			if (retval == -ENOMEM && is_init(current)) {
 				up_read(&current->mm->mmap_sem);
 				blk_congestion_wait(WRITE, HZ/50);
 				goto survive;
arch/i386/mm/fault.c +1 -1
index cf572d9..adec5ef 100644
@@ -485,7 +485,7 @@ no_context:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (tsk->pid == 1) {
+	if (is_init(tsk)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/ia64/mm/fault.c +1 -1
index af7eb08..3d27cf8 100644
@@ -241,7 +241,7 @@ ia64_do_page_fault (unsigned long addres
 
   out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/m32r/mm/fault.c +1 -1
index bf7fb58..3f98d5a 100644
@@ -300,7 +300,7 @@ no_context:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (tsk->pid == 1) {
+	if (is_init(tsk)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/m68k/mm/fault.c +1 -1
index aec1527..0081729 100644
@@ -181,7 +181,7 @@ good_area:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/mips/mm/fault.c +1 -1
index 2d9624f..c615567 100644
@@ -172,7 +172,7 @@ no_context:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (tsk->pid == 1) {
+	if (is_init(tsk)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/powerpc/mm/fault.c +1 -1
index a4815d3..a002917 100644
@@ -351,7 +351,7 @@ bad_area_nosemaphore:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/powerpc/platforms/pseries/ras.c +1 -1
index b046bcf..5d6a4a6 100644
@@ -314,7 +314,7 @@ static int recover_mce(struct pt_regs *r
 		   err->disposition == RTAS_DISP_NOT_RECOVERED &&
 		   err->target == RTAS_TARGET_MEMORY &&
 		   err->type == RTAS_TYPE_ECC_UNCORR &&
-		   !(current->pid == 0 || current->pid == 1)) {
+		   !(current->pid == 0 || is_init(current))) {
 		/* Kill off a user process with an ECC error */
 		printk(KERN_ERR "MCE: uncorrectable ecc error for pid %d\n",
 		       current->pid);
arch/s390/mm/fault.c +1 -1
index 81ade40..9d9c009 100644
@@ -316,7 +316,7 @@ no_context:
 */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (tsk->pid == 1) {
+	if (is_init(tsk)) {
 		yield();
 		goto survive;
 	}
arch/sh/mm/fault.c +1 -1
index 775f86c..46e5e60 100644
@@ -160,7 +160,7 @@ no_context:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/sh64/mm/fault.c +3 -3
index f08d0ea..8e2f6c2 100644
@@ -277,7 +277,7 @@ bad_area:
 			show_regs(regs);
 #endif
 		}
-		if (tsk->pid == 1) {
+		if (is_init(tsk)) {
 			panic("INIT had user mode bad_area\n");
 		}
 		tsk->thread.address = address;
@@ -319,14 +319,14 @@ no_context:
  * us unable to handle the page fault gracefully.
  */
 out_of_memory:
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		panic("INIT out of memory\n");
 		yield();
 		goto survive;
 	}
 	printk("fault:Out of memory\n");
 	up_read(&mm->mmap_sem);
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
arch/um/kernel/trap_kern.c +1 -1
index d56046c..bed3e03 100644
@@ -120,7 +120,7 @@ out_nosemaphore:
  * us unable to handle the page fault gracefully.
  */
 out_of_memory:
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		up_read(&mm->mmap_sem);
 		yield();
 		down_read(&mm->mmap_sem);
arch/x86_64/mm/fault.c +1 -1
index 26eac19..7beb271 100644
@@ -545,7 +545,7 @@ no_context:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (current->pid == 1) { 
+	if (is_init(current)) { 
 		yield();
 		goto again;
 	}
arch/xtensa/mm/fault.c +1 -1
index a945a33..dd0dbec 100644
@@ -144,7 +144,7 @@ bad_area:
 	 */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (current->pid == 1) {
+	if (is_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
drivers/char/snsc_event.c +1 -1
index baaa365..60d1343 100644
@@ -207,7 +207,7 @@ scdrv_dispatch_event(char *event, int le
 		/* first find init's task */
 		read_lock(&tasklist_lock);
 		for_each_process(p) {
-			if (p->pid == 1)
+			if (is_init(p))
 				break;
 		}
 		if (p) { /* we found init's task */
include/linux/sched.h +13 -0
index e8ea561..86a92d6 100644
@@ -894,6 +894,19 @@ static inline int pid_alive(struct task_
 	return p->pids[PIDTYPE_PID].nr != 0;
 }
 
+/**
+ * is_init - check if a task structure is the first user space
+ *	     task the kernel created.
+ * @p: Task structure to be checked.
+ */
+static inline int is_init(struct task_struct *tsk)
+{
+	/* Note there is only one task whose parent knows
+	 * it as pid 1.
+	 */
+	return tsk->wid == 1;
+}
+
 extern void free_task(struct task_struct *tsk);
 extern void __put_task_struct(struct task_struct *tsk);
 #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
kernel/exit.c +1 -1
index 749bc8b..f1af8bb 100644
@@ -786,7 +786,7 @@ fastcall NORET_TYPE void do_exit(long co
 		panic("Aiee, killing interrupt handler!");
 	if (unlikely(!tsk->pid))
 		panic("Attempted to kill the idle task!");
-	if (unlikely(tsk == child_reaper))
+	if (unlikely(is_init(tsk)))
 		panic("Attempted to kill init!");
 	if (tsk->io_context)
 		exit_io_context();
kernel/kexec.c +1 -1
index bf39d28..64d05ab 100644
@@ -40,7 +40,7 @@ struct resource crashk_res = {
 
 int kexec_should_crash(struct task_struct *p)
 {
-	if (in_interrupt() || !p->pid || p->pid == 1 || panic_on_oops)
+	if (in_interrupt() || !p->pid || is_init(p) || panic_on_oops)
 		return 1;
 	return 0;
 }
kernel/sysctl.c +1 -1
index 71dd6f6..8e1bdc5 100644
@@ -1806,7 +1806,7 @@ int proc_dointvec_bset(ctl_table *table,
 		return -EPERM;
 	}
 
-	op = (current->pid == 1) ? OP_SET : OP_AND;
+	op = is_init(current) ? OP_SET : OP_AND;
 	return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
 				do_proc_dointvec_bset_conv,&op);
 }
mm/oom_kill.c +3 -3
index b05ab8f..b417dce 100644
@@ -148,8 +148,8 @@ static struct task_struct * select_bad_p
 		unsigned long points;
 		int releasing;
 
-		/* skip the init task with pid == 1 */
-		if (p->pid == 1)
+		/* skip the init task */
+		if (is_init(p))
 			continue;
 		if (p->oomkilladj == OOM_DISABLE)
 			continue;
@@ -184,7 +184,7 @@ static struct task_struct * select_bad_p
  */
 static void __oom_kill_task(task_t *p)
 {
-	if (p->pid == 1) {
+	if (is_init(p)) {
 		WARN_ON(1);
 		printk(KERN_WARNING "tried to kill init!\n");
 		return;
security/seclvl.c +2 -2
index 8529ea6..a49f2dd 100644
@@ -313,7 +313,7 @@ static int seclvl_ptrace(struct task_str
 static int seclvl_capable(struct task_struct *tsk, int cap)
 {
 	/* init can do anything it wants */
-	if (tsk->pid == 1)
+	if (is_init(tsk))
 		return 0;
 
 	switch (seclvl) {
@@ -479,7 +479,7 @@ static void seclvl_file_free_security(st
  */
 static int seclvl_umount(struct vfsmount *mnt, int flags)
 {
-	if (current->pid == 1)
+	if (is_init(current))
 		return 0;
 	if (seclvl == 2) {
 		seclvl_printk(1, KERN_WARNING, "Attempt to unmount in secure "
Signature · 1 line
1.1.5.g3480
#4 lore raw

RFC PATCH 4/20 pspace: Allow multiple instaces of the process id namespace

This patch modifies the fork/exit, signal handling, and pid and process group manipulating syscalls to support multiple process spaces, and implements the data for allow multiple instaces of the pid namespace.

The implementation is the best compromise I have found between a maintainable implementation that will break users that need to be modified and a minimal impact implementation that doesn't require all of the kernel's process id handling to be modified.

pid,tgid,pgrp,session all retain their current meanings. Functions that operation in an arbitrary context take an additional pspace
parameter. The tuple pspace,pid is globally unique. Making the
tuple pspace, pid the kernel pid and any plain pid value the user space pid.

In conjunction with this patch there will need to be an audit of the kernel to find and fix the places that compare and print pids. The only operations possible with out calling a helper function.

The number of comparisions performed not in conjunction with another pid operation is small so there should not be many pieces of the kernel affected.

Fixing up printing of the pids in debug messages is optional but will likely be useful for understanding what is going on. The pspace->name field is provided for this purpose. Simply adding a "%s/" before the existing "%d is suffient to add the pspace name.

The API for manipulating PID namespaces is defined as follows:

sys_clone(CLONE_NPSPACE) creates a new process id namespace, giving the child process 2 pids. The normal pid which only the parent sees and pid 1. The child the becomes the init process for the namespace in all measurable wasy including reaping all of the namespaces children who die unexpectedly.

Quoted 1 line

From any process in the parents namespace with the appropriate

permissions sending sys_kill( <child pid>) sends a signal to just the leading process of the pid namespace.

Quoted 1 line

From any process in the parents namespace with the appropriate

permissions sending sys_kill( -<child pid>) sends a signal to all of the processes in the pid namespace.

currenty CAP_KILL is defined as the required capability to create a PID namespace. I don't know of anything harmful that could result in making this disallowed but since someone with CAP_KILL can arbitrarily kill any process it sounded like a good safety measure.

When the leading process of the pid namespace exits all of it's children die because init cannot exit :)

Waitpid on the extrenally visible pid of a pid namespace waits for that namespace to exit.

pid namespaces are currently implemented so the can nest one inside the other, as this adds no real complications.

---

 fs/exec.c                 |    7 +-
 include/linux/init_task.h |    2 
 include/linux/kernel.h    |    3 -
 include/linux/pid.h       |   17 +++-
 include/linux/pspace.h    |   95 ++++++++++++++++++++++
 include/linux/sched.h     |   23 +++--
 include/linux/tty.h       |    2 
 init/main.c               |    5 -
 kernel/exit.c             |   79 ++++++++++++-------
 kernel/fork.c             |   56 ++++++++-----
 kernel/pid.c              |  192 ++++++++++++++++++++++++++++++++++-----------
 kernel/signal.c           |  118 +++++++++++++++++++---------
 kernel/sys.c              |   14 ++-
 13 files changed, 450 insertions(+), 163 deletions(-)
 create mode 100644 include/linux/pspace.h

8927729234906eb9fef21ca16bb30598a97b4485

fs/exec.c +4 -3
index 390aafe..1c2fa2c 100644
@@ -49,6 +49,7 @@
 #include <linux/rmap.h>
 #include <linux/acct.h>
 #include <linux/cn_proc.h>
+#include <linux/pspace.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -621,8 +622,8 @@ static int de_thread(struct task_struct 
 	 * Reparenting needs write_lock on tasklist_lock,
 	 * so it is safe to do it under read_lock.
 	 */
-	if (unlikely(current->group_leader == child_reaper))
-		child_reaper = current;
+	if (unlikely(current->group_leader == current->pspace->child_reaper.task))
+		current->pspace->child_reaper.task = current;
 
 	zap_other_threads(current);
 	read_unlock(&tasklist_lock);
@@ -720,7 +721,7 @@ static int de_thread(struct task_struct 
 		list_add_tail(&current->tasks, &init_task.tasks);
 
 		current->parent = current->real_parent = leader->real_parent;
-		leader->parent = leader->real_parent = child_reaper;
+		leader->parent = leader->real_parent = leader->pspace->child_reaper.task;
 		current->group_leader = current;
 		leader->group_leader = leader;
 
include/linux/init_task.h +2 -0
index e182ee6..db93266 100644
@@ -3,6 +3,7 @@
 
 #include <linux/file.h>
 #include <linux/rcupdate.h>
+#include <linux/pspace.h>
 
 #define INIT_FDTABLE \
 {							\
@@ -112,6 +113,7 @@ extern struct group_info init_groups;
 	.thread		= INIT_THREAD,					\
 	.fs		= &init_fs,					\
 	.files		= &init_files,					\
+	.pspace		= &init_pspace,					\
 	.signal		= &init_signals,				\
 	.sighand	= &init_sighand,				\
 	.pending	= {						\
include/linux/kernel.h +2 -1
index b49affa..bd2dd1f 100644
@@ -49,6 +49,7 @@ extern int console_printk[];
 struct completion;
 struct pt_regs;
 struct user;
+struct pspace;
 
 /**
  * might_sleep - annotation for functions that can sleep
@@ -123,7 +124,7 @@ extern unsigned long long memparse(char 
 
 extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
-extern int session_of_pgrp(int pgrp);
+extern int session_of_pgrp(struct pspace *pspace, int pgrp);
 
 extern void dump_thread(struct pt_regs *regs, struct user *dump);
 
include/linux/pid.h +11 -6
index 099e70e..ba38c13 100644
@@ -10,13 +10,16 @@ enum pid_type
 	PIDTYPE_MAX
 };
 
+struct pspace;
 struct pid
 {
 	/* Try to keep pid_chain in the same cacheline as nr for find_pid */
+	struct pspace *pspace;
 	int nr;
 	struct hlist_node pid_chain;
 	/* list of pids with the same nr, only one of them is in the hash */
 	struct list_head pid_list;
+	struct task_struct *task;
 };
 
 #define pid_task(elem, type) \
@@ -34,17 +37,19 @@ extern void FASTCALL(detach_pid(struct t
  * look up a PID in the hash table. Must be called with the tasklist_lock
  * held.
  */
-extern struct pid *FASTCALL(find_pid(enum pid_type, int));
+extern struct pid *FASTCALL(find_pid(enum pid_type, struct pspace *, int));
+#define find_task_by_pid(pspace, nr)	find_task_by_pid_type(PIDTYPE_PID, pspace, nr)
+extern struct task_struct *find_task_by_pid_type(int type, struct pspace *pspace, int pid);
 
-extern int alloc_pidmap(void);
-extern void FASTCALL(free_pidmap(int));
+extern int alloc_pidmap(struct pspace *pspace);
+extern void FASTCALL(free_pidmap(struct pspace *psapce, int pid));
 
-#define do_each_task_pid(who, type, task)				\
-	if ((task = find_task_by_pid_type(type, who))) {		\
+#define do_each_task_pid(pspace, who, type, task)			\
+	if ((task = find_task_by_pid_type(type, pspace, who))) {	\
 		prefetch((task)->pids[type].pid_list.next);		\
 		do {
 
-#define while_each_task_pid(who, type, task)				\
+#define while_each_task_pid(pspace, who, type, task)			\
 		} while (task = pid_task((task)->pids[type].pid_list.next,\
 						type),			\
 			prefetch((task)->pids[type].pid_list.next),	\
include/linux/pspace.h new file +95 -0

95 lines not on this page · raw message

include/linux/sched.h +11 -12
index 86a92d6..1977cb9 100644
@@ -61,6 +61,7 @@ struct exec_domain;
 #define CLONE_UNTRACED		0x00800000	/* set if the tracing process can't force CLONE_PTRACE on this clone */
 #define CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
 #define CLONE_STOPPED		0x02000000	/* Start in stopped state */
+#define CLONE_NPSPACE		0x04000000	/* New process id space */
 
 /*
  * List of flags we want to share for kernel threads,
@@ -94,9 +95,6 @@ extern unsigned long avenrun[];		/* Load
 
 extern unsigned long total_forks;
 extern int nr_threads;
-extern int last_pid;
-DECLARE_PER_CPU(unsigned long, process_counts);
-extern int nr_processes(void);
 extern unsigned long nr_running(void);
 extern unsigned long nr_uninterruptible(void);
 extern unsigned long nr_iowait(void);
@@ -234,6 +232,7 @@ extern signed long schedule_timeout_unin
 asmlinkage void schedule(void);
 
 struct namespace;
+struct pspace;
 
 /* Maximum number of active map areas.. This is a random (large) number */
 #define DEFAULT_MAX_MAP_COUNT	65536
@@ -741,6 +740,7 @@ struct task_struct {
 	unsigned long personality;
 	unsigned did_exec:1;
 	pid_t wid;
+	struct pspace *pspace;	/* process id namespace */
 	pid_t pid;
 	pid_t tgid;
 	/* 
@@ -1037,8 +1037,6 @@ extern struct task_struct init_task;
 
 extern struct   mm_struct init_mm;
 
-#define find_task_by_pid(nr)	find_task_by_pid_type(PIDTYPE_PID, nr)
-extern struct task_struct *find_task_by_pid_type(int type, int pid);
 extern void set_special_pids(pid_t session, pid_t pgrp);
 extern void __set_special_pids(pid_t session, pid_t pgrp);
 
@@ -1096,17 +1094,19 @@ extern int send_sig_info(int, struct sig
 extern int send_group_sig_info(int, struct siginfo *, struct task_struct *);
 extern int force_sigsegv(int, struct task_struct *);
 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
-extern int __kill_pg_info(int sig, struct siginfo *info, pid_t pgrp);
-extern int kill_pg_info(int, struct siginfo *, pid_t);
-extern int kill_proc_info(int, struct siginfo *, pid_t);
-extern int kill_proc_info_as_uid(int, struct siginfo *, pid_t, uid_t, uid_t);
+extern int __kill_pspace_info(int , struct siginfo *, struct pspace *);
+extern int kill_pspace_info(int , struct siginfo *, struct pspace *);
+extern int __kill_pg_info(int sig, struct siginfo *info, struct pspace *, pid_t pgrp);
+extern int kill_pg_info(int, struct siginfo *, struct pspace *, pid_t);
+extern int kill_proc_info(int, struct siginfo *, struct pspace *, pid_t);
+extern int kill_proc_info_as_uid(int, struct siginfo *, struct pspace *, pid_t, uid_t, uid_t);
 extern void do_notify_parent(struct task_struct *, int);
 extern void force_sig(int, struct task_struct *);
 extern void force_sig_specific(int, struct task_struct *);
 extern int send_sig(int, struct task_struct *, int);
 extern void zap_other_threads(struct task_struct *p);
-extern int kill_pg(pid_t, int, int);
-extern int kill_proc(pid_t, int, int);
+extern int kill_pg(struct pspace *, pid_t, int, int);
+extern int kill_proc(struct pspace *, pid_t, int, int);
 extern struct sigqueue *sigqueue_alloc(void);
 extern void sigqueue_free(struct sigqueue *);
 extern int send_sigqueue(int, struct sigqueue *,  struct task_struct *);
@@ -1173,7 +1173,6 @@ extern NORET_TYPE void do_group_exit(int
 extern void daemonize(const char *, ...);
 extern int allow_signal(int);
 extern int disallow_signal(int);
-extern task_t *child_reaper;
 
 extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
 extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
include/linux/tty.h +1 -1
index 3787102..898d593 100644
@@ -292,7 +292,7 @@ extern int tty_read_raw_data(struct tty_
 			     int buflen);
 extern void tty_write_message(struct tty_struct *tty, char *msg);
 
-extern int is_orphaned_pgrp(int pgrp);
+extern int is_orphaned_pgrp(struct pspace *pspace, int pgrp);
 extern int is_ignored(int sig);
 extern int tty_signal(int sig, struct tty_struct *tty);
 extern void tty_hangup(struct tty_struct * tty);
init/main.c +2 -3
index 7c79da5..42dabde 100644
@@ -47,6 +47,7 @@
 #include <linux/rmap.h>
 #include <linux/mempolicy.h>
 #include <linux/key.h>
+#include <linux/pspace.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -555,8 +556,6 @@ static int __init initcall_debug_setup(c
 }
 __setup("initcall_debug", initcall_debug_setup);
 
-struct task_struct *child_reaper = &init_task;
-
 extern initcall_t __initcall_start[], __initcall_end[];
 
 static void __init do_initcalls(void)
@@ -666,7 +665,7 @@ static int init(void * unused)
 	 * assumptions about where in the task array this
 	 * can be found.
 	 */
-	child_reaper = current;
+	init_pspace.child_reaper.task = current;
 
 	/* Sets up cpus_possible() */
 	smp_prepare_cpus(max_cpus);
kernel/exit.c +51 -28

220 lines not on this page · raw message

kernel/fork.c +36 -20

120 lines not on this page · raw message

kernel/pid.c +144 -48

310 lines not on this page · raw message

kernel/signal.c +83 -35

231 lines not on this page · raw message

kernel/sys.c +8 -6
index 0929c69..dc8cb58 100644
@@ -30,6 +30,7 @@
 #include <linux/tty.h>
 #include <linux/signal.h>
 #include <linux/cn_proc.h>
+#include <linux/pspace.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1114,7 +1115,7 @@ asmlinkage long sys_setpgid(pid_t pid, p
 	write_lock_irq(&tasklist_lock);
 
 	err = -ESRCH;
-	p = find_task_by_pid(pid);
+	p = find_task_by_pid(current->pspace, pid);
 	if (!p)
 		goto out;
 
@@ -1140,12 +1141,13 @@ asmlinkage long sys_setpgid(pid_t pid, p
 		goto out;
 
 	if (pgid != pid) {
+		struct pspace *pspace = current->pspace;
 		struct task_struct *p;
 
-		do_each_task_pid(pgid, PIDTYPE_PGID, p) {
+		do_each_task_pid(pspace, pgid, PIDTYPE_PGID, p) {
 			if (p->signal->session == group_leader->signal->session)
 				goto ok_pgid;
-		} while_each_task_pid(pgid, PIDTYPE_PGID, p);
+		} while_each_task_pid(pspace, pgid, PIDTYPE_PGID, p);
 		goto out;
 	}
 
@@ -1176,7 +1178,7 @@ asmlinkage long sys_getpgid(pid_t pid)
 		struct task_struct *p;
 
 		read_lock(&tasklist_lock);
-		p = find_task_by_pid(pid);
+		p = find_task_by_pid(current->pspace, pid);
 
 		retval = -ESRCH;
 		if (p) {
@@ -1208,7 +1210,7 @@ asmlinkage long sys_getsid(pid_t pid)
 		struct task_struct *p;
 
 		read_lock(&tasklist_lock);
-		p = find_task_by_pid(pid);
+		p = find_task_by_pid(current->pspace, pid);
 
 		retval = -ESRCH;
 		if(p) {
@@ -1230,7 +1232,7 @@ asmlinkage long sys_setsid(void)
 	down(&tty_sem);
 	write_lock_irq(&tasklist_lock);
 
-	pid = find_pid(PIDTYPE_PGID, group_leader->pid);
+	pid = find_pid(PIDTYPE_PGID, current->pspace, group_leader->pid);
 	if (pid)
 		goto out;
 
Signature · 1 line
1.1.5.g3480
#5 lore raw

RFC PATCH 5/20 sched: Fixup the scheduler syscalls to deal with pspaces.

The scheduler is controlled by pid, so fix up the guts of it's system calls to pass the appropriate pspace when looking up tasks by pid.

---

 kernel/sched.c |    2 +-
 kernel/sys.c   |   14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

e37379b11b63503c1146cc17cec75c358154a1ec

kernel/sched.c +1 -1
index 6579d49..449cc6e 100644
@@ -3701,7 +3701,7 @@ task_t *idle_task(int cpu)
  */
 static inline task_t *find_process_by_pid(pid_t pid)
 {
-	return pid ? find_task_by_pid(pid) : current;
+	return pid ? find_task_by_pid(current->pspace, pid) : current;
 }
 
 /* Actually do priority change: must hold rq lock. */
kernel/sys.c +8 -6
index dc8cb58..bd594c3 100644
@@ -264,6 +264,7 @@ out:
 
 asmlinkage long sys_setpriority(int which, int who, int niceval)
 {
+	struct pspace *pspace = current->pspace;
 	struct task_struct *g, *p;
 	struct user_struct *user;
 	int error = -EINVAL;
@@ -283,16 +284,16 @@ asmlinkage long sys_setpriority(int whic
 		case PRIO_PROCESS:
 			if (!who)
 				who = current->pid;
-			p = find_task_by_pid(who);
+			p = find_task_by_pid(pspace, who);
 			if (p)
 				error = set_one_prio(p, niceval, error);
 			break;
 		case PRIO_PGRP:
 			if (!who)
 				who = process_group(current);
-			do_each_task_pid(who, PIDTYPE_PGID, p) {
+			do_each_task_pid(pspace, who, PIDTYPE_PGID, p) {
 				error = set_one_prio(p, niceval, error);
-			} while_each_task_pid(who, PIDTYPE_PGID, p);
+			} while_each_task_pid(pspace, who, PIDTYPE_PGID, p);
 			break;
 		case PRIO_USER:
 			user = current->user;
@@ -324,6 +325,7 @@ out:
  */
 asmlinkage long sys_getpriority(int which, int who)
 {
+	struct pspace *pspace = current->pspace;
 	struct task_struct *g, *p;
 	struct user_struct *user;
 	long niceval, retval = -ESRCH;
@@ -336,7 +338,7 @@ asmlinkage long sys_getpriority(int whic
 		case PRIO_PROCESS:
 			if (!who)
 				who = current->pid;
-			p = find_task_by_pid(who);
+			p = find_task_by_pid(pspace, who);
 			if (p) {
 				niceval = 20 - task_nice(p);
 				if (niceval > retval)
@@ -346,11 +348,11 @@ asmlinkage long sys_getpriority(int whic
 		case PRIO_PGRP:
 			if (!who)
 				who = process_group(current);
-			do_each_task_pid(who, PIDTYPE_PGID, p) {
+			do_each_task_pid(pspace, who, PIDTYPE_PGID, p) {
 				niceval = 20 - task_nice(p);
 				if (niceval > retval)
 					retval = niceval;
-			} while_each_task_pid(who, PIDTYPE_PGID, p);
+			} while_each_task_pid(pspace, who, PIDTYPE_PGID, p);
 			break;
 		case PRIO_USER:
 			user = current->user;
Signature · 1 line
1.1.5.g3480
#6 lore raw

RFC PATCH 6/20 cad_pid: Fixup the cad_pid users to assume it is in the initial process id namespace.

Having the kernel memorize pids of running processes is ugly. Especially if those processes are allowed to exit. So we don't introduce any lifetime issues or any other weird uglyness and simply insist that the cad_pid is always interpreted with respect to the initial process id namespace.

---

 drivers/parisc/power.c |    3 ++-
 kernel/sys.c           |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

f343da178ee420b5b35a7fa43cc7995f47024004

drivers/parisc/power.c +2 -1
index 54b2b7f..fbf14d9 100644
@@ -45,6 +45,7 @@
 #include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/workqueue.h>
+#include <linux/pspace.h>
 
 #include <asm/pdc.h>
 #include <asm/io.h>
@@ -86,7 +87,7 @@
 static void deferred_poweroff(void *dummy)
 {
 	extern int cad_pid;	/* from kernel/sys.c */
-	if (kill_proc(cad_pid, SIGINT, 1)) {
+	if (kill_proc(&init_pspace, cad_pid, SIGINT, 1)) {
 		/* just in case killing init process failed */
 		machine_power_off();
 	}
kernel/sys.c +1 -1
index bd594c3..d9fcc0e 100644
@@ -581,7 +581,7 @@ void ctrl_alt_del(void)
 	if (C_A_D)
 		schedule_work(&cad_work);
 	else
-		kill_proc(cad_pid, SIGINT, 1);
+		kill_proc(&init_pspace, cad_pid, SIGINT, 1);
 }
 	
 
Signature · 1 line
1.1.5.g3480
#7 lore raw

RFC PATCH 7/20 tty: Update the tty layer to work with pspaces.

Of kernel subsystems that work with pids the tty layer is probably the largest consumer. But it has the nice virtue that the association with a session only lasts until the session leader exits. Which means that no reference counting is required. Only caching of the pspace, and a few extra comparisons.

---

 drivers/char/n_tty.c  |    9 ++++---
 drivers/char/tty_io.c |   62 ++++++++++++++++++++++++++++++-------------------
 include/linux/tty.h   |    1 +
 3 files changed, 44 insertions(+), 28 deletions(-)

5de29104be4f33d4dca8246e13d2996c1ce745b3

drivers/char/n_tty.c +5 -4
index ccad7ae..5edfd13 100644
@@ -580,7 +580,7 @@ static void eraser(unsigned char c, stru
 static inline void isig(int sig, struct tty_struct *tty, int flush)
 {
 	if (tty->pgrp > 0)
-		kill_pg(tty->pgrp, sig, 1);
+		kill_pg(tty->pspace, tty->pgrp, sig, 1);
 	if (flush || !L_NOFLSH(tty)) {
 		n_tty_flush_buffer(tty);
 		if (tty->driver->flush_buffer)
@@ -1187,11 +1187,12 @@ static int job_control(struct tty_struct
 	    current->signal->tty == tty) {
 		if (tty->pgrp <= 0)
 			printk("read_chan: tty->pgrp <= 0!\n");
-		else if (process_group(current) != tty->pgrp) {
+		else if ((process_group(current) != tty->pgrp) ||
+			 (current->pspace != tty->pspace)) {
 			if (is_ignored(SIGTTIN) ||
-			    is_orphaned_pgrp(process_group(current)))
+			    is_orphaned_pgrp(current->pspace, process_group(current)))
 				return -EIO;
-			kill_pg(process_group(current), SIGTTIN, 1);
+			kill_pg(current->pspace, process_group(current), SIGTTIN, 1);
 			return -ERESTARTSYS;
 		}
 	}
drivers/char/tty_io.c +38 -24

201 lines not on this page · raw message

include/linux/tty.h +1 -0
index 898d593..bc9e9c4 100644
@@ -184,6 +184,7 @@ struct tty_struct {
 	struct semaphore termios_sem;
 	struct termios *termios, *termios_locked;
 	char name[64];
+	struct pspace *pspace;
 	int pgrp;
 	int session;
 	unsigned long flags;
Signature · 1 line
1.1.5.g3480
#8 lore raw

RFC PATCH 8/20 vt: Update the virtual console to handle pspaces.

Currently I am lazy and disable all advanced signal sending features of virtual consoles if you are not a member of the initial process id space. Not quite right but it certainly saves the reference counting hassle, and it is unlikely that anyone cares at this point.

Fix this when I get pspace disappearence notifiers.

---

 drivers/char/keyboard.c |    3 ++-
 drivers/char/vt.c       |    2 +-
 drivers/char/vt_ioctl.c |    9 +++++++--
 3 files changed, 10 insertions(+), 4 deletions(-)

74c362e5aab6c780cf6a27d861874e71cebc8b2e

drivers/char/keyboard.c +2 -1
index 8b603b2..511dad7 100644
@@ -33,6 +33,7 @@
 #include <linux/string.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/pspace.h>
 
 #include <linux/kbd_kern.h>
 #include <linux/kbd_diacr.h>
@@ -568,7 +569,7 @@ static void fn_compose(struct vc_data *v
 static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs)
 {
 	if (spawnpid)
-		if (kill_proc(spawnpid, spawnsig, 1))
+		if (kill_proc(&init_pspace, spawnpid, spawnsig, 1))
 			spawnpid = 0;
 }
 
drivers/char/vt.c +1 -1
index 0900d1d..e354c56 100644
@@ -856,7 +856,7 @@ int vc_resize(struct vc_data *vc, unsign
 		ws.ws_ypixel = vc->vc_scan_lines;
 		if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) &&
 		    vc->vc_tty->pgrp > 0)
-			kill_pg(vc->vc_tty->pgrp, SIGWINCH, 1);
+			kill_pg(vc->vc_tty->pspace, vc->vc_tty->pgrp, SIGWINCH, 1);
 		*cws = ws;
 	}
 
drivers/char/vt_ioctl.c +7 -2
index 24011e7..431c3ed 100644
@@ -26,6 +26,7 @@
 #include <linux/console.h>
 #include <linux/signal.h>
 #include <linux/timex.h>
+#include <linux/pspace.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -649,6 +650,8 @@ int vt_ioctl(struct tty_struct *tty, str
 		extern int spawnpid, spawnsig;
 		if (!perm || !capable(CAP_KILL))
 		  return -EPERM;
+		if (current->pspace != &init_pspace)
+		  return -EPERM;
 		if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
 		  return -EINVAL;
 		spawnpid = current->pid;
@@ -666,6 +669,8 @@ int vt_ioctl(struct tty_struct *tty, str
 			return -EFAULT;
 		if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS)
 			return -EINVAL;
+		if ((tmp.mode == VT_PROCESS) && (current->pspace != &init_pspace))
+			return -EINVAL;
 		acquire_console_sem();
 		vc->vt_mode = tmp;
 		/* the frsig is ignored, so we set it to 0 */
@@ -1113,7 +1118,7 @@ static void complete_change_console(stru
 		 * tell us if the process has gone or something else
 		 * is awry
 		 */
-		if (kill_proc(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
+		if (kill_proc(&init_pspace, vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
 		/*
 		 * The controlling process has died, so we revert back to
 		 * normal operation. In this case, we'll also change back
@@ -1173,7 +1178,7 @@ void change_console(struct vc_data *new_
 		 * tell us if the process has gone or something else
 		 * is awry
 		 */
-		if (kill_proc(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
+		if (kill_proc(&init_pspace, vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
 			/*
 			 * It worked. Mark the vt to switch to and
 			 * return. The process needs to send us a
Signature · 1 line
1.1.5.g3480
#9 lore raw

RFC PATCH 9/20 ptrace: Update ptrace handle pspaces.

---

 kernel/ptrace.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

38464ccf04964acc267370758e89a9b4813b6191

kernel/ptrace.c +1 -1
index 5f33cdb..73dc283 100644
@@ -455,7 +455,7 @@ struct task_struct *ptrace_get_task_stru
 		return ERR_PTR(-EPERM);
 
 	read_lock(&tasklist_lock);
-	child = find_task_by_pid(pid);
+	child = find_task_by_pid(current->pspace, pid);
 	if (child)
 		get_task_struct(child);
 	read_unlock(&tasklist_lock);
Signature · 1 line
1.1.5.g3480
#10 lore raw

RFC PATCH 10/20 capabilities: Update the capabilities code to handle pspaces.

---

 kernel/capability.c |   56 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 34 insertions(+), 22 deletions(-)

d84edcf08e16ef0af7170b494b371493d1829ee7

kernel/capability.c +34 -22
index bfa3c92..80a618b 100644
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/security.h>
 #include <linux/syscalls.h>
+#include <linux/pspace.h>
 #include <asm/uaccess.h>
 
 unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
@@ -68,7 +69,7 @@ asmlinkage long sys_capget(cap_user_head
      read_lock(&tasklist_lock); 
 
      if (pid && pid != current->pid) {
-	     target = find_task_by_pid(pid);
+	     target = find_task_by_pid(current->pspace, pid);
 	     if (!target) {
 	          ret = -ESRCH;
 	          goto out;
@@ -96,11 +97,12 @@ static inline int cap_set_pg(int pgrp, k
 			      kernel_cap_t *inheritable,
 			      kernel_cap_t *permitted)
 {
+	struct pspace *pspace = current->pspace;
 	task_t *g, *target;
 	int ret = -EPERM;
 	int found = 0;
 
-	do_each_task_pid(pgrp, PIDTYPE_PGID, g) {
+	do_each_task_pid(pspace, pgrp, PIDTYPE_PGID, g) {
 		target = g;
 		while_each_thread(g, target) {
 			if (!security_capset_check(target, effective,
@@ -113,7 +115,7 @@ static inline int cap_set_pg(int pgrp, k
 			}
 			found = 1;
 		}
-	} while_each_task_pid(pgrp, PIDTYPE_PGID, g);
+	} while_each_task_pid(pspace, pgrp, PIDTYPE_PGID, g);
 
 	if (!found)
 	     ret = 0;
@@ -121,20 +123,26 @@ static inline int cap_set_pg(int pgrp, k
 }
 
 /*
- * cap_set_all - set capabilities for all processes other than init
- * and self.  We call this holding task_capability_lock and tasklist_lock.
- */
-static inline int cap_set_all(kernel_cap_t *effective,
-			       kernel_cap_t *inheritable,
-			       kernel_cap_t *permitted)
+ * cap_set_pspace - set capabilities for all processes in pspace
+ * other than init and self.  We call this holding
+ * task_capability_lock and tasklist_lock.
+ */
+static inline int cap_set_pspace(struct pspace *pspace,
+					kernel_cap_t *effective,
+					kernel_cap_t *inheritable,
+					kernel_cap_t *permitted)
 {
      task_t *g, *target;
      int ret = -EPERM;
      int found = 0;
 
      do_each_thread(g, target) {
-             if (target == current || target->pid == 1)
-                     continue;
+	     if (target == current)
+		     continue;
+	     if (current_pspace_leader(target))
+		     continue;
+	     if (!in_pspace(pspace, target))
+		     continue;
              found = 1;
 	     if (security_capset_check(target, effective, inheritable,
 						permitted))
@@ -200,7 +208,7 @@ asmlinkage long sys_capset(cap_user_head
      read_lock(&tasklist_lock);
 
      if (pid > 0 && pid != current->pid) {
-          target = find_task_by_pid(pid);
+          target = find_task_by_pid(current->pspace, pid);
           if (!target) {
                ret = -ESRCH;
                goto out;
@@ -212,20 +220,24 @@ asmlinkage long sys_capset(cap_user_head
 
      /* having verified that the proposed changes are legal,
            we now put them into effect. */
-     if (pid < 0) {
-             if (pid == -1)  /* all procs other than current and init */
-                     ret = cap_set_all(&effective, &inheritable, &permitted);
+	if (pid < 0) {
+		struct task_struct *p;
 
-             else            /* all procs in process group */
-                     ret = cap_set_pg(-pid, &effective, &inheritable,
+		p = find_task_by_pid(current->pspace, -pid);
+		if (p && pspace_leader(p))
+			/* all procs other than current and init */
+			ret = cap_set_pspace(p->pspace, &effective, 
+						&inheritable, &permitted);
+		else            /* all procs in process group */
+			ret = cap_set_pg(-pid, &effective, &inheritable,
 		     					&permitted);
-     } else {
-	     ret = security_capset_check(target, &effective, &inheritable,
+	} else {
+		ret = security_capset_check(target, &effective, &inheritable,
 	     						&permitted);
-	     if (!ret)
-		     security_capset_set(target, &effective, &inheritable,
+		if (!ret)
+			security_capset_set(target, &effective, &inheritable,
 		     					&permitted);
-     }
+	}
 
 out:
      read_unlock(&tasklist_lock);
Signature · 1 line
1.1.5.g3480
#11 lore raw

RFC PATCH 11/20 ioprio: Update ioprio to handle pspaces.

---

 fs/ioprio.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

42c8b99a7c1417f8fc587f86c218a0be10ec27d0

fs/ioprio.c +7 -6
index ca77008..008301b 100644
@@ -24,6 +24,7 @@
 #include <linux/blkdev.h>
 #include <linux/capability.h>
 #include <linux/syscalls.h>
+#include <linux/pspace.h>
 
 static int set_task_ioprio(struct task_struct *task, int ioprio)
 {
@@ -78,18 +79,18 @@ asmlinkage long sys_ioprio_set(int which
 			if (!who)
 				p = current;
 			else
-				p = find_task_by_pid(who);
+				p = find_task_by_pid(current->pspace, who);
 			if (p)
 				ret = set_task_ioprio(p, ioprio);
 			break;
 		case IOPRIO_WHO_PGRP:
 			if (!who)
 				who = process_group(current);
-			do_each_task_pid(who, PIDTYPE_PGID, p) {
+			do_each_task_pid(current->pspace, who, PIDTYPE_PGID, p) {
 				ret = set_task_ioprio(p, ioprio);
 				if (ret)
 					break;
-			} while_each_task_pid(who, PIDTYPE_PGID, p);
+			} while_each_task_pid(current->pspace, who, PIDTYPE_PGID, p);
 			break;
 		case IOPRIO_WHO_USER:
 			if (!who)
@@ -131,19 +132,19 @@ asmlinkage long sys_ioprio_get(int which
 			if (!who)
 				p = current;
 			else
-				p = find_task_by_pid(who);
+				p = find_task_by_pid(current->pspace, who);
 			if (p)
 				ret = p->ioprio;
 			break;
 		case IOPRIO_WHO_PGRP:
 			if (!who)
 				who = process_group(current);
-			do_each_task_pid(who, PIDTYPE_PGID, p) {
+			do_each_task_pid(current->pspace, who, PIDTYPE_PGID, p) {
 				if (ret == -ESRCH)
 					ret = p->ioprio;
 				else
 					ret = ioprio_best(ret, p->ioprio);
-			} while_each_task_pid(who, PIDTYPE_PGID, p);
+			} while_each_task_pid(current->pspace, who, PIDTYPE_PGID, p);
 			break;
 		case IOPRIO_WHO_USER:
 			if (!who)
Signature · 1 line
1.1.5.g3480
#12 lore raw

RFC PATCH 12/20 fcntl: Update fcntl to work with pspaces.

---

 fs/fcntl.c         |   25 ++++++++++++++++---------
 include/linux/fs.h |    1 +
 2 files changed, 17 insertions(+), 9 deletions(-)

34f261442c7ac3c160830b86aefd5b15df68de9d

fs/fcntl.c +16 -9
index 5f96786..0a41df8 100644
@@ -18,6 +18,7 @@
 #include <linux/ptrace.h>
 #include <linux/signal.h>
 #include <linux/rcupdate.h>
+#include <linux/pspace.h>
 
 #include <asm/poll.h>
 #include <asm/siginfo.h>
@@ -248,11 +249,14 @@ static int setfl(int fd, struct file * f
 	return error;
 }
 
-static void f_modown(struct file *filp, unsigned long pid,
+static void f_modown(struct file *filp, struct pspace *pspace, unsigned long pid,
                      uid_t uid, uid_t euid, int force)
 {
 	write_lock_irq(&filp->f_owner.lock);
 	if (force || !filp->f_owner.pid) {
+		put_pspace(filp->f_owner.pspace);
+		get_pspace(pspace);
+		filp->f_owner.pspace = pspace;
 		filp->f_owner.pid = pid;
 		filp->f_owner.uid = uid;
 		filp->f_owner.euid = euid;
@@ -268,7 +272,7 @@ int f_setown(struct file *filp, unsigned
 	if (err)
 		return err;
 
-	f_modown(filp, arg, current->uid, current->euid, force);
+	f_modown(filp, current->pspace, arg, current->uid, current->euid, force);
 	return 0;
 }
 
@@ -276,7 +280,7 @@ EXPORT_SYMBOL(f_setown);
 
 void f_delown(struct file *filp)
 {
-	f_modown(filp, 0, 0, 0, 1);
+	f_modown(filp, NULL, 0, 0, 0, 1);
 }
 
 static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
@@ -318,6 +322,9 @@ static long do_fcntl(int fd, unsigned in
 		 * to fix this will be in libc.
 		 */
 		err = filp->f_owner.pid;
+		/* Don't return an owner in a different pspace */
+		if (filp->f_owner.pspace != current->pspace)
+			err = 0;
 		force_successful_syscall_return();
 		break;
 	case F_SETOWN:
@@ -478,14 +485,14 @@ void send_sigio(struct fown_struct *fown
 	
 	read_lock(&tasklist_lock);
 	if (pid > 0) {
-		p = find_task_by_pid(pid);
+		p = find_task_by_pid(fown->pspace, pid);
 		if (p) {
 			send_sigio_to_task(p, fown, fd, band);
 		}
 	} else {
-		do_each_task_pid(-pid, PIDTYPE_PGID, p) {
+		do_each_task_pid(fown->pspace, -pid, PIDTYPE_PGID, p) {
 			send_sigio_to_task(p, fown, fd, band);
-		} while_each_task_pid(-pid, PIDTYPE_PGID, p);
+		} while_each_task_pid(fown->pspace, -pid, PIDTYPE_PGID, p);
 	}
 	read_unlock(&tasklist_lock);
  out_unlock_fown:
@@ -513,14 +520,14 @@ int send_sigurg(struct fown_struct *fown
 	
 	read_lock(&tasklist_lock);
 	if (pid > 0) {
-		p = find_task_by_pid(pid);
+		p = find_task_by_pid(fown->pspace, pid);
 		if (p) {
 			send_sigurg_to_task(p, fown);
 		}
 	} else {
-		do_each_task_pid(-pid, PIDTYPE_PGID, p) {
+		do_each_task_pid(fown->pspace, -pid, PIDTYPE_PGID, p) {
 			send_sigurg_to_task(p, fown);
-		} while_each_task_pid(-pid, PIDTYPE_PGID, p);
+		} while_each_task_pid(fown->pspace, -pid, PIDTYPE_PGID, p);
 	}
 	read_unlock(&tasklist_lock);
  out_unlock_fown:
include/linux/fs.h +1 -0
index e059da9..cabb1b6 100644
@@ -589,6 +589,7 @@ extern struct block_device *I_BDEV(struc
 
 struct fown_struct {
 	rwlock_t lock;          /* protects pid, uid, euid fields */
+	struct pspace *pspace;	/* process space of owner pid */
 	int pid;		/* pid or -pgrp where SIGIO should be sent */
 	uid_t uid, euid;	/* uid/euid of process setting the owner */
 	void *security;
Signature · 1 line
1.1.5.g3480
#13 lore raw

RFC PATCH 13/20 kthread: Update kthread to work with pspaces.

---

 kernel/kthread.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

4dbaead60e8ba1ef38aea6059d1abb6f6a10fd1b

kernel/kthread.c +2 -1
index e75950a..0b4fa7b 100644
@@ -12,6 +12,7 @@
 #include <linux/unistd.h>
 #include <linux/file.h>
 #include <linux/module.h>
+#include <linux/pspace.h>
 #include <asm/semaphore.h>
 
 /*
@@ -114,7 +115,7 @@ static void keventd_create_kthread(void 
 		create->result = ERR_PTR(pid);
 	} else {
 		wait_for_completion(&create->started);
-		create->result = find_task_by_pid(pid);
+		create->result = find_task_by_pid(current->pspace, pid);
 	}
 	complete(&create->done);
 }
Signature · 1 line
1.1.5.g3480
#14 lore raw

RFC PATCH 14/20 mm: Update vmscan to work with pspaces.

---

 mm/vmscan.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

c38033f8c948f7fccb92c290f66d3a757c5cec04

mm/vmscan.c +2 -1
index 5a61080..ca5fceb 100644
@@ -1802,7 +1802,8 @@ static int __init kswapd_init(void)
 	swap_setup();
 	for_each_pgdat(pgdat)
 		pgdat->kswapd
-		= find_task_by_pid(kernel_thread(kswapd, pgdat, CLONE_KERNEL));
+		= find_task_by_pid(current->pspace,
+			kernel_thread(kswapd, pgdat, CLONE_KERNEL));
 	total_memory = nr_free_pagecache_pages();
 	hotcpu_notifier(cpu_callback, 0);
 	return 0;
Signature · 1 line
1.1.5.g3480
#15 lore raw

RFC PATCH 15/20 posix-timers: Update posix timers to work with pspaces.

---

 kernel/posix-cpu-timers.c |    9 +++++----
 kernel/posix-timers.c     |    4 +++-
 2 files changed, 8 insertions(+), 5 deletions(-)

90b04f2eeb0fd42309ed68dad92e1b7bb4d2fba6

kernel/posix-cpu-timers.c +5 -4
index 520f6c5..9eda08a 100644
@@ -3,6 +3,7 @@
  */
 
 #include <linux/sched.h>
+#include <linux/pspace.h>
 #include <linux/posix-timers.h>
 #include <asm/uaccess.h>
 #include <linux/errno.h>
@@ -20,7 +21,7 @@ static int check_clock(const clockid_t w
 		return 0;
 
 	read_lock(&tasklist_lock);
-	p = find_task_by_pid(pid);
+	p = find_task_by_pid(current->pspace, pid);
 	if (!p || (CPUCLOCK_PERTHREAD(which_clock) ?
 		   p->tgid != current->tgid : p->tgid != pid)) {
 		error = -EINVAL;
@@ -292,7 +293,7 @@ int posix_cpu_clock_get(const clockid_t 
 		 */
 		struct task_struct *p;
 		read_lock(&tasklist_lock);
-		p = find_task_by_pid(pid);
+		p = find_task_by_pid(current->pspace, pid);
 		if (p) {
 			if (CPUCLOCK_PERTHREAD(which_clock)) {
 				if (p->tgid == current->tgid) {
@@ -336,7 +337,7 @@ int posix_cpu_timer_create(struct k_itim
 		if (pid == 0) {
 			p = current;
 		} else {
-			p = find_task_by_pid(pid);
+			p = find_task_by_pid(current->pspace, pid);
 			if (p && p->tgid != current->tgid)
 				p = NULL;
 		}
@@ -344,7 +345,7 @@ int posix_cpu_timer_create(struct k_itim
 		if (pid == 0) {
 			p = current->group_leader;
 		} else {
-			p = find_task_by_pid(pid);
+			p = find_task_by_pid(current->pspace, pid);
 			if (p && p->tgid != pid)
 				p = NULL;
 		}
kernel/posix-timers.c +3 -1
index 216f574..5f6775c 100644
@@ -35,6 +35,7 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/time.h>
+#include <linux/pspace.h>
 
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
@@ -365,7 +366,8 @@ static struct task_struct * good_sigeven
 	struct task_struct *rtn = current->group_leader;
 
 	if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
-		(!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
+		(!(rtn = find_task_by_pid(current->pspace, 
+					event->sigev_notify_thread_id)) ||
 		 rtn->tgid != current->tgid ||
 		 (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
 		return NULL;
Signature · 1 line
1.1.5.g3480
#16 lore raw

PATCH 16/20 nfs: Don't use pids to track the lockd server process.

---

 fs/lockd/svc.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

8879803b195822f0a4e6f1b05297f5ffe3f62ad1

fs/lockd/svc.c +14 -11
index 71a30b4..e5c1d5c 100644
@@ -45,7 +45,7 @@ EXPORT_SYMBOL(nlmsvc_ops);
 
 static DECLARE_MUTEX(nlmsvc_sema);
 static unsigned int		nlmsvc_users;
-static pid_t			nlmsvc_pid;
+static struct task_struct *	nlmsvc_task;
 int				nlmsvc_grace_period;
 unsigned long			nlmsvc_timeout;
 
@@ -111,7 +111,8 @@ lockd(struct svc_rqst *rqstp)
 	/*
 	 * Let our maker know we're running.
 	 */
-	nlmsvc_pid = current->pid;
+	get_task_struct(current);
+	nlmsvc_task = current;
 	up(&lockd_start);
 
 	daemonize("lockd");
@@ -135,7 +136,7 @@ lockd(struct svc_rqst *rqstp)
 	 * NFS mount or NFS daemon has gone away, and we've been sent a
 	 * signal, or else another process has taken over our job.
 	 */
-	while ((nlmsvc_users || !signalled()) && nlmsvc_pid == current->pid) {
+	while ((nlmsvc_users || !signalled()) && nlmsvc_task == current) {
 		long timeout = MAX_SCHEDULE_TIMEOUT;
 
 		if (signalled()) {
@@ -184,11 +185,12 @@ lockd(struct svc_rqst *rqstp)
 	 * Check whether there's a new lockd process before
 	 * shutting down the hosts and clearing the slot.
 	 */
-	if (!nlmsvc_pid || current->pid == nlmsvc_pid) {
+	if (!nlmsvc_task || current == nlmsvc_task) {
 		if (nlmsvc_ops)
 			nlmsvc_invalidate_all();
 		nlm_shutdown_hosts();
-		nlmsvc_pid = 0;
+		put_task_struct(nlmsvc_task);
+		nlmsvc_task = NULL;
 	} else
 		printk(KERN_DEBUG
 			"lockd: new process, skipping host shutdown\n");
@@ -224,7 +226,7 @@ lockd_up(void)
 	/*
 	 * Check whether we're already up and running.
 	 */
-	if (nlmsvc_pid)
+	if (nlmsvc_task)
 		goto out;
 
 	/*
@@ -290,26 +292,27 @@ lockd_down(void)
 		if (--nlmsvc_users)
 			goto out;
 	} else
-		printk(KERN_WARNING "lockd_down: no users! pid=%d\n", nlmsvc_pid);
+		printk(KERN_WARNING "lockd_down: no users! pid=%d\n", nlmsvc_task->pid);
 
-	if (!nlmsvc_pid) {
+	if (!nlmsvc_task) {
 		if (warned++ == 0)
 			printk(KERN_WARNING "lockd_down: no lockd running.\n"); 
 		goto out;
 	}
 	warned = 0;
 
-	kill_proc(nlmsvc_pid, SIGKILL, 1);
+	send_group_sig_info(SIGKILL, SEND_SIG_PRIV, nlmsvc_task);
 	/*
 	 * Wait for the lockd process to exit, but since we're holding
 	 * the lockd semaphore, we can't wait around forever ...
 	 */
 	clear_thread_flag(TIF_SIGPENDING);
 	interruptible_sleep_on_timeout(&lockd_exit, HZ);
-	if (nlmsvc_pid) {
+	if (nlmsvc_task) {
 		printk(KERN_WARNING 
 			"lockd_down: lockd failed to exit, clearing pid\n");
-		nlmsvc_pid = 0;
+		put_task_struct(nlmsvc_task);
+		nlmsvc_task = NULL;
 	}
 	spin_lock_irq(&current->sighand->siglock);
 	recalc_sigpending();
Signature · 1 line
1.1.5.g3480
#17 lore raw

RFC PATCH 17/20 usb: Fixup usb so it works with pspaces.

---

 drivers/usb/core/devio.c |   12 ++++++++++--
 drivers/usb/core/inode.c |    4 +++-
 drivers/usb/core/usb.h   |    1 +
 3 files changed, 14 insertions(+), 3 deletions(-)

94873f6924179bc2ee782f6fb72d5e855c780a1b

drivers/usb/core/devio.c +10 -2
index 2b68998..7bccb9a 100644
@@ -47,6 +47,7 @@
 #include <linux/usbdevice_fs.h>
 #include <linux/cdev.h>
 #include <linux/notifier.h>
+#include <linux/pspace.h>
 #include <asm/uaccess.h>
 #include <asm/byteorder.h>
 #include <linux/moduleparam.h>
@@ -61,6 +62,7 @@ static struct class *usb_device_class;
 struct async {
 	struct list_head asynclist;
 	struct dev_state *ps;
+	struct pspace *pspace;
 	pid_t pid;
 	uid_t uid, euid;
 	unsigned int signr;
@@ -224,6 +226,7 @@ static struct async *alloc_async(unsigne
 
 static void free_async(struct async *as)
 {
+	put_pspace(as->pspace);
 	kfree(as->urb->transfer_buffer);
 	kfree(as->urb->setup_packet);
 	usb_free_urb(as->urb);
@@ -316,8 +319,8 @@ static void async_completed(struct urb *
 		sinfo.si_errno = as->urb->status;
 		sinfo.si_code = SI_ASYNCIO;
 		sinfo.si_addr = as->userurb;
-		kill_proc_info_as_uid(as->signr, &sinfo, as->pid, as->uid, 
-				      as->euid);
+		kill_proc_info_as_uid(as->signr, &sinfo, as->pspace, as->pid,
+					 as->uid, as->euid);
 	}
 	snoop(&urb->dev->dev, "urb complete\n");
 	snoop_urb(urb, as->userurb);
@@ -571,6 +574,8 @@ static int usbdev_open(struct inode *ino
 	INIT_LIST_HEAD(&ps->async_completed);
 	init_waitqueue_head(&ps->wait);
 	ps->discsignr = 0;
+	ps->disc_pspace = current->pspace;
+	get_pspace(ps->disc_pspace);
 	ps->disc_pid = current->pid;
 	ps->disc_uid = current->uid;
 	ps->disc_euid = current->euid;
@@ -601,6 +606,7 @@ static int usbdev_release(struct inode *
 	destroy_all_async(ps);
 	usb_unlock_device(dev);
 	usb_put_dev(dev);
+	put_pspace(ps->disc_pspace);
 	ps->dev = NULL;
 	kfree(ps);
         return 0;
@@ -1054,6 +1060,8 @@ static int proc_do_submiturb(struct dev_
 		as->userbuffer = NULL;
 	as->signr = uurb->signr;
 	as->ifnum = ifnum;
+	as->pspace = current->pspace;
+	get_pspace(as->pspace);
 	as->pid = current->pid;
 	as->uid = current->uid;
 	as->euid = current->euid;
drivers/usb/core/inode.c +3 -1
index 3cf945c..94c91b3 100644
@@ -700,7 +700,9 @@ static void usbfs_remove_device(struct u
 			sinfo.si_errno = EPIPE;
 			sinfo.si_code = SI_ASYNCIO;
 			sinfo.si_addr = ds->disccontext;
-			kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid);
+			kill_proc_info_as_uid(ds->discsignr, &sinfo,
+						ds->disc_pspace, ds->disc_pid,
+						ds->disc_uid, ds->disc_euid);
 		}
 	}
 }
drivers/usb/core/usb.h +1 -0
index 4647e1e..512c5c7 100644
@@ -73,6 +73,7 @@ struct dev_state {
 	struct list_head async_completed;
 	wait_queue_head_t wait;     /* wake up if a request completed */
 	unsigned int discsignr;
+	struct pspace *disc_pspace;
 	pid_t disc_pid;
 	uid_t disc_uid, disc_euid;
 	void __user *disccontext;
Signature · 1 line
1.1.5.g3480
#18 lore raw

RFC PATCH 18/20 posix-mqueue: Make mqueues work with pspspaces

---

 ipc/mqueue.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

04e0f90a315df40b07d316c884a28c58eed4de33

ipc/mqueue.c +18 -3
index 59302fc..5c71ae0 100644
@@ -25,6 +25,7 @@
 #include <linux/netlink.h>
 #include <linux/syscalls.h>
 #include <linux/signal.h>
+#include <linux/pspace.h>
 #include <net/sock.h>
 #include "util.h"
 
@@ -69,6 +70,7 @@ struct mqueue_inode_info {
 	struct mq_attr attr;
 
 	struct sigevent notify;
+	struct pspace *notify_pspace;
 	pid_t notify_owner;
 	struct user_struct *user;	/* user who created, for accounting */
 	struct sock *notify_sock;
@@ -131,6 +133,7 @@ static struct inode *mqueue_get_inode(st
 			INIT_LIST_HEAD(&info->e_wait_q[0].list);
 			INIT_LIST_HEAD(&info->e_wait_q[1].list);
 			info->messages = NULL;
+			info->notify_pspace = NULL;
 			info->notify_owner = 0;
 			info->qsize = 0;
 			info->user = NULL;	/* set when all is ok */
@@ -250,6 +253,9 @@ static void mqueue_delete_inode(struct i
 	kfree(info->messages);
 	spin_unlock(&info->lock);
 
+	put_pspace(info->notify_pspace);
+	info->notify_pspace = NULL;
+
 	clear_inode(inode);
 
 	mq_bytes = (info->attr.mq_maxmsg * sizeof(struct msg_msg *) +
@@ -360,7 +366,8 @@ static int mqueue_flush_file(struct file
 	struct mqueue_inode_info *info = MQUEUE_I(filp->f_dentry->d_inode);
 
 	spin_lock(&info->lock);
-	if (current->tgid == info->notify_owner)
+	if ((current->tgid == info->notify_owner) &&
+	    (current->pspace == info->notify_pspace))
 		remove_notification(info);
 
 	spin_unlock(&info->lock);
@@ -516,7 +523,8 @@ static void __do_notify(struct mqueue_in
 			sig_i.si_uid = current->uid;
 
 			kill_proc_info(info->notify.sigev_signo,
-				       &sig_i, info->notify_owner);
+				       &sig_i, 
+				       info->notify_pspace, info->notify_owner);
 			break;
 		case SIGEV_THREAD:
 			set_cookie(info->notify_cookie, NOTIFY_WOKENUP);
@@ -525,7 +533,9 @@ static void __do_notify(struct mqueue_in
 			break;
 		}
 		/* after notification unregisters process */
+		put_pspace(info->notify_pspace);
 		info->notify_owner = 0;
+		info->notify_pspace = NULL;
 	}
 	wake_up(&info->wait_q);
 }
@@ -568,6 +578,8 @@ static void remove_notification(struct m
 		set_cookie(info->notify_cookie, NOTIFY_REMOVED);
 		netlink_sendskb(info->notify_sock, info->notify_cookie, 0);
 	}
+	put_pspace(info->notify_pspace);
+	info->notify_pspace = NULL;
 	info->notify_owner = 0;
 }
 
@@ -1042,7 +1054,8 @@ retry:
 	ret = 0;
 	spin_lock(&info->lock);
 	if (u_notification == NULL) {
-		if (info->notify_owner == current->tgid) {
+		if ((info->notify_owner == current->tgid) &&
+		    (info->notify_pspace == current->pspace)) {
 			remove_notification(info);
 			inode->i_atime = inode->i_ctime = CURRENT_TIME;
 		}
@@ -1066,7 +1079,9 @@ retry:
 			info->notify.sigev_notify = SIGEV_SIGNAL;
 			break;
 		}
+		info->notify_pspace = current->pspace;
 		info->notify_owner = current->tgid;
+		get_pspace(info->notify_pspace);
 		inode->i_atime = inode->i_ctime = CURRENT_TIME;
 	}
 	spin_unlock(&info->lock);
Signature · 1 line
1.1.5.g3480
#19 lore raw

RFC PATCH 19/20 pspace: Upcate the pid_max sysctl to work in a per pspace fashion

It is a pain to export anything in sysctl that is not a global variable but it is possible. So for backwards compatibility.

---

 kernel/sysctl.c |   79 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 75 insertions(+), 4 deletions(-)

dc9bb041416aeaa92add46c7fe7689099768d8fa

kernel/sysctl.c +75 -4
index 8e1bdc5..89476f6 100644
@@ -44,6 +44,7 @@
 #include <linux/limits.h>
 #include <linux/dcache.h>
 #include <linux/syscalls.h>
+#include <linux/pspace.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -64,7 +65,6 @@ extern int core_uses_pid;
 extern int suid_dumpable;
 extern char core_pattern[];
 extern int cad_pid;
-extern int pid_max;
 extern int min_free_kbytes;
 extern int printk_ratelimit_jiffies;
 extern int printk_ratelimit_burst;
@@ -132,6 +132,11 @@ static int parse_table(int __user *, int
 		       ctl_table *, void **);
 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
 		  void __user *buffer, size_t *lenp, loff_t *ppos);
+static int proc_pidmax(ctl_table *table, int write, struct file *filp,
+			void __user *buffer, size_t *lenp, loff_t *ppos);
+static int sysctl_pidmax(ctl_table *table, int __user *name, int nlen,
+		void __user *oldval, size_t __user *oldlenp,
+		void __user *newval, size_t newlen, void **context);
 
 static ctl_table root_table[];
 static struct ctl_table_header root_table_header =
@@ -579,11 +584,11 @@ static ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_PIDMAX,
 		.procname	= "pid_max",
-		.data		= &pid_max,
+		.data		= (void *)1,
 		.maxlen		= sizeof (int),
 		.mode		= 0644,
-		.proc_handler	= &proc_dointvec_minmax,
-		.strategy	= sysctl_intvec,
+		.proc_handler	= &proc_pidmax,
+		.strategy	= sysctl_pidmax,
 		.extra1		= &pid_max_min,
 		.extra2		= &pid_max_max,
 	},
@@ -2157,6 +2162,29 @@ int proc_dointvec_ms_jiffies(ctl_table *
 				do_proc_dointvec_ms_jiffies_conv, NULL);
 }
 
+static int do_pidmax_conv(int *negp, unsigned long *lvalp,
+				int *valp, int write, void *data)
+{
+	if (write) {
+		int val = *negp ? -*lvalp : *lvalp;
+		if ((pid_max_min > val) || (pid_max_max < val))
+			return -EINVAL;
+		current->pspace->max = val;
+	} else {
+		*negp = 0;
+		*lvalp = (unsigned long)(current->pspace->max);
+	}
+	return 0;
+}
+
+static int proc_pidmax(ctl_table *table, int write, struct file *filp,
+			void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
+				do_pidmax_conv, NULL);
+}
+
+
 #else /* CONFIG_PROC_FS */
 
 int proc_dostring(ctl_table *table, int write, struct file *filp,
@@ -2222,6 +2250,12 @@ int proc_doulongvec_ms_jiffies_minmax(ct
 }
 
 
+static int proc_pidmax(ctl_table *table, int write, struct file *filp,
+			void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	return -ENOSYS;
+}
+
 #endif /* CONFIG_PROC_FS */
 
 
@@ -2367,6 +2401,43 @@ int sysctl_ms_jiffies(ctl_table *table, 
 	return 1;
 }
 
+static int sysctl_pidmax(ctl_table *table, int __user *name, int nlen,
+		void __user *oldval, size_t __user *oldlenp,
+		void __user *newval, size_t newlen, void **context)
+{
+	int result = 0;
+	if (oldval && oldlenp) {
+		size_t len;
+		if (get_user(len, oldlenp))
+			return -EFAULT;
+		if (len < sizeof(int))
+			return -EINVAL;
+		if (put_user(current->pspace->max, oldval))
+			return -EFAULT;
+		if (put_user(sizeof(int), oldlenp))
+			return -EFAULT;
+		result = 1;
+	}
+	if (newval && newlen) {
+		int __user *vec = (int __user *)newval;
+		int value;
+
+		if (newlen != sizeof(int))
+			return -EINVAL;
+
+		if (get_user(value, vec))
+			return -EFAULT;
+		if (value < pid_max_min)
+			return -EINVAL;
+		if (value > pid_max_max)
+			return -EINVAL;
+
+		current->pspace->max = value;
+		result = 1;
+	}
+	return result;
+}
+
 #else /* CONFIG_SYSCTL */
 
 
Signature · 1 line
1.1.5.g3480
#20 lore raw

RFC PATCH 20/20 proc: Update /proc to support multiple pid spaces.

This patch does a couple of things.
- It splits proc into proc and proc_sysinfo
- It adds pspace support to proc
- It adds getattr methods to ensure proc has the proper hard link count.
- It increases the size of a couple of buffers by one to avoid buffer overflow
- It moves /proc/mounts and /proc/loadavg into the proc filesystem from proc_sysinfo

Sorry for the big patch. When I start feeding this changes seriously I will split this patch.

The split of /proc into mutliple filesystems works well however it comes with one downsides. There are now some directories where cd -P <subdir>/.. is not a noop. Basically it is doing the equivalent of following symlinks into an internal kernel mount. It is well defined and safe behaviour but I'm not certain if it is desirable.

---

 fs/Kconfig                      |    6 
 fs/proc/Makefile                |   22 +-
 fs/proc/array.c                 |  203 ++++++++++++++++
 fs/proc/base.c                  |  487 +++++++++++++++++++++++++++++++++------
 fs/proc/generic.c               |   28 ++
 fs/proc/inode.c                 |   92 ++-----
 fs/proc/internal.h              |   38 +--
 fs/proc/kcore.c                 |    2 
 fs/proc/mmu.c                   |    4 
 fs/proc/nommu.c                 |    4 
 fs/proc/proc.c                  |  168 +++++++++++++
 fs/proc/proc_devtree.c          |    2 
 fs/proc/proc_misc.c             |   27 --
 fs/proc/proc_tty.c              |    2 
 fs/proc/root.c                  |  101 +-------
 fs/proc/sysinfo.h               |   35 +++
 fs/proc/vmcore.c                |    2 
 include/linux/proc_fs.h         |  216 -----------------
 include/linux/proc_sysinfo_fs.h |  228 ++++++++++++++++++
 include/linux/pspace.h          |    1 
 kernel/pid.c                    |    4 
 security/selinux/hooks.c        |   10 -
 22 files changed, 1156 insertions(+), 526 deletions(-)
 create mode 100644 fs/proc/proc.c
 create mode 100644 fs/proc/sysinfo.h
 create mode 100644 include/linux/proc_sysinfo_fs.h

85533ea023d4002528fe0325406160e69c4ca7dd

fs/Kconfig +6 -0
index 93b5dc4..f953b29 100644
@@ -765,6 +765,7 @@ menu "Pseudo filesystems"
 
 config PROC_FS
 	bool "/proc file system support"
+	select PROC_SYSINFO_FS
 	help
 	  This is a virtual file system providing information about the status
 	  of the system. "Virtual" means that it doesn't take up any space on
@@ -792,6 +793,11 @@ config PROC_FS
 	  This option will enlarge your kernel by about 67 KB. Several
 	  programs depend on this, so everyone should say Y here.
 
+config PROC_SYSINFO_FS
+	bool
+	depends on PROC_FS
+	default n
+
 config PROC_KCORE
 	bool "/proc/kcore support" if !ARM
 	depends on PROC_FS && MMU
fs/proc/Makefile +14 -8
index 7431d7b..1ff44cf 100644
@@ -2,14 +2,20 @@
 # Makefile for the Linux proc filesystem routines.
 #
 
-obj-$(CONFIG_PROC_FS) += proc.o
+obj-$(CONFIG_PROC_FS) += procfs.o
+obj-$(CONFIG_PROC_SYSINFO_FS) += proc-sysinfo.o
 
-proc-y			:= nommu.o task_nommu.o
-proc-$(CONFIG_MMU)	:= mmu.o task_mmu.o
+procfs-y		:= task_nommu.o
+procfs-$(CONFIG_MMU)	:= task_mmu.o
+procfs-y		+= proc.o base.o array.o
 
-proc-y       += inode.o root.o base.o generic.o array.o \
-		kmsg.o proc_tty.o proc_misc.o
 
-proc-$(CONFIG_PROC_KCORE)	+= kcore.o
-proc-$(CONFIG_PROC_VMCORE)	+= vmcore.o
-proc-$(CONFIG_PROC_DEVICETREE)	+= proc_devtree.o
+proc-sysinfo-y			:= nommu.o
+proc-sysinfo-$(CONFIG_MMU)	:= mmu.o
+
+proc-sysinfo-y	+= inode.o root.o generic.o kmsg.o proc_tty.o proc_misc.o
+
+proc-sysinfo-$(CONFIG_PROC_KCORE)	+= kcore.o
+proc-sysinfo-$(CONFIG_PROC_VMCORE)	+= vmcore.o
+proc-sysinfo-$(CONFIG_PROC_DEVICETREE)	+= proc_devtree.o
+
fs/proc/array.c +200 -3

248 lines not on this page · raw message

fs/proc/base.c +410 -77

800 lines not on this page · raw message

fs/proc/generic.c +21 -7
index 20e5c45..9befe4b 100644
@@ -10,7 +10,7 @@
 
 #include <linux/errno.h>
 #include <linux/time.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/stat.h>
 #include <linux/module.h>
 #include <linux/mount.h>
@@ -21,7 +21,7 @@
 #include <linux/bitops.h>
 #include <asm/uaccess.h>
 
-#include "internal.h"
+#include "sysinfo.h"
 
 static ssize_t proc_file_read(struct file *file, char __user *buf,
 			      size_t nbytes, loff_t *ppos);
@@ -254,7 +254,7 @@ static int proc_getattr(struct vfsmount 
 			struct kstat *stat)
 {
 	struct inode *inode = dentry->d_inode;
-	struct proc_dir_entry *de = PROC_I(inode)->pde;
+	struct proc_dir_entry *de = PDE(inode);
 	if (de && de->nlink)
 		inode->i_nlink = de->nlink;
 
@@ -373,7 +373,7 @@ static struct dentry_operations proc_den
  * Don't create negative dentries here, return -ENOENT by hand
  * instead.
  */
-struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
+static struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
 {
 	struct inode *inode = NULL;
 	struct proc_dir_entry * de;
@@ -389,7 +389,7 @@ struct dentry *proc_lookup(struct inode 
 				unsigned int ino = de->low_ino;
 
 				error = -EINVAL;
-				inode = proc_get_inode(dir->i_sb, ino, de);
+				inode = proc_sysinfo_get_inode(dir->i_sb, ino, de);
 				break;
 			}
 		}
@@ -413,7 +413,7 @@ struct dentry *proc_lookup(struct inode 
  * value of the readdir() call, as long as it's non-negative
  * for success..
  */
-int proc_readdir(struct file * filp,
+static int proc_readdir(struct file * filp,
 	void * dirent, filldir_t filldir)
 {
 	struct proc_dir_entry * de;
@@ -492,6 +492,20 @@ static struct inode_operations proc_dir_
 	.setattr	= proc_notify_change,
 };
 
+/*
+ * This is the root "inode" in the /proc tree..
+ */
+struct proc_dir_entry proc_root = {
+	.low_ino	= PROC_SYSINFO_ROOT_INO, 
+	.namelen	= 5, 
+	.name		= "/proc",
+	.mode		= S_IFDIR | S_IRUGO | S_IXUGO, 
+	.nlink		= 2, 
+	.proc_iops	= &proc_dir_inode_operations, 
+	.proc_fops	= &proc_dir_operations,
+	.parent		= &proc_root,
+};
+
 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
 {
 	unsigned int i;
@@ -527,7 +541,7 @@ static int proc_register(struct proc_dir
 static void proc_kill_inodes(struct proc_dir_entry *de)
 {
 	struct list_head *p;
-	struct super_block *sb = proc_mnt->mnt_sb;
+	struct super_block *sb = proc_sysinfo_mnt->mnt_sb;
 
 	/*
 	 * Actually it's a partial revoke().
fs/proc/inode.c +19 -73

169 lines not on this page · raw message

fs/proc/internal.h +16 -22
index 95a1cf3..0a30e23 100644
@@ -11,35 +11,22 @@
 
 #include <linux/proc_fs.h>
 
-struct vmalloc_info {
-	unsigned long	used;
-	unsigned long	largest_chunk;
-};
-
-#ifdef CONFIG_MMU
-#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
-extern void get_vmalloc_info(struct vmalloc_info *vmi);
-#else
-
-#define VMALLOC_TOTAL 0UL
-#define get_vmalloc_info(vmi)			\
-do {						\
-	(vmi)->used = 0;			\
-	(vmi)->largest_chunk = 0;		\
-} while(0)
+/*
+ * Offset of the first process in the /proc root directory..
+ */
+#define FIRST_PROCESS_ENTRY 256
 
-#endif
-
-extern void create_seq_entry(char *name, mode_t mode, struct file_operations *f);
 extern int proc_exe_link(struct inode *, struct dentry **, struct vfsmount **);
 extern int proc_tid_stat(struct task_struct *,  char *);
 extern int proc_tgid_stat(struct task_struct *, char *);
+extern int proc_pspace_stat(struct task_struct *, char *);
 extern int proc_pid_status(struct task_struct *, char *);
+extern int proc_pspace_status(struct task_struct *, char *);
 extern int proc_pid_statm(struct task_struct *, char *);
+extern int proc_pspace_statm(struct task_struct *, char *);
+extern struct inode *proc_pspace_make_inode(struct super_block *sb, struct pspace *pspace);
+extern struct vfsmount *proc_pspace_get_mnt(struct pspace *pspace);
 
-void free_proc_entry(struct proc_dir_entry *de);
-
-int proc_init_inodecache(void);
 
 static inline struct task_struct *proc_task(struct inode *inode)
 {
@@ -50,3 +37,10 @@ static inline int proc_type(struct inode
 {
 	return PROC_I(inode)->type;
 }
+
+static inline struct pspace *proc_pspace(struct inode *inode)
+{
+	struct task_struct *task = proc_task(inode);
+	return task ? task->pspace : NULL;
+}
+
fs/proc/kcore.c +1 -1
index adc2cd9..fa24c71 100644
@@ -11,7 +11,7 @@
 
 #include <linux/config.h>
 #include <linux/mm.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/user.h>
 #include <linux/a.out.h>
 #include <linux/capability.h>
fs/proc/mmu.c +2 -2
index 25d2d9c..887eb5e 100644
@@ -15,7 +15,7 @@
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/mman.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/mm.h>
 #include <linux/mmzone.h>
 #include <linux/pagemap.h>
@@ -29,7 +29,7 @@
 #include <asm/pgtable.h>
 #include <asm/tlb.h>
 #include <asm/div64.h>
-#include "internal.h"
+#include "sysinfo.h"
 
 void get_vmalloc_info(struct vmalloc_info *vmi)
 {
fs/proc/nommu.c +2 -2
index cff10ab..65c66ef 100644
@@ -16,7 +16,7 @@
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/mman.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/mm.h>
 #include <linux/mmzone.h>
 #include <linux/pagemap.h>
@@ -30,7 +30,7 @@
 #include <asm/pgtable.h>
 #include <asm/tlb.h>
 #include <asm/div64.h>
-#include "internal.h"
+#include "sysinfo.h"
 
 /*
  * display a list of all the VMAs the kernel knows about
fs/proc/proc.c new file +168 -0

168 lines not on this page · raw message

fs/proc/proc_devtree.c +1 -1
index 9bdd077..8b749d6 100644
@@ -5,7 +5,7 @@
  */
 #include <linux/errno.h>
 #include <linux/time.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/stat.h>
 #include <linux/string.h>
 #include <asm/prom.h>
fs/proc/proc_misc.c +3 -24
index 8f80142..5037ed6 100644
@@ -24,7 +24,7 @@
 #include <linux/tty.h>
 #include <linux/string.h>
 #include <linux/mman.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/ioport.h>
 #include <linux/config.h>
 #include <linux/mm.h>
@@ -46,15 +46,14 @@
 #include <linux/sysrq.h>
 #include <linux/vmalloc.h>
 #include <linux/crash_dump.h>
+#include <linux/pspace.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 #include <asm/io.h>
 #include <asm/tlb.h>
 #include <asm/div64.h>
-#include "internal.h"
+#include "sysinfo.h"
 
-#define LOAD_INT(x) ((x) >> FSHIFT)
-#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
 /*
  * Warning: stuff below (imported functions) assumes that its output will fit
  * into one page. For some of those functions it may be wrong. Moreover, we
@@ -79,23 +78,6 @@ static int proc_calc_metrics(char *page,
 	return len;
 }
 
-static int loadavg_read_proc(char *page, char **start, off_t off,
-				 int count, int *eof, void *data)
-{
-	int a, b, c;
-	int len;
-
-	a = avenrun[0] + (FIXED_1/200);
-	b = avenrun[1] + (FIXED_1/200);
-	c = avenrun[2] + (FIXED_1/200);
-	len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
-		LOAD_INT(a), LOAD_FRAC(a),
-		LOAD_INT(b), LOAD_FRAC(b),
-		LOAD_INT(c), LOAD_FRAC(c),
-		nr_running(), nr_threads, last_pid);
-	return proc_calc_metrics(page, start, off, count, eof, len);
-}
-
 static int uptime_read_proc(char *page, char **start, off_t off,
 				 int count, int *eof, void *data)
 {
@@ -712,7 +694,6 @@ void __init proc_misc_init(void)
 		char *name;
 		int (*read_proc)(char*,char**,off_t,int,int*,void*);
 	} *p, simple_ones[] = {
-		{"loadavg",     loadavg_read_proc},
 		{"uptime",	uptime_read_proc},
 		{"meminfo",	meminfo_read_proc},
 		{"version",	version_read_proc},
@@ -731,8 +712,6 @@ void __init proc_misc_init(void)
 	for (p = simple_ones; p->name; p++)
 		create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
 
-	proc_symlink("mounts", NULL, "self/mounts");
-
 	/* And now for trickier ones */
 	entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
 	if (entry)
fs/proc/proc_tty.c +1 -1
index 15c4455..9715c1f 100644
@@ -9,7 +9,7 @@
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/time.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/stat.h>
 #include <linux/tty.h>
 #include <linux/seq_file.h>
fs/proc/root.c +15 -86

136 lines not on this page · raw message

fs/proc/sysinfo.h new file +35 -0
new file mode 100644
index 0000000..86cec89
@@ -0,0 +1,35 @@
+/* sysinfo.h: internal proc_sysinfo_fs definitions
+ *
+ * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/proc_sysinfo_fs.h>
+
+struct vmalloc_info {
+	unsigned long	used;
+	unsigned long	largest_chunk;
+};
+
+#ifdef CONFIG_MMU
+#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
+extern void get_vmalloc_info(struct vmalloc_info *vmi);
+#else
+
+#define VMALLOC_TOTAL 0UL
+#define get_vmalloc_info(vmi)			\
+do {						\
+	(vmi)->used = 0;			\
+	(vmi)->largest_chunk = 0;		\
+} while(0)
+
+#endif
+
+extern void create_seq_entry(char *name, mode_t mode, struct file_operations *f);
+
+void free_proc_entry(struct proc_dir_entry *de);
fs/proc/vmcore.c +1 -1
index 4063fb3..fc192ae 100644
@@ -9,7 +9,7 @@
 
 #include <linux/config.h>
 #include <linux/mm.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/user.h>
 #include <linux/a.out.h>
 #include <linux/elf.h>
include/linux/proc_fs.h +3 -213

257 lines not on this page · raw message

include/linux/proc_sysinfo_fs.h new file +228 -0

228 lines not on this page · raw message

include/linux/pspace.h +1 -0
index 950393a..3be247f 100644
@@ -24,6 +24,7 @@ struct pspace
 	int last_pid;
 	int min;
 	int max;
+	struct vfsmount *proc_mnt;
 	struct pidmap pidmap[PIDMAP_ENTRIES];
 	char name[1]; /* For use in debugging print statements */
 };
kernel/pid.c +4 -0
index 221585d..8732176 100644
@@ -22,6 +22,7 @@
 
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/bootmem.h>
@@ -249,6 +250,7 @@ static struct pspace *new_pspace(struct 
 	pspace->nr_threads   = 0;
 	pspace->nr_processes = 0;
 	pspace->last_pid     = 0;
+	pspace->proc_mnt     = NULL;
 	pspace->min          = RESERVED_PIDS;
 	pspace->max          = PID_MAX_DEFAULT;
 	for (i = 0; i < PIDMAP_ENTRIES; i++) {
@@ -303,6 +305,8 @@ void __put_pspace(struct pspace *pspace)
 
 	pspace->child_reaper.pspace->nr_processes--;
 	detach_any_pid(&pspace->child_reaper, PIDTYPE_PID);
+	if (pspace->proc_mnt)
+		mntput(pspace->proc_mnt);
 	parent = pspace->child_reaper.pspace;
 	map    = pspace->pidmap;
 	for (i = 0; i < PIDMAP_ENTRIES; i++) {
security/selinux/hooks.c +5 -5
index 4ae834d..f0e148b 100644
@@ -41,7 +41,7 @@
 #include <linux/namei.h>
 #include <linux/mount.h>
 #include <linux/ext2_fs.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_sysinfo_fs.h>
 #include <linux/kd.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv6.h>
@@ -530,7 +530,7 @@ static int superblock_doinit(struct supe
 		}
 	}
 
-	if (strcmp(sb->s_type->name, "proc") == 0)
+	if (strcmp(sb->s_type->name, "proc_sysinfo") == 0)
 		sbsec->proc = 1;
 
 	sbsec->initialized = 1;
@@ -700,7 +700,7 @@ static int selinux_proc_get_sid(struct p
 		path = end;
 		de = de->parent;
 	}
-	rc = security_genfs_sid("proc", path, tclass, sid);
+	rc = security_genfs_sid("proc_sysinfo", path, tclass, sid);
 	free_page((unsigned long)buffer);
 	return rc;
 }
@@ -849,8 +849,8 @@ static int inode_doinit_with_dentry(stru
 		isec->sid = sbsec->sid;
 
 		if (sbsec->proc) {
-			struct proc_inode *proci = PROC_I(inode);
-			if (proci->pde) {
+			struct proc_dir_entry *pde = PDE(inode);
+			if (pde) {
 				isec->sclass = inode_mode_to_security_class(inode->i_mode);
 				rc = selinux_proc_get_sid(proci->pde,
 							  isec->sclass,
Signature · 1 line
1.1.5.g3480
#21 lore raw

Re: [RFC][PATCH 20/20] proc: Update /proc to support multiple pid spaces.

Hello,

Quoted 10 lines

This patch does a couple of things.
- It splits proc into proc and proc_sysinfo
- It adds pspace support to proc
- It adds getattr methods to ensure proc has the proper hard link count.
- It increases the size of a couple of buffers by one to avoid buffer overflow
- It moves /proc/mounts and /proc/loadavg into the proc filesystem from proc_sysinfo

Sorry for the big patch. When I start feeding this changes seriously I will split this patch.

Quoted 7 lines

The split of /proc into mutliple filesystems works well however it comes with one downsides. There are now some directories where cd -P <subdir>/.. is not a noop. Basically it is doing the equivalent of following symlinks into an internal kernel mount. It is well defined and safe behaviour but I'm not certain if it is desirable.

This one is really ugly.
And it is also controversial to your own idea of having separate namespaces, but introduces a pointer to proc_mnt in pspace.

You have many namespaces to which task_struct refers.
Do you want proc to work in any configuration of namespaces? Then you can't have pointers to proc_mnt from namespaces. Well, I understand that proc is the most painfull for you... yeah...

Kirill

#22 lore raw

Re: [RFC][PATCH 20/20] proc: Update /proc to support multiple pid spaces.

Quoted 18 lines · Kirill Korotaev

Hello,

Quoted 6 lines

This patch does a couple of things.
- It splits proc into proc and proc_sysinfo
- It adds pspace support to proc
- It adds getattr methods to ensure proc has the proper hard link count.
- It increases the size of a couple of buffers by one to avoid buffer overflow
- It moves /proc/mounts and /proc/loadavg into the proc filesystem from

proc_sysinfo

Quoted 8 lines

Sorry for the big patch. When I start feeding this changes seriously I will split this patch.
The split of /proc into mutliple filesystems works well however it comes with one downsides. There are now some directories where cd -P <subdir>/.. is not a noop. Basically it is doing the equivalent of following symlinks into an internal kernel mount. It is well defined and safe behaviour but I'm not certain if it is desirable.

Quoted 1 line

This one is really ugly.

It is certainly to much at one time, and the code while semanticly interesting is still has significant issues with the implementation. But a lot of the ugliness is inherent in the current implementation of /proc and not what I am trying to do with it.

Quoted 2 lines

And it is also controversial to your own idea of having separate namespaces, but introduces a pointer to proc_mnt in pspace.

An instance of /proc being connected to a pid space is perfectly natural. /proc is after all the filesystem that reports what is in a pspace.

I freely admit the way I am using the internal mount of proc is wrong, and is something that needs to be resolved before I submit this for kernel inclusion. I was attempting to solve the problem of having duplicate dcache entries in my recursive structure. Unfortunately it was one of those clever solutions that only gets you 99% of the way to where you want to go.

Quoted 2 lines

You have many namespaces to which task_struct refers. Do you want proc to work in any configuration of namespaces?

Yes.

Quoted 2 lines

Then you can't have pointers to proc_mnt from namespaces. Well, I understand that proc is the most painfull for you... yeah...

proc is the painful for any pid change in how pids are dealt with. So far I have not seen a single implementation that cleanly and correctly addresses all of the issues (including mine :)

Eric

#24 lore raw

Re: [RFC][PATCH 17/20] usb: Fixup usb so it works with pspaces.

Quoted 6 lines · Serge E. Hallyn
Quoted 2 lines · Eric W. Biederman

Just how many of these patches would have been unnecessary given your tref patchset?

As far as the amount of work. It is six of one half a dozen of the other. This current implementation changes the logic of the code least which I really like for maintainability.

Small bit sized chunks.

But one piece can be replaced by the other easily, the patches are not contradictory.

Eric

#25 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Eric W. Biederman

kernel/pid.c line 44

Quoted 3 lines · Eric W. Biederman
kernel/pid.c +1 -1
-#define mk_pid(map, off)	(((map) - pidmap_array)*BITS_PER_PAGE + (off))
+#define mk_pid(map, off)	(((map) - pspace->pidmap)*BITS_PER_PAGE + (off))
 #define find_next_offset(map, off)					\

mk_pid() should be:

#define mk_pid(pspace, map, off)	\
			(((map) - (pspace)->pidmap)*BITS_PER_PAGE + (off))

or otherwise made an inline; pscape escaping like this shouldn't happen.

Quoted 18 lines · Eric W. Biederman
kernel/pid.c +18 -0
+static struct pspace *new_pspace(struct task_struct *leader)
+{
+	struct pspace *pspace, *parent;
+	int i;
+	size_t len;
+	parent = leader->pspace;
+	len = strlen(parent->name) + 10;
+	pspace = kzalloc(sizeof(struct pspace) + len, GFP_KERNEL);
+	if (!pspace)
+		return NULL;
+	atomic_set(&pspace->count, 1);
+	pspace->flags        = 0;
+	pspace->nr_threads   = 0;
+	pspace->nr_processes = 0;
+	pspace->last_pid     = 0;
+	pspace->min          = RESERVED_PIDS;
+	pspace->max          = PID_MAX_DEFAULT;
+	for (i = 0; i < PIDMAP_ENTRIES; i++) {

kernel/pid.c static fastcall int __detach_pid(task_t · line 264

Quoted 10 lines
kernel/pid.c +10 -0
+		atomic_set(&pspace->pidmap[i].nr_free,  BITS_PER_PAGE);
+		pspace->pidmap[i].page = NULL;
+	}
+	attach_any_pid(&pspace->child_reaper, leader, PIDTYPE_PID, 
+			parent, leader->wid);
+	leader->pspace->nr_processes++;
+	snprintf(pspace->name, len + 1, "%s/%d", parent->name, leader->wid);
+
+	return pspace;
+}

kzalloc() followed by zeroing ->flags et al by hand is redundant.

-- wli

#26 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 11 lines · William Lee Irwin III

kernel/pid.c line 44

Quoted 3 lines · Eric W. Biederman
kernel/pid.c +1 -1
-#define mk_pid(map, off)	(((map) - pidmap_array)*BITS_PER_PAGE + (off))
+#define mk_pid(map, off) (((map) - pspace->pidmap)*BITS_PER_PAGE + (off))
 #define find_next_offset(map, off)					\

mk_pid() should be:

#define mk_pid(pspace, map, off)	\
			(((map) - (pspace)->pidmap)*BITS_PER_PAGE + (off))

or otherwise made an inline; pscape escaping like this shouldn't happen.

Agreed that is a bug.

Quoted 23 lines · Eric W. Biederman
Quoted 22 lines
kernel/pid.c +22 -0
+static struct pspace *new_pspace(struct task_struct *leader)
+{
+	struct pspace *pspace, *parent;
+	int i;
+	size_t len;
+	parent = leader->pspace;
+	len = strlen(parent->name) + 10;
+	pspace = kzalloc(sizeof(struct pspace) + len, GFP_KERNEL);
+	if (!pspace)
+		return NULL;
+	atomic_set(&pspace->count, 1);
+	pspace->flags        = 0;
+	pspace->nr_threads   = 0;
+	pspace->nr_processes = 0;
+	pspace->last_pid     = 0;
+	pspace->min          = RESERVED_PIDS;
+	pspace->max          = PID_MAX_DEFAULT;
+	for (i = 0; i < PIDMAP_ENTRIES; i++) {
+		atomic_set(&pspace->pidmap[i].nr_free,  BITS_PER_PAGE);
+		pspace->pidmap[i].page = NULL;
+	}
+	attach_any_pid(&pspace->child_reaper, leader, PIDTYPE_PID, 
Quoted 8 lines

kernel/pid.c static fastcall int __detach_pid(task_t · line 264

Quoted 6 lines
kernel/pid.c +6 -0
+			parent, leader->wid);
+	leader->pspace->nr_processes++;
+	snprintf(pspace->name, len + 1, "%s/%d", parent->name, leader->wid);
+
+	return pspace;
+}

kzalloc() followed by zeroing ->flags et al by hand is redundant.

Totally agreed. I was explicitly initializing all of the fields then I missed one in an update and got bit rather badly. So I went for the shotgun approach. I should probably just make it kmalloc
again at this point. I think kmalloc plus explicitly initializing
the fields is going to be a more readable and more efficient because it removes the redundancy.

Eric

#27 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Eric W. Biederman

Eric,

All my commments are inline below.

Quoted 4 lines

This patch modifies the fork/exit, signal handling, and pid and process group manipulating syscalls to support multiple process spaces, and implements the data for allow multiple instaces of the pid namespace.

[ ... skipped .... ]

include/linux/pspace.h line 33

Quoted 3 lines
include/linux/pspace.h new file +3 -0
+extern struct pspace init_pspace;
+
+#define INVALID_PID 0x7fffffff

<<<< what is it for?

include/linux/pspace.h line 39

Quoted 6 lines
include/linux/pspace.h new file +6 -0
+
+static inline int pspace_task_visible(struct pspace *pspace, struct task_struct *tsk)
+{
+	return (tsk->pspace == pspace) || 
+		((tsk->pspace->child_reaper.pspace == pspace) &&
+		 (tsk->pspace->child_reaper.task == tsk));

<<< the logic with child_reaper which can be somehow partly inside pspace... and this check is not that abvious.

Actually I can't say your patch is cleaner somehow.
It is very big and most of the changes are trivial, which creates an illusion that it is straightforward and clean.

[ ... skipped .... ]

Quoted 4 lines
kernel/exit.c +0 -0
@@ -788,6 +801,16 @@ fastcall NORET_TYPE void do_exit(long co
 		panic("Attempted to kill the idle task!");
 	if (unlikely(is_init(tsk)))
 		panic("Attempted to kill init!");

kernel/exit.c fastcall NORET_TYPE void do_exit(long co · line 813

Quoted 10 lines
kernel/exit.c +10 -0
+
+	/*
+	 * If we are the pspace leader it is nonsense for the pspace
+	 * to continue so kill everyone else in the pspace.
+	 */
+	if (pspace_leader(tsk)) {
+		tsk->pspace->flags = PSPACE_EXIT;
+		kill_pspace_info(SIGKILL, (void *)1, tsk->pspace);
+	}
+

<<<<

1.
flags are neither atomic nor protected with any lock.
So if it will be used later for something else in future, there will be 100% race. You also assigns them here, while everywhere in other places a bit is checked.

2. due to 1) you code is buggy. in this respect do_exit() is not serialized with copy_process().

3. due to the same 1) reason

kernel/exit.c fastcall NORET_TYPE void do_exit(long co · line 811

Quoted 1 line
kernel/exit.c +1 -0
+		kill_pspace_info(SIGKILL, (void *)1, tsk->pspace);

can miss a task being forked. Bang!!!

4.
So you are effectively inserting a code for cleaning up pspace here and the same is actually required for other subsystems like networking/IPC etc.
I think you suppose that other resources are freed when the last reference is dropped, but to tell the truth this is a way to deadlocks. Because refs are put in too many places, where you can't make a real cleanup due to locking etc. You can't for example call syncronize_net() from bh, which is required for network cleanup.

Just an another argument why containers are easier/better and why you will eventually end up with it.

Quoted 3 lines
kernel/exit.c +0 -0
 	if (tsk->io_context)
 		exit_io_context();

[ ... skipped ... ]

Quoted 22 lines
kernel/signal.c +18 -0
@@ -1147,11 +1150,55 @@ retry:
 }
 
 /*
+ * kill_pspace_info() sends a signal to all processes in a process space.
+ * This is what kill(-1, sig) does.
+ */
+
+int __kill_pspace_info(int sig, struct siginfo *info, struct pspace *pspace)
+{
+	struct task_struct *p = NULL;
+	int retval = 0, count = 0;
+
+	for_each_process(p) {
+		int err;
+		/* Skip the current pspace leader */
+		if (current_pspace_leader(p))
+			continue;
+
+		/* Skip the sender of the signal */
+		if (p->signal == current->signal)
+			continue;

kernel/signal.c retry: · line 1180

Quoted 10 lines
kernel/signal.c +10 -0
+
+		/* Skip processes outside the target process space */
+		if (!in_pspace(pspace, p))
+			continue;
+
+		/* Finally it is a good process send the signal. */
+		err = group_send_sig_info(sig, info, p);
+		++count;
+		if (err != -EPERM)
+			retval = err;

<<<<
why EPERM is ok?
do you want to miss some tasks?

kernel/signal.c retry: · line 1184

Quoted 4 lines
kernel/signal.c +4 -0
+	}
+	return count ? retval : -ESRCH;
+}
+

Thanks,
Kirill

#28 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 23 lines · Kirill Korotaev
Quoted 23 lines

+ * kill_pspace_info() sends a signal to all processes in a process space.
+ * This is what kill(-1, sig) does.
+ */

kernel/signal.c +20 -0
+
+int __kill_pspace_info(int sig, struct siginfo *info, struct pspace *pspace)
+{
+	struct task_struct *p = NULL;
+	int retval = 0, count = 0;
+
+	for_each_process(p) {
+		int err;
+		/* Skip the current pspace leader */
+		if (current_pspace_leader(p))
+			continue;
+
+		/* Skip the sender of the signal */
+		if (p->signal == current->signal)
+			continue;
+
+		/* Skip processes outside the target process space */
+		if (!in_pspace(pspace, p))
+			continue;
+
Quoted 8 lines

kernel/signal.c retry: · line 1180

Quoted 5 lines
kernel/signal.c +5 -0
+		/* Finally it is a good process send the signal. */
+		err = group_send_sig_info(sig, info, p);
+		++count;
+		if (err != -EPERM)
+			retval = err;

<<<<
why EPERM is ok?
do you want to miss some tasks?

A good question. This is how kill -1 is currently implemented. It doesn't align with how signals are sent to a process group, so it could very well be wrong.

Quoted 4 lines
Quoted 4 lines
kernel/signal.c +4 -0
+	}
+	return count ? retval : -ESRCH;
+}
+
#29 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Kirill Korotaev
Quoted 9 lines · Kirill Korotaev

Eric,

All my commments are inline below.

Quoted 4 lines

This patch modifies the fork/exit, signal handling, and pid and process group manipulating syscalls to support multiple process spaces, and implements the data for allow multiple instaces of the pid namespace.

Quoted 6 lines

[ ... skipped .... ]

include/linux/pspace.h line 33

Quoted 3 lines
include/linux/pspace.h new file +3 -0
+extern struct pspace init_pspace;
+
+#define INVALID_PID 0x7fffffff

<<<< what is it for?

It is a hold over from an earlier version that never got deleted. oops.

Eric

#30 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Kirill Korotaev
Quoted 9 lines · Kirill Korotaev

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static inline int pspace_task_visible(struct pspace *pspace, struct

task_struct *tsk)

include/linux/pspace.h line 39

Quoted 4 lines
include/linux/pspace.h new file +4 -0
+{
+	return (tsk->pspace == pspace) ||
+		((tsk->pspace->child_reaper.pspace == pspace) &&
+		 (tsk->pspace->child_reaper.task == tsk));

<<< the logic with child_reaper which can be somehow partly inside pspace... and this check is not that abvious.

This is the check for what shows up in /proc.

Given that is how I have explicitly documented things to work, (the init process straddles the boundary) I fail to see how it is not obvious.

Eric

#31 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 13 lines
Quoted 11 lines
Quoted 1 line

+static inline int pspace_task_visible(struct pspace *pspace, struct

task_struct *tsk)

include/linux/pspace.h line 39

Quoted 4 lines
include/linux/pspace.h new file +4 -0
+{
+	return (tsk->pspace == pspace) ||
+		((tsk->pspace->child_reaper.pspace == pspace) &&
+		 (tsk->pspace->child_reaper.task == tsk));

<<< the logic with child_reaper which can be somehow partly inside pspace... and this check is not that abvious.

Quoted 4 lines

This is the check for what shows up in /proc.

Given that is how I have explicitly documented things to work, (the init process straddles the boundary) I fail to see how it is not obvious.

I was confused by the fact that child_reaper.pspace is actually a parent pspace.

Kirill

#32 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Eric W. Biederman
Quoted 10 lines · Eric W. Biederman
Quoted 8 lines · Kirill Korotaev
Quoted 1 line

+static inline int pspace_task_visible(struct pspace *pspace, struct

task_struct *tsk)

include/linux/pspace.h line 39

Quoted 4 lines
include/linux/pspace.h new file +4 -0
+{
+	return (tsk->pspace == pspace) ||
+		((tsk->pspace->child_reaper.pspace == pspace) &&
+		 (tsk->pspace->child_reaper.task == tsk));

<<< the logic with child_reaper which can be somehow partly inside pspace... and this check is not that abvious.

Quoted 4 lines

This is the check for what shows up in /proc.

Given that is how I have explicitly documented things to work, (the init process straddles the boundary) I fail to see how it is not obvious.

I'd claim that the (tsk->pspace == pspace) test is pretty obvious.

However, the child_reaper one takes a little deduction. Sometimes, I think separating out even trivial functions into even trivialler :) functions really does make sense for these. They can be really confusing. BTW, I _still_ don't understand exactly what this is doing, but I haven't had any coffee.

Is something like this more clear?

static inline int pspace_task_visible(struct pspace *pspace, struct task_struct *tsk)

{
	if (tsk->pspace == pspace)
		return 1;

	/*
	 * Init tasks straggle namespaces.  They have the explicit
	 * pspace of their parent, but are visible from thier
	 * children.
	 */
	if (pspace_child_reaper_is_task(pspace, tsk)
		return 1;

	return 0;
}

int pspace_child_reaper_is_task(struct pspace *pspace,
struct task_struct *tsk)

{
	if ((tsk->pspace->child_reaper.pspace == pspace) &&
	    (tsk->pspace->child_reaper.task == tsk))
		return 1;

	return 0;
}

-- Dave

#33 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Kirill Korotaev
Quoted 3 lines · Kirill Korotaev

Actually I can't say your patch is cleaner somehow.
It is very big and most of the changes are trivial, which creates an illusion that it is straightforward and clean.

It is hard to make a comparison. Your patch posted to the mail list was incomplete, and I could only find a giant patch for OpenVZ.

Beyond that if your patch introduced a type change for internal pids and used that generate compile errors when someone did not use the appropriate type, I would be a lot happier and the code would be a lot more maintainable. I.e. It would not take an audit of the kernel source to find the issues an allyesconfig build would find them for you.

I don't think my current implementation actually causes enough compile errors, but I need think closely about it before I go much farther.

Maintainable code is a delicate balancing act between things that trip you up when you get it wrong, and not being so cumbersome you get in the programmers way.

The advantages I see with my approach.
- I have hierarchical pids so nesting is possible.
- The state after migration is not suboptimal.
- I cause compiler errors which makes maintenance easier.
- Other kernel developers gut feel is that (container, pid) is the proper representation.
I actually flip flop on the issue of if I want the internal representation to be (container, pid) or a magic kpid that combines the into one integer. I know I don't want the kpid to be user space visible though.

So far you have not addressed the issues of maintaining code in the kernel tree.

Eric

#34 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 7 lines
Quoted 3 lines

Actually I can't say your patch is cleaner somehow.
It is very big and most of the changes are trivial, which creates an illusion that it is straightforward and clean.

It is hard to make a comparison. Your patch posted to the mail list was incomplete, and I could only find a giant patch for OpenVZ.

this is wrong. it lacked only alpha get_xpid().
sure, we didn't do that dirty games with /proc you did, so maybe this is why you have such a feeling.

Quoted 6 lines

Beyond that if your patch introduced a type change for internal pids and used that generate compile errors when someone did not use the appropriate type, I would be a lot happier and the code would be a lot more maintainable. I.e. It would not take an audit of the kernel source to find the issues an allyesconfig build would find them for you.

it is not a problem at all and can be done.

Quoted 9 lines

I don't think my current implementation actually causes enough compile errors, but I need think closely about it before I go much farther.

Maintainable code is a delicate balancing act between things that trip you up when you get it wrong, and not being so cumbersome you get in the programmers way

The advantages I see with my approach.
- I have hierarchical pids so nesting is possible.

Once again, our approach doesn't prohibit hierarchical pids.
But in addition to yours it allows to select whether weak or strong isolation is required.

Quoted 1 line

- The state after migration is not suboptimal.

sorry?

Quoted 1 line

- I cause compiler errors which makes maintenance easier.

it is not a question to the approach itself, you see? so not an argument.

Quoted 8 lines

- Other kernel developers gut feel is that (container, pid) is the proper representation.
I actually flip flop on the issue of if I want the internal representation to be (container, pid) or a magic kpid that combines the into one integer. I know I don't want the kpid to be user space visible though.

So far you have not addressed the issues of maintaining code in the kernel tree.

Uhhh... I see that you have no real arguments. Nice.

Kirill

#35 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 4 lines · Kirill Korotaev
Quoted 2 lines

So far you have not addressed the issues of maintaining code in the kernel tree.

Uhhh... I see that you have no real arguments. Nice.

Au contraire, this is a central issue which you have yet to address. How do you suggest helping maintainers in the future know which pid they are working with?

For our vpid patchset we had considered using sparse to make sure that the real ('kernel') and user ('virtual') pids were never used in place of each other without going through a conversion. That could be one solution. Using opaque typedefs is of course another solution. But suspect there will be places in the code where it simply isn't clear at first glance which pid you'd want. And if it's not clear at first glance, then it's likely to be done wrong in at least some of those places.

-serge

#36 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Kirill Korotaev
Quoted 8 lines · Kirill Korotaev
Quoted 5 lines
Quoted 3 lines

Actually I can't say your patch is cleaner somehow.
It is very big and most of the changes are trivial, which creates an illusion that it is straightforward and clean.

It is hard to make a comparison. Your patch posted to the mail list was incomplete, and I could only find a giant patch for OpenVZ.

this is wrong. it lacked only alpha get_xpid().
sure, we didn't do that dirty games with /proc you did, so maybe this is why you have such a feeling.

Not at all.
- You didn't have a system call interface.
- You didn't include your patches to proc.
- The fact that you missed several whole subsystems, (as did I) is a minor issue.
etc.

The patches we posted were a different subset of the whole, and as such a clear comparison could not be made.

Quoted 7 lines
Quoted 6 lines

Beyond that if your patch introduced a type change for internal pids and used that generate compile errors when someone did not use the appropriate type, I would be a lot happier and the code would be a lot more maintainable. I.e. It would not take an audit of the kernel source to find the issues an allyesconfig build would find them for you.

it is not a problem at all and can be done.

Then why isn't it done in OpenVZ?

I agree it can be done. But an audit of the entire kernel is painful.

Quoted 5 lines
Quoted 2 lines

The advantages I see with my approach.
- I have hierarchical pids so nesting is possible.

Once again, our approach doesn't prohibit hierarchical pids.
But in addition to yours it allows to select whether weak or strong isolation is required.

Again. I have not heard this assertion before, and I don't see it. But let me ask a question that helps frame the issue.

Can I migrate all of the processes and (containers) on a real server (not in a container) into a container on another machine without any change in pids?

I believe that would require 3 on the inner most nested processes with your approach.

Quoted 2 lines
Quoted 1 line

- The state after migration is not suboptimal.

sorry?

You have 2 approaches, in your patch. I have one approach that works for everything. Possibly I misunderstood my skimming, but usually optimizations are only added when needed.

Quoted 2 lines
Quoted 1 line

- I cause compiler errors which makes maintenance easier.

it is not a question to the approach itself, you see? so not an argument.

How the code will be maintained when discussing merging with the mainline kernel is one of the most important issues to consider.

Quoted 8 lines
Quoted 7 lines

- Other kernel developers gut feel is that (container, pid) is the proper
representation. I actually flip flop on the issue of if I want the
internal representation
to be (container, pid) or a magic kpid that combines the into one integer. I know I don't want the kpid to be user space visible though.
So far you have not addressed the issues of maintaining code in the kernel tree.

Uhhh... I see that you have no real arguments. Nice.

I wasn't trying to argue simply to lay it out as I saw it.

Eric

#37 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Kirill Korotaev
Quoted 18 lines · Kirill Korotaev

[ ... skipped .... ]

Quoted 4 lines
kernel/exit.c +0 -0
@@ -788,6 +801,16 @@ fastcall NORET_TYPE void do_exit(long co
 		panic("Attempted to kill the idle task!");
 	if (unlikely(is_init(tsk)))
 		panic("Attempted to kill init!");

kernel/exit.c fastcall NORET_TYPE void do_exit(long co · line 813

Quoted 10 lines
kernel/exit.c +10 -0
+
+	/*
+	 * If we are the pspace leader it is nonsense for the pspace
+	 * to continue so kill everyone else in the pspace.
+	 */
+	if (pspace_leader(tsk)) {
+		tsk->pspace->flags = PSPACE_EXIT;
+		kill_pspace_info(SIGKILL, (void *)1, tsk->pspace);
+	}
+

<<<<

Quoted 2 lines

1.
flags are neither atomic nor protected with any lock.

flags are atomic as they are a machine word. So they do not require a read/modify write so they will either be written or not written. Plus this allows write-sharing of the appropriate cache line which is very polite (assuming the line is not shared with something else)

I do need a big fat comment about this though.

There is serialization as there is only one process that can write to this value from exactly one spot.

Quoted 3 lines

So if it will be used later for something else in future, there will be 100% race. You also assigns them here, while everywhere in other places a bit is checked.

Agreed. I need to change the name to something like state and stop doing bit tests. To make this clear.

Quoted 2 lines

2. due to 1) you code is buggy. in this respect do_exit() is not serialized with copy_process().

Yes. I may need a memory barrier in there. I need to think about that a little more.

Quoted 3 lines

3. due to the same 1) reason

kernel/exit.c fastcall NORET_TYPE void do_exit(long co · line 811

Quoted 1 line
kernel/exit.c +1 -0
+		kill_pspace_info(SIGKILL, (void *)1, tsk->pspace);

can miss a task being forked. Bang!!!

Well the only bad thing that can happen is that I get a process that can run and observe pid == 1 has exited. So Bang!! is not too painful.

For an initial implementation that is not yet ready for kernel inclusion, and was posted to show the form I expect my patches to take that wasn't too bad.

Quoted 3 lines

4.
So you are effectively inserting a code for cleaning up pspace here and the same is actually required for other subsystems like networking/IPC etc.

So the SIGKILL is not about pspace clean up so much as making it impossible to observe a state where pid == 1 is not running.

Quoted 5 lines

I think you suppose that other resources are freed when the last reference is dropped, but to tell the truth this is a way to deadlocks. Because refs are put in too many places, where you can't make a real cleanup due to locking etc. You can't for example call syncronize_net() from bh, which is required for network cleanup.

Yes references counts can work, and do so regularly in the kernel. Work queues will put you in a process context trivially, so being dropping the last ref from an irq handler and then needed process context to do the cleanup is not a problem.

Quoted 2 lines

Just an another argument why containers are easier/better and why you will eventually end up with it.

Does not follow.

Kirill you are not making all of your reasoning explicit and making mistakes in the gaps.

The steps you are making seem to be.
containers are simpler.
simpler means easier to get correct.
bugs will happen.
therefore you will use the simpler solution.

The above reasoning seems to assume that containers are not prone to the same reference counting bugs as namespaces. Given that we are solving the same problem in similar problems this seems unwarranted.

In addition the rejection of the basic container approach is largely based upon lack of flexibility. No amount of additional simplicity can make up for not meeting real world requirements.

Kirill there may be a case where your container concept performs beautifully and simplifies the problem, but I have looked and I have not seen it.

Eric

#38 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 9 lines
Quoted 2 lines

1.
flags are neither atomic nor protected with any lock.

flags are atomic as they are a machine word. So they do not require a read/modify write so they will either be written or not written. Plus this allows write-sharing of the appropriate cache line which is very polite (assuming the line is not shared with something else)

Eric I'm familiar with SMP, thanks :)
Why do you write all this if you agreed below that have problems with it?

Quoted 4 lines
Quoted 2 lines

2. due to 1) you code is buggy. in this respect do_exit() is not serialized with copy_process().

Yes. I may need a memory barrier in there. I need to think about that a little more.

memory barrier doesn't help. you really need to think about.

Quoted 7 lines
Quoted 3 lines

3. due to the same 1) reason

kernel/exit.c fastcall NORET_TYPE void do_exit(long co · line 811

Quoted 1 line
kernel/exit.c +1 -0
+		kill_pspace_info(SIGKILL, (void *)1, tsk->pspace);

can miss a task being forked. Bang!!!

Well the only bad thing that can happen is that I get a process that can run and observe pid == 1 has exited. So Bang!! is not too painful.

And what about references to pspace->child_reaper which was freed already?

[skipped the flood]

Kirill

#39 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 19 lines · Kirill Korotaev
Quoted 9 lines
Quoted 2 lines

1.
flags are neither atomic nor protected with any lock.

flags are atomic as they are a machine word. So they do not require a read/modify write so they will either be written or not written. Plus this allows write-sharing of the appropriate cache line which is very polite (assuming the line is not shared with something else)

Eric I'm familiar with SMP, thanks :)
Why do you write all this if you agreed below that have problems with it?

Quoted 5 lines
Quoted 3 lines

2. due to 1) you code is buggy. in this respect do_exit() is not serialized with
copy_process().

Yes. I may need a memory barrier in there. I need to think about that a little more.

memory barrier doesn't help. you really need to think about.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

3. due to the same 1) reason

kernel/exit.c fastcall NORET_TYPE void do_exit(long co · line 811

Quoted 1 line
kernel/exit.c +1 -0
+		kill_pspace_info(SIGKILL, (void *)1, tsk->pspace);

can miss a task being forked. Bang!!!

Well the only bad thing that can happen is that I get a process that can run and observe pid == 1 has exited. So Bang!! is not too painful.

And what about references to pspace->child_reaper which was freed already?

This seems a very valid point. And even if you implement code to detect when a process exits whether it is a child_reaper for some pspace, you can't just make pspace->child_reaper = pspace->child_reaper->child_reaper, as the wid may not be valid in the grandparent's namespace, right?

-serge

#40 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 4 lines

This seems a very valid point. And even if you implement code to detect when a process exits whether it is a child_reaper for some pspace, you can't just make pspace->child_reaper = pspace->child_reaper->child_reaper, as the wid may not be valid in the grandparent's namespace, right?

Right. What I have done is in the PSPACE_EXIT condition all children when they die self reap and have the global process reaper set to their parent. However since exit_signal == -1 the initial process reaper never sees them.

Even for a nested pspace I figure it is an error for anything to outlive init. The wid not working is a valid reason for this however if it was really necessary a new wid value could be allocated. As nothing on the inside of a pspace is directly aware of it.

The situation is very similar to being behind a NAT firewall.

Eric

#41 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Kirill Korotaev
Quoted 9 lines · Kirill Korotaev
Quoted 7 lines
Quoted 2 lines

1.
flags are neither atomic nor protected with any lock.

flags are atomic as they are a machine word. So they do not require a read/modify write so they will either be written or not written. Plus this allows write-sharing of the appropriate cache line which is very polite (assuming the line is not shared with something else)

Eric I'm familiar with SMP, thanks :)
Why do you write all this if you agreed below that have problems with it?

To establish a baseline of understanding and because you made an assertion that is counter to my understanding.

Quoted 6 lines
Quoted 1 line
Quoted 1 line

2. due to 1) you code is buggy. in this respect do_exit() is not serialized

with

Quoted 3 lines
Quoted 1 line

copy_process().

Yes. I may need a memory barrier in there. I need to think about that a little more.

memory barrier doesn't help. you really need to think about.

Except for instances where you need an atomic read/modify/write the only primitives you have are reads, writes and barriers.

I have all of the correct reads and writes therefore the only thing that could help are barriers if the logic is otherwise sane.

A write barrier to ensure the write of flags is visible before I write the kill signal will ensure the write of flags is globally visible first. Although I am having a hard time convincing myself even that matters.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

3. due to the same 1) reason

kernel/exit.c fastcall NORET_TYPE void do_exit(long co · line 811

Quoted 1 line
kernel/exit.c +1 -0
+		kill_pspace_info(SIGKILL, (void *)1, tsk->pspace);

can miss a task being forked. Bang!!!

Well the only bad thing that can happen is that I get a process that can run and observe pid == 1 has exited. So Bang!! is not too painful.

And what about references to pspace->child_reaper which was freed already?

The assumes that release_task() is called synchronously with do_exit which is not the case. Looking at the code I do think release_task() for the pspace leader can be called too soon. But that is really has nothing to do with whether or not all of it's children got sent SIGKILL.

That is a significant issue, that needs to be fixed before I submit this piece of code for inclusion into the kernel.

The issue is depending on the context is that a process actively running in kernel space could proceed for a long time before it returns to user space and receives a signal. In that span of time it could execute just about any code in the kernel.

Kirill thank you for spotting this.

This exchange seems to have a hostile and not a cooperative tone so I will finish the investigation and bug fixing elsewhere.

I expect that there might be a few more issues like this. My only expectation was that the code was complete enough to discuss semantics and kernel mechanisms for creating a namespaces, and the code has successfully served that purpose.

Eric

#42 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 2 lines · Eric W. Biederman

That is a significant issue, that needs to be fixed before I submit this piece of code for inclusion into the kernel.

Is there a chance you could re-post your current set, or throw them out on kernel.org? The thread is a week old now, and I would imagine there's been a lot of churn. :)

-- Dave

#43 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Eric W. Biederman

Hello Eric,

Quoted 6 lines
Quoted 1 line

memory barrier doesn't help. you really need to think about.

Except for instances where you need an atomic read/modify/write the only primitives you have are reads, writes and barriers.

I have all of the correct reads and writes therefore the only thing that could help are barriers if the logic is otherwise sane.

the problem is that you do read/write for synchronization of other operations (fork/pspace leader die). i.e. you try to make a serialization, you see? It doesn't work this way.

....

Quoted 2 lines

This exchange seems to have a hostile and not a cooperative tone so I will finish the investigation and bug fixing elsewhere.

Eric, I think it turned this way because you started pointing to our bugs in VPIDs, while having lots of own and not working code.
I can point you another _really_ disastrous bugs in your IPC and networking virtualization. But discussing bugs is not want I want, you see? I want us to make some solution suatable for all the parties.

And while you have not working solution it is hard to discuss whether it is good or not, whether it is beatutiful or not. It is incomplete and doesn't work. So many statements that one solution is better than another are not valid.

And we are too cycled on PIDs. Why? I think this is the most minor feature which can easily live out of mainstream if needed, while virtualization is the main goal.
I also don't understand why you are eager to introduce new sys calls like pkill(path_to_process), but is trying to use waitpid() for pspace die notifications? Maybe it is simply better to introduce container specific syscalls which should be clean and tidy, instead of messing things up with clone()/waitpid() and so on? The more simple code we have, the better it is for all of us.

If possible keep posting your patches. I would even ask you to add me to CC always. You are doing a really good job and discussion solutions is the only possible way to push something to mainstream I suppose. I would also be happy to arrange a meeting with the interested parties, since talking eye to eye can be much more productive.

Quoted 4 lines

I expect that there might be a few more issues like this. My only expectation was that the code was complete enough to discuss semantics and kernel mechanisms for creating a namespaces, and the code has successfully served that purpose.

To some extent yes.

Kirill

#44 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 14 lines · Kirill Korotaev

Hello Eric,

Quoted 6 lines
Quoted 1 line

memory barrier doesn't help. you really need to think about.

Except for instances where you need an atomic read/modify/write the only primitives you have are reads, writes and barriers.

I have all of the correct reads and writes therefore the only thing that could help are barriers if the logic is otherwise sane.

the problem is that you do read/write for synchronization of other operations (fork/pspace leader die).
i.e. you try to make a serialization, you see? It doesn't work this way.

....

Quoted 7 lines
Quoted 2 lines

This exchange seems to have a hostile and not a cooperative tone so I will finish the investigation and bug fixing elsewhere.

Eric, I think it turned this way because you started pointing to our bugs in VPIDs, while having lots of own and not working code. I can point you another _really_ disastrous bugs in your IPC and networking virtualization. But discussing bugs is not want I want, you see? I want us to make some solution suatable for all the parties.

that's good!

Quoted 4 lines

And while you have not working solution it is hard to discuss whether it is good or not, whether it is beatutiful or not. It is incomplete and doesn't work. So many statements that one solution is better than another are not valid.

well, it's kind of moot to demand a final solution just to discuss the implementation ...
usually software design happens before the implementation and the implementation details can be fed back into the cycle later ...

Quoted 3 lines

And we are too cycled on PIDs. Why? I think this is the most minor feature which can easily live out of mainstream if needed, while virtualization is the main goal.

although I could be totally ignorant regarding the PID stuff, it seems to me that it pretty well reflects the requirements for virtualization in general, while being simple enough to check/test several solutions ...

why? simple: it reflects the way 'containers' work in general, it has all the issues with administration and setup, similar to 'guests' (it requires some management and access from outside, while providing security and isolation inside), containers could be easily built on top of that or as an addition to the pid space structures at the same time it's easy to test, and issues will show up quite early, so that they can be discussed and, if necessary, solved without rewriting an entire framework.

Quoted 6 lines

I also don't understand why you are eager to introduce new sys calls like pkill(path_to_process), but is trying to use waitpid() for pspace die notifications? Maybe it is simply better to introduce container specific syscalls which should be clean and tidy, instead of messing things up with clone()/waitpid() and so on? The more simple code we have, the better it is for all of us.

now that you mention it, maybe we should have a few rounds how those 'generic' container syscalls would look like?

best,
Herbert

Quoted 13 lines

If possible keep posting your patches. I would even ask you to add me to CC always. You are doing a really good job and discussion solutions is the only possible way to push something to mainstream I suppose. I would also be happy to arrange a meeting with the interested parties, since talking eye to eye can be much more productive.

Quoted 4 lines

I expect that there might be a few more issues like this. My only expectation was that the code was complete enough to discuss semantics and kernel mechanisms for creating a namespaces, and the code has successfully served that purpose.

To some extent yes.

Kirill

#45 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 10 lines · Herbert Poetzl
Quoted 6 lines

I also don't understand why you are eager to introduce new sys calls like pkill(path_to_process), but is trying to use waitpid() for pspace die notifications? Maybe it is simply better to introduce container specific syscalls which should be clean and tidy, instead of messing things up with clone()/waitpid() and so on? The more simple code we have, the better it is for all of us.

now that you mention it, maybe we should have a few rounds how those 'generic' container syscalls would look like?

I still like the following:

clone(): extended with flags for asking a private copy of various
namespaces. For the CLONE_NEWPIDSPACE flag, the pid which is returned to the parent process is it's handle to the new pidspace.

sys_execpid(pid, argv, envp): exec a new syscall with the requested
pid, if the pid is available. Else either return an error, or pick a random pid. Error makes sense to me, but that's probably debatable.

sys_fork_slide(pid): fork and slide into the pidspace belong to pid.

	This way we can do things like

	p = sys_fork_slide(2794);
	if (p == 0) {
		kill(2974);
	} else {
		waitpid(p, 0, 0);
	}

Ok, this last one in particular needs to be improved, but these two syscalls and the clone flags together give us all we need. Right?

-serge

#46 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I also don't understand why you are eager to introduce new sys calls like pkill(path_to_process), but is trying to use waitpid() for pspace die notifications? Maybe it is simply better to introduce container specific syscalls which should be clean and tidy, instead of messing things up with clone()/waitpid() and so on? The more simple code we have, the better it is for all of us.

now that you mention it, maybe we should have a few rounds how those 'generic' container syscalls would look like?

Quoted 6 lines

I still like the following:

clone(): extended with flags for asking a private copy of various
namespaces. For the CLONE_NEWPIDSPACE flag, the pid which is returned to the parent process is it's handle to the new pidspace.

- clone has limited number of flags.
- sooner or later you will need to add flags about what and how you want to close (e.g. pspace with weak or strong isolation and so on)

Quoted 4 lines

sys_execpid(pid, argv, envp): exec a new syscall with the requested
pid, if the pid is available. Else either return an error, or pick a random pid. Error makes sense to me, but that's probably debatable.

the problem is that in real life environments where executables can be substitutes this is kind of a security issue. Also I really hate the idea of using exec() for changing something. In OpenVZ we successfully do context changes without exec()'s.

Quoted 11 lines

sys_fork_slide(pid): fork and slide into the pidspace belong to pid.

	This way we can do things like

	p = sys_fork_slide(2794);
	if (p == 0) {
		kill(2974);
	} else {
		waitpid(p, 0, 0);
	}

Ok, this last one in particular needs to be improved, but these two syscalls and the clone flags together give us all we need. Right?

Again, you concentrate on PIDspaces forgeting about all the other namespaces.

I would prefer:

- sys_ns_create()
creates namespace and makes a task to inherit this namespace. If _needed_, it _can_ fork inside.

- sys_ns_inherit()
change active namespace.

But how should we reference namespace? by globabl ID?

Kirill

#47 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 18 lines · Kirill Korotaev
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

I also don't understand why you are eager to introduce new sys calls like pkill(path_to_process), but is trying to use waitpid() for pspace die notifications? Maybe it is simply better to introduce container specific syscalls which should be clean and tidy, instead of messing things up with clone()/waitpid() and so on? The more simple code we have, the better it is for all of us.

now that you mention it, maybe we should have a few rounds how those 'generic' container syscalls would look like?

Quoted 6 lines

I still like the following:

clone(): extended with flags for asking a private copy of various
namespaces. For the CLONE_NEWPIDSPACE flag, the pid which is returned to the parent process is it's handle to the new pidspace.

Quoted 4 lines

- clone has limited number of flags.
- sooner or later you will need to add flags about what and how you want to close (e.g. pspace with weak or strong isolation and so on)

I still do not see a need to do that at clone() time but I assume you have your reasons for postulating this ...

Quoted 9 lines
Quoted 4 lines

sys_execpid(pid, argv, envp): exec a new syscall with the requested
pid, if the pid is available. Else either return an error, or pick a random pid. Error makes sense to me, but that's probably debatable.

the problem is that in real life environments where executables can be substitutes this is kind of a security issue. Also I really hate the idea of using exec() for changing something.

In OpenVZ we successfully do context changes without exec()'s.

here I agree, changes between *spaces should be independant from exex(), but IMHO there is no need to reuse existing interfaces for that, a syscall will do fine here ...

Quoted 11 lines
Quoted 11 lines

sys_fork_slide(pid): fork and slide into the pidspace belong to pid.

	This way we can do things like

	p = sys_fork_slide(2794);
	if (p == 0) {
		kill(2974);
	} else {
		waitpid(p, 0, 0);
	}

Ok, this last one in particular needs to be improved, but these two syscalls and the clone flags together give us all we need. Right?

Quoted 8 lines

Again, you concentrate on PIDspaces forgeting about all the other namespaces.

I would prefer:

- sys_ns_create()
creates namespace and makes a task to inherit this namespace. If _needed_, it _can_ fork inside.

I don't see why not have both, the auto-created *space on clone() and the ability to create empty *spaces which can be populated and/or entered

Quoted 2 lines

- sys_ns_inherit()
change active namespace.

hmm, sounds like a misnomer to me ...

Quoted 1 line

But how should we reference namespace? by globabl ID?

definitely by some system-unique identifier ...

best,
Herbert

Quoted 1 line

Kirill

#48 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 8 lines
Quoted 4 lines

I would prefer:
- sys_ns_create()
creates namespace and makes a task to inherit this namespace. If _needed_, it _can_ fork inside.

I don't see why not have both, the auto-created
*space on clone() and the ability to create empty
*spaces which can be populated and/or entered

Can you give more details on what you mean by auto-created *space and empty *space? I see no much difference...

Quoted 3 lines
Quoted 2 lines

- sys_ns_inherit()
change active namespace.

hmm, sounds like a misnomer to me ...

sys_ns_change ? :)

Quoted 2 lines
Quoted 1 line

But how should we reference namespace? by globabl ID?

definitely by some system-unique identifier ...

Should it be integer or path as Eric proposes?

Thanks,
Kirill

#49 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 11 lines · Kirill Korotaev
Quoted 8 lines
Quoted 4 lines

I would prefer:
- sys_ns_create()
creates namespace and makes a task to inherit this namespace. If _needed_, it _can_ fork inside.

I don't see why not have both, the auto-created
*space on clone() and the ability to create empty
*spaces which can be populated and/or entered

Can you give more details on what you mean by auto-created *space and empty *space?
I see no much difference...

good, in this case we can drop the empty/standalone *space and 'just' use the clone() one. glad that we finally agree here ....

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

- sys_ns_inherit()
change active namespace.

hmm, sounds like a misnomer to me ...

sys_ns_change ? :)

personally I prefer to see it as either enter or move, but change is probably fine too (except for the fact that it doesn't change the namespace)

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

But how should we reference namespace? by globabl ID?

definitely by some system-unique identifier ...

Should it be integer or path as Eric proposes?

IMHO the pointer would be sufficient, of course this can be mapped to arbitrary names/int/etc ...

Quoted 2 lines

Thanks,
Kirill

#50 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Herbert Poetzl
Quoted 8 lines
Quoted 1 line

And we are too cycled on PIDs. Why? I think this is the most minor feature which can easily live out of mainstream if needed, while virtualization is the main goal.

although I could be totally ignorant regarding the PID stuff, it seems to me that it pretty well reflects the requirements for virtualization in general, while being simple enough to check/test several solutions ...

Quoted 9 lines

why? simple: it reflects the way 'containers' work in general, it has all the issues with administration and setup, similar to 'guests' (it requires some management and access from outside, while providing security and isolation inside), containers could be easily built on top of that or as an addition to the pid space structures at the same time it's easy to test, and issues will show up quite early, so that they can be discussed and, if necessary, solved without rewriting an entire framework.

I would disagree with you. These discussions IMHO led us to the wrong direction.

Can I ask a bunch of questions which are related to other virtualization issues, but which are not addressed by Eric anyhow?

- How are you planning to make hierarchical namespaces for such resources as IPC? Sockets? Unix sockets? Process tree is hierarchical by it's nature. But what is heirarchical IPC and other resources? And no one ever told me why we need heierarchy at all. No any _real_ use cases. But it's ok.

- Eric wants to introduce name spaces, but totally forgots how much they are tied with each other. IPC refers to netlinks, network refers to proc and sysctl, etc. It is some rare cases when you will be able to use namespaces without full OpenVZ/vserver containers. But yes, you are right it will be quite easy for us to use containers on top of namespaces :)

- How long these namespaces live? And which management interface each of them will have?
For example, can you destroy some namespace? Or it is automatically destroyed when the last reference to it is dropped? This is not that simple question as it may seem to be, especially taking into account that some namespaces can live longer (e.g. time wait buckets should live some time after container died; or shm which also can die in a foreign context...).

So I really hate that we concentrated on discussion of VPIDs, while there are more general and global questions on the whole virtualization itself.

Quoted 2 lines

now that you mention it, maybe we should have a few rounds how those 'generic' container syscalls would look like?

First of all, I don't think syscalls like
"do_something and exec" should be introduced.

Next, these syscalls interfaces can be introduced only after we discussed the _general_ concepts, like: how these containers exist, live, are created, waited and so on. But this is impossible to discuss on PID example only. Because:
1. pids are directly related to process lifetime. no much issues here.
2. pids are hierarchical by its nature.
3. there are much more approaches here, then in network for example.

Kirill

#51 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 20 lines · Kirill Korotaev
Quoted 10 lines
Quoted 3 lines

And we are too cycled on PIDs. Why? I think this is the most minor feature which can easily live out of mainstream if needed, while virtualization is the main goal.

although I could be totally ignorant regarding the PID stuff, it seems to me that it pretty well reflects the requirements for virtualization in general, while being simple enough to check/test several solutions ...

Quoted 9 lines

why? simple: it reflects the way 'containers' work in general, it has all the issues with administration and setup, similar to 'guests' (it requires some management and access from outside, while providing security and isolation inside), containers could be easily built on top of that or as an addition to the pid space structures at the same time it's easy to test, and issues will show up quite early, so that they can be discussed and, if necessary, solved without rewriting an entire framework.

Quoted 8 lines

I would disagree with you. These discussions IMHO led us to the wrong direction.

Can I ask a bunch of questions which are related to other virtualization issues, but which are not addressed by Eric anyhow?

- How are you planning to make hierarchical namespaces for such resources as IPC? Sockets? Unix sockets?

in the same way as for resources or filesystems - management is within the parent, usage within the child

Quoted 2 lines

Process tree is hierarchical by it's nature. But what is heirarchical IPC and other resources?

for resources it's simple, you have to 'give away' a certain share to your children, which in turn will enable them to utilize them up to the given amount, or (depending on the implementation) up to the total amount of the parent.

(check out ckrm as a proof of concept, and example how it should not be done :)

Quoted 2 lines

And no one ever told me why we need heierarchy at all. No any _real_ use cases. But it's ok.

there are many use cases here, first, the VPS within a VPS (of course, not the most useful one, but the most obvious one), then there are all kind of test, build and security scenarios which can benefit from hierarchical structures and 'delegated' administrative power (just think web space management)

Quoted 4 lines

- Eric wants to introduce name spaces, but totally forgots how much they are tied with each other. IPC refers to netlinks, network refers to proc and sysctl, etc. It is some rare cases when you will be able to use namespaces without full OpenVZ/vserver containers.

well, we already visited the following:

- filesystem namespaces (works quite fine completely independant of all other)

- pid spaces (again they are quite fine without any other namespace)

- resource spaces (another one which makes perfect sense to have without the others)

the fact that some things like proc or netlink is tied to networking and ipc IMHO is just a sign that those interfaces need revisiting and proper isolation or virtualization ...

Quoted 5 lines

But yes, you are right it will be quite easy for us to use containers on top of namespaces :)

- How long these namespaces live? And which management interface each of them will have?

well, the lifetime of such a space is very likely to be at least the time of the users, including all created sockets, file-handles, ipc resources, etc ...

Quoted 1 line

For example, can you destroy some namespace?

not directly, well, you 'could' make some kind of crawler which goes and kills off all structures keeping a reference to that particular namespace

Quoted 2 lines

Or it is automatically destroyed when the last reference to it is dropped?

yup, that's how it could/should work ...

Quoted 4 lines

This is not that simple question as it may seem to be, especially taking into account that some namespaces can live longer (e.g. time wait buckets should live some time after container died; or shm which also can die in a foreign context...).

yes, those have to be adressed and a very specific semantic has to be found, so that no surprises happen

Quoted 3 lines

So I really hate that we concentrated on discussion of VPIDs, while there are more general and global questions on the whole virtualization itself.

well, I was not the one rolling out the 'perfect' vpid solution ...

Quoted 6 lines
Quoted 3 lines

now that you mention it, maybe we should have a few rounds how those 'generic' container syscalls would look like?

First of all, I don't think syscalls like
"do_something and exec" should be introduced.

Linux-VServer does not have any of those syscalls and it works quite well, so why should we need such syscalls?

note: I do not consider clone() or unshare() to be of this category (just to avoid confusion)

Quoted 8 lines

Next, these syscalls interfaces can be introduced only after we discussed the _general_ concepts, like: how these containers exist, live, are created, waited and so on. But this is impossible to discuss on PID example only. Because:

1. pids are directly related to process lifetime. no much issues here.
2. pids are hierarchical by its nature.
3. there are much more approaches here, then in network for example.

I have no problem at all to discuss a general plan (hey I though we were already doing so :) or move to some other area (like networking :)

best,
Herbert

Quoted 1 line

Kirill

#52 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 6 lines
Quoted 6 lines

I would disagree with you. These discussions IMHO led us to the wrong direction.

Can I ask a bunch of questions which are related to other virtualization issues, but which are not addressed by Eric anyhow?

Quoted 6 lines
Quoted 2 lines

- How are you planning to make hierarchical namespaces for such resources as IPC? Sockets? Unix sockets?

in the same way as for resources or filesystems - management is within the parent, usage within the child

So taking example with IPC, you propose the following:
- parent is able to setup limits on segments, sizes, messages etc.
- parent doesn't see child objects itself, i.e. it is unable to share segments with a child, send messages to child etc. Am I correct?

Provided I got it correctly, how does this differ from the situation, when one container is granted rights to manage another container? So where is hierarchy?

Moreover, granting/revoking rights is more fine grained I suppose. And it is more secure, since uses the model - allow only things which are safe, while heirarchy uses model "allow everything" to do with a child and leads to possible DoS.

Quoted 6 lines
Quoted 1 line

Process tree is hierarchical by it's nature. But what is heirarchical IPC and other resources?

for resources it's simple, you have to 'give away' a certain share to your children, which in turn will enable them to utilize them up to the given amount, or (depending on the implementation) up to the total amount of the parent.

Again, how does this differ from the situation when one container is granted to manage another one? In this case it grant some portion of it's resources to anyone he wishes.

Take a look at this from another angle:
You have a child container, which was granted 1/2 of your resources.
But since parent consumed 3/4 of it, child will never be able to get his 1/2 portion. And child will be unable to find out the reason for resources allocation denies.

Quoted 2 lines

(check out ckrm as a proof of concept, and example how it should not be done :)

let's be more friendly to each other :)

Quoted 9 lines
Quoted 2 lines

And no one ever told me why we need heierarchy at all. No any _real_ use cases. But it's ok.

there are many use cases here, first, the VPS within a VPS (of course, not the most useful one, but the most obvious one), then there are all kind of test, build and security scenarios which can benefit from hierarchical structures and 'delegated' administrative power (just think web space management)

If you are talking about management, then see my prev paragraph. Rights can be granted. Can you provide some other example, what do you want from hierarchy?

Quoted 9 lines
Quoted 4 lines

- Eric wants to introduce name spaces, but totally forgots how much they are tied with each other. IPC refers to netlinks, network refers to proc and sysctl, etc. It is some rare cases when you will be able to use namespaces without full OpenVZ/vserver containers.

well, we already visited the following:

- filesystem namespaces (works quite fine completely independant of all other)

it is tightly interconnected with unix sockets, proc, sysfs, ipc, and I'm sure something else :)
Herber, Eric, I'm not against namespaces. Actualy OpenVZ doesn't care whether we have single container or namespaces, I'm just trying to show you, that all of them are not that separate namespaces as you are trying to think of them.

Quoted 2 lines

- pid spaces (again they are quite fine without any other namespace)

only if we remove all these pid uses from fown, netlinks etc.

Quoted 2 lines

- resource spaces (another one which makes perfect sense to have without the others)

which one? give me an example please.

Quoted 4 lines

the fact that some things like proc or netlink is tied to networking and ipc IMHO is just a sign that those interfaces need revisiting and proper isolation or virtualization ...

it needs virtualization, really. But being virtualized they are still tied to the subsystems they were.

Quoted 5 lines
Quoted 2 lines

- How long these namespaces live? And which management interface each of them will have?

well, the lifetime of such a space is very likely to be at least the time of the users, including all created sockets, file-handles, ipc resources, etc ...

So if you have a socket in TCP_FIN_WAIT1 state, which can live long time, what do you do with it?
Full example: the process dies, but network space is still alive due to such a socket. You won't be able to reuse the address:port until it died. I'm curios about how do you propose to handle similar issues in separate namespaces?

Also as a continuation of this example, if all the processes exited, how can you manage namespaces which leaked? where should you go to see these sockets if /proc is tightly related to pspace on the task, but there are no tasks?

Quoted 7 lines
Quoted 3 lines

So I really hate that we concentrated on discussion of VPIDs, while there are more general and global questions on the whole virtualization itself.

well, I was not the one rolling out the 'perfect' vpid solution ...

ha ha :) won't start flaming with you.

Quoted 5 lines
Quoted 2 lines

First of all, I don't think syscalls like
"do_something and exec" should be introduced.

Linux-VServer does not have any of those syscalls and it works quite well, so why should we need such syscalls?

My question is the same! Why?

Quoted 3 lines

I have no problem at all to discuss a general plan (hey I though we were already doing so :) or move to some other area (like networking :)

Yup. Would be nice to switch to networking, IPC or something like this.

Kirill

#53 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 13 lines · Kirill Korotaev
Quoted 6 lines
Quoted 6 lines

I would disagree with you. These discussions IMHO led us to the wrong direction.

Can I ask a bunch of questions which are related to other virtualization issues, but which are not addressed by Eric anyhow?

Quoted 6 lines
Quoted 2 lines

- How are you planning to make hierarchical namespaces for such resources as IPC? Sockets? Unix sockets?

in the same way as for resources or filesystems - management is within the parent, usage within the child

Quoted 5 lines

So taking example with IPC, you propose the following:
- parent is able to setup limits on segments, sizes, messages etc.
- parent doesn't see child objects itself, i.e. it is unable to share segments with a child, send messages to child etc.
Am I correct?

that is limits, not resources, but for them, you are right ...

Quoted 3 lines

Provided I got it correctly, how does this differ from the situation, when one container is granted rights to manage another container? So where is hierarchy?

this is permissions, yet another *space we have not really covered that well ...

Quoted 4 lines

Moreover, granting/revoking rights is more fine grained I suppose. And it is more secure, since uses the model - allow only things which are safe, while heirarchy uses model "allow everything" to do with a child and leads to possible DoS.

DoS of what? of course a hierarhical model would allow to control 'everything' for/within a child space. this doesn't mean that it would escape the refinements it has received from the parent ...

in this way it is _very_ different from one container being able to administrate a completely different container (as there is no inheritance), which would easily cause the beforementioned DoS situation ...

Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

Process tree is hierarchical by it's nature. But what is heirarchical IPC and other resources?

for resources it's simple, you have to 'give away' a certain share to your children, which in turn will enable them to utilize them up to the given amount, or (depending on the implementation) up to the total amount of the parent.

Quoted 3 lines

Again, how does this differ from the situation when one container is granted to manage another one? In this case it grant some portion of it's resources to anyone he wishes.

well, if one container can give away resources to another one, and can maintain that context, as well as inspect tasks and resources inside that context, then the structure is hierarchical in my book :)

Quoted 5 lines

Take a look at this from another angle:
You have a child container, which was granted 1/2 of your resources. But since parent consumed 3/4 of it, child will never be able to get his 1/2 portion. And child will be unable to find out the reason for resources allocation denies.

well, this is called overbooking, and if you want to allow that, you ahve to accept the consequences (doesn't mean I'm against it :)

Quoted 3 lines
Quoted 2 lines

(check out ckrm as a proof of concept, and example how it should not be done :)

let's be more friendly to each other :)

I'm not being 'unfriendly' here, we all agree that the basic idea of ckrm was really great, but the implementation and complexity makes it somewhat unusable ...

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

And no one ever told me why we need heierarchy at all. No any _real_ use cases. But it's ok.

there are many use cases here, first, the VPS within a VPS (of course, not the most useful one, but the most obvious one), then there are all kind of test, build and security scenarios which can benefit from hierarchical structures and 'delegated' administrative power (just think web space management)

Quoted 3 lines

If you are talking about management, then see my prev paragraph. Rights can be granted. Can you provide some other example, what do you want from hierarchy?

see my reply to your paragraph :)

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

- Eric wants to introduce name spaces, but totally forgots how much they are tied with each other. IPC refers to netlinks, network refers to proc and sysctl, etc. It is some rare cases when you will be able to use namespaces without full OpenVZ/vserver containers.

Quoted 7 lines
Quoted 4 lines

well, we already visited the following:

- filesystem namespaces (works quite fine completely independant of all other)

it is tightly interconnected with unix sockets, proc, sysfs, ipc, and I'm sure something else :)

well, for procfs and sysfs that does not come surprisingly, as they _are_ filesystems after all, named sockets do belong there too, for ipc I do not see the direct conenction as long as the elements are not represented by files ...

Quoted 4 lines

Herber, Eric, I'm not against namespaces. Actualy OpenVZ doesn't care whether we have single container or namespaces, I'm just trying to show you, that all of them are not that separate namespaces as you are trying to think of them.

I guess all of the involved parties _know_ that they are somewhat interconencted, and as I said several times now, I think we should try to split them and separate 'em wherever possible, sometimes even by changing existing semantics and structures

Quoted 3 lines
Quoted 2 lines

- pid spaces (again they are quite fine without any other namespace)

only if we remove all these pid uses from fown, netlinks etc.

again, some cleanup is probably required ...

Quoted 3 lines
Quoted 2 lines

- resource spaces (another one which makes perfect sense to have without the others)

which one? give me an example please.

- cpu resources (scheduler)

Quoted 7 lines
Quoted 4 lines

the fact that some things like proc or netlink is tied to networking and ipc IMHO is just a sign that those interfaces need revisiting and proper isolation or virtualization ...

it needs virtualization, really. But being virtualized they are still tied to the subsystems they were.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

- How long these namespaces live? And which management interface each of them will have?

well, the lifetime of such a space is very likely to be at least the time of the users, including all created sockets, file-handles, ipc resources, etc ...

So if you have a socket in TCP_FIN_WAIT1 state, which can live long time, what do you do with it?

IMHO you have two options there:

- zap the sockets when you destroy the context (a machine which is rebooted will do the same :)

- keep them hanging around for some days, until the timeout is reached and they go away quite naturally

note: this is something which does not even have to be a design decision right now, as the zapping can be done later quite easily ...

Quoted 4 lines

Full example: the process dies, but network space is still alive due to such a socket. You won't be able to reuse the address:port until it died. I'm curios about how do you propose to handle similar issues in separate namespaces?

see above, btw, the network space would only be partially alive, i.e. no new sockets could be created within it, or it might even be persistant and you can 'handle' the sockets after a restart as if they were on a 'normal' machine ...

(btw, this issue is quite common on a real machine, no?)

Quoted 4 lines

Also as a continuation of this example, if all the processes exited, how can you manage namespaces which leaked? where should you go to see these sockets if /proc is tightly related to pspace on the task, but there are no tasks?

that is where an administrative interfaces makes sense you can review and investigate those spaces and take proper actions if you like ...

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

So I really hate that we concentrated on discussion of VPIDs, while there are more general and global questions on the whole virtualization itself.

well, I was not the one rolling out the 'perfect' vpid solution ...

Quoted 8 lines

ha ha :) won't start flaming with you.

Quoted 5 lines
Quoted 2 lines

First of all, I don't think syscalls like
"do_something and exec" should be introduced.

Linux-VServer does not have any of those syscalls and it works quite well, so why should we need such syscalls?

My question is the same! Why?

because we don't need them?!

Quoted 4 lines
Quoted 3 lines

I have no problem at all to discuss a general plan (hey I though we were already doing so :) or move to some other area (like networking :)

Yup. Would be nice to switch to networking, IPC or something like this.

best,
Herbert

Quoted 1 line

Kirill

#54 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

Quoted 11 lines · Herbert Poetzl
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

First of all, I don't think syscalls like
"do_something and exec" should be introduced.

Linux-VServer does not have any of those syscalls and it works quite well, so why should we need such syscalls?

My question is the same! Why?

because we don't need them?!

I think that the reason behind such syscalls is to make sure that the process is "clean" when it enters a new container. "clean" means that the process is not holding in memory an identifier, like a pid for instance, that doesn't make sense in the new container.

This is really a edge case which supposes that processes changing containers don't know what they are doing. This case also depends on how identifiers will be virtualized.

C.

#55 lore raw

Re: [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace

In reply to Kirill Korotaev
Quoted 10 lines · Kirill Korotaev

Hello Eric,

Quoted 5 lines
Quoted 1 line

memory barrier doesn't help. you really need to think about.

Except for instances where you need an atomic read/modify/write the only primitives you have are reads, writes and barriers. I have all of the correct reads and writes therefore the only thing that could help are barriers if the logic is otherwise sane.

the problem is that you do read/write for synchronization of other operations (fork/pspace leader die).
i.e. you try to make a serialization, you see? It doesn't work this way.

I'm missing something, and unfortunately that usually seems to be the case when discussing problems of this kind. When we pick up discussing bugs again, please small simple steps. We have different backgrounds and different base line assumptions, and different points of view, so what is obvious to you is not obvious to me and vice versa.

Quoted 9 lines

....

Quoted 2 lines

This exchange seems to have a hostile and not a cooperative tone so I will finish the investigation and bug fixing elsewhere.

Eric, I think it turned this way because you started pointing to our bugs in VPIDs, while having lots of own and not working code.
I can point you another _really_ disastrous bugs in your IPC and networking virtualization. But discussing bugs is not want I want, you see? I want us to make some solution suatable for all the parties.

But with an incomplete implementation we can discussion each others approaches.

Basically what is of interest right now are the userspace interface, the semantics we are trying to implement, and the maintenance issues for the users of the code.

Quoted 3 lines

And while you have not working solution it is hard to discuss whether it is good or not, whether it is beatutiful or not. It is incomplete and doesn't work. So many statements that one solution is better than another are not valid.

:)

I would draw a distinction between a mostly but buggy implementation and an in incomplete implementation. When you can run the code and see it doing things some of the subtle issues are interesting.

Quoted 7 lines

And we are too cycled on PIDs. Why? I think this is the most minor feature which can easily live out of mainstream if needed, while virtualization is the main goal.

I also don't understand why you are eager to introduce new sys calls like pkill(path_to_process), but is trying to use waitpid() for pspace die notifications?

I am not eager to introduce new syscalls. But I am willing to consider it when we reach far enough past a certain point.

Quoted 4 lines

Maybe it is simply better to introduce container specific
syscalls which should be clean and tidy, instead of messing things up with clone()/waitpid() and so on? The more simple code we have, the better it is for all of us.

Could be propose it and we can discuss it. I suspect you already have something in mid.

Quoted 5 lines

If possible keep posting your patches. I would even ask you to add me to CC always. You are doing a really good job and discussion solutions is the only possible way to push something to mainstream I suppose.
I would also be happy to arrange a meeting with the interested parties, since talking eye to eye can be much more productive.

Thanks. As for a meeting given that there are at least 4 different groups in at least USA and Europe arranging it could be hard. Currently I am aiming at the Ottowa Linux Symposium in June. Hopefully we won't have major unresolved issues by then, but it if we do we really need to get together face to face.

Eric

#56 lore raw

Re: [RFC][PATCH 03/20] pid: Introduce a generic helper to test for init.

In reply to Eric W. Biederman
Quoted 5 lines · Eric W. Biederman

Introduce is_init to capture this case.

With multiple pid spaces for all of the cases affected we are looking for only the first process on the system, not some other process that has pid == 1.

If we have cases where each container has its own init (like vserver, right?), will this naming get confusing? Will we have pseudo-init tasks as well?

-- Dave

#57 lore raw

Re: [RFC][PATCH 03/20] pid: Introduce a generic helper to test for init.

Quoted 10 lines · Dave Hansen
Quoted 5 lines · Eric W. Biederman

Introduce is_init to capture this case.

With multiple pid spaces for all of the cases affected we are looking for only the first process on the system, not some other process that has pid == 1.

If we have cases where each container has its own init (like vserver, right?), will this naming get confusing? Will we have pseudo-init tasks as well?

Agreed. That is a potential issue. I couldn't think of a better name. Suggestions?

Eric

#58 lore raw

Re: [RFC][PATCH 03/20] pid: Introduce a generic helper to test for init.

In reply to Eric W. Biederman

include/linux/sched.h static inline int pid_alive(struct task_ · line 900

Quoted 10 lines · Eric W. Biederman
include/linux/sched.h +4 -0
@@ -894,6 +894,19 @@ static inline int pid_alive(struct task_
 	return p->pids[PIDTYPE_PID].nr != 0;
 }
 
+/**
+ * is_init - check if a task structure is the first user space
+ *	     task the kernel created.
+ * @p: Task structure to be checked.
       ^

include/linux/sched.h static inline int pid_alive(struct task_ · line 902

Quoted 2 lines
include/linux/sched.h +2 -0
+ */
+static inline int is_init(struct task_struct *tsk)
                                                 ^^^

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#59 lore raw

Re: [RFC][PATCH 03/20] pid: Introduce a generic helper to test for init.

Quoted 7 lines · Geert Uytterhoeven
Quoted 6 lines · Eric W. Biederman
include/linux/sched.h +0 -0
@@ -894,6 +894,19 @@ static inline int pid_alive(struct task_
 	return p->pids[PIDTYPE_PID].nr != 0;
 }
 
Quoted 8 lines

include/linux/sched.h static inline int pid_alive(struct task_ · line 900

Quoted 4 lines
include/linux/sched.h +4 -0
+/**
+ * is_init - check if a task structure is the first user space
+ *	     task the kernel created.
+ * @p: Task structure to be checked.
       ^

include/linux/sched.h static inline int pid_alive(struct task_ · line 902

Quoted 2 lines
include/linux/sched.h +2 -0
+ */
+static inline int is_init(struct task_struct *tsk)
                                                 ^^^

Thanks. The perils of cut & past documentation!

Eric

#60 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

In reply to Eric W. Biederman
Quoted 5 lines · Eric W. Biederman

The wait id is the pid returned by wait. For tasks that span 2 namespaces (i.e. the process leaders of the pid namespaces) their parent knows the task by a different PID value than the task knows itself. Having a child with PID == 1 would be confusing.

Is it possible here to have wid conflicts?

Does that matter?

Looking at sysvinit, it seems that it does. If the wid happens to conflict with the pid of one of the children init knows about, it could confuse init.

-serge

#61 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

Quoted 7 lines · Serge E. Hallyn
Quoted 5 lines · Eric W. Biederman

The wait id is the pid returned by wait. For tasks that span 2 namespaces (i.e. the process leaders of the pid namespaces) their parent knows the task by a different PID value than the task knows itself. Having a child with PID == 1 would be confusing.

Quoted 7 lines

Is it possible here to have wid conflicts?

Does that matter?

Looking at sysvinit, it seems that it does. If the wid happens to conflict with the pid of one of the children init knows about, it could confuse init.

No. The wid is in the pspace of the parent, and the pid is in the processes pspace. Add is in any pspace are unique.

Eric

#62 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

In reply to Eric W. Biederman

First of all, for an RFC, this is very thorough.

Second, I've been thinking along these lines for UML. The motivation is to get UML out of the system call tracing business as much as possible, and to do so by having the host set up such that it can run system calls itself and they do the same thing as the UML system call would.

For example, for a UML process chrooted into a UML filesystem, the file operations on normal files will do the same thing as they would in UML, so they could be left to run on the host.

Similarly, something like virtualized processes could be made to do the same thing with the process operations. Trivially, getpid() will return the right value if left to run on the host, so UML wouldn't need to intercept it. If there is a process tree inside a container that mirrors the UML process tree, then lots of other system calls also work, and don't need to be intercepted.

Ideally, I'd like namespaces on the host for all the resources under UML control, and for a container to group those namespaces. However, something which stops short of that is still usable - UML just gets less benefit from it.

As far as processes go, ideally I'd like a containerized process to be an empty shell which can be completely filled from userspace. The motivation for this is that when you have a UP UML with 100 processes, it's wasteful to have 100 virtualized processes on the host. What I would want is one virtualized process which can be completely refilled with new attributes on a context switch.

What I want to do is related to process migration, where you want to move a process but have it not be able to tell. I'm describing migrating a process from the UML to the host such that the host performs as many system calls itself, but those which can't get intercepted and executed within the UML. For migration between physical machines, this would be the same as redirecting a system call from the new host back to its original home. You want to do that as infrequently as possible, so you want the container to provide as much context from the home host as possible.

Jeff

#63 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

Quoted 1 line · Jeff Dike

First of all, for an RFC, this is very thorough.

Thank you.

Quoted 17 lines

Second, I've been thinking along these lines for UML. The motivation is to get UML out of the system call tracing business as much as possible, and to do so by having the host set up such that it can run system calls itself and they do the same thing as the UML system call would.

For example, for a UML process chrooted into a UML filesystem, the file operations on normal files will do the same thing as they would in UML, so they could be left to run on the host.

Similarly, something like virtualized processes could be made to do the same thing with the process operations. Trivially, getpid() will return the right value if left to run on the host, so UML wouldn't need to intercept it. If there is a process tree inside a container that mirrors the UML process tree, then lots of other system calls also work, and don't need to be intercepted.

Quoted 4 lines

Ideally, I'd like namespaces on the host for all the resources under UML control, and for a container to group those namespaces. However, something which stops short of that is still usable - UML just gets less benefit from it.

Having all of the namespaces is certainly on my TODO list.

I'm not at all certain if there is a need for a kernel container concept.

Quoted 7 lines

As far as processes go, ideally I'd like a containerized process to be an empty shell which can be completely filled from userspace. The motivation for this is that when you have a UP UML with 100 processes, it's wasteful to have 100 virtualized processes on the host. What I would want is one virtualized process which can be completely refilled with new attributes on a context switch.

Quoted 9 lines

What I want to do is related to process migration, where you want to move a process but have it not be able to tell. I'm describing migrating a process from the UML to the host such that the host performs as many system calls itself, but those which can't get intercepted and executed within the UML. For migration between physical machines, this would be the same as redirecting a system call from the new host back to its original home. You want to do that as infrequently as possible, so you want the container to provide as much context from the home host as possible.

Currently redirecting a system call from the new host back to it's original home is not something I had planned on. Most of the reasons I want to migrate relate to avoiding the hardware I am migrating from. Either to reduce it's load or to leave before the hardware dies.

That said the idea of a user space monitor that can handle the strange virtualization things that don't fit well into the kernel is appealing.

Note all of the migration I am looking is not process migration but container migration. So I want a container per application.

Eric

#64 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

In reply to Eric W. Biederman

Eric,

1. I would rename wid to wpid :)
2. Maybe I'm missing something in the discussions, but why is it required? if you provide fully isolated pid spaces, why do you care for wid? And how ptrace can work at all if cldstop reports some pid, but child is not accessiable via ptrace()? and if it doesn't work, what are your changes for?

Kirill

Quoted 176 lines

The wait id is the pid returned by wait. For tasks that span 2 namespaces (i.e. the process leaders of the pid namespaces) their parent knows the task by a different PID value than the task knows itself. Having a child with PID == 1 would be confusing.

This patch introduces the wid and walks through kernel and modifies the places that observe the pid from the parent processes perspective to use the wid instead of the pid.

---

 include/linux/sched.h |    1 +
 kernel/exit.c         |   18 +++++++++---------
 kernel/fork.c         |    4 ++--
 kernel/sched.c        |    2 +-
 kernel/signal.c       |    6 +++---
 5 files changed, 16 insertions(+), 15 deletions(-)

598714d79648463ab3f2cbf6f6acd3cd6c09c87a

include/linux/sched.h +1 -0
index f368048..e8ea561 100644
@@ -740,6 +740,7 @@ struct task_struct {
 	/* ??? */
 	unsigned long personality;
 	unsigned did_exec:1;
+	pid_t wid;
 	pid_t pid;
 	pid_t tgid;
 	/* 
kernel/exit.c +9 -9
index fb4c8b1..749bc8b 100644
@@ -941,7 +941,7 @@ asmlinkage void sys_exit_group(int error
 static int eligible_child(pid_t pid, int options, task_t *p)
 {
 	if (pid > 0) {
-		if (p->pid != pid)
+		if (p->wid != pid)
 			return 0;
 	} else if (!pid) {
 		if (process_group(p) != process_group(current))
@@ -1018,7 +1018,7 @@ static int wait_task_zombie(task_t *p, i
 	int status;
 
 	if (unlikely(noreap)) {
-		pid_t pid = p->pid;
+		pid_t pid = p->wid;
 		uid_t uid = p->uid;
 		int exit_code = p->exit_code;
 		int why, status;
@@ -1130,7 +1130,7 @@ static int wait_task_zombie(task_t *p, i
 			retval = put_user(status, &infop->si_status);
 	}
 	if (!retval && infop)
-		retval = put_user(p->pid, &infop->si_pid);
+		retval = put_user(p->wid, &infop->si_pid);
 	if (!retval && infop)
 		retval = put_user(p->uid, &infop->si_uid);
 	if (retval) {
@@ -1138,7 +1138,7 @@ static int wait_task_zombie(task_t *p, i
 		p->exit_state = EXIT_ZOMBIE;
 		return retval;
 	}
-	retval = p->pid;
+	retval = p->wid;
 	if (p->real_parent != p->parent) {
 		write_lock_irq(&tasklist_lock);
 		/* Double-check with lock held.  */
@@ -1198,7 +1198,7 @@ static int wait_task_stopped(task_t *p, 
 	read_unlock(&tasklist_lock);
 
 	if (unlikely(noreap)) {
-		pid_t pid = p->pid;
+		pid_t pid = p->wid;
 		uid_t uid = p->uid;
 		int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
 
@@ -1269,11 +1269,11 @@ bail_ref:
 	if (!retval && infop)
 		retval = put_user(exit_code, &infop->si_status);
 	if (!retval && infop)
-		retval = put_user(p->pid, &infop->si_pid);
+		retval = put_user(p->wid, &infop->si_pid);
 	if (!retval && infop)
 		retval = put_user(p->uid, &infop->si_uid);
 	if (!retval)
-		retval = p->pid;
+		retval = p->wid;
 	put_task_struct(p);
 
 	BUG_ON(!retval);
@@ -1310,7 +1310,7 @@ static int wait_task_continued(task_t *p
 		p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
 	spin_unlock_irq(&p->sighand->siglock);
 
-	pid = p->pid;
+	pid = p->wid;
 	uid = p->uid;
 	get_task_struct(p);
 	read_unlock(&tasklist_lock);
@@ -1321,7 +1321,7 @@ static int wait_task_continued(task_t *p
 		if (!retval && stat_addr)
 			retval = put_user(0xffff, stat_addr);
 		if (!retval)
-			retval = p->pid;
+			retval = pid;
 	} else {
 		retval = wait_noreap_copyout(p, pid, uid,
 					     CLD_CONTINUED, SIGCONT,
kernel/fork.c +2 -2
index f4a7281..743d46c 100644
@@ -931,10 +931,10 @@ static task_t *copy_process(unsigned lon
 
 	p->did_exec = 0;
 	copy_flags(clone_flags, p);
-	p->pid = pid;
+	p->wid = p->pid = pid;
 	retval = -EFAULT;
 	if (clone_flags & CLONE_PARENT_SETTID)
-		if (put_user(p->pid, parent_tidptr))
+		if (put_user(p->wid, parent_tidptr))
 			goto bad_fork_cleanup;
 
 	p->proc_dentry = NULL;
kernel/sched.c +1 -1
index f77f23f..6579d49 100644
@@ -1674,7 +1674,7 @@ asmlinkage void schedule_tail(task_t *pr
 	preempt_enable();
 #endif
 	if (current->set_child_tid)
-		put_user(current->pid, current->set_child_tid);
+		put_user(current->wid, current->set_child_tid);
 }
 
 /*
kernel/signal.c +3 -3
index 1f54ed7..70c226c 100644
@@ -1564,7 +1564,7 @@ void do_notify_parent(struct task_struct
 
 	info.si_signo = sig;
 	info.si_errno = 0;
-	info.si_pid = tsk->pid;
+	info.si_pid = tsk->wid;
 	info.si_uid = tsk->uid;
 
 	/* FIXME: find out whether or not this is supposed to be c*time. */
@@ -1629,7 +1629,7 @@ static void do_notify_parent_cldstop(str
 
 	info.si_signo = SIGCHLD;
 	info.si_errno = 0;
-	info.si_pid = tsk->pid;
+	info.si_pid = tsk->wid;
 	info.si_uid = tsk->uid;
 
 	/* FIXME: find out whether or not this is supposed to be c*time. */
@@ -1732,7 +1732,7 @@ void ptrace_notify(int exit_code)
 	memset(&info, 0, sizeof info);
 	info.si_signo = SIGTRAP;
 	info.si_code = exit_code;
-	info.si_pid = current->pid;
+	info.si_pid = current->wid;
 	info.si_uid = current->uid;
 
 	/* Let the debugger run.  */
#65 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

Quoted 3 lines · Kirill Korotaev

Eric,

1. I would rename wid to wpid :)

:)

Quoted 4 lines

2. Maybe I'm missing something in the discussions, but why is it required? if you provide fully isolated pid spaces, why do you care for wid? And how ptrace can work at all if cldstop reports some pid, but child is not accessiable via ptrace()? and if it doesn't work, what are your changes for?

A good question.

My pid spaces while isolated from each other are connected together in something that resembles the mount relationship when mounting a filesystem.

The init process of a child pspace is visible in the parent pspace, by it's wid. So you should be able to ptrace pid == 1. The other children remain inaccessible directly.

The idea was to do my very best to preserve the unix process tree when constructing a separate pid space.

I have to admit I have not yet tested the ptrace corner case, or digested all of it's ramifications. Unless I have messed up somewhere it should just work.

This visibility of the child tree by a single pid inside the parent tree is why I think my approach doesn't suffer from most of the problems a completely isolated pid space has.

In fact I would even be willing to look at it as a global but hierarchical pid space if that proved an interesting case.
So you could have something like pkill(int sig, int which, char *pid_path). Where pid_path is something like "1537/3/58", and which specified what kind of pid you are talking about (thread, pid, process group...)

Quoted 1 line

From a security stand point I want the option of a fully isolated

group of processes, so there is a possibility of keeping secrets from the system administrator, but there is no reason that needs to be tied to a pid space.

Eric

#66 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

Quoted 10 lines
Quoted 4 lines

2. Maybe I'm missing something in the discussions, but why is it required? if you provide fully isolated pid spaces, why do you care for wid? And how ptrace can work at all if cldstop reports some pid, but child is not accessiable via ptrace()? and if it doesn't work, what are your changes for?

A good question.

My pid spaces while isolated from each other are connected together in something that resembles the mount relationship when mounting a filesystem.

why? is it really required?
doing it this way, you get all the issues with external refs we have with a weak isolation, i.e. pspace init can be seen from outside and inside (correct? or am I wrong?). This makes your approach eseentially the same as ours from checkpointing point of view BTW.

Quoted 6 lines

The init process of a child pspace is visible in the parent pspace, by it's wid. So you should be able to ptrace pid == 1. The other children remain inaccessible directly.

The idea was to do my very best to preserve the unix process tree when constructing a separate pid space

This more looks like you were trying to make less changes with it and avoid fixing issus which can arise when pspaces are fully isolated. Maybe I'm wrong.

Quoted 7 lines

I have to admit I have not yet tested the ptrace corner case, or digested all of it's ramifications. Unless I have messed up somewhere it should just work.

This visibility of the child tree by a single pid inside the parent tree is why I think my approach doesn't suffer from most of the problems a completely isolated pid space has.

which problems? Actually I can't see much problems with isolated pid spaces. And isolated pid spaces doesn't require hierarchy, since they are fully isolated.

Quoted 5 lines

In fact I would even be willing to look at it as a global but hierarchical pid space if that proved an interesting case.
So you could have something like pkill(int sig, int which, char *pid_path). Where pid_path is something like "1537/3/58", and which specified what kind of pid you are talking about (thread, pid, process group...)

And here you need to introduce new non-unix semantics, security checks on lookups, etc.

Quoted 4 lines
Quoted 1 line

From a security stand point I want the option of a fully isolated

group of processes, so there is a possibility of keeping secrets from the system administrator, but there is no reason that needs to be tied to a pid space.

Kirill

#67 lore raw

Re: [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id)

Quoted 8 lines · Kirill Korotaev
Quoted 7 lines
Quoted 4 lines

2. Maybe I'm missing something in the discussions, but why is it required? if you provide fully isolated pid spaces, why do you care for wid? And how ptrace can work at all if cldstop reports some pid, but child is not accessiable via ptrace()? and if it doesn't work, what are your changes for?

A good question.
My pid spaces while isolated from each other are connected together in something that resembles the mount relationship when mounting a filesystem.

why? is it really required?

A very good question. Supporting waitpid and the normal process management semantics seems to be a requirement for usability. Completely separate pid spaces would probably be easier to implement. However then we would need to implement another interface like waitpid to allow for notifications when the all of the processes exited.

I have not seen any alternatives being proposed to handle that case.

Quoted 3 lines

doing it this way, you get all the issues with external refs we have with a weak isolation, i.e. pspace init can be seen from outside and inside (correct? or am I wrong?).

Largely correct. Looking at it from the outside is like looking at a thread group leader. Sometimes you see the leader sometimes you see the entire group of processes.

Quoted 2 lines

This makes your approach eseentially the same as ours from checkpointing point of view BTW.

Sure. Any attempt to build a general purpose mechanism will suffer from that. But it is easy enough to drop the external references from the init processes, and then it's children don't have a chance to get them.

Quoted 7 lines
Quoted 5 lines

The init process of a child pspace is visible in the parent pspace, by it's wid. So you should be able to ptrace pid == 1. The other children remain inaccessible directly.
The idea was to do my very best to preserve the unix process tree when constructing a separate pid space

This more looks like you were trying to make less changes with it and avoid fixing issus which can arise when pspaces are fully isolated. Maybe I'm wrong.

It's not sloth. Simply trying to extend the existing API. Not changing what doesn't need to be changed is a virtue.

But yes fully isolated pid spaces are unmanageable unless you add and API to deal with it. My api is using the wid to allow a parent process to manage it essentially like normal.

Quoted 8 lines
Quoted 6 lines

I have to admit I have not yet tested the ptrace corner case, or digested all of it's ramifications. Unless I have messed up somewhere it should just work.
This visibility of the child tree by a single pid inside the parent tree is why I think my approach doesn't suffer from most of the problems a completely isolated pid space has.

which problems? Actually I can't see much problems with isolated pid spaces. And isolated pid spaces doesn't require hierarchy, since they are fully isolated.

You also don't find them interesting enough to implement. Or else we are using the same terms to mean different things.

Quoted 7 lines
Quoted 5 lines

In fact I would even be willing to look at it as a global but hierarchical pid space if that proved an interesting case.
So you could have something like pkill(int sig, int which, char *pid_path). Where pid_path is something like "1537/3/58", and which specified what kind of pid you are talking about (thread, pid, process group...)

And here you need to introduce new non-unix semantics, security checks on lookups, etc.

Sure you need to introduce new semantics, etc. But nothing more than what you already have in OpenVZ. The only necessary difference
is in how you name the process. The target process is still being
manipulated by a process outside of it's scope of existence.

So if the need for doing that is as great as you say it is something that is doable, and their may be other methods that are easier to work with.

Personally I only implemented as much manipulation of the init processes as I did because it came for free. I don't see the need to manipulate a process in another pid namespace.

Eric

#68 lore raw
In reply to Eric W. Biederman
Quoted 6 lines · Eric W. Biederman

There have been several discussions in the past month about how to do a good job of implementing a subset of user space that looks like it has the system to itself. Essentially making chroot everything it could be. This is my take on what the implementation of a pid namespace should look like.

Eric, this looks very good. The pspace internal implementation is very similar to what I was working on objectifying the pidmap etc. I was pursuing the same route in using find_pid() functions as the means to distinguish pspaces rather then actually virtualizing them.

But this code already goes so much further in many many aspects. Kudos to you.
I am still going through some of the details, but this is an excellent starting position.

Quoted 10 lines

What follows is a real patch set that is sufficiently complete to be used and useful in it's own right. There are a few areas of the kernel where the patchset does not reach, mostly these cause the compile to fail. In addition a good thorough review still needs to be done. This patchset does paint a picture of how I think things should look.

From the kernel community at large I am asking:
Does the code look generally sane?

Yes, but I have one question for you...
Large parts of the patch are adding the pspace argument to find_task_by_pid() and in many cases that argument is current->pspace.
It might bring down the size of the patch if you have

find_task_by_pid( pid ) { return find_task_pidspace_by_pid ( current->pspace, pid ); }

and then only deal with the exceptional cases using find_task_pidspace_by_pid when the pidspace is different..

Quoted 4 lines

Does the use of clone to create a new namespace instance look like the sane approach?

At he surface it looks OK .. how does this work in a multi-threaded process which does cloen ( CLONE_NPSPACE ) ?
We discussed at some point that exec is the right place to do it, but what I get is that because this is the container_init task we are OK !
A bit clarification would help here ...

Quoted 3 lines

Hopefully this code is sufficiently comprehensible to allow a good discussion to come out of this.

Yes

Quoted 3 lines

Thanks for your time,

Eric

-- Hubertus

#69 lore raw
Quoted 10 lines · Hubertus Franke
Quoted 2 lines

From the kernel community at large I am asking:
Does the code look generally sane?

Yes, but I have one question for you...
Large parts of the patch are adding the pspace argument to find_task_by_pid() and in many cases that argument is current->pspace.
It might bring down the size of the patch if you have

Quoted 5 lines

find_task_by_pid( pid ) { return find_task_pidspace_by_pid ( current->pspace, pid ); }

and then only deal with the exceptional cases using find_task_pidspace_by_pid when the pidspace is different..

That is a possibility. However I want to break some eggs so that the users are updated appropriately. It is only by a strenuous act of will that I don't change the type of pid,tgid,pgrp,session.

The size of the changes is much less important than being clear. So for I want find_task_by_pid to be an absolute interface.

Quoted 10 lines
Quoted 3 lines

Does the use of clone to create a new namespace instance look like the sane approach?

At he surface it looks OK .. how does this work in a multi-threaded process which does cloen ( CLONE_NPSPACE ) ?
We discussed at some point that exec is the right place to do it, but what I get is that because this is the container_init task we are OK !
A bit clarification would help here ...

Well the parent doesn't much matter. But the child must have a fresh start on all the groups of processes. As all other groupings known by a pid are per pspace, so they can't cross that line.

Eric

#70 lore raw
Quoted 10 lines · Eric W. Biederman
Quoted 5 lines · Hubertus Franke

find_task_by_pid( pid ) { return find_task_pidspace_by_pid ( current->pspace, pid ); }

and then only deal with the exceptional cases using find_task_pidspace_by_pid when the pidspace is different..

Quoted 7 lines

That is a possibility. However I want to break some eggs so that the users are updated appropriately. It is only by a strenuous act of will that I don't change the type of pid,tgid,pgrp,session.

The size of the changes is much less important than being clear. So for I want find_task_by_pid to be an absolute interface.

Fair enough, valid answers .. I checked the patch and it would only take 19/33 instances out .. so not the end of the world.

Quoted 14 lines
Quoted 6 lines
Quoted 5 lines

Does the use of clone to create a new namespace instance look like the sane approach?

Quoted 6 lines

At he surface it looks OK .. how does this work in a multi-threaded process which does cloen ( CLONE_NPSPACE ) ?
We discussed at some point that exec is the right place to do it, but what I get is that because this is the container_init task we are OK !
A bit clarification would help here ...

Quoted 4 lines

Well the parent doesn't much matter. But the child must have a fresh start on all the groups of processes. As all other groupings known by a pid are per pspace, so they can't cross that line.

Now, on which kernel does this compile/work ?
Do you have a "helper" program you can share that starts/exec's an app under a new container (uhmm, namespace). No point for us to actually write that..

-- Hubertus

#71 lore raw
Quoted 30 lines · Hubertus Franke
Quoted 6 lines · Eric W. Biederman
Quoted 3 lines · Hubertus Franke

find_task_by_pid( pid ) { return find_task_pidspace_by_pid ( current->pspace, pid ); }

Quoted 8 lines
Quoted 2 lines

and then only deal with the exceptional cases using find_task_pidspace_by_pid when the pidspace is different..

That is a possibility. However I want to break some eggs so that the users are updated appropriately. It is only by a strenuous act of will that I don't change the type of pid,tgid,pgrp,session. The size of the changes is much less important than being clear. So for I want find_task_by_pid to be an absolute interface.

Fair enough, valid answers .. I checked the patch and it would only take 19/33 instances out .. so not the end of the world.

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

Does the use of clone to create a new namespace instance look like the sane approach?

At he surface it looks OK .. how does this work in a multi-threaded process which does cloen ( CLONE_NPSPACE ) ?
We discussed at some point that exec is the right place to do it, but what I get is that because this is the container_init task we are OK !
A bit clarification would help here ...

Quoted 6 lines
Quoted 4 lines

Well the parent doesn't much matter. But the child must have a fresh start on all the groups of processes. As all other groupings known by a pid are per pspace, so they can't cross that line.

Now, on which kernel does this compile/work ?

2.6.latest plus a few patches I have already sent off to Andrew.

Quoted 3 lines

Do you have a "helper" program you can share that starts/exec's an app under a new container (uhmm, namespace). No point for us to actually write that..

Ok here is my little helper/tester program. Not beautiful but it should work.

Eric

/* gcc -Wall -O2 -g chpid.c -o chpid */
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
#define _SVID_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/mount.h>
#include <sys/vfs.h>
#include <fcntl.h>
#include <unistd.h>
#include <sched.h>
#include <stdarg.h>
#include <dirent.h>

#ifndef MNT_FORCE
#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
#endif /* MNT_FORCE */
#ifndef MNT_DETACH
#define MNT_DETACH 0x00000002 /* Just detach from the tree */
#endif /* MNT_DETACH */
#ifndef MNT_EXPIRE
#define MNT_EXPIRE 0x00000004 /* Mark for expiry */
#endif /* MNT_EXPIRE */

#ifndef MS_MOVE
#define MS_MOVE 8192
#endif
#ifndef MS_REC
#define MS_REC 16384
#endif

#ifndef CLONE_NPSPACE
#define CLONE_NPSPACE 0x04000000 /* New process space */
#endif

#ifndef PROC_SUPER_MAGIC
#define PROC_SUPER_MAGIC 0x9fa0
#endif /* PROC_SUPER_MAGIC */

struct user_desc;
static pid_t raw_clone(int flags, void *child_stack,
int *parent_tidptr, struct user_desc *newtls, int *child_tidptr)

{
	return syscall(__NR_clone, flags, child_stack, parent_tidptr, newtls, child_tidptr);
}

static int raw_pivot_root(const char *new_root, const char *old_root)

{
	return syscall(__NR_pivot_root, new_root, old_root);
}

static void (*my_exit)(int status) = exit;

static void die(char *fmt, ...)

{
	va_list ap;
	va_start(ap, fmt);
	vfprintf(stderr, fmt, ap);
	va_end(ap);
	fflush(stderr);
	fflush(stdout);
	my_exit(1);
}

static void *xmalloc(size_t size)

{
	void *ptr;
	ptr = malloc(size);
	if (!ptr) die("malloc of %d bytes failed: %s\n", size, strerror(errno));
	return ptr;
}

int main(int argc, char **argv, char **envp)

{
	pid_t pid;
	int status;
	struct rlimit rlim;
	int clone_flags;
	char **cmd_argv, *shell_argv[2];
	char *root = "/", *old = "/mnt";
	int i;
	int tty, tty_force;
	
	tty = 0;
	tty_force = 0;
	clone_flags = CLONE_NPSPACE | SIGCHLD;

	for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
		if (strcmp(argv[i], "--") == 0) {
			break;
		}
		else if (((argc - i) >= 2) && (strcmp(argv[i], "-r") == 0)) {
			clone_flags |= CLONE_NEWNS;
			root = argv[i + 1];
			i++;
		}
		else if (((argc - i) >= 2) && (strcmp(argv[i], "-o") == 0)) {
			old = argv[i + 1];
			i++;
		}
		else if (strcmp(argv[i], "-n") == 0) {
			clone_flags |= CLONE_NEWNS;
		}
		else if (strcmp(argv[i], "--tty") == 0) {
			tty = 1;
		}
		else if (strcmp(argv[i], "--tty-force") == 0) {
			tty = 1; tty_force = 1;
		}
		else {
			die("Bad argument %s\n", argv[i]);
		}
	}
	cmd_argv = argv + i;
	if (cmd_argv[0] == NULL) {
		cmd_argv = shell_argv;
		shell_argv[0] = getenv("SHELL");
		shell_argv[1] = NULL;
	}
	if (cmd_argv[0] == NULL) {
		die("No command specified\n");
	}
#if 1
	fprintf(stderr, "cmd_argv: %s\n", cmd_argv[0]);
#endif
	if (root[0] != '/') {
		die("root path: '%s' not absolute\n", root);
	}
	if (old[0] != '/') {
		die("old path: '%s' not absolute\n", old);
	}
	
	pid = raw_clone(clone_flags, NULL, NULL, NULL, NULL);
	if (pid < 0) {
		fprintf(stderr, "clone_failed: pid: %d %d:%s\n", 
			pid, errno, strerror(errno));
		exit(2);
	}
	if (pid == 0) {
		/* In the child */
		int result;
		my_exit = _exit;

		/* FIXME allocate a process inside for controlling the new process space */

		fprintf(stderr, "pid: %d, ppid: %d pgrp: %d sid: %d\n",
			getpid(), getppid(), getpgid(0), getsid(0));
		/* If CLONE_NPSPACE isn't implemented exit */
		if (getpid() != 1) 
			die("CLONE_NPSPACE not implemented\n");
		if (clone_flags & CLONE_NEWNS) {
			struct statfs stfs;
			if (strcmp(root, "/") != 0) {
				char put_old[PATH_MAX];
				result = snprintf(put_old, sizeof(put_old), "%s%s", root, old);
				if (result >= sizeof(put_old))
					die("path name to long\n");
				if (result < 0)
					die("snprintf failed: %d:%s\n",
						errno, strerror(errno));
				
				/* Ensure I have a mount point at the directory I want to export */
				result = mount(root, root, NULL, MS_BIND | MS_REC, NULL);
				if (result < 0)
					die("bind of '%s' failed: %d:%s\n",
						root, errno, strerror(errno));
				
				/* Switch the mount points */
				result = raw_pivot_root(root, put_old);
				if (result < 0)
					die("pivot_root('%s', '%s') failed: %d:%s\n",
						root, put_old, errno, strerror(errno));
				
				/* Unmount all of the old mounts */
				result = umount2(old, MNT_DETACH);
				if (result < 0)
					die("umount2 of '%s' failed: %d:%s\n",
						put_old, errno, strerror(errno));
			}

			result = statfs("/proc", &stfs);
			if ((result == 0) && (stfs.f_type == PROC_SUPER_MAGIC))  {
				/* Unmount and remount proc so it reflects the new pid space */
				result = umount2("/proc", 0);
				if (result < 0) 
					die("umount failed: %d:%s\n", errno, strerror(errno));
				
				result = mount("proc", "/proc", "proc", 0, NULL);
				if (result < 0)
					die("mount failed: %d:%s\n",
						errno, strerror(errno));
			}
		}
		if (tty) {
			pid_t sid, pgrp;
			sid = setsid();
			if (sid < 0)
				die("setsid failed: %d:%s\n",
					errno, strerror(errno));
			fprintf(stderr, "pid: %d, ppid: %d pgrp: %d sid: %d\n",
				getpid(), getppid(), getpgid(0), getsid(0));

			result = ioctl(STDIN_FILENO, TIOCSCTTY, tty_force);
			if (result < 0)
				die("tiocsctty failed: %d:%s\n",
					errno, strerror(errno));

			pgrp = tcgetpgrp(STDIN_FILENO);
			
			fprintf(stderr, "pgrp: %d\n", pgrp);

			fprintf(stderr, "pid: %d, ppid: %d pgrp: %d sid: %d\n",
				getpid(), getppid(), getpgid(0), getsid(0));

		}
		result = execve(cmd_argv[0], cmd_argv, envp);
		die("execve of %s failed: %d:%s\n",
			cmd_argv[0], errno, strerror(errno));
	}
	/* In the parent */
	fprintf(stderr, "child pid: %d\n", pid);
	pid = waitpid(pid, &status, 0);
	fprintf(stderr, "pid: %d exited status: %d\n", 
		pid, status);
	if (pid < 0) {
		fprintf(stderr, "waitpid failed: %d %s\n",
			errno, strerror(errno));
		exit(9);
	}
	if (pid == 0) {
		fprintf(stderr, "waitpid returned no pid!\n");
		exit(10);
	}
	if (WIFEXITED(status)) {
		fprintf(stderr, "pid: %d exited: %d\n",
			pid, WEXITSTATUS(status));
	}
	if (WIFSIGNALED(status)) {
		fprintf(stderr, "pid: %d exited with a uncaught signal: %d %s\n",
			pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
	}
	if (WIFSTOPPED(status)) {
		fprintf(stderr, "pid: %d stopped with signal: %d\n", 
			pid, WSTOPSIG(status));
	}
	return 0;
}
#72 lore raw
In reply to Eric W. Biederman
Quoted 6 lines · Eric W. Biederman

p.s. My apologies at the size of the CC list. It is very hard to tell who the interested parties are, and since there is no one list we all subscribe to other than linux-kernel how to reach everyone in a timely manner. I am copying everyone who has chimed in on a previous thread on the subject. If you don't want to be copied in the future tell and I will take your name off of my list.

Is it worth creating a vger or OSDL mailing list for these discussions? There was some concern the cc list is getting too large. :)

If yes, would "linux-containers" be an appropriate name?

-- Dave

#73 lore raw
Quoted 8 lines · Dave Hansen
Quoted 6 lines · Eric W. Biederman

p.s. My apologies at the size of the CC list. It is very hard to tell who the interested parties are, and since there is no one list we all subscribe to other than linux-kernel how to reach everyone in a timely manner. I am copying everyone who has chimed in on a previous thread on the subject. If you don't want to be copied in the future tell and I will take your name off of my list.

Quoted 4 lines

Is it worth creating a vger or OSDL mailing list for these discussions? There was some concern the cc list is getting too large. :)

If yes, would "linux-containers" be an appropriate name?

I have think we can wait until the current discussion is over, as I have not received any complaints yet.

For ongoing maintenance of the future in kernel implementation I think it is worth setting something up.

Eric

#74 lore raw
In reply to Dave Hansen
Quoted 10 lines · Dave Hansen
Quoted 6 lines · Eric W. Biederman

p.s. My apologies at the size of the CC list. It is very hard to tell who the interested parties are, and since there is no one list we all subscribe to other than linux-kernel how to reach everyone in a timely manner. I am copying everyone who has chimed in on a previous thread on the subject. If you don't want to be copied in the future tell and I will take your name off of my list.

Is it worth creating a vger or OSDL mailing list for these discussions? There was some concern the cc list is getting too large. :)

No, linux-kernel is fine. It will keep everybody informed, instead of small groups doing their own things. But just keep the cc lists short please. I'm sure all interested people can get it from l-k.

-Andi

#75 lore raw
Quoted 9 lines · On Tue, 7 Feb 2006 10:33:21 +0100 Andi Kleen wrote:
Quoted 8 lines · Dave Hansen
Quoted 6 lines · Eric W. Biederman

p.s. My apologies at the size of the CC list. It is very hard to tell who the interested parties are, and since there is no one list we all subscribe to other than linux-kernel how to reach everyone in a timely manner. I am copying everyone who has chimed in on a previous thread on the subject. If you don't want to be copied in the future tell and I will take your name off of my list.

Quoted 6 lines
Quoted 2 lines

Is it worth creating a vger or OSDL mailing list for these discussions? There was some concern the cc list is getting too large. :)

No, linux-kernel is fine. It will keep everybody informed, instead of small groups doing their own things. But just keep the cc lists short please. I'm sure all interested people can get it from l-k.

OK. (Yes, I have a dream.)

I'd like to see less traffic on lkml, with various things moved off to other mailing lists.

According to http://marc.theaimsgroup.com/?l=linux-kernel,
Jan. 2006 was a near record month and Feb. is on track to be large also.

---
~Randy

#76 lore raw
Quoted 7 lines · Randy.Dunlap

OK. (Yes, I have a dream.)

I'd like to see less traffic on lkml, with various things moved off to other mailing lists.

According to http://marc.theaimsgroup.com/?l=linux-kernel,
Jan. 2006 was a near record month and Feb. is on track to be large also.

A dream I can understand.

However discussion about core kernel infrastructure is very much on topic. Or nothing is on topic on the mailing list.

Once this matures to the point where we are discussing the maintenance of a subsystem we can consider moving off lkml.

Eric

#77 lore raw
Quoted 10 lines · On Tue, 07 Feb 2006 21:28:04 -0700 Eric W. Biederman wrote:
Quoted 7 lines · Randy.Dunlap

OK. (Yes, I have a dream.)

I'd like to see less traffic on lkml, with various things moved off to other mailing lists.

According to http://marc.theaimsgroup.com/?l=linux-kernel,
Jan. 2006 was a near record month and Feb. is on track to be large also.

Quoted 7 lines

A dream I can understand.

However discussion about core kernel infrastructure is very much on topic. Or nothing is on topic on the mailing list.

Once this matures to the point where we are discussing the maintenance of a subsystem we can consider moving off lkml.

Yes, I wasn't referring to this particular topic for offloading.

thanks,
---
~Randy