tree 22a287e729df2a945610e18ba947cd1f10e440de
parent ab4300bfea64ef7e14c9fa3fad3d49bb14a2db70
author NeilBrown <[EMAIL PROTECTED]> Tue Apr 12 08:27:07 2005
committer Linus Torvalds <[EMAIL PROTECTED]> Tue Apr 12 08:27:07 2005

[PATCH] md: close a small race in md thread deregistration

There is a tiny race when de-registering an MD thread, in that the thread
could disappear before it is set a SIGKILL, causing send_sig to have
problems.  

This is most easily closed by holding tasklist_lock between enabling the
thread to exit (setting ->run to NULL) and telling it to exit.

(akpm: ick.  Needs to use kthread API and stop using signals)

Signed-off-by: Neil Brown <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>

 md.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

Index: drivers/md/md.c
===================================================================
--- c4252d5f77f700089e90fc68dccf65b047013574/drivers/md/md.c  (mode:100644 
sha1:e8f1473c7640577a36220048d10921d88bb23023)
+++ 22a287e729df2a945610e18ba947cd1f10e440de/drivers/md/md.c  (mode:100644 
sha1:9af4a9ebea153b8ed987041b9635d2b98c8b5200)
@@ -2840,16 +2840,6 @@
        return thread;
 }
 
-static void md_interrupt_thread(mdk_thread_t *thread)
-{
-       if (!thread->tsk) {
-               MD_BUG();
-               return;
-       }
-       dprintk("interrupting MD-thread pid %d\n", thread->tsk->pid);
-       send_sig(SIGKILL, thread->tsk, 1);
-}
-
 void md_unregister_thread(mdk_thread_t *thread)
 {
        struct completion event;
@@ -2857,9 +2847,15 @@
        init_completion(&event);
 
        thread->event = &event;
+
+       /* As soon as ->run is set to NULL, the task could disappear,
+        * so we need to hold tasklist_lock until we have sent the signal
+        */
+       dprintk("interrupting MD-thread pid %d\n", thread->tsk->pid);
+       read_lock(&tasklist_lock);
        thread->run = NULL;
-       thread->name = NULL;
-       md_interrupt_thread(thread);
+       send_sig(SIGKILL, thread->tsk, 1);
+       read_unlock(&tasklist_lock);
        wait_for_completion(&event);
        kfree(thread);
 }
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to