[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 25/30] libvhost-user: handle NOFD flag in call/kick/err better
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 25/30] libvhost-user: handle NOFD flag in call/kick/err better |
Date: |
Wed, 26 Feb 2020 04:07:38 -0500 |
From: Johannes Berg <address@hidden>
The code here is odd, for example will it print out invalid
file descriptor numbers that were never sent in the message.
Clean that up a bit so it's actually possible to implement
a device that uses polling.
Signed-off-by: Johannes Berg <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
contrib/libvhost-user/libvhost-user.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/contrib/libvhost-user/libvhost-user.c
b/contrib/libvhost-user/libvhost-user.c
index 533d55d82a..3abc9689e5 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -948,6 +948,7 @@ static bool
vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg)
{
int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
+ bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
if (index >= dev->max_queues) {
vmsg_close_fds(vmsg);
@@ -955,8 +956,12 @@ vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg)
return false;
}
- if (vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK ||
- vmsg->fd_num != 1) {
+ if (nofd) {
+ vmsg_close_fds(vmsg);
+ return true;
+ }
+
+ if (vmsg->fd_num != 1) {
vmsg_close_fds(vmsg);
vu_panic(dev, "Invalid fds in request: %d", vmsg->request);
return false;
@@ -1053,6 +1058,7 @@ static bool
vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg)
{
int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
+ bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64);
@@ -1066,8 +1072,8 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg)
dev->vq[index].kick_fd = -1;
}
- dev->vq[index].kick_fd = vmsg->fds[0];
- DPRINT("Got kick_fd: %d for vq: %d\n", vmsg->fds[0], index);
+ dev->vq[index].kick_fd = nofd ? -1 : vmsg->fds[0];
+ DPRINT("Got kick_fd: %d for vq: %d\n", dev->vq[index].kick_fd, index);
dev->vq[index].started = true;
if (dev->iface->queue_set_started) {
@@ -1147,6 +1153,7 @@ static bool
vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg)
{
int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
+ bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64);
@@ -1159,14 +1166,14 @@ vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg)
dev->vq[index].call_fd = -1;
}
- dev->vq[index].call_fd = vmsg->fds[0];
+ dev->vq[index].call_fd = nofd ? -1 : vmsg->fds[0];
/* in case of I/O hang after reconnecting */
- if (eventfd_write(vmsg->fds[0], 1)) {
+ if (dev->vq[index].call_fd != -1 && eventfd_write(vmsg->fds[0], 1)) {
return -1;
}
- DPRINT("Got call_fd: %d for vq: %d\n", vmsg->fds[0], index);
+ DPRINT("Got call_fd: %d for vq: %d\n", dev->vq[index].call_fd, index);
return false;
}
@@ -1175,6 +1182,7 @@ static bool
vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg)
{
int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
+ bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64);
@@ -1187,7 +1195,7 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg)
dev->vq[index].err_fd = -1;
}
- dev->vq[index].err_fd = vmsg->fds[0];
+ dev->vq[index].err_fd = nofd ? -1 : vmsg->fds[0];
return false;
}
--
MST
- [PULL v2 15/30] virtio-iommu: Implement map/unmap, (continued)
- [PULL v2 15/30] virtio-iommu: Implement map/unmap, Michael S. Tsirkin, 2020/02/26
- [PULL v2 16/30] virtio-iommu: Implement translate, Michael S. Tsirkin, 2020/02/26
- [PULL v2 17/30] virtio-iommu: Implement fault reporting, Michael S. Tsirkin, 2020/02/26
- [PULL v2 18/30] virtio-iommu: Support migration, Michael S. Tsirkin, 2020/02/26
- [PULL v2 19/30] virtio-iommu-pci: Add virtio iommu pci support, Michael S. Tsirkin, 2020/02/26
- [PULL v2 20/30] hw/arm/virt: Add the virtio-iommu device tree mappings, Michael S. Tsirkin, 2020/02/26
- [PULL v2 21/30] MAINTAINERS: add virtio-iommu related files, Michael S. Tsirkin, 2020/02/26
- [PULL v2 22/30] libvhost-user: implement VHOST_USER_PROTOCOL_F_REPLY_ACK, Michael S. Tsirkin, 2020/02/26
- [PULL v2 23/30] libvhost-user-glib: fix VugDev main fd cleanup, Michael S. Tsirkin, 2020/02/26
- [PULL v2 24/30] libvhost-user-glib: use g_main_context_get_thread_default(), Michael S. Tsirkin, 2020/02/26
- [PULL v2 25/30] libvhost-user: handle NOFD flag in call/kick/err better,
Michael S. Tsirkin <=
- [PULL v2 26/30] docs: vhost-user: add in-band kick/call messages, Michael S. Tsirkin, 2020/02/26
- [PULL v2 27/30] libvhost-user: implement in-band notifications, Michael S. Tsirkin, 2020/02/26
- [PULL v2 28/30] acpi: cpuhp: document CPHP_GET_CPU_ID_CMD command, Michael S. Tsirkin, 2020/02/26
- [PULL v2 29/30] vhost-user: only set slave channel for first vq, Michael S. Tsirkin, 2020/02/26
- [PULL v2 30/30] Fixed assert in vhost_user_set_mem_table_postcopy, Michael S. Tsirkin, 2020/02/26
- Re: [PULL v2 00/30] virtio, pc: fixes, features, Michael S. Tsirkin, 2020/02/27