aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2011-05-12 04:47:23 -0400
committerOleg Nesterov <oleg@redhat.com>2011-05-13 12:56:02 -0400
commit19e274630c9e23a84d5940af83cf5db35103f968 (patch)
tree334344b87c92cf9d9ec6ea04151e1bf65742c58f /kernel
parent40ae717d1e78d982bd469b2013a4cbf4ec1ca434 (diff)
job control: reorganize wait_task_stopped()
wait_task_stopped() tested task_stopped_code() without acquiring siglock and, if stop condition existed, called wait_task_stopped() and directly returned the result. This patch moves the initial task_stopped_code() testing into wait_task_stopped() and make wait_consider_task() fall through to wait_task_continue() on 0 return. This is for the following two reasons. * Because the initial task_stopped_code() test is done without acquiring siglock, it may race against SIGCONT generation. The stopped condition might have been replaced by continued state by the time wait_task_stopped() acquired siglock. This may lead to unexpected failure of WNOHANG waits. This reorganization addresses this single race case but there are other cases - TASK_RUNNING -> TASK_STOPPED transition and EXIT_* transitions. * Scheduled ptrace updates require changes to the initial test which would fit better inside wait_task_stopped(). Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/exit.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 5cbc83e83a5d..33837936b98c 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1377,11 +1377,23 @@ static int *task_stopped_code(struct task_struct *p, bool ptrace)
1377 return NULL; 1377 return NULL;
1378} 1378}
1379 1379
1380/* 1380/**
1381 * Handle sys_wait4 work for one task in state TASK_STOPPED. We hold 1381 * wait_task_stopped - Wait for %TASK_STOPPED or %TASK_TRACED
1382 * read_lock(&tasklist_lock) on entry. If we return zero, we still hold 1382 * @wo: wait options
1383 * the lock and this task is uninteresting. If we return nonzero, we have 1383 * @ptrace: is the wait for ptrace
1384 * released the lock and the system call should return. 1384 * @p: task to wait for
1385 *
1386 * Handle sys_wait4() work for %p in state %TASK_STOPPED or %TASK_TRACED.
1387 *
1388 * CONTEXT:
1389 * read_lock(&tasklist_lock), which is released if return value is
1390 * non-zero. Also, grabs and releases @p->sighand->siglock.
1391 *
1392 * RETURNS:
1393 * 0 if wait condition didn't exist and search for other wait conditions
1394 * should continue. Non-zero return, -errno on failure and @p's pid on
1395 * success, implies that tasklist_lock is released and wait condition
1396 * search should terminate.
1385 */ 1397 */
1386static int wait_task_stopped(struct wait_opts *wo, 1398static int wait_task_stopped(struct wait_opts *wo,
1387 int ptrace, struct task_struct *p) 1399 int ptrace, struct task_struct *p)
@@ -1397,6 +1409,9 @@ static int wait_task_stopped(struct wait_opts *wo,
1397 if (!ptrace && !(wo->wo_flags & WUNTRACED)) 1409 if (!ptrace && !(wo->wo_flags & WUNTRACED))
1398 return 0; 1410 return 0;
1399 1411
1412 if (!task_stopped_code(p, ptrace))
1413 return 0;
1414
1400 exit_code = 0; 1415 exit_code = 0;
1401 spin_lock_irq(&p->sighand->siglock); 1416 spin_lock_irq(&p->sighand->siglock);
1402 1417
@@ -1607,8 +1622,9 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
1607 * Wait for stopped. Depending on @ptrace, different stopped state 1622 * Wait for stopped. Depending on @ptrace, different stopped state
1608 * is used and the two don't interact with each other. 1623 * is used and the two don't interact with each other.
1609 */ 1624 */
1610 if (task_stopped_code(p, ptrace)) 1625 ret = wait_task_stopped(wo, ptrace, p);
1611 return wait_task_stopped(wo, ptrace, p); 1626 if (ret)
1627 return ret;
1612 1628
1613 /* 1629 /*
1614 * Wait for continued. There's only one continued state and the 1630 * Wait for continued. There's only one continued state and the