patches for DPDK stable branches
 help / color / Atom feed
* [dpdk-stable] [PATCH] vhost: return -EAGAIN during unregistering vhost if it is busy.
@ 2020-03-12  9:57 Zhike Wang
  2020-03-18  3:31 ` 王志克
  0 siblings, 1 reply; 2+ messages in thread
From: Zhike Wang @ 2020-03-12  9:57 UTC (permalink / raw)
  To: dev; +Cc: maxime.coquelin, xiaolong.ye, zhihong.wang, stable, Zhike Wang

The vhost_user_read_cb() and rte_vhost_driver_unregister()
can be called at the same time by 2 threads, and may lead to deadlock.
Eg thread1 calls vhost_user_read_cb()->vhost_user_get_vring_base()->destroy_device(),
then thread2 calls rte_vhost_driver_unregister(), and will retry the fdset_try_del() in loop.

Some application implements destroy_device() as a blocking function, eg
OVS calls ovsrcu_synchronize() insides destroy_device(). As a result,
thread1(eg vhost_events) is blocked to wait quiesce of thread2(eg ovs-vswitchd),
and thread2 is in a loop to wait thread1 to give up the use of the vhost fd,
then leads to deadlock.

It is better to return -EAGAIN to application, who will decide how to handle
(eg OVS can call ovsrcu_quiesce() and then retry).

Signed-off-by: Zhike Wang <wangzhike@jd.com>
---
 lib/librte_vhost/rte_vhost.h | 4 +++-
 lib/librte_vhost/socket.c    | 8 ++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index c7b619a..276db11 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -389,7 +389,9 @@ void rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
  */
 int rte_vhost_driver_register(const char *path, uint64_t flags);
 
-/* Unregister vhost driver. This is only meaningful to vhost user. */
+/* Unregister vhost driver. This is only meaningful to vhost user.
+ * Return -EAGAIN if device is busy, and leave it to be handled by application.
+ */
 int rte_vhost_driver_unregister(const char *path);
 
 /**
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 7c80121..a75a3f6 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -1027,7 +1027,8 @@ struct vhost_user_reconnect_list {
 }
 
 /**
- * Unregister the specified vhost socket
+ * Unregister the specified vhost socket.
+ * Return -EAGAIN if device is busy, and leave it to be handled by application.
  */
 int
 rte_vhost_driver_unregister(const char *path)
@@ -1039,7 +1040,6 @@ struct vhost_user_reconnect_list {
 	if (path == NULL)
 		return -1;
 
-again:
 	pthread_mutex_lock(&vhost_user.mutex);
 
 	for (i = 0; i < vhost_user.vsocket_cnt; i++) {
@@ -1063,7 +1063,7 @@ struct vhost_user_reconnect_list {
 					pthread_mutex_unlock(
 							&vsocket->conn_mutex);
 					pthread_mutex_unlock(&vhost_user.mutex);
-					goto again;
+					return -EAGAIN;
 				}
 
 				VHOST_LOG_CONFIG(INFO,
@@ -1085,7 +1085,7 @@ struct vhost_user_reconnect_list {
 				if (fdset_try_del(&vhost_user.fdset,
 						vsocket->socket_fd) == -1) {
 					pthread_mutex_unlock(&vhost_user.mutex);
-					goto again;
+					return -EAGAIN;
 				}
 
 				close(vsocket->socket_fd);
-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-stable] [PATCH] vhost: return -EAGAIN during unregistering vhost if it is busy.
  2020-03-12  9:57 [dpdk-stable] [PATCH] vhost: return -EAGAIN during unregistering vhost if it is busy Zhike Wang
@ 2020-03-18  3:31 ` 王志克
  0 siblings, 0 replies; 2+ messages in thread
From: 王志克 @ 2020-03-18  3:31 UTC (permalink / raw)
  To: Zhike Wang, dev; +Cc: dev, maxime.coquelin, xiaolong.ye, zhihong.wang, stable

Involve openvswitch group since this fix is highly coupled with OVS.
welcome comment.
At 2020-03-12 17:57:19, "Zhike Wang" <wangzhike@jd.com> wrote:
>The vhost_user_read_cb() and rte_vhost_driver_unregister()
>can be called at the same time by 2 threads, and may lead to deadlock.
>Eg thread1 calls vhost_user_read_cb()->vhost_user_get_vring_base()->destroy_device(),
>then thread2 calls rte_vhost_driver_unregister(), and will retry the fdset_try_del() in loop.
>
>Some application implements destroy_device() as a blocking function, eg
>OVS calls ovsrcu_synchronize() insides destroy_device(). As a result,
>thread1(eg vhost_events) is blocked to wait quiesce of thread2(eg ovs-vswitchd),
>and thread2 is in a loop to wait thread1 to give up the use of the vhost fd,
>then leads to deadlock.
>
>It is better to return -EAGAIN to application, who will decide how to handle
>(eg OVS can call ovsrcu_quiesce() and then retry).
>
>Signed-off-by: Zhike Wang <wangzhike@jd.com>
>---
> lib/librte_vhost/rte_vhost.h | 4 +++-
> lib/librte_vhost/socket.c    | 8 ++++----
> 2 files changed, 7 insertions(+), 5 deletions(-)
>
>diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
>index c7b619a..276db11 100644
>--- a/lib/librte_vhost/rte_vhost.h
>+++ b/lib/librte_vhost/rte_vhost.h
>@@ -389,7 +389,9 @@ void rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
>  */
> int rte_vhost_driver_register(const char *path, uint64_t flags);
> 
>-/* Unregister vhost driver. This is only meaningful to vhost user. */
>+/* Unregister vhost driver. This is only meaningful to vhost user.
>+ * Return -EAGAIN if device is busy, and leave it to be handled by application.
>+ */
> int rte_vhost_driver_unregister(const char *path);
> 
> /**
>diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
>index 7c80121..a75a3f6 100644
>--- a/lib/librte_vhost/socket.c
>+++ b/lib/librte_vhost/socket.c
>@@ -1027,7 +1027,8 @@ struct vhost_user_reconnect_list {
> }
> 
> /**
>- * Unregister the specified vhost socket
>+ * Unregister the specified vhost socket.
>+ * Return -EAGAIN if device is busy, and leave it to be handled by application.
>  */
> int
> rte_vhost_driver_unregister(const char *path)
>@@ -1039,7 +1040,6 @@ struct vhost_user_reconnect_list {
> 	if (path == NULL)
> 		return -1;
> 
>-again:
> 	pthread_mutex_lock(&vhost_user.mutex);
> 
> 	for (i = 0; i < vhost_user.vsocket_cnt; i++) {
>@@ -1063,7 +1063,7 @@ struct vhost_user_reconnect_list {
> 					pthread_mutex_unlock(
> 							&vsocket->conn_mutex);
> 					pthread_mutex_unlock(&vhost_user.mutex);
>-					goto again;
>+					return -EAGAIN;
> 				}
> 
> 				VHOST_LOG_CONFIG(INFO,
>@@ -1085,7 +1085,7 @@ struct vhost_user_reconnect_list {
> 				if (fdset_try_del(&vhost_user.fdset,
> 						vsocket->socket_fd) == -1) {
> 					pthread_mutex_unlock(&vhost_user.mutex);
>-					goto again;
>+					return -EAGAIN;
> 				}
> 
> 				close(vsocket->socket_fd);
>-- 
>1.8.3.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12  9:57 [dpdk-stable] [PATCH] vhost: return -EAGAIN during unregistering vhost if it is busy Zhike Wang
2020-03-18  3:31 ` 王志克

patches for DPDK stable branches

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ http://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/ public-inbox