public inbox for iommu@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Auger Eric <eric.auger@redhat.com>
To: Zenghui Yu <yuzenghui@huawei.com>,
	eric.auger.pro@gmail.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, robin.murphy@arm.com
Subject: Re: [PATCH v10 05/11] vfio/pci: Register an iommu fault handler
Date: Fri, 13 Nov 2020 17:11:47 +0100	[thread overview]
Message-ID: <80befd0f-8876-2cd2-7af0-c5e32e79323b@redhat.com> (raw)
In-Reply-To: <571978ff-ee8a-6e9f-6755-519d0871646f@huawei.com>

Hi Zenghui,

On 9/24/20 10:49 AM, Zenghui Yu wrote:
> 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 <eric.auger@redhat.com>
> 
> [...]
> 
>> 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 <linux/vfio.h>
>>   #include <linux/vgaarb.h>
>>   #include <linux/nospec.h>
>> +#include <linux/circ_buf.h>
>>     #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.

Yes I modified the locking

Thanks

Eric
> 
>> +    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
> 

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2020-11-13 16:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20 16:19 [PATCH v10 00/11] SMMUv3 Nested Stage Setup (VFIO part) Eric Auger
2020-03-20 16:19 ` [PATCH v10 01/11] vfio: VFIO_IOMMU_SET_PASID_TABLE Eric Auger
2020-03-21  5:18   ` kbuild test robot
2020-09-23 11:27   ` Zenghui Yu
2020-09-23 11:47     ` Auger Eric
2020-10-27 12:20       ` Shameerali Kolothum Thodi
2020-10-27 13:04         ` Auger Eric
2020-03-20 16:19 ` [PATCH v10 02/11] vfio: VFIO_IOMMU_CACHE_INVALIDATE Eric Auger
2020-03-20 16:19 ` [PATCH v10 03/11] vfio: VFIO_IOMMU_SET_MSI_BINDING Eric Auger
2020-03-20 16:19 ` [PATCH v10 04/11] vfio/pci: Add VFIO_REGION_TYPE_NESTED region type Eric Auger
2020-04-01 13:18   ` Liu, Yi L
2020-04-01 13:31     ` Auger Eric
2020-04-06  6:29       ` Liu, Yi L
2020-09-24  8:23   ` Zenghui Yu
2020-11-13 16:12     ` Auger Eric
2020-03-20 16:19 ` [PATCH v10 05/11] vfio/pci: Register an iommu fault handler Eric Auger
2020-09-24  8:49   ` Zenghui Yu
2020-11-13 16:11     ` Auger Eric [this message]
2020-03-20 16:19 ` [PATCH v10 06/11] vfio/pci: Allow to mmap the fault queue Eric Auger
2020-03-20 16:19 ` [PATCH v10 07/11] vfio: Use capability chains to handle device specific irq Eric Auger
2020-03-20 16:19 ` [PATCH v10 08/11] vfio: Add new IRQ for DMA fault reporting Eric Auger
2020-03-20 16:19 ` [PATCH v10 09/11] vfio/pci: Add framework for custom interrupt indices Eric Auger
2020-03-20 16:19 ` [PATCH v10 10/11] vfio/pci: Register and allow DMA FAULT IRQ signaling Eric Auger
2020-03-20 16:19 ` [PATCH v10 11/11] vfio: Document nested stage control Eric Auger
2020-09-24 13:42   ` Zenghui Yu
2020-10-06 15:29     ` Auger Eric

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80befd0f-8876-2cd2-7af0-c5e32e79323b@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=yi.l.liu@intel.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox