[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [RFC v5 21/29] vfio/pci: Set up the DMA FAULT region
From: |
Eric Auger |
Subject: |
[Qemu-arm] [RFC v5 21/29] vfio/pci: Set up the DMA FAULT region |
Date: |
Thu, 11 Jul 2019 19:39:25 +0200 |
Set up the fault region which is composed of the actual fault
queue (mmappable) and a header used to handle it. The fault
queue is mmapped.
Signed-off-by: Eric Auger <address@hidden>
---
v4 -> v5:
- use a single DMA FAULT region. No version selection anymore
---
hw/vfio/pci.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
hw/vfio/pci.h | 1 +
2 files changed, 65 insertions(+)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 19702cdbbf..8c8647c4b5 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2511,11 +2511,67 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
return 0;
}
+static void vfio_init_fault_regions(VFIOPCIDevice *vdev, Error **errp)
+{
+ struct vfio_region_info *fault_region_info = NULL;
+ struct vfio_region_info_cap_fault *cap_fault;
+ VFIODevice *vbasedev = &vdev->vbasedev;
+ struct vfio_info_cap_header *hdr;
+ char *fault_region_name;
+ int ret;
+
+ ret = vfio_get_dev_region_info(&vdev->vbasedev,
+ VFIO_REGION_TYPE_NESTED,
+ VFIO_REGION_SUBTYPE_NESTED_DMA_FAULT,
+ &fault_region_info);
+ if (ret) {
+ goto out;
+ }
+
+ hdr = vfio_get_region_info_cap(fault_region_info,
+ VFIO_REGION_INFO_CAP_DMA_FAULT);
+ if (!hdr) {
+ error_setg(errp, "failed to retrieve DMA FAULT capability");
+ goto out;
+ }
+ cap_fault = container_of(hdr, struct vfio_region_info_cap_fault,
+ header);
+ if (cap_fault->version != 1) {
+ error_setg(errp, "Unsupported DMA FAULT API version %d",
+ cap_fault->version);
+ goto out;
+ }
+
+ fault_region_name = g_strdup_printf("%s DMA FAULT %d",
+ vbasedev->name,
+ fault_region_info->index);
+
+ ret = vfio_region_setup(OBJECT(vdev), vbasedev,
+ &vdev->dma_fault_region,
+ fault_region_info->index,
+ fault_region_name);
+ g_free(fault_region_name);
+ if (ret) {
+ error_setg_errno(errp, -ret,
+ "failed to set up the DMA FAULT region %d",
+ fault_region_info->index);
+ goto out;
+ }
+
+ ret = vfio_region_mmap(&vdev->dma_fault_region);
+ if (ret) {
+ error_setg_errno(errp, -ret, "Failed to mmap the DMA FAULT queue");
+ }
+out:
+ g_free(fault_region_info);
+}
+
static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
{
VFIODevice *vbasedev = &vdev->vbasedev;
struct vfio_region_info *reg_info;
struct vfio_irq_info irq_info = { .argsz = sizeof(irq_info) };
+ Error *err = NULL;
int i, ret = -1;
/* Sanity check device */
@@ -2579,6 +2635,12 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,
Error **errp)
}
}
+ vfio_init_fault_regions(vdev, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
+
irq_info.index = VFIO_PCI_ERR_IRQ_INDEX;
ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info);
@@ -3159,6 +3221,7 @@ static void vfio_instance_finalize(Object *obj)
vfio_display_finalize(vdev);
vfio_bars_finalize(vdev);
+ vfio_region_finalize(&vdev->dma_fault_region);
g_free(vdev->emulated_config_bits);
g_free(vdev->rom);
/*
@@ -3179,6 +3242,7 @@ static void vfio_exitfn(PCIDevice *pdev)
vfio_unregister_req_notifier(vdev);
vfio_unregister_err_notifier(vdev);
vfio_unregister_ext_irq_notifiers(vdev);
+ vfio_region_exit(&vdev->dma_fault_region);
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
vfio_disable_interrupts(vdev);
if (vdev->intx.mmap_timer) {
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 893d074375..815154656c 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -141,6 +141,7 @@ typedef struct VFIOPCIDevice {
EventNotifier err_notifier;
EventNotifier req_notifier;
VFIOPCIExtIRQ *ext_irqs;
+ VFIORegion dma_fault_region;
int (*resetfn)(struct VFIOPCIDevice *);
uint32_t vendor_id;
uint32_t device_id;
--
2.20.1
- [Qemu-arm] [RFC v5 10/29] memory: Introduce IOMMU Memory Region inject_faults API, (continued)
- [Qemu-arm] [RFC v5 10/29] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 11/29] memory: Add arch_id and leaf fields in IOTLBEntry, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 13/29] pci: introduce PCIPASIDOps to PCIDevice, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 14/29] vfio: Force nested if iommu requires it, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 15/29] vfio: Introduce hostwin_from_range helper, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 16/29] vfio: Introduce helpers to DMA map/unmap a RAM section, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 17/29] vfio: Set up nested stage mappings, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 18/29] vfio: Pass stage 1 MSI bindings to the host, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 19/29] vfio: Helper to get IRQ info including capabilities, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 20/29] vfio/pci: Register handler for iommu fault, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 21/29] vfio/pci: Set up the DMA FAULT region,
Eric Auger <=
- [Qemu-arm] [RFC v5 24/29] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 22/29] vfio/pci: Implement the DMA fault handler, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 23/29] hw/arm/smmuv3: Advertise MSI_TRANSLATE attribute, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 25/29] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 26/29] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 27/29] hw/arm/smmuv3: Pass stage 1 configurations to the host, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 28/29] hw/arm/smmuv3: Implement fault injection, Eric Auger, 2019/07/11
- [Qemu-arm] [RFC v5 29/29] vfio: Remove VFIO/SMMUv3 assert, Eric Auger, 2019/07/11
- Re: [Qemu-arm] [Qemu-devel] [RFC v5 00/29] vSMMUv3/pSMMUv3 2 stage VFIO integration, no-reply, 2019/07/11