[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v3 25/27] vfio-pci: register handler for iommu fault
From: |
Eric Auger |
Subject: |
[Qemu-devel] [RFC v3 25/27] vfio-pci: register handler for iommu fault |
Date: |
Fri, 12 Apr 2019 12:03:52 +0200 |
We use the VFIO_PCI_DMA_FAULT_IRQ_INDEX "irq" index to set/unset
a notifier for physical DMA faults. The associated eventfd is
triggered, in nested mode, whenever a fault is detected at IOMMU
physical level.
The actual handler will be implemented in subsequent patches.
Signed-off-by: Eric Auger <address@hidden>
---
---
hw/vfio/pci.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
hw/vfio/pci.h | 1 +
2 files changed, 46 insertions(+)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index aeb4dfa388..91714cea84 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2722,6 +2722,49 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice
*vdev)
vdev->req_enabled = false;
}
+static void vfio_dma_fault_notifier_handler(void *opaque)
+{
+ VFIOPCIDevice *vdev = opaque;
+
+ if (!event_notifier_test_and_clear(&vdev->dma_fault_notifier)) {
+ return;
+ }
+}
+
+static void vfio_register_dma_fault_notifier(VFIOPCIDevice *vdev)
+{
+ Error *err = NULL;
+ int32_t fd;
+
+ if (event_notifier_init(&vdev->dma_fault_notifier, 0)) {
+ error_report("vfio: Unable to init event notifier for dma fault");
+ return;
+ }
+
+ fd = event_notifier_get_fd(&vdev->dma_fault_notifier);
+ qemu_set_fd_handler(fd, vfio_dma_fault_notifier_handler, NULL, vdev);
+
+ if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_DMA_FAULT_IRQ_INDEX,
0,
+ VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) {
+ error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
+ qemu_set_fd_handler(fd, NULL, NULL, vdev);
+ event_notifier_cleanup(&vdev->dma_fault_notifier);
+ }
+}
+
+static void vfio_unregister_dma_fault_notifier(VFIOPCIDevice *vdev)
+{
+ Error *err = NULL;
+
+ if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_DMA_FAULT_IRQ_INDEX,
0,
+ VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) {
+ error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
+ }
+ qemu_set_fd_handler(event_notifier_get_fd(&vdev->dma_fault_notifier),
+ NULL, NULL, vdev);
+ event_notifier_cleanup(&vdev->dma_fault_notifier);
+}
+
static void vfio_realize(PCIDevice *pdev, Error **errp)
{
VFIOPCIDevice *vdev = PCI_VFIO(pdev);
@@ -3007,6 +3050,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vfio_register_err_notifier(vdev);
vfio_register_req_notifier(vdev);
+ vfio_register_dma_fault_notifier(vdev);
vfio_setup_resetfn_quirk(vdev);
return;
@@ -3045,6 +3089,7 @@ static void vfio_exitfn(PCIDevice *pdev)
vfio_unregister_req_notifier(vdev);
vfio_unregister_err_notifier(vdev);
+ vfio_unregister_dma_fault_notifier(vdev);
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 c11c3f1670..55b14a1ece 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -135,6 +135,7 @@ typedef struct VFIOPCIDevice {
PCIHostDeviceAddress host;
EventNotifier err_notifier;
EventNotifier req_notifier;
+ EventNotifier dma_fault_notifier;
int (*resetfn)(struct VFIOPCIDevice *);
uint32_t vendor_id;
uint32_t device_id;
--
2.20.1
- [Qemu-devel] [RFC v3 15/27] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, (continued)
- [Qemu-devel] [RFC v3 15/27] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 16/27] hw/arm/smmuv3: Notify on config changes, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 17/27] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 18/27] hw/vfio/common: Introduce hostwin_from_range helper, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 19/27] hw/vfio/common: Introduce helpers to DMA map/unap a RAM section, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 20/27] hw/vfio/common: Setup nested stage mappings, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 21/27] hw/vfio/common: Register a MAP notifier for MSI binding, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 22/27] vfio-pci: Expose MSI stage 1 bindings to the host, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 23/27] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 24/27] hw/arm/smmuv3: Implement fault injection, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 25/27] vfio-pci: register handler for iommu fault,
Eric Auger <=
- [Qemu-devel] [RFC v3 26/27] vfio-pci: Set up fault regions, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 27/27] vfio-pci: Implement the DMA fault handler, Eric Auger, 2019/04/12
- Re: [Qemu-devel] [RFC v3 00/27] vSMMUv3/pSMMUv3 2 stage VFIO integration, no-reply, 2019/04/12