From: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
To: dev@dpdk.org
Cc: Pawel Wodkowski <pawelx.wodkowski@intel.com>,
Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Subject: [dpdk-dev] [PATCH] vhost: fix deadlock on rte_vhost_driver_unregister()
Date: Tue, 16 May 2017 16:34:32 +0200 [thread overview]
Message-ID: <1494945272-126732-1-git-send-email-dariuszx.stojaczyk@intel.com> (raw)
Consider the following scenario, threads A and B:
(A)
* fdset_event_dispatch() start
* pfdentry->busy = 1;
* vhost_user_read_cb() start
* vhost_destroy_device() start
(B)
* rte_vhost_driver_unregister() start
* pthread_mutex_lock(&vsocket->conn_mutex);
* fdset_del()
* endless loop, waiting for pfdentry->busy == 0
(A)
* vhost_destroy_device() end
* pthread_mutex_lock(&vsocket->conn_mutex);
(mutex already locked - deadlock at this point)
Thread B has locked vsocket->conn_mutex and is in while(1)
loop waiting for given fd to change it's busy flag to 0.
Thread A would have to finish vhost_user_read_cb() in order
to set busy flag back to 0, but that can't happen due to
the vsocket->conn_mutex lock.
This patch synchronizes rte_vhost_driver_unregister() with
vhost_user_read_cb() through vhost_user.mutex.
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
---
lib/librte_vhost/socket.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index c7f99b0..77e58fe 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -273,6 +273,8 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)
ret = vhost_user_msg_handler(conn->vid, connfd);
if (ret < 0) {
+ pthread_mutex_lock(&vhost_user.mutex);
+
close(connfd);
*remove = 1;
vhost_destroy_device(conn->vid);
@@ -287,6 +289,8 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)
create_unix_socket(vsocket);
vhost_user_start_client(vsocket);
}
+
+ pthread_mutex_unlock(&vhost_user.mutex);
}
}
--
2.7.4
next reply other threads:[~2017-05-16 11:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 14:34 Dariusz Stojaczyk [this message]
2017-05-16 13:57 ` Stojaczyk, DariuszX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1494945272-126732-1-git-send-email-dariuszx.stojaczyk@intel.com \
--to=dariuszx.stojaczyk@intel.com \
--cc=dev@dpdk.org \
--cc=pawelx.wodkowski@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).