From 0f7e663dea7f0e22f3b2d07156c5e9d2e8656610 Mon Sep 17 00:00:00 2001 From: Bodo Stroesser Date: Fri, 6 May 2005 21:30:54 -0700 Subject: [PATCH] uml: Fix process exit race tt-mode closes switch_pipes in exit_thread_tt and kills processes in switch_to_tt, if the exit_state is EXIT_DEAD or EXIT_ZOMBIE. In very rare cases the exiting process can be scheduled out after having set exit_state and closed switch_pipes (from release_task it calls proc_pid_flush, which might sleep). If this process is to be restarted, UML failes in switch_to_tt with: write of switch_pipe failed, err = 9 We fix this by closing switch_pipes not in exit_thread_tt, but later in release_thread_tt. Additionally, we set switch_pipe[0] = 0 after closing. switch_to_tt must not kill "from" process depending on its exit_state, but must kill it after release_thread was processed only, so it examines switch_pipe[0] for its decision. Signed-off-by: Bodo Stroesser Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/kernel/tt/process_kern.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'arch/um/kernel/tt/process_kern.c') diff --git a/arch/um/kernel/tt/process_kern.c b/arch/um/kernel/tt/process_kern.c index f19f7c18febe..df810ca8fc12 100644 --- a/arch/um/kernel/tt/process_kern.c +++ b/arch/um/kernel/tt/process_kern.c @@ -65,8 +65,7 @@ void *switch_to_tt(void *prev, void *next, void *last) panic("write of switch_pipe failed, err = %d", -err); reading = 1; - if((from->exit_state == EXIT_ZOMBIE) || - (from->exit_state == EXIT_DEAD)) + if(from->thread.mode.tt.switch_pipe[0] == -1) os_kill_process(os_getpid(), 0); err = os_read_file(from->thread.mode.tt.switch_pipe[0], &c, sizeof(c)); @@ -81,8 +80,7 @@ void *switch_to_tt(void *prev, void *next, void *last) * in case it has not already killed itself. */ prev_sched = current->thread.prev_sched; - if((prev_sched->exit_state == EXIT_ZOMBIE) || - (prev_sched->exit_state == EXIT_DEAD)) + if(prev_sched->thread.mode.tt.switch_pipe[0] == -1) os_kill_process(prev_sched->thread.mode.tt.extern_pid, 1); change_sig(SIGVTALRM, vtalrm); @@ -101,14 +99,18 @@ void release_thread_tt(struct task_struct *task) { int pid = task->thread.mode.tt.extern_pid; + /* + * We first have to kill the other process, before + * closing its switch_pipe. Else it might wake up + * and receive "EOF" before we could kill it. + */ if(os_getpid() != pid) os_kill_process(pid, 0); -} -void exit_thread_tt(void) -{ - os_close_file(current->thread.mode.tt.switch_pipe[0]); - os_close_file(current->thread.mode.tt.switch_pipe[1]); + os_close_file(task->thread.mode.tt.switch_pipe[0]); + os_close_file(task->thread.mode.tt.switch_pipe[1]); + /* use switch_pipe as flag: thread is released */ + task->thread.mode.tt.switch_pipe[0] = -1; } void suspend_new_thread(int fd) -- cgit v1.2.3-59-g8ed1b