From patchwork Thu Jan 17 21:06:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 1027000 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43gc940Grsz9s9G for ; Fri, 18 Jan 2019 08:07:35 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkEsv-0004y7-Qh for incoming@patchwork.ozlabs.org; Thu, 17 Jan 2019 16:07:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkEsQ-0004uq-Vm for qemu-devel@nongnu.org; Thu, 17 Jan 2019 16:07:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkEsP-0007Nx-7C for qemu-devel@nongnu.org; Thu, 17 Jan 2019 16:07:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55152) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkEsO-0007IV-5O for qemu-devel@nongnu.org; Thu, 17 Jan 2019 16:07:01 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DD4689AF7; Thu, 17 Jan 2019 21:06:50 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-183.ams2.redhat.com [10.36.116.183]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D0F6600C0; Thu, 17 Jan 2019 21:06:48 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, alex.williamson@redhat.com Date: Thu, 17 Jan 2019 22:06:32 +0100 Message-Id: <20190117210632.18567-3-eric.auger@redhat.com> In-Reply-To: <20190117210632.18567-1-eric.auger@redhat.com> References: <20190117210632.18567-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 17 Jan 2019 21:06:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/2] vfio-pci: Use vfio_set_event_handler in vfio_intx_enable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, cohuck@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" vfio_set_event_handler() can be used in vfio_intx_enable() to set the signalling associated with VFIO_PCI_INTX_IRQ_INDEX. We also turn vfio_intx_enable() into a void function. Signed-off-by: Eric Auger --- vfio_set_event_handler cannot be used in vfio_intx_disable. The reason is not a call sequence issue but the VFIO_DEVICE_SET_IRQS invoction. vfio_disable_irqindex uses ACTION_TRIGGER/DATA_NONE/count==0 whereas the new helper uses ACTION_TRIGGER/DATA_EVENTFD/fd==-1. Surprisingly to me, both are not resulting into the same kernel actions. The first one does a complete tear down of the INTx (vfio_intx_disable), while the second - just taking care of a single index, the only one by the way for INTx -, does an incomplete tear down (vfio_intx_set_signal). If the last one is used, a subsequent setup of MSIx vectors fails. v1 -> v2: - turn vfio_intx_enable into a void function - s/vfio_intx_enable_kvm/vfio_intx_enable in title and commit msg --- hw/vfio/pci.c | 51 +++++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 3cae4c99ef..dcba7a1539 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -136,6 +136,9 @@ static void vfio_set_event_handler(VFIOPCIDevice *vdev, case VFIO_PCI_ERR_IRQ_INDEX: notifier = &vdev->err_notifier; break; + case VFIO_PCI_INTX_IRQ_INDEX: + notifier = &vdev->intx.interrupt; + break; default: g_assert_not_reached(); } @@ -349,16 +352,13 @@ static void vfio_intx_update(PCIDevice *pdev) vfio_intx_eoi(&vdev->vbasedev); } -static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) +static void vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) { uint8_t pin = vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1); - int ret, argsz, retval = 0; - struct vfio_irq_set *irq_set; - int32_t *pfd; Error *err = NULL; if (!pin) { - return 0; + return; } vfio_disable_interrupts(vdev); @@ -377,32 +377,11 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) } #endif - ret = event_notifier_init(&vdev->intx.interrupt, 0); - if (ret) { - error_setg_errno(errp, -ret, "event_notifier_init failed"); - return ret; - } - - argsz = sizeof(*irq_set) + sizeof(*pfd); - - irq_set = g_malloc0(argsz); - irq_set->argsz = argsz; - irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER; - irq_set->index = VFIO_PCI_INTX_IRQ_INDEX; - irq_set->start = 0; - irq_set->count = 1; - pfd = (int32_t *)&irq_set->data; - - *pfd = event_notifier_get_fd(&vdev->intx.interrupt); - qemu_set_fd_handler(*pfd, vfio_intx_interrupt, NULL, vdev); - - ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); - if (ret) { - error_setg_errno(errp, -ret, "failed to setup INTx fd"); - qemu_set_fd_handler(*pfd, NULL, NULL, vdev); - event_notifier_cleanup(&vdev->intx.interrupt); - retval = -errno; - goto cleanup; + vfio_set_event_handler(vdev, VFIO_PCI_INTX_IRQ_INDEX, true, + vfio_intx_interrupt, &err); + if (err) { + error_propagate(errp, err); + return; } vfio_intx_enable_kvm(vdev, &err); @@ -413,11 +392,6 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) vdev->interrupt = VFIO_INT_INTx; trace_vfio_intx_enable(vdev->vbasedev.name); - -cleanup: - g_free(irq_set); - - return retval; } static void vfio_intx_disable(VFIOPCIDevice *vdev) @@ -2982,8 +2956,9 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, vfio_intx_mmap_enable, vdev); pci_device_set_intx_routing_notifier(&vdev->pdev, vfio_intx_update); - ret = vfio_intx_enable(vdev, errp); - if (ret) { + vfio_intx_enable(vdev, &err); + if (err) { + error_propagate(errp, err); goto out_teardown; } }