From nobody Sat May 18 04:13:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646225714203794.29466176448; Wed, 2 Mar 2022 04:55:14 -0800 (PST) Received: from localhost ([::1]:35478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPOVb-0003Jc-Vh for importer@patchew.org; Wed, 02 Mar 2022 07:55:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPNJ4-0002IT-RW for qemu-devel@nongnu.org; Wed, 02 Mar 2022 06:38:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34534) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPNJ0-0004Sk-8X for qemu-devel@nongnu.org; Wed, 02 Mar 2022 06:38:10 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-502-vBGggTztN5OCEgHnwx1IWw-1; Wed, 02 Mar 2022 06:36:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9ECB1006AA6; Wed, 2 Mar 2022 11:36:35 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3A2783091; Wed, 2 Mar 2022 11:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646221085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fsI0rd1+/yhpewL+McPGbxUkLwktmCIIJADEjYF8A7o=; b=Nv/PGtu7PR1KKWCKsc4FwtkoEoW0aFOTgPssnoYg9BwPW9xBGfNEpHdKF5rD0TAZ7wGTlq 11ZVmlrS+9jqhwwfg0/68pSBVzYOHtNdhxdMiXheMiLoIjB3bP1Zo7IXGWHb6iMGOz5Bwy emnnAMk3jFCM5kij68VCHy1enBPnM3A= X-MC-Unique: vBGggTztN5OCEgHnwx1IWw-1 From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH 1/2] Allow returning EventNotifier's wfd Date: Wed, 2 Mar 2022 12:36:43 +0100 Message-Id: <20220302113644.43717-2-slp@redhat.com> In-Reply-To: <20220302113644.43717-1-slp@redhat.com> References: <20220302113644.43717-1-slp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=slp@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Elena Ufimtseva , kvm@vger.kernel.org, John G Johnson , David Hildenbrand , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jagannathan Raman , Matthew Rosato , qemu-block@nongnu.org, "Michael S. Tsirkin" , Halil Pasic , Christian Borntraeger , vgoyal@redhat.com, Eric Farman , Sergio Lopez , Richard Henderson , qemu-s390x@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Cornelia Huck , Alex Williamson , Hanna Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646225716881100001 Content-Type: text/plain; charset="utf-8" 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 =3D=3D 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). Signed-off-by: Sergio Lopez --- 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(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 0e66ebb497..c84ee98b17 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1573,7 +1573,7 @@ static void kvm_mem_ioeventfd_add(MemoryListener *lis= tener, bool match_data, uint64_t data, EventNotifier *e) { - int fd =3D event_notifier_get_fd(e); + int fd =3D event_notifier_get_fd(e, false); int r; =20 r =3D kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space, @@ -1591,7 +1591,7 @@ static void kvm_mem_ioeventfd_del(MemoryListener *lis= tener, bool match_data, uint64_t data, EventNotifier *e) { - int fd =3D event_notifier_get_fd(e); + int fd =3D event_notifier_get_fd(e, false); int r; =20 r =3D kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space, @@ -1609,7 +1609,7 @@ static void kvm_io_ioeventfd_add(MemoryListener *list= ener, bool match_data, uint64_t data, EventNotifier *e) { - int fd =3D event_notifier_get_fd(e); + int fd =3D event_notifier_get_fd(e, false); int r; =20 r =3D kvm_set_ioeventfd_pio(fd, section->offset_within_address_space, @@ -1628,7 +1628,7 @@ static void kvm_io_ioeventfd_del(MemoryListener *list= ener, EventNotifier *e) =20 { - int fd =3D event_notifier_get_fd(e); + int fd =3D event_notifier_get_fd(e, false); int r; =20 r =3D kvm_set_ioeventfd_pio(fd, section->offset_within_address_space, @@ -2045,8 +2045,8 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, Even= tNotifier *event, EventNotifier *resample, int virq, bool assign) { - int fd =3D event_notifier_get_fd(event); - int rfd =3D resample ? event_notifier_get_fd(resample) : -1; + int fd =3D event_notifier_get_fd(event, false); + int rfd =3D resample ? event_notifier_get_fd(resample, false) : -1; =20 struct kvm_irqfd irqfd =3D { .fd =3D fd, diff --git a/block/linux-aio.c b/block/linux-aio.c index 4c423fcccf..6068353528 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -390,7 +390,7 @@ static int laio_do_submit(int fd, struct qemu_laiocb *l= aiocb, 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)); =20 QSIMPLEQ_INSERT_TAIL(&s->io_q.pending, laiocb, next); s->io_q.in_queue++; diff --git a/block/nvme.c b/block/nvme.c index dd20de3865..851c552a4f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -229,7 +229,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *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, fa= lse)); bytes =3D QEMU_ALIGN_UP(s->page_size * NVME_NUM_REQS, qemu_real_host_page_size); q->prp_list_pages =3D qemu_try_memalign(qemu_real_host_page_size, byte= s); diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-serv= er/ivshmem-server.c index 39a6ffdb5d..90f2e46ada 100644 --- a/contrib/ivshmem-server/ivshmem-server.c +++ b/contrib/ivshmem-server/ivshmem-server.c @@ -204,7 +204,8 @@ ivshmem_server_handle_new_conn(IvshmemServer *server) /* advertise the new peer to itself */ for (i =3D 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)); } =20 QTAILQ_INSERT_TAIL(&server->peer_list, peer, next); @@ -456,7 +457,7 @@ ivshmem_server_dump(const IvshmemServer *server) =20 for (vector =3D 0; vector < peer->vectors_count; vector++) { printf(" vector %d is enabled (fd=3D%d)\n", vector, - event_notifier_get_fd(&peer->vectors[vector])); + event_notifier_get_fd(&peer->vectors[vector], false)); } } } diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index cb1074f234..8a59b4bd0d 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -616,7 +616,7 @@ int hyperv_set_event_flag_handler(uint32_t conn_id, Eve= ntNotifier *notifier) if (!process_event_flags_userspace) { struct kvm_hyperv_eventfd hvevfd =3D { .conn_id =3D conn_id, - .fd =3D notifier ? event_notifier_get_fd(notifier) : -1, + .fd =3D notifier ? event_notifier_get_fd(notifier, false) : -1, .flags =3D notifier ? 0 : KVM_HYPERV_EVENTFD_DEASSIGN, }; =20 diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 299837e5c1..f68701ac5c 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -351,7 +351,7 @@ static void ivshmem_vector_poll(PCIDevice *dev, static void watch_vector_notifier(IVShmemState *s, EventNotifier *n, int vector) { - int eventfd =3D event_notifier_get_fd(n); + int eventfd =3D event_notifier_get_fd(n, false); =20 assert(!s->msi_vectors[vector].pdev); s->msi_vectors[vector].pdev =3D PCI_DEVICE(s); diff --git a/hw/remote/iohub.c b/hw/remote/iohub.c index 547d597f0f..4c6cafbebf 100644 --- a/hw/remote/iohub.c +++ b/hw/remote/iohub.c @@ -37,10 +37,11 @@ void remote_iohub_init(RemoteIOHubState *iohub) void remote_iohub_finalize(RemoteIOHubState *iohub) { int pirq; + int fd; =20 for (pirq =3D 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) { - qemu_set_fd_handler(event_notifier_get_fd(&iohub->resamplefds[pirq= ]), - NULL, NULL, NULL); + fd =3D 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, MPQemuMs= g *msg) { RemoteMachineState *machine =3D REMOTE_MACHINE(current_machine); RemoteIOHubState *iohub =3D &machine->iohub; - int pirq, intx; + int pirq, intx, fd; =20 intx =3D pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; =20 pirq =3D remote_iohub_map_irq(pci_dev, intx); =20 - if (event_notifier_get_fd(&iohub->irqfds[pirq]) !=3D -1) { - qemu_set_fd_handler(event_notifier_get_fd(&iohub->resamplefds[pirq= ]), - NULL, NULL, NULL); + if (event_notifier_get_fd(&iohub->irqfds[pirq], false) !=3D -1) { + fd =3D 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)); diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index bad164299d..9935e5a778 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -61,8 +61,8 @@ static void setup_irqfd(PCIProxyDev *dev) memset(&msg, 0, sizeof(MPQemuMsg)); msg.cmd =3D MPQEMU_CMD_SET_IRQFD; msg.num_fds =3D 2; - msg.fds[0] =3D event_notifier_get_fd(&dev->intr); - msg.fds[1] =3D event_notifier_get_fd(&dev->resample); + msg.fds[0] =3D event_notifier_get_fd(&dev->intr, false); + msg.fds[1] =3D event_notifier_get_fd(&dev->resample, false); msg.size =3D 0; =20 if (!mpqemu_msg_send(&msg, dev->ioc, &local_err)) { diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 0354737666..0c7531dc9c 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -437,7 +437,7 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevic= e *vcdev, goto out_free_info; } =20 - fd =3D event_notifier_get_fd(notifier); + fd =3D event_notifier_get_fd(notifier, false); qemu_set_fd_handler(fd, fd_read, NULL, vcdev); =20 if (vfio_set_irq_signaling(vdev, irq, 0, @@ -476,7 +476,7 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDev= ice *vcdev, warn_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name); } =20 - 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); } diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 0cf69a8c6d..b9afbfe445 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -309,7 +309,7 @@ static void vfio_ioeventfd_exit(VFIOPCIDevice *vdev, VF= IOIOEventFD *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); } =20 @@ -387,14 +387,14 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevi= ce *vdev, vfio_ioeventfd.data =3D ioeventfd->data; vfio_ioeventfd.offset =3D ioeventfd->region->fd_offset + ioeventfd->region_addr; - vfio_ioeventfd.fd =3D event_notifier_get_fd(&ioeventfd->e); + vfio_ioeventfd.fd =3D event_notifier_get_fd(&ioeventfd->e, false); =20 ioeventfd->vfio =3D !ioctl(vdev->vbasedev.fd, VFIO_DEVICE_IOEVENTFD, &vfio_ioeventfd); } =20 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); } =20 diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 7b45353ce2..04f2d455b2 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -113,7 +113,7 @@ static void vfio_intx_eoi(VFIODevice *vbasedev) static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) { #ifdef CONFIG_KVM - int irq_fd =3D event_notifier_get_fd(&vdev->intx.interrupt); + int irq_fd =3D event_notifier_get_fd(&vdev->intx.interrupt, false); =20 if (vdev->no_kvm_intx || !kvm_irqfds_enabled() || vdev->intx.route.mode !=3D PCI_INTX_ENABLED || @@ -143,7 +143,7 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, E= rror **errp) =20 if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0, VFIO_IRQ_SET_ACTION_UNMASK, - event_notifier_get_fd(&vdev->intx.unmask), + event_notifier_get_fd(&vdev->intx.unmask, f= alse), errp)) { goto fail_vfio; } @@ -193,7 +193,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) event_notifier_cleanup(&vdev->intx.unmask); =20 /* QEMU starts listening for interrupt events. */ - qemu_set_fd_handler(event_notifier_get_fd(&vdev->intx.interrupt), + qemu_set_fd_handler(event_notifier_get_fd(&vdev->intx.interrupt, false= ), vfio_intx_interrupt, NULL, vdev); =20 vdev->intx.kvm_accel =3D false; @@ -286,7 +286,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) error_setg_errno(errp, -ret, "event_notifier_init failed"); return ret; } - fd =3D event_notifier_get_fd(&vdev->intx.interrupt); + fd =3D event_notifier_get_fd(&vdev->intx.interrupt, false); qemu_set_fd_handler(fd, vfio_intx_interrupt, NULL, vdev); =20 if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0, @@ -318,7 +318,7 @@ static void vfio_intx_disable(VFIOPCIDevice *vdev) pci_irq_deassert(&vdev->pdev); vfio_mmap_set_enabled(vdev, true); =20 - fd =3D event_notifier_get_fd(&vdev->intx.interrupt); + fd =3D event_notifier_get_fd(&vdev->intx.interrupt, false); qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->intx.interrupt); =20 @@ -393,9 +393,11 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bo= ol msix) if (vdev->msi_vectors[i].use) { if (vdev->msi_vectors[i].virq < 0 || (msix && msix_is_masked(&vdev->pdev, i))) { - fd =3D event_notifier_get_fd(&vdev->msi_vectors[i].interru= pt); + fd =3D event_notifier_get_fd(&vdev->msi_vectors[i].interru= pt, + false); } else { - fd =3D event_notifier_get_fd(&vdev->msi_vectors[i].kvm_int= errupt); + fd =3D event_notifier_get_fd(&vdev->msi_vectors[i].kvm_int= errupt, + false); } } =20 @@ -475,7 +477,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, msix_vector_use(pdev, nr); } =20 - qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), + qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt, false), handler, NULL, vector); =20 /* @@ -511,9 +513,9 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, int32_t fd; =20 if (vector->virq >=3D 0) { - fd =3D event_notifier_get_fd(&vector->kvm_interrupt); + fd =3D event_notifier_get_fd(&vector->kvm_interrupt, false); } else { - fd =3D event_notifier_get_fd(&vector->interrupt); + fd =3D event_notifier_get_fd(&vector->interrupt, false); } =20 if (vfio_set_irq_signaling(&vdev->vbasedev, @@ -556,7 +558,7 @@ static void vfio_msix_vector_release(PCIDevice *pdev, u= nsigned int nr) * be re-asserted on unmask. Nothing to do if already using QEMU mode. */ if (vector->virq >=3D 0) { - int32_t fd =3D event_notifier_get_fd(&vector->interrupt); + int32_t fd =3D event_notifier_get_fd(&vector->interrupt, false); Error *err =3D NULL; =20 if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDE= X, nr, @@ -614,7 +616,7 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev) =20 static void vfio_msi_enable(VFIOPCIDevice *vdev) { - int ret, i; + int ret, i, fd; =20 vfio_disable_interrupts(vdev); =20 @@ -633,8 +635,8 @@ retry: error_report("vfio: Error: event_notifier_init failed"); } =20 - qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), - vfio_msi_interrupt, NULL, vector); + fd =3D event_notifier_get_fd(&vector->interrupt, false); + qemu_set_fd_handler(fd, vfio_msi_interrupt, NULL, vector); =20 /* * Attempt to enable route through KVM irqchip, @@ -660,8 +662,8 @@ retry: if (vector->virq >=3D 0) { vfio_remove_kvm_msi_virq(vector); } - qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), - NULL, NULL, NULL); + fd =3D event_notifier_get_fd(&vector->interrupt, false); + qemu_set_fd_handler(fd, NULL, NULL, NULL); event_notifier_cleanup(&vector->interrupt); } =20 @@ -691,7 +693,7 @@ retry: static void vfio_msi_disable_common(VFIOPCIDevice *vdev) { Error *err =3D NULL; - int i; + int i, fd; =20 for (i =3D 0; i < vdev->nr_vectors; i++) { VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; @@ -699,8 +701,8 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev) if (vector->virq >=3D 0) { vfio_remove_kvm_msi_virq(vector); } - qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), - NULL, NULL, NULL); + fd =3D event_notifier_get_fd(&vector->interrupt, false); + qemu_set_fd_handler(fd, NULL, NULL, NULL); event_notifier_cleanup(&vector->interrupt); } } @@ -2700,7 +2702,7 @@ static void vfio_register_err_notifier(VFIOPCIDevice = *vdev) return; } =20 - fd =3D event_notifier_get_fd(&vdev->err_notifier); + fd =3D event_notifier_get_fd(&vdev->err_notifier, false); qemu_set_fd_handler(fd, vfio_err_notifier_handler, NULL, vdev); =20 if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, @@ -2724,7 +2726,7 @@ static void vfio_unregister_err_notifier(VFIOPCIDevic= e *vdev) VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } - qemu_set_fd_handler(event_notifier_get_fd(&vdev->err_notifier), + qemu_set_fd_handler(event_notifier_get_fd(&vdev->err_notifier, false), NULL, NULL, vdev); event_notifier_cleanup(&vdev->err_notifier); } @@ -2765,7 +2767,7 @@ static void vfio_register_req_notifier(VFIOPCIDevice = *vdev) return; } =20 - fd =3D event_notifier_get_fd(&vdev->req_notifier); + fd =3D event_notifier_get_fd(&vdev->req_notifier, false); qemu_set_fd_handler(fd, vfio_req_notifier_handler, NULL, vdev); =20 if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, @@ -2790,7 +2792,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevic= e *vdev) VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } - qemu_set_fd_handler(event_notifier_get_fd(&vdev->req_notifier), + qemu_set_fd_handler(event_notifier_get_fd(&vdev->req_notifier, false), NULL, NULL, vdev); event_notifier_cleanup(&vdev->req_notifier); =20 diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index f8f08a0f36..0db2870140 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -111,7 +111,7 @@ static int vfio_set_trigger_eventfd(VFIOINTp *intp, eventfd_user_side_handler_t handler) { VFIODevice *vbasedev =3D &intp->vdev->vbasedev; - int32_t fd =3D event_notifier_get_fd(intp->interrupt); + int32_t fd =3D event_notifier_get_fd(intp->interrupt, false); Error *err =3D NULL; int ret; =20 @@ -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= )); =20 intp->state =3D VFIO_IRQ_ACTIVE; =20 @@ -244,7 +244,7 @@ static void vfio_intp_interrupt(VFIOINTp *intp) ret =3D event_notifier_test_and_clear(intp->interrupt); if (!ret) { error_report("Error when clearing fd=3D%d (ret =3D %d)", - event_notifier_get_fd(intp->interrupt), ret); + event_notifier_get_fd(intp->interrupt, false), ret); } =20 intp->state =3D VFIO_IRQ_ACTIVE; @@ -291,7 +291,7 @@ static void vfio_platform_eoi(VFIODevice *vbasedev) QLIST_FOREACH(intp, &vdev->intp_list, next) { if (intp->state =3D=3D VFIO_IRQ_ACTIVE) { trace_vfio_platform_eoi(intp->pin, - event_notifier_get_fd(intp->interrupt)); + event_notifier_get_fd(intp->interrupt, fal= se)); intp->state =3D VFIO_IRQ_INACTIVE; =20 /* 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 =3D event_notifier_get_fd(intp->unmask); + int32_t fd =3D event_notifier_get_fd(intp->unmask, false); VFIODevice *vbasedev =3D &intp->vdev->vbasedev; Error *err =3D 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, fa= lse), + 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, fa= lse)); } =20 intp->kvm_accel =3D true; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 7b03efccec..dc49ff7984 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1149,7 +1149,7 @@ static int vhost_virtqueue_start(struct vhost_dev *de= v, goto fail_alloc; } =20 - file.fd =3D event_notifier_get_fd(virtio_queue_get_host_notifier(vvq)); + file.fd =3D event_notifier_get_fd(virtio_queue_get_host_notifier(vvq),= false); r =3D 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; } =20 - file.fd =3D event_notifier_get_fd(&vq->masked_notifier); + file.fd =3D event_notifier_get_fd(&vq->masked_notifier, true); r =3D 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, Vi= rtIODevice *vdev, int n, =20 if (mask) { assert(vdev->use_guest_notifier_mask); - file.fd =3D event_notifier_get_fd(&hdev->vqs[index].masked_notifie= r); + file.fd =3D event_notifier_get_fd(&hdev->vqs[index].masked_notifie= r, + true); } else { - file.fd =3D event_notifier_get_fd(virtio_queue_get_guest_notifier(= vvq)); + file.fd =3D event_notifier_get_fd(virtio_queue_get_guest_notifier(= vvq), + true); } =20 file.index =3D hdev->vhost_ops->vhost_get_vq_index(hdev, n); diff --git a/include/qemu/event_notifier.h b/include/qemu/event_notifier.h index b79add035d..3b3f9c86bd 100644 --- a/include/qemu/event_notifier.h +++ b/include/qemu/event_notifier.h @@ -37,7 +37,7 @@ int event_notifier_test_and_clear(EventNotifier *); =20 #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 diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 6acf14d5ec..c773df906b 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -2019,7 +2019,7 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *no= tifier, uint32_t sch, struct kvm_ioeventfd kick =3D { .flags =3D KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY | KVM_IOEVENTFD_FLAG_DATAMATCH, - .fd =3D event_notifier_get_fd(notifier), + .fd =3D event_notifier_get_fd(notifier, false), .datamatch =3D vq, .addr =3D sch, .len =3D 8, diff --git a/util/aio-posix.c b/util/aio-posix.c index 7b9f629218..8d9c2b00b3 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -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_ext= ernal, (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); } diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c index 8307013c5d..695ec8e2bf 100644 --- a/util/event_notifier-posix.c +++ b/util/event_notifier-posix.c @@ -94,8 +94,11 @@ void event_notifier_cleanup(EventNotifier *e) e->initialized =3D false; } =20 -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; } =20 diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 00a80431a0..c3f89c5512 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -221,7 +221,7 @@ int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotif= ier *e, .count =3D 1, }; =20 - *(int *)&irq_set->data =3D event_notifier_get_fd(e); + *(int *)&irq_set->data =3D event_notifier_get_fd(e, false); r =3D ioctl(s->device, VFIO_DEVICE_SET_IRQS, irq_set); g_free(irq_set); if (r) { --=20 2.35.1 From nobody Sat May 18 04:13:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646227694253566.6152934597665; Wed, 2 Mar 2022 05:28:14 -0800 (PST) Received: from localhost ([::1]:35166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPP1Z-0003P0-MX for importer@patchew.org; Wed, 02 Mar 2022 08:28:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPNJ2-00029x-8k for qemu-devel@nongnu.org; Wed, 02 Mar 2022 06:38:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36523) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPNIz-0004S6-Eo for qemu-devel@nongnu.org; Wed, 02 Mar 2022 06:38:07 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-356-ENLXuy0lNkq7HsTh9kSKhw-1; Wed, 02 Mar 2022 06:36:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3ACA5801AAD; Wed, 2 Mar 2022 11:36:41 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38AE783286; Wed, 2 Mar 2022 11:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646221084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qb9pfajxXaiGyktL+dfrQe0s0K4x9B79EqLml1X3lZo=; b=X74eOF/0K8XVKHDDtv6oM5EvxEL7Tq04clXI1hITgzsbykaf/fKSVPj+HK09XWi6dx9NLE JzePzgF4EAZP+PPMqoyyxpTnERrda32a60kXpF0JqilEGY+sdEZvUc2nTzwPhl7tT/5o1t xsAIgeqEWvP+1EfQr5RhTwrP5laTdiI= X-MC-Unique: ENLXuy0lNkq7HsTh9kSKhw-1 From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH 2/2] Allow building vhost-user in BSD Date: Wed, 2 Mar 2022 12:36:44 +0100 Message-Id: <20220302113644.43717-3-slp@redhat.com> In-Reply-To: <20220302113644.43717-1-slp@redhat.com> References: <20220302113644.43717-1-slp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=slp@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Elena Ufimtseva , kvm@vger.kernel.org, John G Johnson , David Hildenbrand , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jagannathan Raman , Matthew Rosato , qemu-block@nongnu.org, "Michael S. Tsirkin" , Halil Pasic , Christian Borntraeger , vgoyal@redhat.com, Eric Farman , Sergio Lopez , Richard Henderson , qemu-s390x@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Cornelia Huck , Alex Williamson , Hanna Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646227704312100001 Content-Type: text/plain; charset="utf-8" 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 --- configure | 5 +++-- meson.build | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/configure b/configure index c56ed53ee3..93aa22e345 100755 --- a/configure +++ b/configure @@ -1659,8 +1659,9 @@ fi # vhost interdependencies and host support =20 # vhost backends -if test "$vhost_user" =3D "yes" && test "$linux" !=3D "yes"; then - error_exit "vhost-user is only available on Linux" +if test "$vhost_user" =3D "yes" && \ + test "$linux" !=3D "yes" && test "$bsd" !=3D "yes" ; then + error_exit "vhost-user is only available on Linux and BSD" fi test "$vhost_vdpa" =3D "" && vhost_vdpa=3D$linux if test "$vhost_vdpa" =3D "yes" && test "$linux" !=3D "yes"; then diff --git a/meson.build b/meson.build index 8df40bfac4..f2bc439c30 100644 --- a/meson.build +++ b/meson.build @@ -2701,7 +2701,7 @@ if have_system or have_user endif =20 vhost_user =3D not_found -if 'CONFIG_VHOST_USER' in config_host +if targetos =3D=3D 'linux' and 'CONFIG_VHOST_USER' in config_host libvhost_user =3D subproject('libvhost-user') vhost_user =3D libvhost_user.get_variable('vhost_user_dep') endif --=20 2.35.1