Skip to contentSkip to conversation

exitc-call-proc_exit_connector-after-exit_state-is-set.patch removed from -mm tree

merged [email protected] 1 participant 1 message Apr 8, 2014

lore
Share & tools
lore
#0 lore raw

Subject: [merged] exitc-call-proc_exit_connector-after-exit_state-is-set.patch removed from -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Tue, 08 Apr 2014 14:15:44 -0700

The patch titled
Subject: kernel/exit.c: call proc_exit_connector() after exit_state is set
has been removed from the -mm tree. Its filename was
exitc-call-proc_exit_connector-after-exit_state-is-set.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Guillaume Morin <[email protected]>
Subject: kernel/exit.c: call proc_exit_connector() after exit_state is set

The process events connector delivers a notification when a process exits.
This is really convenient for a process that spawns and wants to monitor
its children through an epoll-able() interface.

Unfortunately, there is a small window between when the event is delivered and the child become wait()-able.

This is creates a race if the parent wants to make sure that it knows about the exit, e.g

pid_t pid = fork();

if (pid > 0) {
	register_interest_for_pid(pid);
	if (waitpid(pid, NULL, WNOHANG) > 0)
	{
	  /* We might have raced with exit() */
	}
	return;
}

/* Child */
execve(...)

register_interest_for_pid() would be telling the the connector socket reader to pay attention to events related to pid.

Though this is not a bug, I think it would make the connector a bit more usable if this race was closed by simply moving the call to proc_exit_connector() from just before exit_notify() to right after.

Oleg said:

: Even with this patch the code above is still "racy" if the child is : multi-threaded. Plus it should obviously filter-out subthreads. And : afaics there is no way to make it reliable, even if you change the code : above so that waitpid() is called only after the last thread exits WNOHANG : still can fail.

Cc Matt Helsley <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc David S. Miller <[email protected]>

---

 kernel/exit.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/exit.c renamed from kernel/exit.c~exitc-call-proc_exit_connector-after-exit_state-is-set +1 -1
diff -puN kernel/exit.c~exitc-call-proc_exit_connector-after-exit_state-is-set kernel/exit.c
@@ -802,13 +802,13 @@ void do_exit(long code)
 
 	module_put(task_thread_info(tsk)->exec_domain->module);
 
-	proc_exit_connector(tsk);
 	/*
 	 * FIXME: do that only when needed, using sched_exit tracepoint
 	 */
 	flush_ptrace_hw_breakpoint(tsk);
 
 	exit_notify(tsk, group_dead);
+	proc_exit_connector(tsk);
 #ifdef CONFIG_NUMA
 	task_lock(tsk);
 	mpol_put(tsk->mempolicy);

_

Patches currently in -mm which might be from [email protected] are

origin.patch