From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeremy Fitzhardinge Subject: [PATCH 2 of 2] xs: avoid pthread_join deadlock in xs_daemon_close Date: Tue, 11 May 2010 15:03:47 -0700 Message-ID: <4BE9D443.20106@goop.org> References: <4BE9D3B9.2050206@goop.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4BE9D3B9.2050206@goop.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: Xen-devel , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org 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 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);