From patchwork Mon Oct 5 20:36:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 54507 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id F138722F05 for ; Mon, 5 Oct 2015 20:38:24 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf33733484wic.3 for ; Mon, 05 Oct 2015 13:38:24 -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=hEv2Hm0+IFA/oC5XaZK0aUPeNh7bU8BlxQBWS6sNOBRGY7v3NXYBXfZrr6xwyBFFka Ph8VidmyOiXe9Z2pS1nTlMQ+DJWcXITKZYsBHHjvwLOyL4J5E4IeWmmkQv7vz4BFoxrL 6OB/0iqhNS5+I9MriGFb7GdPZ7CzCxKbEzkK69sO6jZHKgcG5AUXoH0rxXwZfgvIZ4aG kvdTGhlIwI+ObqafP/O/irjuxA8iGgDs5hszxArfCdVuZktDHL2PblttFgy2Xg23QcP3 91bgkPhPQBPTPsnv4YBkfQjohwI/8PXiZE784QUvQsqgqi4zSqOMwGJmdJnhsByt/dZy 7o4A== X-Gm-Message-State: ALoCoQmxVaqKO2aZBxM1ciW9wdv0OrZX9q4J3D05Qm2B4YdZ/n5pf+DNLol9rLLwYTO1CWgIkxZw X-Received: by 10.112.55.69 with SMTP id q5mr5577438lbp.24.1444077504232; Mon, 05 Oct 2015 13:38:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.29.148 with SMTP id d142ls446175lfd.27.gmail; Mon, 05 Oct 2015 13:38:24 -0700 (PDT) X-Received: by 10.25.205.198 with SMTP id d189mr8153911lfg.72.1444077504056; Mon, 05 Oct 2015 13:38:24 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id r136si18207552lfr.149.2015.10.05.13.38.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2015 13:38:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by laag4 with SMTP id g4so6045779laa.2 for ; Mon, 05 Oct 2015 13:38:23 -0700 (PDT) X-Received: by 10.25.210.206 with SMTP id j197mr8462443lfg.86.1444077503862; Mon, 05 Oct 2015 13:38:23 -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 w3csp1465293lbq; Mon, 5 Oct 2015 13:38:22 -0700 (PDT) X-Received: by 10.55.55.199 with SMTP id e190mr42166523qka.87.1444077502764; Mon, 05 Oct 2015 13:38:22 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q191si24734165qha.128.2015.10.05.13.38.22 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 05 Oct 2015 13:38:22 -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]:47619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjCWc-0005lQ-Ad for patch@linaro.org; Mon, 05 Oct 2015 16:38:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjCUu-0003bJ-HT for qemu-devel@nongnu.org; Mon, 05 Oct 2015 16:36:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZjCUr-0008JX-9q for qemu-devel@nongnu.org; Mon, 05 Oct 2015 16:36:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjCUr-0008JH-2f for qemu-devel@nongnu.org; Mon, 05 Oct 2015 16:36:33 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id C6C0DC0B1B34; Mon, 5 Oct 2015 20:36:32 +0000 (UTC) Received: from gimli.home (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t95KaWJ0016041; Mon, 5 Oct 2015 16:36:32 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 05 Oct 2015 14:36:32 -0600 Message-ID: <20151005203624.310.6547.stgit@gimli.home> In-Reply-To: <20151005203357.310.44414.stgit@gimli.home> References: <20151005203357.310.44414.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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 01/10] 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.215.44 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 = {