patch 'vhost: fix VDUSE device destruction failure' has been queued to stable release 23.11.1

Xueming Li xuemingl at nvidia.com
Sat Apr 13 14:48:13 CEST 2024


Hi,

FYI, your patch has been queued to stable release 23.11.1

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 04/15/24. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=23.11-staging

This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/commit/?h=23.11-staging&id=b2dba501cf2d141ae2cb01faf58077b62ffb57d2

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From b2dba501cf2d141ae2cb01faf58077b62ffb57d2 Mon Sep 17 00:00:00 2001
From: Maxime Coquelin <maxime.coquelin at redhat.com>
Date: Thu, 29 Feb 2024 13:24:56 +0100
Subject: [PATCH] vhost: fix VDUSE device destruction failure
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit deedfb86a7a6e10064d3cccd593f62072de96e36 ]

VDUSE_DESTROY_DEVICE ioctl can fail because the device's
chardev is not released despite close syscall having been
called. It happens because the events handler thread is
still polling the file descriptor.

fdset_pipe_notify() is not enough because it does not
ensure the notification has been handled by the event
thread, it just returns once the notification is sent.

To fix this, this patch introduces a synchronization
mechanism based on pthread's condition, so that
fdset_pipe_notify_sync() only returns once the pipe's
read callback has been executed.

Fixes: 51d018fdac4e ("vhost: add VDUSE events handler")

Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
Signed-off-by: David Marchand <david.marchand at redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin at redhat.com>
---
 lib/vhost/fd_man.c | 23 +++++++++++++++++++++--
 lib/vhost/fd_man.h |  6 ++++++
 lib/vhost/socket.c |  1 +
 lib/vhost/vduse.c  |  3 ++-
 4 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c
index 134414fb4b..84c5da0793 100644
--- a/lib/vhost/fd_man.c
+++ b/lib/vhost/fd_man.c
@@ -307,10 +307,11 @@ fdset_event_dispatch(void *arg)
 }
 
 static void
-fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
+fdset_pipe_read_cb(int readfd, void *dat,
 		   int *remove __rte_unused)
 {
 	char charbuf[16];
+	struct fdset *fdset = dat;
 	int r = read(readfd, charbuf, sizeof(charbuf));
 	/*
 	 * Just an optimization, we don't care if read() failed
@@ -318,6 +319,11 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
 	 * compiler happy
 	 */
 	RTE_SET_USED(r);
+
+	pthread_mutex_lock(&fdset->sync_mutex);
+	fdset->sync = true;
+	pthread_cond_broadcast(&fdset->sync_cond);
+	pthread_mutex_unlock(&fdset->sync_mutex);
 }
 
 void
@@ -340,7 +346,7 @@ fdset_pipe_init(struct fdset *fdset)
 	}
 
 	ret = fdset_add(fdset, fdset->u.readfd,
-			fdset_pipe_read_cb, NULL, NULL);
+			fdset_pipe_read_cb, NULL, fdset);
 
 	if (ret < 0) {
 		RTE_LOG(ERR, VHOST_FDMAN,
@@ -364,5 +370,18 @@ fdset_pipe_notify(struct fdset *fdset)
 	 * compiler happy
 	 */
 	RTE_SET_USED(r);
+}
+
+void
+fdset_pipe_notify_sync(struct fdset *fdset)
+{
+	pthread_mutex_lock(&fdset->sync_mutex);
+
+	fdset->sync = false;
+	fdset_pipe_notify(fdset);
+
+	while (!fdset->sync)
+		pthread_cond_wait(&fdset->sync_cond, &fdset->sync_mutex);
 
+	pthread_mutex_unlock(&fdset->sync_mutex);
 }
diff --git a/lib/vhost/fd_man.h b/lib/vhost/fd_man.h
index 6315904c8e..7816fb11ac 100644
--- a/lib/vhost/fd_man.h
+++ b/lib/vhost/fd_man.h
@@ -6,6 +6,7 @@
 #define _FD_MAN_H_
 #include <pthread.h>
 #include <poll.h>
+#include <stdbool.h>
 
 #define MAX_FDS 1024
 
@@ -35,6 +36,10 @@ struct fdset {
 			int writefd;
 		};
 	} u;
+
+	pthread_mutex_t sync_mutex;
+	pthread_cond_t sync_cond;
+	bool sync;
 };
 
 
@@ -53,5 +58,6 @@ int fdset_pipe_init(struct fdset *fdset);
 void fdset_pipe_uninit(struct fdset *fdset);
 
 void fdset_pipe_notify(struct fdset *fdset);
+void fdset_pipe_notify_sync(struct fdset *fdset);
 
 #endif
diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index 5882e44176..0b95c54c5b 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -93,6 +93,7 @@ static struct vhost_user vhost_user = {
 		.fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
 		.fd_mutex = PTHREAD_MUTEX_INITIALIZER,
 		.fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER,
+		.sync_mutex = PTHREAD_MUTEX_INITIALIZER,
 		.num = 0
 	},
 	.vsocket_cnt = 0,
diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c
index e198eeef64..b46f0e53c7 100644
--- a/lib/vhost/vduse.c
+++ b/lib/vhost/vduse.c
@@ -36,6 +36,7 @@ static struct vduse vduse = {
 		.fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
 		.fd_mutex = PTHREAD_MUTEX_INITIALIZER,
 		.fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER,
+		.sync_mutex = PTHREAD_MUTEX_INITIALIZER,
 		.num = 0
 	},
 };
@@ -618,7 +619,7 @@ vduse_device_destroy(const char *path)
 	vduse_device_stop(dev);
 
 	fdset_del(&vduse.fdset, dev->vduse_dev_fd);
-	fdset_pipe_notify(&vduse.fdset);
+	fdset_pipe_notify_sync(&vduse.fdset);
 
 	if (dev->vduse_dev_fd >= 0) {
 		close(dev->vduse_dev_fd);
-- 
2.34.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2024-04-13 20:43:05.548843712 +0800
+++ 0013-vhost-fix-VDUSE-device-destruction-failure.patch	2024-04-13 20:43:04.907754049 +0800
@@ -1 +1 @@
-From deedfb86a7a6e10064d3cccd593f62072de96e36 Mon Sep 17 00:00:00 2001
+From b2dba501cf2d141ae2cb01faf58077b62ffb57d2 Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit deedfb86a7a6e10064d3cccd593f62072de96e36 ]
@@ -21 +23,0 @@
-Cc: stable at dpdk.org
@@ -34 +36 @@
-index 79a8d2c006..481e6b900a 100644
+index 134414fb4b..84c5da0793 100644
@@ -37 +39 @@
-@@ -309,10 +309,11 @@ fdset_event_dispatch(void *arg)
+@@ -307,10 +307,11 @@ fdset_event_dispatch(void *arg)
@@ -50 +52 @@
-@@ -320,6 +321,11 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
+@@ -318,6 +319,11 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
@@ -62 +64 @@
-@@ -342,7 +348,7 @@ fdset_pipe_init(struct fdset *fdset)
+@@ -340,7 +346,7 @@ fdset_pipe_init(struct fdset *fdset)
@@ -70,2 +72,2 @@
- 		VHOST_FDMAN_LOG(ERR,
-@@ -366,5 +372,18 @@ fdset_pipe_notify(struct fdset *fdset)
+ 		RTE_LOG(ERR, VHOST_FDMAN,
+@@ -364,5 +370,18 @@ fdset_pipe_notify(struct fdset *fdset)
@@ -121 +123 @@
-index a2fdac30a4..96b3ab5595 100644
+index 5882e44176..0b95c54c5b 100644
@@ -133 +135 @@
-index d462428d2c..e0c6991b69 100644
+index e198eeef64..b46f0e53c7 100644


More information about the stable mailing list