[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [linux-2.6.18-xen] Avoid deadlock when unregistering a xenbus watch.



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1206697762 0
# Node ID 0637d22ed554eb0b9cecc7a74fa0a77a7c456497
# Parent  fdb998e79aba45e27948047f680bf70ca5dddbd9
Avoid deadlock when unregistering a xenbus watch.

Watch handlers which run in a separate thread (XBWF_new_thread) should
run without the xenbus_mutex held since kthread_run can block waiting
for memory which causes a deadlock if further watches need to be
unregistered in order to activate the swap device on resume.

XBWF_new_thread cannot be safely unregistered anyway since the mutex
only protects thread startup.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 drivers/xen/xenbus/xenbus_xs.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

diff -r fdb998e79aba -r 0637d22ed554 drivers/xen/xenbus/xenbus_xs.c
--- a/drivers/xen/xenbus/xenbus_xs.c    Fri Mar 28 09:44:51 2008 +0000
+++ b/drivers/xen/xenbus/xenbus_xs.c    Fri Mar 28 09:49:22 2008 +0000
@@ -629,6 +629,8 @@ void unregister_xenbus_watch(struct xenb
        char token[sizeof(watch) * 2 + 1];
        int err;
 
+       BUG_ON(watch->flags & XBWF_new_thread);
+
        sprintf(token, "%lX", (long)watch);
 
        down_read(&xs_state.watch_mutex);
@@ -738,16 +740,29 @@ static int xenwatch_thread(void *unused)
                        list_del(ent);
                spin_unlock(&watch_events_lock);
 
-               if (ent != &watch_events) {
-                       msg = list_entry(ent, struct xs_stored_msg, list);
-                       if (msg->u.watch.handle->flags & XBWF_new_thread)
-                               kthread_run(xenwatch_handle_callback,
-                                           msg, "xenwatch_cb");
-                       else
-                               xenwatch_handle_callback(msg);
+               if (ent == &watch_events) {
+                       mutex_unlock(&xenwatch_mutex);
+                       continue;
                }
 
-               mutex_unlock(&xenwatch_mutex);
+               msg = list_entry(ent, struct xs_stored_msg, list);
+
+               /*
+                * Unlock the mutex before running an XBWF_new_thread
+                * handler. kthread_run can block which can deadlock
+                * against unregister_xenbus_watch() if we need to
+                * unregister other watches in order to make
+                * progress. This can occur on resume before the swap
+                * device is attached.
+                */
+               if (msg->u.watch.handle->flags & XBWF_new_thread) {
+                       mutex_unlock(&xenwatch_mutex);
+                       kthread_run(xenwatch_handle_callback,
+                                   msg, "xenwatch_cb");
+               } else {
+                       xenwatch_handle_callback(msg);
+                       mutex_unlock(&xenwatch_mutex);
+               }
        }
 
        return 0;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.