OpenVZ Forum


Home » Mailing lists » Devel » [PATCH 6/6] Define is_global_init() and is_container_init()
[PATCH 6/6] Define is_global_init() and is_container_init() [message #19180] Fri, 06 July 2007 05:56 Go to next message
Sukadev Bhattiprolu is currently offline  Sukadev Bhattiprolu
Messages: 413
Registered: August 2006
Senior Member
Subject: [PATCH 6/6] Define is_global_init() and is_container_init().

From: Serge E. Hallyn <serue@us.ibm.com>


is_init() is an ambiguous name for the pid==1 check.  Split it into
is_global_init() and is_container_init().

A container init has it's tsk->pid == 1.

A global init also has it's tsk->pid == 1 and it's active pid namespace
is the init_pid_ns.  But rather than check the active pid namespace,
compare the task structure with 'init_pid_ns.child_reaper', which is
initialized during boot to the /sbin/init process and never changes.

Changelog:

	2.6.22-rc4-mm2-pidns1:
	- Use 'init_pid_ns.child_reaper' to determine if a given task is the
	  global init (/sbin/init) process. This would improve performance
	  and remove dependence on the task_pid().

	2.6.21-mm2-pidns2:

	- [Sukadev Bhattiprolu] Changed is_container_init() calls in {powerpc,
	  ppc,avr32}/traps.c for the _exception() call to is_global_init().
	  This way, we kill only the container if the container's init has a
	  bug rather than force a kernel panic.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com>
---
 arch/alpha/mm/fault.c                |    2 +-
 arch/arm/mm/fault.c                  |    2 +-
 arch/arm26/mm/fault.c                |    2 +-
 arch/avr32/kernel/traps.c            |    2 +-
 arch/avr32/mm/fault.c                |    6 +++---
 arch/i386/lib/usercopy.c             |    2 +-
 arch/i386/mm/fault.c                 |    2 +-
 arch/ia64/mm/fault.c                 |    2 +-
 arch/m68k/mm/fault.c                 |    2 +-
 arch/mips/mm/fault.c                 |    2 +-
 arch/powerpc/kernel/traps.c          |    2 +-
 arch/powerpc/mm/fault.c              |    2 +-
 arch/powerpc/platforms/pseries/ras.c |    2 +-
 arch/ppc/kernel/traps.c              |    2 +-
 arch/ppc/mm/fault.c                  |    2 +-
 arch/s390/lib/uaccess_pt.c           |    2 +-
 arch/s390/mm/fault.c                 |    2 +-
 arch/sh/mm/fault.c                   |    2 +-
 arch/sh64/mm/fault.c                 |    6 +++---
 arch/um/kernel/trap.c                |    2 +-
 arch/x86_64/mm/fault.c               |    2 +-
 arch/xtensa/mm/fault.c               |    2 +-
 drivers/char/sysrq.c                 |    2 +-
 include/linux/sched.h                |   12 ++++++++++--
 kernel/capability.c                  |    3 ++-
 kernel/exit.c                        |    2 +-
 kernel/kexec.c                       |    2 +-
 kernel/pid.c                         |    5 +++++
 kernel/signal.c                      |    2 +-
 kernel/sysctl.c                      |    2 +-
 mm/oom_kill.c                        |    4 ++--
 security/commoncap.c                 |    3 ++-
 32 files changed, 52 insertions(+), 37 deletions(-)

Index: lx26-22-rc6-mm1/include/linux/sched.h
===================================================================
--- lx26-22-rc6-mm1.orig/include/linux/sched.h	2007-07-05 18:57:34.000000000 -0700
+++ lx26-22-rc6-mm1/include/linux/sched.h	2007-07-05 18:59:06.000000000 -0700
@@ -1248,12 +1248,20 @@ static inline int pid_alive(struct task_
 }
 
 /**
- * is_init - check if a task structure is init
+ * is_global_init - check if a task structure is init
  * @tsk: Task structure to be checked.
  *
  * Check if a task structure is the first user space task the kernel created.
+ *
+ * TODO: We should inline this function after some cleanups in pid_namespace.h
+ */
+extern int is_global_init(struct task_struct *tsk);
+
+/*
+ * is_container_init:
+ * check whether in the task is init in it's own pid namespace.
  */
-static inline int is_init(struct task_struct *tsk)
+static inline int is_container_init(struct task_struct *tsk)
 {
 	return tsk->pid == 1;
 }
Index: lx26-22-rc6-mm1/kernel/pid.c
===================================================================
--- lx26-22-rc6-mm1.orig/kernel/pid.c	2007-07-05 18:53:48.000000000 -0700
+++ lx26-22-rc6-mm1/kernel/pid.c	2007-07-05 18:59:06.000000000 -0700
@@ -71,6 +71,11 @@ struct pid_namespace init_pid_ns = {
 	.child_reaper = &init_task
 };
 
+int is_global_init(struct task_struct *tsk)
+{
+	return tsk == init_pid_ns.child_reaper;
+}
+
 /*
  * Note: disable interrupts while the pidmap_lock is held as an
  * interrupt might come in and do read_lock(&tasklist_lock).
Index: lx26-22-rc6-mm1/arch/alpha/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/alpha/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/alpha/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -192,7 +192,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 (is_init(current)) {
+	if (is_global_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
Index: lx26-22-rc6-mm1/arch/arm/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/arm/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/arm/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -197,7 +197,7 @@ survive:
 		return fault;
 	}
 
-	if (!is_init(tsk))
+	if (!is_global_init(tsk))
 		goto out;
 
 	/*
Index: lx26-22-rc6-mm1/arch/arm26/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/arm26/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/arm26/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -185,7 +185,7 @@ survive:
 	}
 
 	fault = -3; /* out of memory */
-	if (!is_init(tsk))
+	if (!is_global_init(tsk))
 		goto out;
 
 	/*
Index: lx26-22-rc6-mm1/arch/i386/lib/usercopy.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/i386/lib/usercopy.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/i386/lib/usercopy.c	2007-07-05 18:59:06.000000000 -0700
@@ -748,7 +748,7 @@ survive:
 			retval = get_user_pages(current, current->mm,
 					(unsigned long )to, 1, 1, 0, &pg, NULL);
 
-			if (retval == -ENOMEM && is_init(current)) {
+			if (retval == -ENOMEM && is_global_init(current)) {
 				up_read(&current->mm->mmap_sem);
 				congestion_wait(WRITE, HZ/50);
 				goto survive;
Index: lx26-22-rc6-mm1/arch/i386/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/i386/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/i386/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -595,7 +595,7 @@ no_context:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (is_init(tsk)) {
+	if (is_global_init(tsk)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
Index: lx26-22-rc6-mm1/arch/ia64/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/ia64/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/ia64/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -270,7 +270,7 @@ ia64_do_page_fault (unsigned long addres
 
   out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (is_init(current)) {
+	if (is_global_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
Index: lx26-22-rc6-mm1/arch/m68k/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/m68k/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/m68k/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -181,7 +181,7 @@ good_area:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (is_init(current)) {
+	if (is_global_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
Index: lx26-22-rc6-mm1/arch/mips/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/mips/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/mips/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -174,7 +174,7 @@ no_context:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (is_init(tsk)) {
+	if (is_global_init(tsk)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
Index: lx26-22-rc6-mm1/arch/powerpc/kernel/traps.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/powerpc/kernel/traps.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/powerpc/kernel/traps.c	2007-07-05 18:59:06.000000000 -0700
@@ -191,7 +191,7 @@ void _exception(int signr, struct pt_reg
 	 * generate the same exception over and over again and we get
 	 * nowhere.  Better to kill it and let the kernel panic.
 	 */
-	if (is_init(current)) {
+	if (is_global_init(current)) {
 		__sighandler_t handler;
 
 		spin_lock_irq(&current->sighand->siglock);
Index: lx26-22-rc6-mm1/arch/powerpc/mm/fault.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/powerpc/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/powerpc/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
@@ -374,7 +374,7 @@ bad_area_nosemaphore:
  */
 out_of_memory:
 	up_read(&mm->mmap_sem);
-	if (is_init(current)) {
+	if (is_global_init(current)) {
 		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
Index: lx26-22-rc6-mm1/arch/powerpc/platforms/pseries/ras.c
===================================================================
--- lx26-22-rc6-mm1.orig/arch/powerpc/platforms/pseries/ras.c	2007-07-05 18:53:42.000000000 -0700
+++ lx26-22-rc6-mm1/arch/powerpc/platforms/pseries/ras.c	2007-07-05 18:59:06.000000000 -0700
@@ -332,7 +332,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-
...

Re: [PATCH 6/6] Define is_global_init() and is_container_init() [message #19332 is a reply to message #19180] Fri, 13 July 2007 05:24 Go to previous message
Pavel Emelianov is currently offline  Pavel Emelianov
Messages: 1149
Registered: September 2006
Senior Member
sukadev@us.ibm.com wrote:
> Subject: [PATCH 6/6] Define is_global_init() and is_container_init().
> 
> From: Serge E. Hallyn <serue@us.ibm.com>
> 
> 
> is_init() is an ambiguous name for the pid==1 check.  Split it into
> is_global_init() and is_container_init().
> 
> A container init has it's tsk->pid == 1.
> 
> A global init also has it's tsk->pid == 1 and it's active pid namespace
> is the init_pid_ns.  But rather than check the active pid namespace,
> compare the task structure with 'init_pid_ns.child_reaper', which is
> initialized during boot to the /sbin/init process and never changes.
> 
> Changelog:
> 
> 	2.6.22-rc4-mm2-pidns1:
> 	- Use 'init_pid_ns.child_reaper' to determine if a given task is the
> 	  global init (/sbin/init) process. This would improve performance
> 	  and remove dependence on the task_pid().
> 
> 	2.6.21-mm2-pidns2:
> 
> 	- [Sukadev Bhattiprolu] Changed is_container_init() calls in {powerpc,
> 	  ppc,avr32}/traps.c for the _exception() call to is_global_init().
> 	  This way, we kill only the container if the container's init has a
> 	  bug rather than force a kernel panic.
> 
> Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
> Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com>

Acked-by: Pavel Emelianov <xemul@openvz.org>

> ---
>  arch/alpha/mm/fault.c                |    2 +-
>  arch/arm/mm/fault.c                  |    2 +-
>  arch/arm26/mm/fault.c                |    2 +-
>  arch/avr32/kernel/traps.c            |    2 +-
>  arch/avr32/mm/fault.c                |    6 +++---
>  arch/i386/lib/usercopy.c             |    2 +-
>  arch/i386/mm/fault.c                 |    2 +-
>  arch/ia64/mm/fault.c                 |    2 +-
>  arch/m68k/mm/fault.c                 |    2 +-
>  arch/mips/mm/fault.c                 |    2 +-
>  arch/powerpc/kernel/traps.c          |    2 +-
>  arch/powerpc/mm/fault.c              |    2 +-
>  arch/powerpc/platforms/pseries/ras.c |    2 +-
>  arch/ppc/kernel/traps.c              |    2 +-
>  arch/ppc/mm/fault.c                  |    2 +-
>  arch/s390/lib/uaccess_pt.c           |    2 +-
>  arch/s390/mm/fault.c                 |    2 +-
>  arch/sh/mm/fault.c                   |    2 +-
>  arch/sh64/mm/fault.c                 |    6 +++---
>  arch/um/kernel/trap.c                |    2 +-
>  arch/x86_64/mm/fault.c               |    2 +-
>  arch/xtensa/mm/fault.c               |    2 +-
>  drivers/char/sysrq.c                 |    2 +-
>  include/linux/sched.h                |   12 ++++++++++--
>  kernel/capability.c                  |    3 ++-
>  kernel/exit.c                        |    2 +-
>  kernel/kexec.c                       |    2 +-
>  kernel/pid.c                         |    5 +++++
>  kernel/signal.c                      |    2 +-
>  kernel/sysctl.c                      |    2 +-
>  mm/oom_kill.c                        |    4 ++--
>  security/commoncap.c                 |    3 ++-
>  32 files changed, 52 insertions(+), 37 deletions(-)
> 
> Index: lx26-22-rc6-mm1/include/linux/sched.h
> ===================================================================
> --- lx26-22-rc6-mm1.orig/include/linux/sched.h	2007-07-05 18:57:34.000000000 -0700
> +++ lx26-22-rc6-mm1/include/linux/sched.h	2007-07-05 18:59:06.000000000 -0700
> @@ -1248,12 +1248,20 @@ static inline int pid_alive(struct task_
>  }
>  
>  /**
> - * is_init - check if a task structure is init
> + * is_global_init - check if a task structure is init
>   * @tsk: Task structure to be checked.
>   *
>   * Check if a task structure is the first user space task the kernel created.
> + *
> + * TODO: We should inline this function after some cleanups in pid_namespace.h
> + */
> +extern int is_global_init(struct task_struct *tsk);
> +
> +/*
> + * is_container_init:
> + * check whether in the task is init in it's own pid namespace.
>   */
> -static inline int is_init(struct task_struct *tsk)
> +static inline int is_container_init(struct task_struct *tsk)
>  {
>  	return tsk->pid == 1;
>  }
> Index: lx26-22-rc6-mm1/kernel/pid.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/kernel/pid.c	2007-07-05 18:53:48.000000000 -0700
> +++ lx26-22-rc6-mm1/kernel/pid.c	2007-07-05 18:59:06.000000000 -0700
> @@ -71,6 +71,11 @@ struct pid_namespace init_pid_ns = {
>  	.child_reaper = &init_task
>  };
>  
> +int is_global_init(struct task_struct *tsk)
> +{
> +	return tsk == init_pid_ns.child_reaper;
> +}
> +
>  /*
>   * Note: disable interrupts while the pidmap_lock is held as an
>   * interrupt might come in and do read_lock(&tasklist_lock).
> Index: lx26-22-rc6-mm1/arch/alpha/mm/fault.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/alpha/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/alpha/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
> @@ -192,7 +192,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 (is_init(current)) {
> +	if (is_global_init(current)) {
>  		yield();
>  		down_read(&mm->mmap_sem);
>  		goto survive;
> Index: lx26-22-rc6-mm1/arch/arm/mm/fault.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/arm/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/arm/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
> @@ -197,7 +197,7 @@ survive:
>  		return fault;
>  	}
>  
> -	if (!is_init(tsk))
> +	if (!is_global_init(tsk))
>  		goto out;
>  
>  	/*
> Index: lx26-22-rc6-mm1/arch/arm26/mm/fault.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/arm26/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/arm26/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
> @@ -185,7 +185,7 @@ survive:
>  	}
>  
>  	fault = -3; /* out of memory */
> -	if (!is_init(tsk))
> +	if (!is_global_init(tsk))
>  		goto out;
>  
>  	/*
> Index: lx26-22-rc6-mm1/arch/i386/lib/usercopy.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/i386/lib/usercopy.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/i386/lib/usercopy.c	2007-07-05 18:59:06.000000000 -0700
> @@ -748,7 +748,7 @@ survive:
>  			retval = get_user_pages(current, current->mm,
>  					(unsigned long )to, 1, 1, 0, &pg, NULL);
>  
> -			if (retval == -ENOMEM && is_init(current)) {
> +			if (retval == -ENOMEM && is_global_init(current)) {
>  				up_read(&current->mm->mmap_sem);
>  				congestion_wait(WRITE, HZ/50);
>  				goto survive;
> Index: lx26-22-rc6-mm1/arch/i386/mm/fault.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/i386/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/i386/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
> @@ -595,7 +595,7 @@ no_context:
>   */
>  out_of_memory:
>  	up_read(&mm->mmap_sem);
> -	if (is_init(tsk)) {
> +	if (is_global_init(tsk)) {
>  		yield();
>  		down_read(&mm->mmap_sem);
>  		goto survive;
> Index: lx26-22-rc6-mm1/arch/ia64/mm/fault.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/ia64/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/ia64/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
> @@ -270,7 +270,7 @@ ia64_do_page_fault (unsigned long addres
>  
>    out_of_memory:
>  	up_read(&mm->mmap_sem);
> -	if (is_init(current)) {
> +	if (is_global_init(current)) {
>  		yield();
>  		down_read(&mm->mmap_sem);
>  		goto survive;
> Index: lx26-22-rc6-mm1/arch/m68k/mm/fault.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/m68k/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/m68k/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
> @@ -181,7 +181,7 @@ good_area:
>   */
>  out_of_memory:
>  	up_read(&mm->mmap_sem);
> -	if (is_init(current)) {
> +	if (is_global_init(current)) {
>  		yield();
>  		down_read(&mm->mmap_sem);
>  		goto survive;
> Index: lx26-22-rc6-mm1/arch/mips/mm/fault.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/mips/mm/fault.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/mips/mm/fault.c	2007-07-05 18:59:06.000000000 -0700
> @@ -174,7 +174,7 @@ no_context:
>   */
>  out_of_memory:
>  	up_read(&mm->mmap_sem);
> -	if (is_init(tsk)) {
> +	if (is_global_init(tsk)) {
>  		yield();
>  		down_read(&mm->mmap_sem);
>  		goto survive;
> Index: lx26-22-rc6-mm1/arch/powerpc/kernel/traps.c
> ===================================================================
> --- lx26-22-rc6-mm1.orig/arch/powerpc/kernel/traps.c	2007-07-05 18:53:42.000000000 -0700
> +++ lx26-22-rc6-mm1/arch/powerpc/kernel/traps.c	2007-07-05 18:59:06.000000000 -0700
> @@ -191,7 +191,7 @@ void _exception(int signr, struct pt_reg
>  	 * generate the same exception over and over again and we get
>  	 * nowhere.  Better to kill it and let the kernel panic.
>  	 */
> -	if (is_init(current))
...

Previous Topic: [PATCH 5/6] Use task_pid() to find leader's pid
Next Topic: [PATCH 1/6] Define and use task_active_pid_ns() wrapper
Goto Forum:
  


Current Time: Wed Jul 17 12:26:05 GMT 2024

Total time taken to generate the page: 0.02994 seconds