From patchwork Mon Oct 17 19:52:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 9380393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6C10E600CA for ; Mon, 17 Oct 2016 19:53:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59C4C2911B for ; Mon, 17 Oct 2016 19:53:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E6D72917A; Mon, 17 Oct 2016 19:53:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C8CFA2911B for ; Mon, 17 Oct 2016 19:53:10 +0000 (UTC) Received: from localhost ([::1]:35537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwDy9-0004V1-Mk for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Oct 2016 15:53:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwDxZ-0004RT-4U for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:52:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwDxY-00087T-4y for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:52:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwDxX-00086w-TC for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:52:32 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 229C885A07 for ; Mon, 17 Oct 2016 19:52:31 +0000 (UTC) Received: from gimli.home (ovpn-116-107.phx2.redhat.com [10.3.116.107]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9HJqUCx008478; Mon, 17 Oct 2016 15:52:30 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 17 Oct 2016 13:52:30 -0600 Message-ID: <20161017195227.17307.85151.stgit@gimli.home> In-Reply-To: <20161017194945.17307.78340.stgit@gimli.home> References: <20161017194945.17307.78340.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 17 Oct 2016 19:52:31 +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] [PULL 05/19] vfio/pci: Pass an error object to 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: Eric Auger , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Auger Pass an error object to prepare for migration to VFIO-PCI realize. The error object is propagated down to vfio_intx_enable_kvm(). The three other callers, vfio_intx_enable_kvm(), vfio_msi_disable_common() and vfio_pci_post_reset() do not propagate the error and simply call error_reportf_err() with the ERR_PREFIX formatting. Signed-off-by: Eric Auger Reviewed-by: Markus Armbruster Signed-off-by: Alex Williamson --- hw/vfio/pci.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 02e92b0..42161c8 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -100,7 +100,7 @@ static void vfio_intx_eoi(VFIODevice *vbasedev) vfio_unmask_single_irqindex(vbasedev, VFIO_PCI_INTX_IRQ_INDEX); } -static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev) +static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) { #ifdef CONFIG_KVM struct kvm_irqfd irqfd = { @@ -126,7 +126,7 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev) /* Get an eventfd for resample/unmask */ if (event_notifier_init(&vdev->intx.unmask, 0)) { - error_report("vfio: Error: event_notifier_init failed eoi"); + error_setg(errp, "event_notifier_init failed eoi"); goto fail; } @@ -134,7 +134,7 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev) irqfd.resamplefd = event_notifier_get_fd(&vdev->intx.unmask); if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) { - error_report("vfio: Error: Failed to setup resample irqfd: %m"); + error_setg_errno(errp, errno, "failed to setup resample irqfd"); goto fail_irqfd; } @@ -153,7 +153,7 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev) ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); g_free(irq_set); if (ret) { - error_report("vfio: Error: Failed to setup INTx unmask fd: %m"); + error_setg_errno(errp, -ret, "failed to setup INTx unmask fd"); goto fail_vfio; } @@ -222,6 +222,7 @@ static void vfio_intx_update(PCIDevice *pdev) { VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); PCIINTxRoute route; + Error *err = NULL; if (vdev->interrupt != VFIO_INT_INTx) { return; @@ -244,18 +245,22 @@ static void vfio_intx_update(PCIDevice *pdev) return; } - vfio_intx_enable_kvm(vdev); + vfio_intx_enable_kvm(vdev, &err); + if (err) { + error_reportf_err(err, WARN_PREFIX, vdev->vbasedev.name); + } /* Re-enable the interrupt in cased we missed an EOI */ vfio_intx_eoi(&vdev->vbasedev); } -static int vfio_intx_enable(VFIOPCIDevice *vdev) +static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) { uint8_t pin = vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1); int ret, argsz; struct vfio_irq_set *irq_set; int32_t *pfd; + Error *err = NULL; if (!pin) { return 0; @@ -279,7 +284,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev) ret = event_notifier_init(&vdev->intx.interrupt, 0); if (ret) { - error_report("vfio: Error: event_notifier_init failed"); + error_setg_errno(errp, -ret, "event_notifier_init failed"); return ret; } @@ -299,13 +304,16 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev) ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); g_free(irq_set); if (ret) { - error_report("vfio: Error: Failed to setup INTx fd: %m"); + error_setg_errno(errp, -ret, "failed to setup INTx fd"); qemu_set_fd_handler(*pfd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->intx.interrupt); return -errno; } - vfio_intx_enable_kvm(vdev); + vfio_intx_enable_kvm(vdev, &err); + if (err) { + error_reportf_err(err, WARN_PREFIX, vdev->vbasedev.name); + } vdev->interrupt = VFIO_INT_INTx; @@ -707,6 +715,7 @@ retry: static void vfio_msi_disable_common(VFIOPCIDevice *vdev) { + Error *err = NULL; int i; for (i = 0; i < vdev->nr_vectors; i++) { @@ -726,7 +735,10 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev) vdev->nr_vectors = 0; vdev->interrupt = VFIO_INT_NONE; - vfio_intx_enable(vdev); + vfio_intx_enable(vdev, &err); + if (err) { + error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name); + } } static void vfio_msix_disable(VFIOPCIDevice *vdev) @@ -1908,7 +1920,12 @@ static void vfio_pci_pre_reset(VFIOPCIDevice *vdev) static void vfio_pci_post_reset(VFIOPCIDevice *vdev) { - vfio_intx_enable(vdev); + Error *err = NULL; + + vfio_intx_enable(vdev, &err); + if (err) { + error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name); + } } static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name) @@ -2724,7 +2741,7 @@ static int vfio_initfn(PCIDevice *pdev) 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); + ret = vfio_intx_enable(vdev, &err); if (ret) { goto out_teardown; }