Enable vhost-user to be used on BSD systems
Subsystems (3)
cover Enable vhost-user to be used on BSD systems
Since QEMU is already able to emulate ioeventfd using pipefd, we're already pretty close to supporting vhost-user on non-Linux systems.
This two patches bridge the gap by:
1. Extending event_notifier_get_fd() to be able to return wfd when needed.
2. Modifying the build system to it allows enabling vhost-user on BSD.
Sergio Lopez (2):
Allow returning EventNotifier's wfd
Allow building vhost-user in BSD
accel/kvm/kvm-all.c | 12 +++---- block/linux-aio.c | 2 +- block/nvme.c | 2 +- configure | 5 +-- contrib/ivshmem-server/ivshmem-server.c | 5 +-- hw/hyperv/hyperv.c | 2 +- hw/misc/ivshmem.c | 2 +- hw/remote/iohub.c | 13 +++---- hw/remote/proxy.c | 4 +-- hw/vfio/ccw.c | 4 +-- hw/vfio/pci-quirks.c | 6 ++-- hw/vfio/pci.c | 48 +++++++++++++------------ hw/vfio/platform.c | 16 ++++----- hw/virtio/vhost.c | 10 +++--- include/qemu/event_notifier.h | 2 +- meson.build | 2 +- target/s390x/kvm/kvm.c | 2 +- util/aio-posix.c | 4 +-- util/event_notifier-posix.c | 5 ++- util/vfio-helpers.c | 2 +- 20 files changed, 79 insertions(+), 69 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/2 Allow returning EventNotifier's wfd
event_notifier_get_fd(const EventNotifier *e) always returns EventNotifier's read file descriptor (rfd). This is not a problem when the EventNotifier is backed by a an eventfd, as a single file descriptor is used both for reading and triggering events (rfd == wfd).
But, when EventNotifier is backed by a pipefd, we have two file descriptors, one that can only be used for reads (rfd), and the other only for writes (wfd).
There's, at least, one known situation in which we need to obtain wfd instead of rfd, which is when setting up the file that's going to be sent to the peer in vhost's SET_VRING_CALL.
Extend event_notifier_get_fd() to receive an argument which indicates whether the caller wants to obtain rfd (false) or wfd (true).
--- accel/kvm/kvm-all.c | 12 +++---- block/linux-aio.c | 2 +- block/nvme.c | 2 +- contrib/ivshmem-server/ivshmem-server.c | 5 +-- hw/hyperv/hyperv.c | 2 +- hw/misc/ivshmem.c | 2 +- hw/remote/iohub.c | 13 +++---- hw/remote/proxy.c | 4 +-- hw/vfio/ccw.c | 4 +-- hw/vfio/pci-quirks.c | 6 ++-- hw/vfio/pci.c | 48 +++++++++++++------------ hw/vfio/platform.c | 16 ++++----- hw/virtio/vhost.c | 10 +++--- include/qemu/event_notifier.h | 2 +- target/s390x/kvm/kvm.c | 2 +- util/aio-posix.c | 4 +-- util/event_notifier-posix.c | 5 ++- util/vfio-helpers.c | 2 +- 18 files changed, 75 insertions(+), 66 deletions(-)
accel/kvm/kvm-all.c +6 -6
@@ -1573,7 +1573,7 @@ static void kvm_mem_ioeventfd_add(MemoryListener *listener, bool match_data, uint64_t data, EventNotifier *e) { - int fd = event_notifier_get_fd(e); + int fd = event_notifier_get_fd(e, false);int r; r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
@@ -1591,7 +1591,7 @@ static void kvm_mem_ioeventfd_del(MemoryListener *listener, bool match_data, uint64_t data, EventNotifier *e) { - int fd = event_notifier_get_fd(e); + int fd = event_notifier_get_fd(e, false);int r; r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
@@ -1609,7 +1609,7 @@ static void kvm_io_ioeventfd_add(MemoryListener *listener, bool match_data, uint64_t data, EventNotifier *e) { - int fd = event_notifier_get_fd(e); + int fd = event_notifier_get_fd(e, false);int r; r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
@@ -1628,7 +1628,7 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener, EventNotifier *e) { -int fd =event_notifier_get_fd (e); +int fd =event_notifier_get_fd (e, false);int r; r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
@@ -2045,8 +2045,8 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, EventNotifier *event, EventNotifier *resample, int virq, bool assign) { - int fd = event_notifier_get_fd(event); -int rfd = resample ?event_notifier_get_fd (resample) :-1 ; + int fd = event_notifier_get_fd(event, false); +int rfd = resample ?event_notifier_get_fd (resample, false) :-1 ; struct kvm_irqfd irqfd = { .fd = fd,
block/linux-aio.c +1 -1
@@ -390,7 +390,7 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset, __func__, type);return -EIO ; } -io_set_eventfd (&laiocb->iocb,event_notifier_get_fd (&s->e)); +io_set_eventfd (&laiocb->iocb,event_notifier_get_fd (&s->e, false));QSIMPLEQ_INSERT_TAIL (&s->io_q.pending, laiocb, next); s->io_q.in_queue++;
block/nvme.c +1 -1
@@ -229,7 +229,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,return NULL ; }trace_nvme_create_queue_pair (idx, q, size, aio_context, -event_notifier_get_fd (s->irq_notifier)); +event_notifier_get_fd (s->irq_notifier, false)); bytes =QEMU_ALIGN_UP (s->page_size *NVME_NUM_REQS , qemu_real_host_page_size); q->prp_list_pages =qemu_try_memalign (qemu_real_host_page_size, bytes);
contrib/ivshmem-server/ivshmem-server.c +3 -2
@@ -204,7 +204,8 @@ ivshmem_server_handle_new_conn(IvshmemServer *server)/* advertise the new peer to itself */ for (i =0 ; i < peer->vectors_count; i++) {ivshmem_server_send_one_msg (peer->sock_fd, peer->id, -event_notifier_get_fd (&peer->vectors[i])); +event_notifier_get_fd (&peer->vectors[i], + false)); }QTAILQ_INSERT_TAIL (&server->peer_list, peer, next);
@@ -456,7 +457,7 @@ ivshmem_server_dump(const IvshmemServer *server)for (vector =0 ; vector < peer->vectors_count; vector++) {printf (" vector %d is enabled (fd=%d)\n" , vector, -event_notifier_get_fd (&peer->vectors[vector])); +event_notifier_get_fd (&peer->vectors[vector], false)); } } }
hw/hyperv/hyperv.c +1 -1
@@ -616,7 +616,7 @@ int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier)if (!process_event_flags_userspace) {struct kvm_hyperv_eventfd hvevfd = { .conn_id = conn_id, - .fd = notifier ?event_notifier_get_fd (notifier) :-1 , + .fd = notifier ?event_notifier_get_fd (notifier, false) :-1 , .flags = notifier ?0 :KVM_HYPERV_EVENTFD_DEASSIGN , };
hw/misc/ivshmem.c +1 -1
@@ -351,7 +351,7 @@ static void ivshmem_vector_poll(PCIDevice *dev,static void watch_vector_notifier (IVShmemState *s,EventNotifier *n,int vector) { -int eventfd =event_notifier_get_fd (n); +int eventfd =event_notifier_get_fd (n, false);assert (!s->msi_vectors[vector].pdev); s->msi_vectors[vector].pdev =PCI_DEVICE (s);
hw/remote/iohub.c +7 -6
@@ -37,10 +37,11 @@ void remote_iohub_init(RemoteIOHubState *iohub)void remote_iohub_finalize (RemoteIOHubState *iohub) {int pirq; +int fd;for (pirq =0 ; pirq <REMOTE_IOHUB_NB_PIRQS ; pirq++) { -qemu_set_fd_handler (event_notifier_get_fd (&iohub->resamplefds[pirq]), -NULL ,NULL ,NULL ); + fd =event_notifier_get_fd (&iohub->resamplefds[pirq], false); +qemu_set_fd_handler (fd,NULL ,NULL ,NULL );event_notifier_cleanup (&iohub->irqfds[pirq]);event_notifier_cleanup (&iohub->resamplefds[pirq]);qemu_mutex_destroy (&iohub->irq_level_lock[pirq]);
@@ -93,15 +94,15 @@ void process_set_irqfd_msg(PCIDevice *pci_dev, MPQemuMsg *msg) {RemoteMachineState *machine =REMOTE_MACHINE (current_machine);RemoteIOHubState *iohub = &machine->iohub; -int pirq, intx; +int pirq, intx, fd; intx =pci_get_byte (pci_dev->config +PCI_INTERRUPT_PIN ) -1 ; pirq =remote_iohub_map_irq (pci_dev, intx); -if (event_notifier_get_fd (&iohub->irqfds[pirq]) !=-1 ) { -qemu_set_fd_handler (event_notifier_get_fd (&iohub->resamplefds[pirq]), -NULL ,NULL ,NULL ); +if (event_notifier_get_fd (&iohub->irqfds[pirq], false) !=-1 ) { + fd =event_notifier_get_fd (&iohub->resamplefds[pirq], false); +qemu_set_fd_handler (fd,NULL ,NULL ,NULL );event_notifier_cleanup (&iohub->irqfds[pirq]);event_notifier_cleanup (&iohub->resamplefds[pirq]);memset (&iohub->token[pirq],0 ,sizeof (ResampleToken));
hw/remote/proxy.c +2 -2
@@ -61,8 +61,8 @@ static void setup_irqfd(PCIProxyDev *dev)memset (&msg,0 ,sizeof (MPQemuMsg)); msg.cmd =MPQEMU_CMD_SET_IRQFD ; msg.num_fds =2 ; - msg.fds[0 ] =event_notifier_get_fd (&dev->intr); - msg.fds[1 ] =event_notifier_get_fd (&dev->resample); + msg.fds[0 ] =event_notifier_get_fd (&dev->intr, false); + msg.fds[1 ] =event_notifier_get_fd (&dev->resample, false); msg.size =0 ;if (!mpqemu_msg_send (&msg, dev->ioc, &local_err)) {
hw/vfio/ccw.c +2 -2
@@ -437,7 +437,7 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, goto out_free_info; } - fd =event_notifier_get_fd (notifier); + fd =event_notifier_get_fd (notifier, false);qemu_set_fd_handler (fd, fd_read,NULL , vcdev); if (vfio_set_irq_signaling(vdev, irq, 0,
@@ -476,7 +476,7 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,warn_reportf_err (err,VFIO_MSG_PREFIX , vcdev->vdev.name); } -qemu_set_fd_handler (event_notifier_get_fd (notifier), +qemu_set_fd_handler (event_notifier_get_fd (notifier, false),NULL ,NULL , vcdev);event_notifier_cleanup (notifier); }
hw/vfio/pci-quirks.c +3 -3
@@ -309,7 +309,7 @@ static void vfio_ioeventfd_exit(VFIOPCIDevice *vdev, VFIOIOEventFD *ioeventfd) ioeventfd->size, ioeventfd->data); } }else { -qemu_set_fd_handler (event_notifier_get_fd (&ioeventfd->e), +qemu_set_fd_handler (event_notifier_get_fd (&ioeventfd->e, false),NULL ,NULL ,NULL ); }
@@ -387,14 +387,14 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev, vfio_ioeventfd.data = ioeventfd->data; vfio_ioeventfd.offset = ioeventfd->region->fd_offset + ioeventfd->region_addr; - vfio_ioeventfd.fd =event_notifier_get_fd (&ioeventfd->e); + vfio_ioeventfd.fd =event_notifier_get_fd (&ioeventfd->e, false); ioeventfd->vfio = !ioctl (vdev->vbasedev.fd,VFIO_DEVICE_IOEVENTFD , &vfio_ioeventfd); }if (!ioeventfd->vfio) { -qemu_set_fd_handler (event_notifier_get_fd (&ioeventfd->e), +qemu_set_fd_handler (event_notifier_get_fd (&ioeventfd->e, false), vfio_ioeventfd_handler,NULL , ioeventfd); }
hw/vfio/pci.c +25 -23
158 lines not on this page · raw message
hw/vfio/platform.c +8 -8
@@ -111,7 +111,7 @@ static int vfio_set_trigger_eventfd(VFIOINTp *intp, eventfd_user_side_handler_t handler) {VFIODevice *vbasedev = &intp->vdev->vbasedev; -int32_t fd =event_notifier_get_fd (intp->interrupt); +int32_t fd =event_notifier_get_fd (intp->interrupt, false);Error *err =NULL ;int ret;
@@ -192,7 +192,7 @@ static void vfio_intp_mmap_enable(void *opaque)static void vfio_intp_inject_pending_lockheld (VFIOINTp *intp) {trace_vfio_platform_intp_inject_pending_lockheld (intp->pin, -event_notifier_get_fd (intp->interrupt)); +event_notifier_get_fd (intp->interrupt, false)); intp->state =VFIO_IRQ_ACTIVE ;
@@ -244,7 +244,7 @@ static void vfio_intp_interrupt(VFIOINTp *intp) ret =event_notifier_test_and_clear (intp->interrupt);if (!ret) {error_report ("Error when clearing fd=%d (ret = %d)" , -event_notifier_get_fd (intp->interrupt), ret); +event_notifier_get_fd (intp->interrupt, false), ret); } intp->state =VFIO_IRQ_ACTIVE ;
@@ -291,7 +291,7 @@ static void vfio_platform_eoi(VFIODevice *vbasedev) QLIST_FOREACH(intp, &vdev->intp_list, next) {if (intp->state ==VFIO_IRQ_ACTIVE ) {trace_vfio_platform_eoi (intp->pin, -event_notifier_get_fd (intp->interrupt)); +event_notifier_get_fd (intp->interrupt, false)); intp->state =VFIO_IRQ_INACTIVE ;/* deassert the virtual IRQ */
@@ -350,7 +350,7 @@ static void vfio_start_eventfd_injection(SysBusDevice *sbdev, qemu_irq irq)*/ static int vfio_set_resample_eventfd (VFIOINTp *intp) { -int32_t fd =event_notifier_get_fd (intp->unmask); +int32_t fd =event_notifier_get_fd (intp->unmask, false);VFIODevice *vbasedev = &intp->vdev->vbasedev;Error *err =NULL ;int ret;
@@ -403,11 +403,11 @@ static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) goto fail_vfio; }trace_vfio_platform_start_level_irqfd_injection (intp->pin, -event_notifier_get_fd (intp->interrupt), -event_notifier_get_fd (intp->unmask)); +event_notifier_get_fd (intp->interrupt, false), +event_notifier_get_fd (intp->unmask, false)); }else {trace_vfio_platform_start_edge_irqfd_injection (intp->pin, -event_notifier_get_fd (intp->interrupt)); +event_notifier_get_fd (intp->interrupt, false)); } intp->kvm_accel = true;
hw/virtio/vhost.c +6 -4
@@ -1149,7 +1149,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, goto fail_alloc; } - file.fd =event_notifier_get_fd (virtio_queue_get_host_notifier (vvq)); + file.fd =event_notifier_get_fd (virtio_queue_get_host_notifier (vvq), false); r = dev->vhost_ops->vhost_set_vring_kick (dev, &file);if (r) {VHOST_OPS_DEBUG (r,"vhost_set_vring_kick failed" );
@@ -1287,7 +1287,7 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,return r; } - file.fd =event_notifier_get_fd (&vq->masked_notifier); + file.fd =event_notifier_get_fd (&vq->masked_notifier, true); r = dev->vhost_ops->vhost_set_vring_call (dev, &file);if (r) {VHOST_OPS_DEBUG (r,"vhost_set_vring_call failed" );
@@ -1542,9 +1542,11 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,if (mask) {assert (vdev->use_guest_notifier_mask); - file.fd =event_notifier_get_fd (&hdev->vqs[index].masked_notifier); + file.fd =event_notifier_get_fd (&hdev->vqs[index].masked_notifier, + true); }else { - file.fd =event_notifier_get_fd (virtio_queue_get_guest_notifier (vvq)); + file.fd =event_notifier_get_fd (virtio_queue_get_guest_notifier (vvq), + true); } file.index = hdev->vhost_ops->vhost_get_vq_index (hdev, n);
include/qemu/event_notifier.h +1 -1
@@ -37,7 +37,7 @@ int event_notifier_test_and_clear(EventNotifier *);#ifdef CONFIG_POSIX void event_notifier_init_fd (EventNotifier *,int fd); -int event_notifier_get_fd (const EventNotifier *); +int event_notifier_get_fd (const EventNotifier *,bool );#else HANDLE event_notifier_get_handle (EventNotifier *);#endif
target/s390x/kvm/kvm.c +1 -1
@@ -2019,7 +2019,7 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,struct kvm_ioeventfd kick = { .flags =KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY |KVM_IOEVENTFD_FLAG_DATAMATCH , - .fd =event_notifier_get_fd (notifier), + .fd =event_notifier_get_fd (notifier, false), .datamatch = vq, .addr = sch, .len =8 ,
util/aio-posix.c +2 -2
@@ -200,7 +200,7 @@ void aio_set_event_notifier(AioContext *ctx, AioPollFn *io_poll, EventNotifierHandler *io_poll_ready) { -aio_set_fd_handler (ctx,event_notifier_get_fd (notifier), is_external, +aio_set_fd_handler (ctx,event_notifier_get_fd (notifier, false), is_external, (IOHandler *)io_read,NULL , io_poll, (IOHandler *)io_poll_ready, notifier); }
@@ -210,7 +210,7 @@ void aio_set_event_notifier_poll(AioContext *ctx, EventNotifierHandler *io_poll_begin, EventNotifierHandler *io_poll_end) { -aio_set_fd_poll (ctx,event_notifier_get_fd (notifier), +aio_set_fd_poll (ctx,event_notifier_get_fd (notifier, false), (IOHandler *)io_poll_begin, (IOHandler *)io_poll_end); }
util/event_notifier-posix.c +4 -1
@@ -94,8 +94,11 @@ void event_notifier_cleanup(EventNotifier *e) e->initialized = false; } -int event_notifier_get_fd (const EventNotifier *e) +int event_notifier_get_fd (const EventNotifier *e,bool write) { +if (write) { +return e->wfd; + }return e->rfd; }
util/vfio-helpers.c +1 -1
@@ -221,7 +221,7 @@ int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotifier *e, .count = 1, }; - *(int *)&irq_set->data =event_notifier_get_fd (e); + *(int *)&irq_set->data =event_notifier_get_fd (e, false); r =ioctl (s->device,VFIO_DEVICE_SET_IRQS , irq_set);g_free (irq_set);if (r) {
Signature · 1 line
2.35.1
Re: [PATCH 1/2] Allow returning EventNotifier's wfd
Quoted 10 lines · On Wed, 2 Mar 2022 12:36:43 +0100 Sergio Lopez <[email protected]> wrote:
event_notifier_get_fd(const EventNotifier *e)always returns EventNotifier's read file descriptor (rfd). This is not a problem when the EventNotifier is backed by a an eventfd, as a single file descriptor is used both for reading and triggering events (rfd == wfd).But, when EventNotifier is backed by a pipefd, we have two file descriptors, one that can only be used for reads (rfd), and the other only for writes (wfd).
Quoted 6 lines
There's, at least, one known situation in which we need to obtain wfd instead of rfd, which is when setting up the file that's going to be sent to the peer in vhost's
SET_VRING_CALL.Extend
event_notifier_get_fd()to receive an argument which indicates whether the caller wants to obtain rfd (false) or wfd (true).
There are about 50 places where we add the false arg here and 1 where we use true. Seems it would save a lot of churn to hide this internally, event_notifier_get_fd() returns an rfd, a new event_notifier_get_wfd() returns the wfd. Thanks,
Alex
Re: [PATCH 1/2] Allow returning EventNotifier's wfd
Quoted 17 lines · Alex Williamson
Quoted 14 lines · On Wed, 2 Mar 2022 12:36:43 +0100 Sergio Lopez <[email protected]> wrote:
event_notifier_get_fd(const EventNotifier *e)always returns EventNotifier's read file descriptor (rfd). This is not a problem when the EventNotifier is backed by a an eventfd, as a single file descriptor is used both for reading and triggering events (rfd == wfd).But, when EventNotifier is backed by a pipefd, we have two file descriptors, one that can only be used for reads (rfd), and the other only for writes (wfd).
There's, at least, one known situation in which we need to obtain wfd instead of rfd, which is when setting up the file that's going to be sent to the peer in vhost's
SET_VRING_CALL.
Quoted 7 lines
Quoted 2 lines
Extend
event_notifier_get_fd()to receive an argument which indicates whether the caller wants to obtain rfd (false) or wfd (true).There are about 50 places where we add the false arg here and 1 where we use true. Seems it would save a lot of churn to hide this internally,
event_notifier_get_fd()returns an rfd, a newevent_notifier_get_wfd()returns the wfd. Thanks,
I agree. In fact, that's what I implemented in the first place. I changed to this version in which event_notifier_get_fd() is extended because it feels more "correct". But yes, the pragmatic option would be adding a new event_notifier_get_wfd().
I'll wait for more reviews, and unless someone voices against it, I'll respin the patches with that strategy (I already have it around here).
Thanks,
Sergio.
Re: [PATCH 1/2] Allow returning EventNotifier's wfd
Quoted 26 lines · On Wed, 2 Mar 2022 16:23:42 +0100 Sergio Lopez <[email protected]> wrote:
Quoted 17 lines · Alex Williamson
Quoted 14 lines · On Wed, 2 Mar 2022 12:36:43 +0100 Sergio Lopez <[email protected]> wrote:
event_notifier_get_fd(const EventNotifier *e)always returns EventNotifier's read file descriptor (rfd). This is not a problem when the EventNotifier is backed by a an eventfd, as a single file descriptor is used both for reading and triggering events (rfd == wfd).But, when EventNotifier is backed by a pipefd, we have two file descriptors, one that can only be used for reads (rfd), and the other only for writes (wfd).
There's, at least, one known situation in which we need to obtain wfd instead of rfd, which is when setting up the file that's going to be sent to the peer in vhost's
SET_VRING_CALL.Quoted 7 lines
Quoted 2 lines
Extend
event_notifier_get_fd()to receive an argument which indicates whether the caller wants to obtain rfd (false) or wfd (true).There are about 50 places where we add the false arg here and 1 where we use true. Seems it would save a lot of churn to hide this internally,
event_notifier_get_fd()returns an rfd, a newevent_notifier_get_wfd()returns the wfd. Thanks,
Quoted 7 lines
I agree. In fact, that's what I implemented in the first place. I changed to this version in which
event_notifier_get_fd()is extended because it feels more "correct". But yes, the pragmatic option would be adding a newevent_notifier_get_wfd().I'll wait for more reviews, and unless someone voices against it, I'll respin the patches with that strategy (I already have it around here).
I'd argue that adding a bool as an arg to a function to change the return value is sufficiently non-intuitive to program for that the wrapper method is actually more correct. event_notifier_get_fd() essentially becomes a shorthand for event_notifier_get_rfd(). Thanks,
Alex
Re: [PATCH 1/2] Allow returning EventNotifier's wfd
In reply to Sergio LopezQuoted 26 lines · Sergio Lopez
Quoted 17 lines · Alex Williamson
Quoted 14 lines · On Wed, 2 Mar 2022 12:36:43 +0100 Sergio Lopez <[email protected]> wrote:
event_notifier_get_fd(const EventNotifier *e)always returns EventNotifier's read file descriptor (rfd). This is not a problem when the EventNotifier is backed by a an eventfd, as a single file descriptor is used both for reading and triggering events (rfd == wfd).But, when EventNotifier is backed by a pipefd, we have two file descriptors, one that can only be used for reads (rfd), and the other only for writes (wfd).
There's, at least, one known situation in which we need to obtain wfd instead of rfd, which is when setting up the file that's going to be sent to the peer in vhost's
SET_VRING_CALL.Quoted 7 lines
Quoted 2 lines
Extend
event_notifier_get_fd()to receive an argument which indicates whether the caller wants to obtain rfd (false) or wfd (true).There are about 50 places where we add the false arg here and 1 where we use true. Seems it would save a lot of churn to hide this internally,
event_notifier_get_fd()returns an rfd, a newevent_notifier_get_wfd()returns the wfd. Thanks,
Quoted 7 lines
I agree. In fact, that's what I implemented in the first place. I changed to this version in which
event_notifier_get_fd()is extended because it feels more "correct". But yes, the pragmatic option would be adding a newevent_notifier_get_wfd().I'll wait for more reviews, and unless someone voices against it, I'll respin the patches with that strategy (I already have it around here).
I had the same thought looking through the patch before I read Alex's suggestion. A separate get_wfd() function makes sense to me.
Stefan
Paolo Bonzini
maintainerRe: [PATCH 1/2] Allow returning EventNotifier's wfd
Quoted 9 lines · Stefan Hajnoczi
Quoted 7 lines
I agree. In fact, that's what I implemented in the first place. I changed to this version in which
event_notifier_get_fd()is extended because it feels more "correct". But yes, the pragmatic option would be adding a newevent_notifier_get_wfd().I'll wait for more reviews, and unless someone voices against it, I'll respin the patches with that strategy (I already have it around here).
I had the same thought looking through the patch before I read Alex's suggestion. A separate
get_wfd()function makes sense to me.
And that's four with me. :) It's not just pragmatic, I cannot imagine a case where the caller doesn't know exactly which of the two file descriptors they want.
Paolo
PATCH 2/2 Allow building vhost-user in BSD
In reply to Sergio LopezWith the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
This change allows enabling vhost-user on BSD platforms too and makes libvhost_user (which still depends on eventfd) a linux-only feature.
--- configure | 5 +++-- meson.build | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
configure +3 -2
@@ -1659,8 +1659,9 @@ fi # vhost interdependencies and host support # vhost backends -if test "$vhost_user" = "yes" && test "$linux" != "yes"; then - error_exit "vhost-user is only available on Linux" +if test "$vhost_user" = "yes" && \ + test "$linux" != "yes" && test "$bsd" != "yes" ; then + error_exit "vhost-user is only available on Linux and BSD" fi test "$vhost_vdpa" = "" && vhost_vdpa=$linux if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
meson.build +1 -1
@@ -2701,7 +2701,7 @@ if have_system or have_user endif vhost_user = not_found -if 'CONFIG_VHOST_USER' in config_host +if targetos == 'linux' and 'CONFIG_VHOST_USER' in config_host libvhost_user = subproject('libvhost-user') vhost_user = libvhost_user.get_variable('vhost_user_dep') endif
Signature · 1 line
2.35.1
Paolo Bonzini
maintainerRe: [PATCH 2/2] Allow building vhost-user in BSD
Quoted 9 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>
I would just check for !windows.
Paolo
Quoted 34 lines
--- configure | 5 +++-- meson.build | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)configure +3
-2@@ -1659,8 +1659,9 @@ fi # vhost interdependencies and host support # vhost backends -if test "$vhost_user" = "yes" && test "$linux" != "yes"; then - error_exit "vhost-user is only available on Linux" +if test "$vhost_user" = "yes" && \ + test "$linux" != "yes" && test "$bsd" != "yes" ; then + error_exit "vhost-user is only available on Linux and BSD" fi test "$vhost_vdpa" = "" && vhost_vdpa=$linux if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; thenmeson.build +1
-1@@ -2701,7 +2701,7 @@ if have_system or have_user endif vhost_user = not_found -if 'CONFIG_VHOST_USER' in config_host +if targetos == 'linux' and 'CONFIG_VHOST_USER' in config_host libvhost_user = subproject('libvhost-user') vhost_user = libvhost_user.get_variable('vhost_user_dep') endif
Re: [PATCH 2/2] Allow building vhost-user in BSD
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
Quoted 7 lines
Quoted 5 lines
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>I would just check for !windows.
What about Darwin / Haiku / Illumnos?
Re: [PATCH 2/2] Allow building vhost-user in BSD
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Sergio Lopez <[email protected]>I would just check for !windows.
What about Darwin / Haiku / Illumnos?
It should work on every system providing pipe() or pipe2(), so I guess Paolo's right, every platform except Windows. FWIW, I already tested it with Darwin.
Thanks,
Sergio.
Re: [PATCH 2/2] Allow building vhost-user in BSD
Quoted 13 lines · Sergio Lopez
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
I would just check for !windows.
What about Darwin / Haiku / Illumnos?
It should work on every system providing
pipe()orpipe2(), so I guess Paolo's right, every platform except Windows. FWIW, I already tested it with Darwin.
Wow, nice.
So maybe simply check for pipe/pipe2 rather than !windows?
Re: [PATCH 2/2] Allow building vhost-user in BSD
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Sergio Lopez
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
Quoted 7 lines
Quoted 5 lines
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>I would just check for !windows.
What about Darwin / Haiku / Illumnos?
Quoted 8 lines
Quoted 3 lines
It should work on every system providing
pipe()orpipe2(), so I guess Paolo's right, every platform except Windows. FWIW, I already tested it with Darwin.Wow, nice.
So maybe simply check for pipe/pipe2 rather than !windows?
Is it worth it? In "configure", CONFIG_POSIX is set to "y" if the target isn't "mingw32", and CONFIG_POSIX brings "util/oslib-posix.c" into the build, which expects to have either pipe or pipe2.
Thanks,
Sergio.
Re: [PATCH 2/2] Allow building vhost-user in BSD
In reply to Philippe Mathieu-DaudéQuoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Sergio Lopez
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
Quoted 7 lines
Quoted 5 lines
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>I would just check for !windows.
What about Darwin / Haiku / Illumnos?
Quoted 7 lines
Quoted 3 lines
It should work on every system providing
pipe()orpipe2(), so I guess Paolo's right, every platform except Windows. FWIW, I already tested it with Darwin.Wow, nice.
So maybe simply check for pipe/pipe2 rather than !windows?
NB that would make the check more fragile.
We already use pipe/pipe2 without checking for it, because its usage is confined to oslib-posix.c and we know all POSIX OS have it. There is no impl at all of qemu_pipe in oslib-win.c and the declaration is masked out too in the header file.
Thus if we check for pipe2 and windows did ever implement it, then we would actually break the windows build due to qemu_pipe not existing.
IOW, checking !windows matches our logic for picking oslib-posix.c in builds and so is better than checking for pipe directly.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 2/2] Allow building vhost-user in BSD
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Sergio Lopez
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
Quoted 7 lines
Quoted 5 lines
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>I would just check for !windows.
What about Darwin / Haiku / Illumnos?
Quoted 7 lines
Quoted 3 lines
It should work on every system providing
pipe()orpipe2(), so I guess Paolo's right, every platform except Windows. FWIW, I already tested it with Darwin.Wow, nice.
So maybe simply check for pipe/pipe2 rather than !windows?
NB that would make the check more fragile.
We already use pipe/pipe2 without checking for it, because its usage is confined to
oslib-posix.cand we know all POSIX OS have it. There is no impl at all ofqemu_pipeinoslib-win.cand the declaration is masked out too in the header file.
Quoted 6 lines
Thus if we check for pipe2 and windows did ever implement it, then we would actually break the windows build due to
qemu_pipenot existing.IOW, checking !windows matches our logic for picking
oslib-posix.cin builds and so is better than checking for pipe directly.
OK I see, thanks.
Paolo Bonzini
maintainerRe: [PATCH 2/2] Allow building vhost-user in BSD
In reply to Philippe Mathieu-DaudéQuoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Sergio Lopez
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
Quoted 7 lines
Quoted 5 lines
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>I would just check for !windows.
What about Darwin / Haiku / Illumnos?
Quoted 7 lines
Quoted 3 lines
It should work on every system providing
pipe()orpipe2(), so I guess Paolo's right, every platform except Windows. FWIW, I already tested it with Darwin.Wow, nice.
So maybe simply check for pipe/pipe2 rather than !windows?
What you really need is not pipes, but AF_UNIX.
Paolo
Re: [PATCH 2/2] Allow building vhost-user in BSD
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Sergio Lopez
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Sergio Lopez
With the possibility of using pipefd as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on BSD systems.
This change allows enabling vhost-user on BSD platforms too and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Sergio Lopez <[email protected]>I would just check for !windows.
What about Darwin / Haiku / Illumnos?
It should work on every system providing
pipe()orpipe2(), so I guess Paolo's right, every platform except Windows. FWIW, I already tested it with Darwin.
Quoted 5 lines
Quoted 3 lines
Wow, nice.
So maybe simply check for pipe/pipe2 rather than !windows?
What you really need is not pipes, but
AF_UNIX.
Recent Windows has AF_UNIX so don't check for that ! What you really need is AF_UNIX and FD passing and pipes and probably more POSIX only features ...
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|