Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1012475pxb; Sun, 11 Apr 2021 04:51:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBrVgl3bSuWOpcce9rZ70TDpyoQ8O5ol6xPDBc+qqN/Evt7e2gd5Oiv0l15+iAJ9xL2bUj X-Received: by 2002:a17:90b:4d0f:: with SMTP id mw15mr23594638pjb.92.1618141908374; Sun, 11 Apr 2021 04:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618141908; cv=none; d=google.com; s=arc-20160816; b=fFWtsiEmJi09Urckj95+KajuXEJlvKkpnbc66Abj6tmO22lFH++bQElo6Yovxvt0cr vyUMcT/7qdBCKOVOaZ3o/hN5odNdX/aEBQV1bGZsSjamIqL6mAuxfcz4/aqn2YlAhraE FKldQ+BlF1efhhhgyBAZMhuStUGg5MMXCRCG1B1qywY6NpXo/fXB95bX3LwG0xEcGU4G r+Na6OY5e/Aa0wmh4owdK9d4Z9J08NA7z5xGZcYhHoBhoUVgNVsBg0qTmldrbEZORVXZ lDa4MAxJLwXHT4cbNHc00ziHOZPrHa7fx4EX92eXBwQx9YCY8k39CNCJiLy3Zf2aFOyL DUkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Mj5q5ilBMh/r2vwGJ6rlVHg7OgJNRJNzvApNTpL32jQ=; b=wwAZR5TTmK9/rOE8RP8/NFmpdkoXhrQuz6DqKuQeyHLRb84JfVQOnPZFk3DJVlyiPc 5drpOFy60mFDlfB8pb7zjvmxd6pXjjeAfLP+uhlNell1eKdlY3pcTCQ9GKNSBHAlVPzT lPBYjhF1kAl97BLfMVwhXNyA0509lzEjobkhD5dHgEuNevkE51k7LyttnefpGipBiu6/ WenlcJppcVOp0CuRZJYowXSF+D9bALn6YC8livjRmJeSt9FmSV5T0rDe6EdF4Hwx4dZu 0WrnCFyBlTPy5/AG5xfBASh1oUEfE+7Gg2f3AJNCEGj7EbQOio/M0aLP3bfFVUm4m6O3 UrXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aSsIX3wp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id d23si9793599pll.393.2021.04.11.04.51.36; Sun, 11 Apr 2021 04:51:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aSsIX3wp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S235671AbhDKLth (ORCPT + 99 others); Sun, 11 Apr 2021 07:49:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55791 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235623AbhDKLtc (ORCPT ); Sun, 11 Apr 2021 07:49:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618141756; 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=Mj5q5ilBMh/r2vwGJ6rlVHg7OgJNRJNzvApNTpL32jQ=; b=aSsIX3wpca4NaIquXn8NhbgDoWadfv5tRc/P1PyscpOEsxqSrabvPNKP4P3kpMW9v6DULM Gm6HxOvKLxBbaubHIjCXF8dzTfugFh2h6HTUSk7SWSRJvYGwaKKLjCggZCGW8STnD/QSTP C/DT3TDYRwBNIdJx2NX/3F0+JJNSEXg= 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-524-k7qzawZgNE2CGpyWSqyRjg-1; Sun, 11 Apr 2021 07:49:15 -0400 X-MC-Unique: k7qzawZgNE2CGpyWSqyRjg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1151718397A0; Sun, 11 Apr 2021 11:49:12 +0000 (UTC) Received: from laptop.redhat.com (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97A475C3E4; Sun, 11 Apr 2021 11:48:58 +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, will@kernel.org, maz@kernel.org, robin.murphy@arm.com, joro@8bytes.org, alex.williamson@redhat.com, tn@semihalf.com, zhukeqian1@huawei.com Cc: jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, wangxingang5@huawei.com, jean-philippe@linaro.org, zhangfei.gao@linaro.org, zhangfei.gao@gmail.com, vivek.gautam@arm.com, shameerali.kolothum.thodi@huawei.com, yuzenghui@huawei.com, nicoleotsuka@gmail.com, lushenming@huawei.com, vsethi@nvidia.com, chenxiang66@hisilicon.com, vdumpa@nvidia.com, jiangkunkun@huawei.com Subject: [PATCH v13 10/13] vfio/pci: Register and allow DMA FAULT IRQ signaling Date: Sun, 11 Apr 2021 13:46:56 +0200 Message-Id: <20210411114659.15051-11-eric.auger@redhat.com> In-Reply-To: <20210411114659.15051-1-eric.auger@redhat.com> References: <20210411114659.15051-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 --- v10 -> v11: - the irq now is registered in vfio_pci_dma_fault_init() in case the domain is nested --- drivers/vfio/pci/vfio_pci.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index b3fc6ed4ed7a..72d7c667b64c 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -396,6 +396,7 @@ vfio_pci_iommu_dev_fault_handler(struct iommu_fault *fault, void *data) (struct vfio_region_dma_fault *)vdev->fault_pages; struct iommu_fault *new; u32 head, tail, size; + int ext_irq_index; int ret = -EINVAL; if (WARN_ON(!reg)) @@ -420,7 +421,19 @@ vfio_pci_iommu_dev_fault_handler(struct iommu_fault *fault, void *data) ret = 0; unlock: mutex_unlock(&vdev->fault_queue_lock); - return ret; + if (ret) + return ret; + + ext_irq_index = 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; } #define DMA_FAULT_RING_LENGTH 512 @@ -475,6 +488,12 @@ static int vfio_pci_dma_fault_init(struct vfio_pci_device *vdev) if (ret) /* the dma fault region is freed in vfio_pci_disable() */ goto out; + ret = vfio_pci_register_irq(vdev, VFIO_IRQ_TYPE_NESTED, + VFIO_IRQ_SUBTYPE_DMA_FAULT, + VFIO_IRQ_INFO_EVENTFD); + if (ret) /* the fault handler is also freed in vfio_pci_disable() */ + goto out; + return 0; out: kfree(vdev->fault_pages); -- 2.26.3