Re: [PATCH] fix send_sigqueue() vs thread exit race

From: Thomas Gleixner
Date: Sun Aug 21 2005 - 16:50:12 EST


On Sun, 2005-08-21 at 23:24 +0200, Thomas Gleixner wrote:
> Oleg,

Sorry for making noise. I introduced the race again.

tglx


--- linux-2.6.13-rc6.signal/kernel/signal.oleg.c 2005-08-21 23:07:03.000000000 +0200
+++ linux-2.6.13-rc6.signal/kernel/signal.c 2005-08-21 23:48:52.000000000 +0200
@@ -1381,8 +1381,15 @@ send_sigqueue(int sig, struct sigqueue *
int ret = 0;

BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
- read_lock(&tasklist_lock);

+retry:
+ if (unlikely(p->flags & PF_EXITING))
+ return -1;
+
+ if (unlikely(!read_trylock(&tasklist_lock))) {
+ cpu_relax();
+ goto retry;
+ }
if (unlikely(p->flags & PF_EXITING)) {
ret = -1;
goto out_err;
@@ -1427,7 +1434,18 @@ send_group_sigqueue(int sig, struct sigq
int ret = 0;

BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
- read_lock(&tasklist_lock);
+retry:
+ if (unlikely(p->flags & PF_EXITING))
+ return -1;
+
+ if (unlikely(!read_trylock(&tasklist_lock))) {
+ cpu_relax();
+ goto retry;
+ }
+ if (unlikely(p->flags & PF_EXITING)) {
+ ret = -1;
+ goto out_err;
+ }
spin_lock_irqsave(&p->sighand->siglock, flags);
handle_stop_signal(sig, p);

@@ -1461,8 +1479,9 @@ send_group_sigqueue(int sig, struct sigq
__group_complete_signal(sig, p);
out:
spin_unlock_irqrestore(&p->sighand->siglock, flags);
+out_err:
read_unlock(&tasklist_lock);
- return(ret);
+ return ret;
}

/*
--- linux-2.6.13-rc6.signal/kernel/posix-timers.oleg.c 2005-08-21 23:09:58.000000000 +0200
+++ linux-2.6.13-rc6.signal/kernel/posix-timers.c 2005-08-21 23:19:42.000000000 +0200
@@ -501,7 +501,8 @@ static void posix_timer_fn(unsigned long
remove_from_abslist(timr);
}

- if (posix_timer_event(timr, si_private))
+ /* Do not rearm the timer, when we are exiting */
+ if (posix_timer_event(timr, si_private) > 0)
/*
* signal was not sent because of sig_ignor
* we will not get a call back to restart it AND


-
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/