diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2012-08-01 18:03:42 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2012-11-19 08:59:12 -0500 |
commit | af4b8a83add95ef40716401395b44a1b579965f4 (patch) | |
tree | 2f3f606b7327f74c1c1beb8a75886318c51c838a /kernel | |
parent | 5e1182deb81ae8c68494017c4a8a71811659c870 (diff) |
pidns: Wait in zap_pid_ns_processes until pid_ns->nr_hashed == 1
Looking at pid_ns->nr_hashed is a bit simpler and it works for
disjoint process trees that an unshare or a join of a pid_namespace
may create.
Acked-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/exit.c | 12 | ||||
-rw-r--r-- | kernel/pid.c | 16 | ||||
-rw-r--r-- | kernel/pid_namespace.c | 15 |
3 files changed, 17 insertions, 26 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index 346616c0092c..d7fe58db4527 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -72,18 +72,6 @@ static void __unhash_process(struct task_struct *p, bool group_dead) | |||
72 | list_del_rcu(&p->tasks); | 72 | list_del_rcu(&p->tasks); |
73 | list_del_init(&p->sibling); | 73 | list_del_init(&p->sibling); |
74 | __this_cpu_dec(process_counts); | 74 | __this_cpu_dec(process_counts); |
75 | /* | ||
76 | * If we are the last child process in a pid namespace to be | ||
77 | * reaped, notify the reaper sleeping zap_pid_ns_processes(). | ||
78 | */ | ||
79 | if (IS_ENABLED(CONFIG_PID_NS)) { | ||
80 | struct task_struct *parent = p->real_parent; | ||
81 | |||
82 | if ((task_active_pid_ns(parent)->child_reaper == parent) && | ||
83 | list_empty(&parent->children) && | ||
84 | (parent->flags & PF_EXITING)) | ||
85 | wake_up_process(parent); | ||
86 | } | ||
87 | } | 75 | } |
88 | list_del_rcu(&p->thread_group); | 76 | list_del_rcu(&p->thread_group); |
89 | } | 77 | } |
diff --git a/kernel/pid.c b/kernel/pid.c index 9c219117af36..6e8da291de49 100644 --- a/kernel/pid.c +++ b/kernel/pid.c | |||
@@ -273,10 +273,20 @@ void free_pid(struct pid *pid) | |||
273 | spin_lock_irqsave(&pidmap_lock, flags); | 273 | spin_lock_irqsave(&pidmap_lock, flags); |
274 | for (i = 0; i <= pid->level; i++) { | 274 | for (i = 0; i <= pid->level; i++) { |
275 | struct upid *upid = pid->numbers + i; | 275 | struct upid *upid = pid->numbers + i; |
276 | struct pid_namespace *ns = upid->ns; | ||
276 | hlist_del_rcu(&upid->pid_chain); | 277 | hlist_del_rcu(&upid->pid_chain); |
277 | if (--upid->ns->nr_hashed == 0) { | 278 | switch(--ns->nr_hashed) { |
278 | upid->ns->nr_hashed = -1; | 279 | case 1: |
279 | schedule_work(&upid->ns->proc_work); | 280 | /* When all that is left in the pid namespace |
281 | * is the reaper wake up the reaper. The reaper | ||
282 | * may be sleeping in zap_pid_ns_processes(). | ||
283 | */ | ||
284 | wake_up_process(ns->child_reaper); | ||
285 | break; | ||
286 | case 0: | ||
287 | ns->nr_hashed = -1; | ||
288 | schedule_work(&ns->proc_work); | ||
289 | break; | ||
280 | } | 290 | } |
281 | } | 291 | } |
282 | spin_unlock_irqrestore(&pidmap_lock, flags); | 292 | spin_unlock_irqrestore(&pidmap_lock, flags); |
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 84591cfeefc1..3cc29b830e9e 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
@@ -217,22 +217,15 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) | |||
217 | 217 | ||
218 | /* | 218 | /* |
219 | * sys_wait4() above can't reap the TASK_DEAD children. | 219 | * sys_wait4() above can't reap the TASK_DEAD children. |
220 | * Make sure they all go away, see __unhash_process(). | 220 | * Make sure they all go away, see free_pid(). |
221 | */ | 221 | */ |
222 | for (;;) { | 222 | for (;;) { |
223 | bool need_wait = false; | 223 | set_current_state(TASK_UNINTERRUPTIBLE); |
224 | 224 | if (pid_ns->nr_hashed == 1) | |
225 | read_lock(&tasklist_lock); | ||
226 | if (!list_empty(¤t->children)) { | ||
227 | __set_current_state(TASK_UNINTERRUPTIBLE); | ||
228 | need_wait = true; | ||
229 | } | ||
230 | read_unlock(&tasklist_lock); | ||
231 | |||
232 | if (!need_wait) | ||
233 | break; | 225 | break; |
234 | schedule(); | 226 | schedule(); |
235 | } | 227 | } |
228 | __set_current_state(TASK_RUNNING); | ||
236 | 229 | ||
237 | if (pid_ns->reboot) | 230 | if (pid_ns->reboot) |
238 | current->signal->group_exit_code = pid_ns->reboot; | 231 | current->signal->group_exit_code = pid_ns->reboot; |