60 lines
2.2 KiB
Diff
60 lines
2.2 KiB
Diff
|
|
From 4b38d60e4a4a1fc4b7191ec94959f304b222b604 Mon Sep 17 00:00:00 2001
|
||
|
|
From: zhujun2 <zhujun2_yewu@cmss.chinamobile.com>
|
||
|
|
Date: Thu, 15 Aug 2024 20:20:35 -0700
|
||
|
|
Subject: [PATCH] vhost-user-server: do not set memory fd non-blocking
|
||
|
|
MIME-Version: 1.0
|
||
|
|
Content-Type: text/plain; charset=UTF-8
|
||
|
|
Content-Transfer-Encoding: 8bit
|
||
|
|
|
||
|
|
In vhost-user-server we set all fd received from the other peer
|
||
|
|
in non-blocking mode. For some of them (e.g. memfd, shm_open, etc.)
|
||
|
|
it's not really needed, because we don't use these fd with blocking
|
||
|
|
operations, but only to map memory.
|
||
|
|
|
||
|
|
In addition, in some systems this operation can fail (e.g. in macOS
|
||
|
|
setting an fd returned by shm_open() non-blocking fails with errno
|
||
|
|
= ENOTTY).
|
||
|
|
|
||
|
|
So, let's avoid setting fd non-blocking for those messages that we
|
||
|
|
know carry memory fd (e.g. VHOST_USER_ADD_MEM_REG,
|
||
|
|
VHOST_USER_SET_MEM_TABLE).
|
||
|
|
|
||
|
|
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
||
|
|
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
||
|
|
Reviewed-by: David Hildenbrand <david@redhat.com>
|
||
|
|
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
|
||
|
|
Message-Id: <20240618100043.144657-6-sgarzare@redhat.com>
|
||
|
|
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
||
|
|
(cherry picked from commit 4c58843e5d3192c67394b28a3330144ea56eefac)
|
||
|
|
Signed-off-by: zhujun2 <zhujun2_yewu@cmss.chinamobile.com>
|
||
|
|
---
|
||
|
|
util/vhost-user-server.c | 12 ++++++++++++
|
||
|
|
1 file changed, 12 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c
|
||
|
|
index 783d847a6d..eda82447bd 100644
|
||
|
|
--- a/util/vhost-user-server.c
|
||
|
|
+++ b/util/vhost-user-server.c
|
||
|
|
@@ -64,6 +64,18 @@ static void vmsg_close_fds(VhostUserMsg *vmsg)
|
||
|
|
static void vmsg_unblock_fds(VhostUserMsg *vmsg)
|
||
|
|
{
|
||
|
|
int i;
|
||
|
|
+
|
||
|
|
+ /*
|
||
|
|
+ * These messages carry fd used to map memory, not to send/receive messages,
|
||
|
|
+ * so this operation is useless. In addition, in some systems this
|
||
|
|
+ * operation can fail (e.g. in macOS setting an fd returned by shm_open()
|
||
|
|
+ * non-blocking fails with errno = ENOTTY)
|
||
|
|
+ */
|
||
|
|
+ if (vmsg->request == VHOST_USER_ADD_MEM_REG ||
|
||
|
|
+ vmsg->request == VHOST_USER_SET_MEM_TABLE) {
|
||
|
|
+ return;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
for (i = 0; i < vmsg->fd_num; i++) {
|
||
|
|
qemu_set_nonblock(vmsg->fds[i]);
|
||
|
|
}
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|