[PATCH 09/19] ptrace: make TRAPPING wait interruptible

From: Tejun Heo
Date: Tue May 24 2011 - 14:40:43 EST


With JOBCTL_TRAPPING waits moved to wait_task_stopped() and
ptrace_check_attach(), and both using full syscall retries after wait,
TRAPPING wait can switch to interruptible sleeps.

As all transitions are interlocked and all cancellation events
(supposedly) clear TRAPPING, this doesn't change the actual behavior
but it makes the TRAPPING wait mechanism much more forgiving when
something goes wrong and allows using TRAPPING waits across freezing
points.

Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
---
kernel/ptrace.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 14aedcf..71e1034 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -28,7 +28,7 @@
static int ptrace_trapping_sleep_fn(void *flags)
{
schedule();
- return 0;
+ return signal_pending(current);
}

/**
@@ -45,7 +45,11 @@ static int ptrace_trapping_sleep_fn(void *flags)
* to make sure no transition is in progress before proceeding.
*
* This function checks whether @child is TRAPPING and, if so, waits for
- * the transition to complete.
+ * the transition to complete. Interruptible sleep is used for waiting and
+ * %true will be returned regardless of why it is woken up. On %true
+ * return, callers should ensure that the whole operation is restarted
+ * using the syscall restart mechanism so that operations like freezing or
+ * killing don't get blocked by TRAPPING waits.
*
* CONTEXT:
* read_lock(&tasklist_lock) and spin_lock_irq(&child->sighand->siglock).
@@ -67,7 +71,7 @@ bool ptrace_wait_trapping(struct task_struct *child)
get_task_struct(child);
read_unlock(&tasklist_lock);
wait_on_bit(&child->jobctl, ilog2(JOBCTL_TRAPPING),
- ptrace_trapping_sleep_fn, TASK_UNINTERRUPTIBLE);
+ ptrace_trapping_sleep_fn, TASK_INTERRUPTIBLE);
put_task_struct(child);
return true;
}
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/