Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp868180ybb; Fri, 20 Mar 2020 09:22:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs3QWA+GJepVXSt7YcYWWlAHzHpNKpGjhsvYG0q1IaWl5Ep5SOVn0oRAjlJSFHIJecc2c/u X-Received: by 2002:a05:6830:1195:: with SMTP id u21mr7099231otq.351.1584721327684; Fri, 20 Mar 2020 09:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584721327; cv=none; d=google.com; s=arc-20160816; b=zZWi7DPwOvWk/Nxh0yf5BgNfKzaOvJO/sFir6UWIrgBq7+vheFo81B7C/Bz+vRwrlf cArzSslMQp/tyrKSPAgdfPtJnL13BDpSFYHImMKbTON4h07avpgzwrdLi0fjerlQhej1 aO1I5QUoTuGqyB/+G9B1TK4B/0TASEAbAlg072Z9+iqrLoqLXsSM3LWNa1LcUXzT/xd1 JE7aqY6CvlVIyPpINNKOn6jfCWfTDSxsP/bmlga7QgyeJTfzlLepswdx4jYPIoDStLgC uEocUuukfLIY70XWDBhFcPKrD6NQ4SC3qeOLV/sqJ29lUTeWeSj1q+txPFyR3EZR9RzZ w6cg== 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 :dkim-signature; bh=7/L+s/k/xsB4f4cvLzAisRvkibfj9jdOS8fZjMHEbC4=; b=gB4HEy2PkaqhQylCKs7YFIXNaTy268nvO60E+w/NeZSpKvnT/ujfB//m9wO9s5Of10 vhVDB3XZQpaSu7lP41cp6wXRbZqejk2YOsXJ6FNG9/rBQRtEb9P4yvAowi4dUiu2mnc2 Cq5HCUJtqIHrUEZCkHZv5jrGF6mHeceEul05oltcRc46o22eG6bNMZDKJmv5TBMl/uEO uAeB34VhESX7YDQeppBQc2O+RPWU65IsaJkPrBCAdeZ72K3IbB6ma7PGdTDUwrdKNSOT BtTNgfPA8Eizl+DjjY2Vggn8GRZAxuA/VVjvPlILFnD7ovXLAN2nkNWRbK8iSSeyKOjk bpiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aal8Wp4p; 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=pass (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 i6si3158380oia.100.2020.03.20.09.21.50; Fri, 20 Mar 2020 09:22:07 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aal8Wp4p; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727835AbgCTQVG (ORCPT + 99 others); Fri, 20 Mar 2020 12:21:06 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:55671 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727778AbgCTQVF (ORCPT ); Fri, 20 Mar 2020 12:21:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584721264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7/L+s/k/xsB4f4cvLzAisRvkibfj9jdOS8fZjMHEbC4=; b=aal8Wp4ppAHUkmY9sHrj/nYC7goGqqePPnxnBGfzHkfzM673ROg3X2qLWv696Yp0xzHFsO 1/0Kn1MSWpfwu/5GXxIQLiNo9rky9NfAoIzhLodgiYTk1jm+6zkkBZj6B6lhUo2V8Jfj7m mQdvIeAJEM/mkiDDV41LiuEd16MUYqY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-1vByIYMSNDSfArOtpiTuOQ-1; Fri, 20 Mar 2020 12:21:01 -0400 X-MC-Unique: 1vByIYMSNDSfArOtpiTuOQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2DEF3DB31; Fri, 20 Mar 2020 16:20:59 +0000 (UTC) Received: from laptop.redhat.com (ovpn-113-142.ams2.redhat.com [10.36.113.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9C3660BFB; Fri, 20 Mar 2020 16:20:48 +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@intel.com, jean-philippe.brucker@arm.com, will.deacon@arm.com, robin.murphy@arm.com Cc: marc.zyngier@arm.com, peter.maydell@linaro.org, zhangfei.gao@gmail.com Subject: [PATCH v10 10/11] vfio/pci: Register and allow DMA FAULT IRQ signaling Date: Fri, 20 Mar 2020 17:19:10 +0100 Message-Id: <20200320161911.27494-11-eric.auger@redhat.com> In-Reply-To: <20200320161911.27494-1-eric.auger@redhat.com> References: <20200320161911.27494-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Register the VFIO_IRQ_TYPE_NESTED/VFIO_IRQ_SUBTYPE_DMA_FAULT IRQ that allows to signal a nested mode DMA fault. Signed-off-by: Eric Auger --- drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index ca13067e4718..70e3a31da9f0 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -346,7 +346,7 @@ int vfio_pci_iommu_dev_fault_handler(struct iommu_fau= lt *fault, void *data) struct iommu_fault *new =3D (struct iommu_fault *)(vdev->fault_pages + reg->offset + reg->head * reg->entry_size); - int head, tail, size; + int head, tail, size, ext_irq_index; int ret =3D 0; =20 if (fault->type !=3D IOMMU_FAULT_DMA_UNRECOV) @@ -367,7 +367,19 @@ int vfio_pci_iommu_dev_fault_handler(struct iommu_fa= ult *fault, void *data) reg->head =3D (head + 1) % size; unlock: mutex_unlock(&vdev->fault_queue_lock); - return ret; + if (ret) + return ret; + + ext_irq_index =3D vfio_pci_get_ext_irq_index(vdev, VFIO_IRQ_TYPE_NESTED= , + VFIO_IRQ_SUBTYPE_DMA_FAULT); + if (ext_irq_index < 0) + return -EINVAL; + + mutex_lock(&vdev->igate); + if (vdev->ext_irqs[ext_irq_index].trigger) + eventfd_signal(vdev->ext_irqs[ext_irq_index].trigger, 1); + mutex_unlock(&vdev->igate); + return 0; } =20 #define DMA_FAULT_RING_LENGTH 512 @@ -520,6 +532,12 @@ static int vfio_pci_enable(struct vfio_pci_device *v= dev) if (ret) goto disable_exit; =20 + ret =3D vfio_pci_register_irq(vdev, VFIO_IRQ_TYPE_NESTED, + VFIO_IRQ_SUBTYPE_DMA_FAULT, + VFIO_IRQ_INFO_EVENTFD); + if (ret) + goto disable_exit; + vfio_pci_probe_mmaps(vdev); =20 return 0; --=20 2.20.1