From: Maxime Coquelin Date: Tue, 14 Jan 2020 18:53:57 +0000 (+0100) Subject: vhost: fix deadlock on port deletion X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=5efb18e85f7fdb436d3e56591656051c16802066;p=dpdk.git vhost: fix deadlock on port deletion If the vhost-user application (e.g. OVS) deletes the vhost-user port while Qemu sends a vhost-user request, a deadlock can happen if the request handler tries to acquire vhost-user's global mutex, which is also locked by the vhost-user port deletion API (rte_vhost_driver_unregister). This patch prevents the deadlock by making rte_vhost_driver_unregister() to release the mutex and try again if a request is being handled to give a chance to the request handler to complete. Fixes: 8b4b949144b8 ("vhost: fix dead lock on closing in server mode") Fixes: 5fbb3941da9f ("vhost: introduce driver features related APIs") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin Reviewed-by: Tiwei Bie Acked-by: Eelco Chaudron --- diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 8bc1e3a03c..9740fb3403 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -1052,9 +1052,10 @@ again: next = TAILQ_NEXT(conn, next); /* - * If r/wcb is executing, release the - * conn_mutex lock, and try again since - * the r/wcb may use the conn_mutex lock. + * If r/wcb is executing, release vsocket's + * conn_mutex and vhost_user's mutex locks, and + * try again since the r/wcb may use the + * conn_mutex and mutex locks. */ if (fdset_try_del(&vhost_user.fdset, conn->connfd) == -1) { @@ -1075,8 +1076,17 @@ again: pthread_mutex_unlock(&vsocket->conn_mutex); if (vsocket->is_server) { - fdset_del(&vhost_user.fdset, - vsocket->socket_fd); + /* + * If r/wcb is executing, release vhost_user's + * mutex lock, and try again since the r/wcb + * may use the mutex lock. + */ + if (fdset_try_del(&vhost_user.fdset, + vsocket->socket_fd) == -1) { + pthread_mutex_unlock(&vhost_user.mutex); + goto again; + } + close(vsocket->socket_fd); unlink(path); } else if (vsocket->reconnect) {