From patchwork Wed Oct 7 15:42:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 54597 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 7E9AF22FF8 for ; Wed, 7 Oct 2015 15:50:16 +0000 (UTC) Received: by lbwr8 with SMTP id r8sf9186924lbw.0 for ; Wed, 07 Oct 2015 08:50:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=X2VybvOq51vJ+D9N3CDSt49gp/0thF0J2YHzRsNzZQY=; b=F3iXdhm4JM1HLNTY6NCwufxEv1SEg5AX5DoGBQT76FJox7WggpkWwAPzDGGecdMCc1 njgVu0Uj0bQM622+NDpPa/lnCqN8V0Rj8hcM5YshqU5MGKu+x/awifGU01ZDad6M+1Ax w88slK0JD1tVKCIz2Ue4zaz+uQ2KQQDLuWbeO+o5sW9NlG1VkjWhhvvXqeyYtroQAG0U InvzE+lEfKGFCAmWmawMiTYXtdCD35ET/y9BWP9dxVICwIos0mTw0tenTLPZqiFSquDc cwPIEpQBjmy4R0OuuWZnWLBt6+HHwIb7Y/0XHEIYmXWUo0Qk6LNCeIirJN24NGaHm89c ggXA== X-Gm-Message-State: ALoCoQmOAtu+KkbWOoGHc8amkr3HhwtxQvTr10vPgEPXQR/vBu8GPHRR33w5r9owkvFcVbFxu8uC X-Received: by 10.180.105.98 with SMTP id gl2mr5006091wib.0.1444233015504; Wed, 07 Oct 2015 08:50:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.163.73 with SMTP id m70ls85919lfe.39.gmail; Wed, 07 Oct 2015 08:50:15 -0700 (PDT) X-Received: by 10.25.161.136 with SMTP id k130mr657992lfe.25.1444233015311; Wed, 07 Oct 2015 08:50:15 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id j9si11485079lbc.171.2015.10.07.08.50.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Oct 2015 08:50:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbos8 with SMTP id s8so16195310lbo.0 for ; Wed, 07 Oct 2015 08:50:15 -0700 (PDT) X-Received: by 10.25.28.73 with SMTP id c70mr559453lfc.76.1444233015185; Wed, 07 Oct 2015 08:50:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp61757lbq; Wed, 7 Oct 2015 08:50:13 -0700 (PDT) X-Received: by 10.55.203.144 with SMTP id u16mr2193815qkl.36.1444233013750; Wed, 07 Oct 2015 08:50:13 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o65si34808459qki.3.2015.10.07.08.50.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 07 Oct 2015 08:50:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:58282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zjqt4-0001K8-Tr for patch@linaro.org; Wed, 07 Oct 2015 11:44:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zjqrs-0000R2-ON for qemu-devel@nongnu.org; Wed, 07 Oct 2015 11:43:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zjqrr-0006IO-Ed for qemu-devel@nongnu.org; Wed, 07 Oct 2015 11:43:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zjqrr-0006IH-6n for qemu-devel@nongnu.org; Wed, 07 Oct 2015 11:42:59 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id CFDDE345AB9; Wed, 7 Oct 2015 15:42:58 +0000 (UTC) Received: from gimli.home (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t97Fgw1n028244; Wed, 7 Oct 2015 11:42:58 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Wed, 07 Oct 2015 09:42:58 -0600 Message-ID: <20151007154257.22135.75088.stgit@gimli.home> In-Reply-To: <20151007153840.22135.78451.stgit@gimli.home> References: <20151007153840.22135.78451.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Eric Auger Subject: [Qemu-devel] [PULL 1/9] hw/vfio/platform: irqfd setup sequence update X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.williamson@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Eric Auger With current implementation, eventfd VFIO signaling is first set up and then irqfd is setup, if supported and allowed. This start sequence causes several issues with IRQ forwarding setup which, if supported, is transparently attempted on irqfd setup: IRQ forwarding setup is likely to fail if the IRQ is detected as under injection into the guest (active at irqchip level or VFIO masked). This currently always happens because the current sequence explicitly VFIO-masks the IRQ before setting irqfd. Even if that masking were removed, we couldn't prevent the case where the IRQ is under injection into the guest. So the simpler solution is to remove this 2-step startup and directly attempt irqfd setup. This is what this patch does. Also in case the eventfd setup fails, there is no reason to go farther: let's abort. Signed-off-by: Eric Auger Signed-off-by: Alex Williamson --- hw/vfio/platform.c | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index a6726cd..d864342 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -310,18 +310,29 @@ static void vfio_platform_eoi(VFIODevice *vbasedev) /** * vfio_start_eventfd_injection - starts the virtual IRQ injection using * user-side handled eventfds - * @intp: the IRQ struct pointer + * @sbdev: the sysbus device handle + * @irq: the qemu irq handle */ -static int vfio_start_eventfd_injection(VFIOINTp *intp) +static void vfio_start_eventfd_injection(SysBusDevice *sbdev, qemu_irq irq) { int ret; + VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); + VFIOINTp *intp; + + QLIST_FOREACH(intp, &vdev->intp_list, next) { + if (intp->qemuirq == irq) { + break; + } + } + assert(intp); ret = vfio_set_trigger_eventfd(intp, vfio_intp_interrupt); if (ret) { - error_report("vfio: Error: Failed to pass IRQ fd to the driver: %m"); + error_report("vfio: failed to start eventfd signaling for IRQ %d: %m", + intp->pin); + abort(); } - return ret; } /* @@ -359,6 +370,15 @@ static int vfio_set_resample_eventfd(VFIOINTp *intp) return ret; } +/** + * vfio_start_irqfd_injection - starts the virtual IRQ injection using + * irqfd + * + * @sbdev: the sysbus device handle + * @irq: the qemu irq handle + * + * In case the irqfd setup fails, we fallback to userspace handled eventfd + */ static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) { VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); @@ -366,7 +386,7 @@ static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) if (!kvm_irqfds_enabled() || !kvm_resamplefds_enabled() || !vdev->irqfd_allowed) { - return; + goto fail_irqfd; } QLIST_FOREACH(intp, &vdev->intp_list, next) { @@ -376,13 +396,6 @@ static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) } assert(intp); - /* Get to a known interrupt state */ - qemu_set_fd_handler(event_notifier_get_fd(&intp->interrupt), - NULL, NULL, vdev); - - vfio_mask_single_irqindex(&vdev->vbasedev, intp->pin); - qemu_set_irq(intp->qemuirq, 0); - if (kvm_irqchip_add_irqfd_notifier(kvm_state, &intp->interrupt, &intp->unmask, irq) < 0) { goto fail_irqfd; @@ -395,9 +408,6 @@ static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) goto fail_vfio; } - /* Let's resume injection with irqfd setup */ - vfio_unmask_single_irqindex(&vdev->vbasedev, intp->pin); - intp->kvm_accel = true; trace_vfio_platform_start_irqfd_injection(intp->pin, @@ -406,9 +416,11 @@ static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) return; fail_vfio: kvm_irqchip_remove_irqfd_notifier(kvm_state, &intp->interrupt, irq); + error_report("vfio: failed to start eventfd signaling for IRQ %d: %m", + intp->pin); + abort(); fail_irqfd: - vfio_start_eventfd_injection(intp); - vfio_unmask_single_irqindex(&vdev->vbasedev, intp->pin); + vfio_start_eventfd_injection(sbdev, irq); return; } @@ -646,7 +658,6 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(dev); SysBusDevice *sbdev = SYS_BUS_DEVICE(dev); VFIODevice *vbasedev = &vdev->vbasedev; - VFIOINTp *intp; int i, ret; vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM; @@ -665,10 +676,6 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) vfio_map_region(vdev, i); sysbus_init_mmio(sbdev, &vdev->regions[i]->mem); } - - QLIST_FOREACH(intp, &vdev->intp_list, next) { - vfio_start_eventfd_injection(intp); - } } static const VMStateDescription vfio_platform_vmstate = {