Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp1321536imc; Sun, 17 Mar 2019 10:26:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLTj/H08p4xdoZMvnsOQvhSf2hhkiklPqHx+AffsNVVFuEi+1W0xBjmor1dX/qWtUBVGGD X-Received: by 2002:aa7:85cc:: with SMTP id z12mr946913pfn.142.1552843593934; Sun, 17 Mar 2019 10:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552843593; cv=none; d=google.com; s=arc-20160816; b=hUugmLqA/L/ShzLtnZNfsE1ix0yuwTkm3L5cqBzFGGyHavqbgUnFDpBGjeaV7SUJe2 tFU++YIs9/1hweHk776HflEOFVK66CVxaORkqzXtkdv7IVoDi0ba4bM7jVWeFjSDguDZ vTKEFoAMNhY+m+k8SoNiaGXiR9Ov/pPdFnsitn8y0MJeXk1jODt9hwXsLVCj/QbRe/4s j7k8g/I7yfEBSUDZyk2ZYzw09yfmNL4JVlMr0S2XqitqcqIUrF0Ltv3eXd88qbZUMn0v MMIZk36kjvJ/jGnJ0fSv5CJvX68spJxh59CZz0/zehYx/6e7THYg4EdA0KhaycRhvc0C RBMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JdBBPoMRWG9aJkwRWJz7OvlXk/GUKIbEa8G7GP+X3Rs=; b=FGzzUwUJMFFrDGDsye4pD45y5rCGu55oG1yp06s2OoEUKgTLzTIgFWipQtuM4BTqkG iwVtouTdmap2KlvxuXFP7gzfmljmyYlvg+oD0cZq3GElo/xDdN4yls+xbUOAX69RCNj6 5L7j1hTl9GklTTHiYnti5XpVNgSnhZUalQTCwlWH7JkLnA2A+d3pH6f2w+TEzJLrObyb K9TMDN+Gd1XgfkQpvrJ/fqhdqsd17FBbDRE19ESdyaNSCJv5VuU6SoWEnKBPU0OQWYB/ bLvjl+akaAD9uyqg/wn9zsorTHXLuV7qBua6FEzmGdYZaFn1bo/J/GEOn8HlgNC3CcZN 0uyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x17si7334845pgg.431.2019.03.17.10.26.18; Sun, 17 Mar 2019 10:26:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727706AbfCQRY4 (ORCPT + 99 others); Sun, 17 Mar 2019 13:24:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46526 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727698AbfCQRYy (ORCPT ); Sun, 17 Mar 2019 13:24:54 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5B6686678; Sun, 17 Mar 2019 17:24:53 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-102.ams2.redhat.com [10.36.116.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA4A319C71; Sun, 17 Mar 2019 17:24:49 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, joro@8bytes.org, alex.williamson@redhat.com, jacob.jun.pan@linux.intel.com, yi.l.liu@linux.intel.com, jean-philippe.brucker@arm.com, will.deacon@arm.com, robin.murphy@arm.com Cc: kevin.tian@intel.com, ashok.raj@intel.com, marc.zyngier@arm.com, christoffer.dall@arm.com, peter.maydell@linaro.org, vincent.stehle@arm.com Subject: [PATCH v6 21/22] vfio-pci: Add VFIO_PCI_DMA_FAULT_IRQ_INDEX Date: Sun, 17 Mar 2019 18:22:31 +0100 Message-Id: <20190317172232.1068-22-eric.auger@redhat.com> In-Reply-To: <20190317172232.1068-1-eric.auger@redhat.com> References: <20190317172232.1068-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 17 Mar 2019 17:24:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new VFIO_PCI_DMA_FAULT_IRQ_INDEX index. This allows to set/unset an eventfd that will be triggered when DMA translation faults are detected at physical level when the nested mode is used. Signed-off-by: Eric Auger --- drivers/vfio/pci/vfio_pci.c | 3 +++ drivers/vfio/pci/vfio_pci_intrs.c | 19 +++++++++++++++++++ include/uapi/linux/vfio.h | 1 + 3 files changed, 23 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 8c895ece4750..36b57fe363d7 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -750,6 +750,8 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) return 1; } else if (irq_type == VFIO_PCI_REQ_IRQ_INDEX) { return 1; + } else if (irq_type == VFIO_PCI_DMA_FAULT_IRQ_INDEX) { + return 1; } return 0; @@ -1086,6 +1088,7 @@ static long vfio_pci_ioctl(void *device_data, switch (info.index) { case VFIO_PCI_INTX_IRQ_INDEX ... VFIO_PCI_MSIX_IRQ_INDEX: case VFIO_PCI_REQ_IRQ_INDEX: + case VFIO_PCI_DMA_FAULT_IRQ_INDEX: break; case VFIO_PCI_ERR_IRQ_INDEX: if (pci_is_pcie(vdev->pdev)) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 1c46045b0e7f..28a96117daf3 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -622,6 +622,18 @@ static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev, count, flags, data); } +static int vfio_pci_set_dma_fault_trigger(struct vfio_pci_device *vdev, + unsigned index, unsigned start, + unsigned count, uint32_t flags, + void *data) +{ + if (index != VFIO_PCI_DMA_FAULT_IRQ_INDEX || start != 0 || count > 1) + return -EINVAL; + + return vfio_pci_set_ctx_trigger_single(&vdev->dma_fault_trigger, + count, flags, data); +} + int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags, unsigned index, unsigned start, unsigned count, void *data) @@ -671,6 +683,13 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags, break; } break; + case VFIO_PCI_DMA_FAULT_IRQ_INDEX: + switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) { + case VFIO_IRQ_SET_ACTION_TRIGGER: + func = vfio_pci_set_dma_fault_trigger; + break; + } + break; } if (!func) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 40b7aec8fefa..b47f65df5b86 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -555,6 +555,7 @@ enum { VFIO_PCI_MSIX_IRQ_INDEX, VFIO_PCI_ERR_IRQ_INDEX, VFIO_PCI_REQ_IRQ_INDEX, + VFIO_PCI_DMA_FAULT_IRQ_INDEX, VFIO_PCI_NUM_IRQS }; -- 2.20.1