[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 19/22] libvhost-user: add vmsg_set_reply_u64() helper
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 19/22] libvhost-user: add vmsg_set_reply_u64() helper |
Date: |
Tue, 2 Jul 2019 11:08:20 -0400 |
From: Stefan Hajnoczi <address@hidden>
The VhostUserMsg request is reused as the reply by message processing
functions. This is risky since request fields may corrupt the reply if
the vhost-user message handler function forgets to re-initialize them.
Changing this practice would be very invasive but we can introduce a
helper function to make u64 payload replies safe. This also eliminates
code duplication in message processing functions.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Marc-André Lureau <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 | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/contrib/libvhost-user/libvhost-user.c
b/contrib/libvhost-user/libvhost-user.c
index 443b7e08c3..a8657c7af2 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -216,6 +216,15 @@ vmsg_close_fds(VhostUserMsg *vmsg)
}
}
+/* Set reply payload.u64 and clear request flags and fd_num */
+static void vmsg_set_reply_u64(VhostUserMsg *vmsg, uint64_t val)
+{
+ vmsg->flags = 0; /* defaults will be set by vu_send_reply() */
+ vmsg->size = sizeof(vmsg->payload.u64);
+ vmsg->payload.u64 = val;
+ vmsg->fd_num = 0;
+}
+
/* A test to see if we have userfault available */
static bool
have_userfault(void)
@@ -1168,10 +1177,7 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg
*vmsg)
features |= dev->iface->get_protocol_features(dev);
}
- vmsg->payload.u64 = features;
- vmsg->size = sizeof(vmsg->payload.u64);
- vmsg->fd_num = 0;
-
+ vmsg_set_reply_u64(vmsg, features);
return true;
}
@@ -1307,17 +1313,14 @@ out:
static bool
vu_set_postcopy_listen(VuDev *dev, VhostUserMsg *vmsg)
{
- vmsg->payload.u64 = -1;
- vmsg->size = sizeof(vmsg->payload.u64);
-
if (dev->nregions) {
vu_panic(dev, "Regions already registered at postcopy-listen");
+ vmsg_set_reply_u64(vmsg, -1);
return true;
}
dev->postcopy_listening = true;
- vmsg->flags = VHOST_USER_VERSION | VHOST_USER_REPLY_MASK;
- vmsg->payload.u64 = 0; /* Success */
+ vmsg_set_reply_u64(vmsg, 0);
return true;
}
@@ -1332,10 +1335,7 @@ vu_set_postcopy_end(VuDev *dev, VhostUserMsg *vmsg)
DPRINT("%s: Done close\n", __func__);
}
- vmsg->fd_num = 0;
- vmsg->payload.u64 = 0;
- vmsg->size = sizeof(vmsg->payload.u64);
- vmsg->flags = VHOST_USER_VERSION | VHOST_USER_REPLY_MASK;
+ vmsg_set_reply_u64(vmsg, 0);
DPRINT("%s: exit\n", __func__);
return true;
}
--
MST
- Re: [Qemu-devel] [PATCH v2 5/7] hmp: Handle virtio-pmem when printing memory device infos, (continued)
- [Qemu-devel] [PULL 11/22] pc: Support for virtio-pmem-pci, Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 12/22] virtio-pci: fix missing device properties, Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 13/22] virtio: add "use-started" property, Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 14/22] virtio: Set "start_on_kick" for legacy devices, Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 15/22] virtio: Set "start_on_kick" on virtio_set_features(), Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 16/22] virtio: Make sure we get correct state of device on handle_aio_output(), Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 17/22] virtio: Don't change "started" flag on virtio_vmstate_change(), Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 18/22] pc: Move compat_apic_id_mode variable to PCMachineClass, Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 19/22] libvhost-user: add vmsg_set_reply_u64() helper,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 20/22] libvhost-user: support many virtqueues, Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 21/22] libvhost-user: implement VHOST_USER_PROTOCOL_F_MQ, Michael S. Tsirkin, 2019/07/02
- [Qemu-devel] [PULL 22/22] docs: avoid vhost-user-net specifics in multiqueue section, Michael S. Tsirkin, 2019/07/02
- Re: [Qemu-devel] [PULL 00/22] virtio, pc, pci: features, fixes, cleanups, Peter Maydell, 2019/07/02
- Re: [Qemu-devel] [PULL 00/22] virtio, pc, pci: features, fixes, cleanups, Michael S. Tsirkin, 2019/07/02
- Re: [Qemu-devel] [PULL 00/22] virtio, pc, pci: features, fixes, cleanups, Peter Maydell, 2019/07/02
- Re: [Qemu-devel] [PULL 00/22] virtio, pc, pci: features, fixes, cleanups, Michael S. Tsirkin, 2019/07/02
- Re: [Qemu-devel] [PULL 00/22] virtio, pc, pci: features, fixes, cleanups, Peter Maydell, 2019/07/02
- Re: [Qemu-devel] [PULL 00/22] virtio, pc, pci: features, fixes, cleanups, Michael S. Tsirkin, 2019/07/02
- Re: [Qemu-devel] [PULL 00/22] virtio, pc, pci: features, fixes, cleanups, Peter Maydell, 2019/07/26