From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD1FC4346E for ; Thu, 24 Sep 2020 08:50:12 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id DF90D23772 for ; Thu, 24 Sep 2020 08:50:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF90D23772 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 574634B1BD; Thu, 24 Sep 2020 04:50:11 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t16aBcYiNcoV; Thu, 24 Sep 2020 04:50:10 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 230534B1C8; Thu, 24 Sep 2020 04:50:10 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 3F09D4B1C0 for ; Thu, 24 Sep 2020 04:50:09 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jyYAmoxVcvw0 for ; Thu, 24 Sep 2020 04:50:08 -0400 (EDT) Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id A42BD4B1BD for ; Thu, 24 Sep 2020 04:50:05 -0400 (EDT) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E1988906A3711F42ACCA; Thu, 24 Sep 2020 16:49:59 +0800 (CST) Received: from [10.174.185.226] (10.174.185.226) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Thu, 24 Sep 2020 16:49:53 +0800 Subject: Re: [PATCH v10 05/11] vfio/pci: Register an iommu fault handler To: Eric Auger , , , , , , , , , , References: <20200320161911.27494-1-eric.auger@redhat.com> <20200320161911.27494-6-eric.auger@redhat.com> From: Zenghui Yu Message-ID: <571978ff-ee8a-6e9f-6755-519d0871646f@huawei.com> Date: Thu, 24 Sep 2020 16:49:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200320161911.27494-6-eric.auger@redhat.com> Content-Language: en-US X-Originating-IP: [10.174.185.226] X-CFilter-Loop: Reflected X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Hi Eric, On 2020/3/21 0:19, Eric Auger wrote: > Register an IOMMU fault handler which records faults in > the DMA FAULT region ring buffer. In a subsequent patch, we > will add the signaling of a specific eventfd to allow the > userspace to be notified whenever a new fault as shown up. > > Signed-off-by: Eric Auger [...] > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c > index 586b89debed5..69595c240baf 100644 > --- a/drivers/vfio/pci/vfio_pci.c > +++ b/drivers/vfio/pci/vfio_pci.c > @@ -27,6 +27,7 @@ > #include > #include > #include > +#include > > #include "vfio_pci_private.h" > > @@ -283,6 +284,38 @@ static const struct vfio_pci_regops vfio_pci_dma_fault_regops = { > .add_capability = vfio_pci_dma_fault_add_capability, > }; > > +int vfio_pci_iommu_dev_fault_handler(struct iommu_fault *fault, void *data) > +{ > + struct vfio_pci_device *vdev = (struct vfio_pci_device *)data; > + struct vfio_region_dma_fault *reg = > + (struct vfio_region_dma_fault *)vdev->fault_pages; > + struct iommu_fault *new = > + (struct iommu_fault *)(vdev->fault_pages + reg->offset + > + reg->head * reg->entry_size); Shouldn't 'reg->head' be protected under the fault_queue_lock? Otherwise things may change behind our backs... We shouldn't take any assumption about how IOMMU driver would report the fault (serially or in parallel), I think. > + int head, tail, size; > + int ret = 0; > + > + if (fault->type != IOMMU_FAULT_DMA_UNRECOV) > + return -ENOENT; > + > + mutex_lock(&vdev->fault_queue_lock); > + > + head = reg->head; > + tail = reg->tail; > + size = reg->nb_entries; > + > + if (CIRC_SPACE(head, tail, size) < 1) { > + ret = -ENOSPC; > + goto unlock; > + } > + > + *new = *fault; > + reg->head = (head + 1) % size; > +unlock: > + mutex_unlock(&vdev->fault_queue_lock); > + return ret; > +} > + > #define DMA_FAULT_RING_LENGTH 512 > > static int vfio_pci_init_dma_fault_region(struct vfio_pci_device *vdev) > @@ -317,6 +350,13 @@ static int vfio_pci_init_dma_fault_region(struct vfio_pci_device *vdev) > header->entry_size = sizeof(struct iommu_fault); > header->nb_entries = DMA_FAULT_RING_LENGTH; > header->offset = sizeof(struct vfio_region_dma_fault); > + > + ret = iommu_register_device_fault_handler(&vdev->pdev->dev, > + vfio_pci_iommu_dev_fault_handler, > + vdev); > + if (ret) > + goto out; > + > return 0; > out: > kfree(vdev->fault_pages); Thanks, Zenghui _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm