WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 2 of 2] xs: avoid pthread_join deadlock in xs_daemon_

To: Keir Fraser <keir.fraser@xxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 2 of 2] xs: avoid pthread_join deadlock in xs_daemon_close
From: Jeremy Fitzhardinge <jeremy@xxxxxxxx>
Date: Tue, 11 May 2010 15:03:47 -0700
Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <Stefano.Stabellini@xxxxxxxxxxxxx>
Delivery-date: Tue, 11 May 2010 15:05:36 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4BE9D3B9.2050206@xxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <4BE9D3B9.2050206@xxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-2.fc12 Lightning/1.0b2pre Thunderbird/3.0.4
Doing a pthread_cancel and join on the reader thread while holding all
the request/reply/watch mutexes can deadlock if the thread needs to
take any of those mutexes to exit.  Kill off the reader thread before
taking any mutexes (which should be redundant if we're  single-threaded
at that point).

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>

diff -r 84ee0559ddc1 tools/xenstore/xs.c
--- a/tools/xenstore/xs.c       Tue May 11 14:55:14 2010 -0700
+++ b/tools/xenstore/xs.c       Tue May 11 14:55:20 2010 -0700
@@ -260,10 +260,6 @@
 
 void xs_daemon_close(struct xs_handle *h)
 {
-       mutex_lock(&h->request_mutex);
-       mutex_lock(&h->reply_mutex);
-       mutex_lock(&h->watch_mutex);
-
 #ifdef USE_PTHREAD
        if (h->read_thr_exists) {
                pthread_cancel(h->read_thr);
@@ -271,6 +267,10 @@
        }
 #endif
 
+       mutex_lock(&h->request_mutex);
+       mutex_lock(&h->reply_mutex);
+       mutex_lock(&h->watch_mutex);
+
         close_free_msgs(h);
 
        mutex_unlock(&h->request_mutex);



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

<Prev in Thread] Current Thread [Next in Thread>