The patch titled

     fix-send_sigqueue-vs-thread-exit-race fix

has been added to the -mm tree.  Its filename is

     fix-send_sigqueue-vs-thread-exit-race-fix.patch

Patches currently in -mm which might be from [EMAIL PROTECTED] are

fix-send_sigqueue-vs-thread-exit-race.patch
fix-send_sigqueue-vs-thread-exit-race-fix.patch
ppc-c99-initializers-for-hw_interrupt_type-structures.patch
sh-c99-initializers-for-hw_interrupt_type-structures.patch
v850-c99-initializers-for-hw_interrupt_type-structures.patch
sh64-c99-initializers-for-hw_interrupt_type-structures.patch



From: Thomas Gleixner <[EMAIL PROTECTED]>

The patch below on top of your patch should solve this.  We don't need
tasklist_lock to check p->flags.  As you pointed out p cannot be invalid in
send_sigqueue as it's protected by get_task_struct() in create_timer()

For send_group_sigqueue it's protected by exit_itimers() waiting for
k_itimer.it_lock.

It still does not solve the ugly dependency on tasklist_lock but at least the
race and the deadlock are fixed.

Signed-off-by: Thomas Gleixner <[EMAIL PROTECTED]>
Cc: Oleg Nesterov <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
---

 kernel/posix-timers.c |    3 ++-
 kernel/signal.c       |   25 ++++++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff -puN kernel/posix-timers.c~fix-send_sigqueue-vs-thread-exit-race-fix 
kernel/posix-timers.c
--- devel/kernel/posix-timers.c~fix-send_sigqueue-vs-thread-exit-race-fix       
2005-08-21 22:31:05.000000000 -0700
+++ devel-akpm/kernel/posix-timers.c    2005-08-21 22:31:05.000000000 -0700
@@ -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
diff -puN kernel/signal.c~fix-send_sigqueue-vs-thread-exit-race-fix 
kernel/signal.c
--- devel/kernel/signal.c~fix-send_sigqueue-vs-thread-exit-race-fix     
2005-08-21 22:31:05.000000000 -0700
+++ devel-akpm/kernel/signal.c  2005-08-21 22:31:05.000000000 -0700
@@ -1367,8 +1367,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;
@@ -1413,7 +1420,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);
 
@@ -1447,8 +1465,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;
 }
 
 /*
_
-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to