Re: [PATCH 2/3] pidns: Guarantee that the pidns init will be thelast pidns process reaped.

From: Oleg Nesterov
Date: Wed May 16 2012 - 15:36:11 EST


On 05/16, Oleg Nesterov wrote:
>
> Hmm. I don't think the patch is 100% correct. Afaics, this needs more
> delay_pidns_leader() checks.

Anyway, if we rely on ->children, can't we make a simpler fix?

Something like below. It can be simplified even more, just to explain
the idea. Perhaps we don't even need the new PF_ flag and we can
re-use ->wait_chldexit.

Oleg.

--- x/kernel/pid_namespace.c
+++ x/kernel/pid_namespace.c
@@ -184,6 +184,22 @@ void zap_pid_ns_processes(struct pid_nam
rc = sys_wait4(-1, NULL, __WALL, NULL);
} while (rc != -ECHILD);

+ current->flags |= PF_DEAD_INIT;
+ for (;;) {
+ bool need_wait;
+
+ __set_current_state(TASK_UNINTERRUPTIBLE);
+ read_lock(&tasklist_lock);
+ need_wait = !list_empty(current->children);
+ read_unlock(&tasklist_lock);
+
+ if (!need_wait)
+ break;
+ schedule();
+ }
+ __set_current_state(TASK_RUNNING);
+ current->flags &= ~PF_DEAD_INIT;
+
if (pid_ns->reboot)
current->signal->group_exit_code = pid_ns->reboot;

--- x/kernel/exit.c
+++ x/kernel/exit.c
@@ -71,6 +71,11 @@ static void __unhash_process(struct task

list_del_rcu(&p->tasks);
list_del_init(&p->sibling);
+
+ if (unlikely(p->real_parent->flags & PF_DEAD_INIT)
+ if (list_empty(&p->real_parent->children))
+ wake_up_process(p->real_parent);
+
__this_cpu_dec(process_counts);
}
list_del_rcu(&p->thread_group);

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