Skip to content

Commit af9fe6d

Browse files
committed
pid: Improve the comment about waiting in zap_pid_ns_processes
Oleg wrote a very informative comment, but with the removal of proc_cleanup_work it is no longer accurate. Rewrite the comment so that it only talks about the details that are still relevant, and hopefully is a little clearer. Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 69879c0 commit af9fe6d

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

kernel/pid_namespace.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,27 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
224224
} while (rc != -ECHILD);
225225

226226
/*
227-
* kernel_wait4() above can't reap the EXIT_DEAD children but we do not
228-
* really care, we could reparent them to the global init. We could
229-
* exit and reap ->child_reaper even if it is not the last thread in
230-
* this pid_ns, free_pid(pid_allocated == 0) calls proc_cleanup_work(),
231-
* pid_ns can not go away until proc_kill_sb() drops the reference.
227+
* kernel_wait4() misses EXIT_DEAD children, and EXIT_ZOMBIE
228+
* process whose parents processes are outside of the pid
229+
* namespace. Such processes are created with setns()+fork().
232230
*
233-
* But this ns can also have other tasks injected by setns()+fork().
234-
* Again, ignoring the user visible semantics we do not really need
235-
* to wait until they are all reaped, but they can be reparented to
236-
* us and thus we need to ensure that pid->child_reaper stays valid
237-
* until they all go away. See free_pid()->wake_up_process().
231+
* If those EXIT_ZOMBIE processes are not reaped by their
232+
* parents before their parents exit, they will be reparented
233+
* to pid_ns->child_reaper. Thus pidns->child_reaper needs to
234+
* stay valid until they all go away.
238235
*
239-
* We rely on ignored SIGCHLD, an injected zombie must be autoreaped
240-
* if reparented.
236+
* The code relies on the the pid_ns->child_reaper ignoring
237+
* SIGCHILD to cause those EXIT_ZOMBIE processes to be
238+
* autoreaped if reparented.
239+
*
240+
* Semantically it is also desirable to wait for EXIT_ZOMBIE
241+
* processes before allowing the child_reaper to be reaped, as
242+
* that gives the invariant that when the init process of a
243+
* pid namespace is reaped all of the processes in the pid
244+
* namespace are gone.
245+
*
246+
* Once all of the other tasks are gone from the pid_namespace
247+
* free_pid() will awaken this task.
241248
*/
242249
for (;;) {
243250
set_current_state(TASK_INTERRUPTIBLE);

0 commit comments

Comments
 (0)