From patchwork Wed May 24 20:13:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9746857 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 386B5601C2 for ; Wed, 24 May 2017 20:16:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CFEB2897C for ; Wed, 24 May 2017 20:16:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2178E28998; Wed, 24 May 2017 20:16:07 +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=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA50D2897C for ; Wed, 24 May 2017 20:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032120AbdEXUOD (ORCPT ); Wed, 24 May 2017 16:14:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50810 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032044AbdEXUN4 (ORCPT ); Wed, 24 May 2017 16:13:56 -0400 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 E0A897F6B3; Wed, 24 May 2017 20:13:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E0A897F6B3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eric.auger@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E0A897F6B3 Received: from localhost.localdomain.com (ovpn-116-222.ams2.redhat.com [10.36.116.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E8D0189E0; Wed, 24 May 2017 20:13:52 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, alex.williamson@redhat.com, pbonzini@redhat.com, marc.zyngier@arm.com, christoffer.dall@linaro.org Cc: drjones@redhat.com, wei@redhat.com Subject: [PATCH 05/10] VFIO: pci: Introduce direct EOI INTx interrupt handler Date: Wed, 24 May 2017 22:13:18 +0200 Message-Id: <1495656803-28011-6-git-send-email-eric.auger@redhat.com> In-Reply-To: <1495656803-28011-1-git-send-email-eric.auger@redhat.com> References: <1495656803-28011-1-git-send-email-eric.auger@redhat.com> 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.25]); Wed, 24 May 2017 20:13:56 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We add two new fields in vfio_pci_irq_ctx struct: deoi and handler. If deoi is set, this means the physical IRQ attached to the virtual IRQ is directly deactivated by the guest and the VFIO driver does not need to disable the physical IRQ and mask it at VFIO level. The handler pointer is set accordingly and a wrapper handler is introduced that calls the chosen handler function. Signed-off-by: Eric Auger --- --- drivers/vfio/pci/vfio_pci_intrs.c | 32 ++++++++++++++++++++++++++------ drivers/vfio/pci/vfio_pci_private.h | 2 ++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index d4d377b..06aa713 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -121,11 +121,8 @@ void vfio_pci_intx_unmask(struct vfio_pci_device *vdev) static irqreturn_t vfio_intx_handler(int irq, void *dev_id) { struct vfio_pci_device *vdev = dev_id; - unsigned long flags; int ret = IRQ_NONE; - spin_lock_irqsave(&vdev->irqlock, flags); - if (!vdev->pci_2_3) { disable_irq_nosync(vdev->pdev->irq); vdev->ctx[0].automasked = true; @@ -137,14 +134,33 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id) ret = IRQ_HANDLED; } - spin_unlock_irqrestore(&vdev->irqlock, flags); - if (ret == IRQ_HANDLED) vfio_send_intx_eventfd(vdev, NULL); return ret; } +static irqreturn_t vfio_intx_handler_deoi(int irq, void *dev_id) +{ + struct vfio_pci_device *vdev = dev_id; + + vfio_send_intx_eventfd(vdev, NULL); + return IRQ_HANDLED; +} + +static irqreturn_t vfio_intx_wrapper_handler(int irq, void *dev_id) +{ + struct vfio_pci_device *vdev = dev_id; + unsigned long flags; + irqreturn_t ret; + + spin_lock_irqsave(&vdev->irqlock, flags); + ret = vdev->ctx[0].handler(irq, dev_id); + spin_unlock_irqrestore(&vdev->irqlock, flags); + + return ret; +} + static int vfio_intx_enable(struct vfio_pci_device *vdev) { if (!is_irq_none(vdev)) @@ -208,7 +224,11 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd) if (!vdev->pci_2_3) irqflags = 0; - ret = request_irq(pdev->irq, vfio_intx_handler, + if (vdev->ctx[0].deoi) + vdev->ctx[0].handler = vfio_intx_handler_deoi; + else + vdev->ctx[0].handler = vfio_intx_handler; + ret = request_irq(pdev->irq, vfio_intx_wrapper_handler, irqflags, vdev->ctx[0].name, vdev); if (ret) { vdev->ctx[0].trigger = NULL; diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index f7f1101..5cfe59a 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -36,6 +36,8 @@ struct vfio_pci_irq_ctx { char *name; bool masked; bool automasked; + bool deoi; + irqreturn_t (*handler)(int irq, void *dev_id); struct irq_bypass_producer producer; };