Skip to contentSkip to conversation

VFIO: Clear stale MSIx table during EEH reset

PATCH Superseded Gavin Shan 3 participants 21 messages Mar 16, 2015 – Mar 26, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Gavin Shan

author
#0 lore raw

PATCH v2 1/3 VFIO: Clear stale MSIx table during EEH reset

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +7 -0
index 148eb53..ed07814 100644
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {
+            error_report("vfio: cannot handle EEH event on group %d\n",
+                         groupid);
+            return -1;
+        }
+
         break;
     default:
         /* Return an error on unknown requests */
hw/vfio/pci-stub.c new file +17 -0
new file mode 100644
index 0000000..7726a7a
@@ -0,0 +1,17 @@
+/*
+ * To include the file on !CONFIG_PCI
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <linux/vfio.h>
+
+#include "exec/memory.h"
+#include "hw/vfio/vfio.h"
+
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    return -1;
+}
hw/vfio/pci.c +38 -0
index 6b80539..fca1edc 100644
@@ -3319,6 +3319,44 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
     vdev->req_enabled = false;
 }
 
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    VFIOGroup *group;
+    VFIODevice *vbasedev;
+    VFIOPCIDevice *vdev;
+
+    group = vfio_get_group(groupid, as);
+    if (!group) {
+        error_report("vfio: group %d not found\n", groupid);
+        return -1;
+    }
+
+    switch (op->op) {
+    case VFIO_EEH_PE_RESET_HOT:
+    case VFIO_EEH_PE_RESET_FUNDAMENTAL:
+        /*
+         * The MSIx table will be cleaned out by reset. We need
+         * disable it so that it can be reenabled properly. Also,
+         * the cached MSIx table should be cleared as it's not
+         * reflecting the contents in hardware.
+         */
+        QLIST_FOREACH(vbasedev, &group->device_list, next) {
+            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+            if (msix_enabled(&vdev->pdev)) {
+                vfio_disable_msix(vdev);
+            }
+
+            msix_reset(&vdev->pdev);
+        }
+
+        break;
+    }
+
+    vfio_put_group(group);
+    return 0;
+}
+
 static int vfio_initfn(PCIDevice *pdev)
 {
     VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
include/hw/vfio/vfio.h +2 -0
index 0b26cd8..e9a3abb 100644
@@ -5,5 +5,7 @@
 
 extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
                                 int req, void *param);
+extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                                    struct vfio_eeh_pe_op *op);
 
 #endif
Signature · 1 line
1.8.3.2
author
#1 lore raw

PATCH v2 2/3 VFIO: Disable INTx interrupt on EEH reset

When Linux guest recovers from EEH error on the following Emulex adapter, the MSIx interrupts are disabled and the INTx emulation is enabled. One INTx interrupt is injected to the guest by host because of detected pending INTx interrupts on the adapter. QEMU disables mmap'ed BAR regions and starts a timer to enable those regions at later point the INTx interrupt handler. Unfortunately, "VFIOPCIDevice->intx.pending" isn't cleared, meaning those disabled mapp'ed BAR regions won't be reenabled properly. It leads to EEH recovery failure at guest side because of hanged MMIO access.

 # lspci | grep Emulex
 0000:01:00.0 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)
 0000:01:00.1 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)

The patch disables INTx interrupt before doing EEH reset to avoid the issue.

---
 hw/vfio/pci.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/vfio/pci.c +13 -0
index fca1edc..bfa3d0c 100644
@@ -3340,6 +3340,14 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
          * disable it so that it can be reenabled properly. Also,
          * the cached MSIx table should be cleared as it's not
          * reflecting the contents in hardware.
+         *
+         * We might have INTx interrupt whose handler disables the
+         * memory mapped BARs. The INTx pending state can't be
+         * cleared with memory BAR access in slow path. The timer
+         * kicked by the INTx interrupt handler won't enable those
+         * disabled memory mapped BARs, which leads to hanged MMIO
+         * register access and EEH recovery failure. We simply disable
+         * INTx if it has been enabled.
          */
         QLIST_FOREACH(vbasedev, &group->device_list, next) {
             vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
@@ -3348,6 +3356,11 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
             }
 
             msix_reset(&vdev->pdev);
+
+            /* Disable INTx */
+            if (vdev->interrupt == VFIO_INT_INTx) {
+                vfio_disable_intx(vdev);
+            }
         }
 
         break;
Signature · 1 line
1.8.3.2
#2 lore raw

Re: [Qemu-devel] [PATCH v2 2/3] VFIO: Disable INTx interrupt on EEH reset

Quoted 31 lines · Gavin Shan

When Linux guest recovers from EEH error on the following Emulex adapter, the MSIx interrupts are disabled and the INTx emulation is enabled. One INTx interrupt is injected to the guest by host because of detected pending INTx interrupts on the adapter. QEMU disables mmap'ed BAR regions and starts a timer to enable those regions at later point the INTx interrupt handler. Unfortunately, "VFIOPCIDevice->intx.pending" isn't cleared, meaning those disabled mapp'ed BAR regions won't be reenabled properly. It leads to EEH recovery failure at guest side because of hanged MMIO access.

 # lspci | grep Emulex
 0000:01:00.0 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)
 0000:01:00.1 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)

The patch disables INTx interrupt before doing EEH reset to avoid the issue.

---
 hw/vfio/pci.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/vfio/pci.c +0 -0
index fca1edc..bfa3d0c 100644
@@ -3340,6 +3340,14 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
          * disable it so that it can be reenabled properly. Also,
          * the cached MSIx table should be cleared as it's not

hw/vfio/pci.c int vfio_container_eeh_event(AddressSpace *as, int32_t groupid, · line 3351

Quoted 10 lines
hw/vfio/pci.c +8 -0
          * reflecting the contents in hardware.
+         *
+         * We might have INTx interrupt whose handler disables the
+         * memory mapped BARs. The INTx pending state can't be
+         * cleared with memory BAR access in slow path. The timer
+         * kicked by the INTx interrupt handler won't enable those
+         * disabled memory mapped BARs, which leads to hanged MMIO
+         * register access and EEH recovery failure. We simply disable
+         * INTx if it has been enabled.
          */

This feels like a quick hack for a problem we don't really understand. Why is INTx being fired through QEMU rather than KVM? Why isn't the INTx re-enabling happening since this is exactly the scenario where it's supposed to work (ie. INTx occurs, BAR mmap disabled, guest accesses BAR, mmap re-enabled, INTx unmasked)?

Quoted 14 lines
hw/vfio/pci.c +5 -0
         QLIST_FOREACH(vbasedev, &group->device_list, next) {
             vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
@@ -3348,6 +3356,11 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
             }
 
             msix_reset(&vdev->pdev);
+
+            /* Disable INTx */
+            if (vdev->interrupt == VFIO_INT_INTx) {
+                vfio_disable_intx(vdev);
+            }
         }
 
         break;
author
#3 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 2/3] VFIO: Disable INTx interrupt on EEH reset

Quoted 40 lines · Alex Williamson
Quoted 39 lines · Gavin Shan

When Linux guest recovers from EEH error on the following Emulex adapter, the MSIx interrupts are disabled and the INTx emulation is enabled. One INTx interrupt is injected to the guest by host because of detected pending INTx interrupts on the adapter. QEMU disables mmap'ed BAR regions and starts a timer to enable those regions at later point the INTx interrupt handler. Unfortunately, "VFIOPCIDevice->intx.pending" isn't cleared, meaning those disabled mapp'ed BAR regions won't be reenabled properly. It leads to EEH recovery failure at guest side because of hanged MMIO access.

 # lspci | grep Emulex
 0000:01:00.0 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)
 0000:01:00.1 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)

The patch disables INTx interrupt before doing EEH reset to avoid the issue.

---
 hw/vfio/pci.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/vfio/pci.c +7 -0
index fca1edc..bfa3d0c 100644
@@ -3340,6 +3340,14 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
          * disable it so that it can be reenabled properly. Also,
          * the cached MSIx table should be cleared as it's not
          * reflecting the contents in hardware.
+         *
+         * We might have INTx interrupt whose handler disables the
+         * memory mapped BARs. The INTx pending state can't be
+         * cleared with memory BAR access in slow path. The timer
+         * kicked by the INTx interrupt handler won't enable those
+         * disabled memory mapped BARs, which leads to hanged MMIO
+         * register access and EEH recovery failure. We simply disable
Quoted 9 lines

hw/vfio/pci.c int vfio_container_eeh_event(AddressSpace *as, int32_t groupid, · line 3351

Quoted 2 lines
hw/vfio/pci.c +1 -0
+         * INTx if it has been enabled.
          */

This feels like a quick hack for a problem we don't really understand. Why is INTx being fired through QEMU rather than KVM? Why isn't the INTx re-enabling happening since this is exactly the scenario where it's supposed to work (ie. INTx occurs, BAR mmap disabled, guest accesses BAR, mmap re-enabled, INTx unmasked)?

Indeed. It's a quick hack before finding the root cause about why slow path doesn't work when fast path is disabled. I'm still tracing it and hopefully I can find something soon. Note that: KVM IRQFD isn't enabled on the system I was doing experiments.

Thanks,
Gavin

Quoted 18 lines
Quoted 14 lines
hw/vfio/pci.c +5 -0
         QLIST_FOREACH(vbasedev, &group->device_list, next) {
             vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
@@ -3348,6 +3356,11 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
             }
 
             msix_reset(&vdev->pdev);
+
+            /* Disable INTx */
+            if (vdev->interrupt == VFIO_INT_INTx) {
+                vfio_disable_intx(vdev);
+            }
         }
 
         break;
author
#4 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 2/3] VFIO: Disable INTx interrupt on EEH reset

Quoted 51 lines · Gavin Shan
Quoted 40 lines · Alex Williamson
Quoted 39 lines · Gavin Shan

When Linux guest recovers from EEH error on the following Emulex adapter, the MSIx interrupts are disabled and the INTx emulation is enabled. One INTx interrupt is injected to the guest by host because of detected pending INTx interrupts on the adapter. QEMU disables mmap'ed BAR regions and starts a timer to enable those regions at later point the INTx interrupt handler. Unfortunately, "VFIOPCIDevice->intx.pending" isn't cleared, meaning those disabled mapp'ed BAR regions won't be reenabled properly. It leads to EEH recovery failure at guest side because of hanged MMIO access.

 # lspci | grep Emulex
 0000:01:00.0 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)
 0000:01:00.1 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)

The patch disables INTx interrupt before doing EEH reset to avoid the issue.

---
 hw/vfio/pci.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/vfio/pci.c +7 -0
index fca1edc..bfa3d0c 100644
@@ -3340,6 +3340,14 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
          * disable it so that it can be reenabled properly. Also,
          * the cached MSIx table should be cleared as it's not
          * reflecting the contents in hardware.
+         *
+         * We might have INTx interrupt whose handler disables the
+         * memory mapped BARs. The INTx pending state can't be
+         * cleared with memory BAR access in slow path. The timer
+         * kicked by the INTx interrupt handler won't enable those
+         * disabled memory mapped BARs, which leads to hanged MMIO
+         * register access and EEH recovery failure. We simply disable
Quoted 9 lines

hw/vfio/pci.c int vfio_container_eeh_event(AddressSpace *as, int32_t groupid, · line 3351

Quoted 2 lines
hw/vfio/pci.c +1 -0
+         * INTx if it has been enabled.
          */

This feels like a quick hack for a problem we don't really understand. Why is INTx being fired through QEMU rather than KVM? Why isn't the INTx re-enabling happening since this is exactly the scenario where it's supposed to work (ie. INTx occurs, BAR mmap disabled, guest accesses BAR, mmap re-enabled, INTx unmasked)?

Quoted 5 lines

Indeed. It's a quick hack before finding the root cause about why slow path doesn't work when fast path is disabled. I'm still tracing it and hopefully I can find something soon. Note that: KVM IRQFD isn't enabled on the system I was doing experiments.

I'm not sure if there're further replies to this thread since then. My mailbox is broken for quite a while. Also, I don't know how Ben is missed from the cc list. Add him who might have more thoughts. Sorry for mail flooding to you, Ben :-)

The root cause of the problem would be specific to how MMIO regions are supported on KVM for book3s_hv, where invalid page table entries (PTEs) are built to trace the address mapping between guest virtual address and host physical address. Since they're marked as "invalid", accessing to the MMIO region will cause page fault in host kernel and then the PTE table is searched to locate the address mapping, the access is propogated to QEMU for emulation if the address mapping exits in PTE table. It's how the "slow path" works.

For the "fast path", KVM creates memory slot and update PTE table with the mappings upon page fault. Those PTEs are "valid" and seen by CPU to do address translation automatically. When the memory region for the "fast path" is disabled from QEMU, the host will purge TLB/PTEs for the mappings. So when the "fast path" regions are disabled, the PTE table doesn't have the entries required for "slow path" access any more. At later point, guest tries access to the region and the host just doesn't know how to handle the case.

I already have couple of patches to introduce addtional flag to identify the "fast path" region, which has properties that RAM region and MMIO region have. Once the region is disabled, host purges its mappings in PTEs/TLB, and then update PTEs with the mappings required by "slow path" region. With that, I didn't see the problem. Both host/QEMU needs changes. I'll remove this patch from the series and send out a new revision. The patches to address the "fast path" issue will be sent separately after checking with Ben or Paul they're worthy to be sent out.

Thanks,
Gavin

Quoted 19 lines
Quoted 19 lines
Quoted 15 lines
hw/vfio/pci.c +5 -0
         QLIST_FOREACH(vbasedev, &group->device_list, next) {
             vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
@@ -3348,6 +3356,11 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
             }
 
             msix_reset(&vdev->pdev);
+
+            /* Disable INTx */
+            if (vdev->interrupt == VFIO_INT_INTx) {
+                vfio_disable_intx(vdev);
+            }
         }
 
         break;
author
#5 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 2/3] VFIO: Disable INTx interrupt on EEH reset

Quoted 81 lines · Gavin Shan
Quoted 51 lines · Gavin Shan
Quoted 40 lines · Alex Williamson
Quoted 39 lines · Gavin Shan

When Linux guest recovers from EEH error on the following Emulex adapter, the MSIx interrupts are disabled and the INTx emulation is enabled. One INTx interrupt is injected to the guest by host because of detected pending INTx interrupts on the adapter. QEMU disables mmap'ed BAR regions and starts a timer to enable those regions at later point the INTx interrupt handler. Unfortunately, "VFIOPCIDevice->intx.pending" isn't cleared, meaning those disabled mapp'ed BAR regions won't be reenabled properly. It leads to EEH recovery failure at guest side because of hanged MMIO access.

 # lspci | grep Emulex
 0000:01:00.0 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)
 0000:01:00.1 Ethernet controller: Emulex Corporation \
              OneConnect 10Gb NIC (be3) (rev 02)

The patch disables INTx interrupt before doing EEH reset to avoid the issue.

---
 hw/vfio/pci.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/vfio/pci.c +7 -0
index fca1edc..bfa3d0c 100644
@@ -3340,6 +3340,14 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
          * disable it so that it can be reenabled properly. Also,
          * the cached MSIx table should be cleared as it's not
          * reflecting the contents in hardware.
+         *
+         * We might have INTx interrupt whose handler disables the
+         * memory mapped BARs. The INTx pending state can't be
+         * cleared with memory BAR access in slow path. The timer
+         * kicked by the INTx interrupt handler won't enable those
+         * disabled memory mapped BARs, which leads to hanged MMIO
+         * register access and EEH recovery failure. We simply disable
Quoted 9 lines

hw/vfio/pci.c int vfio_container_eeh_event(AddressSpace *as, int32_t groupid, · line 3351

Quoted 2 lines
hw/vfio/pci.c +1 -0
+         * INTx if it has been enabled.
          */

This feels like a quick hack for a problem we don't really understand. Why is INTx being fired through QEMU rather than KVM? Why isn't the INTx re-enabling happening since this is exactly the scenario where it's supposed to work (ie. INTx occurs, BAR mmap disabled, guest accesses BAR, mmap re-enabled, INTx unmasked)?

Quoted 5 lines

Indeed. It's a quick hack before finding the root cause about why slow path doesn't work when fast path is disabled. I'm still tracing it and hopefully I can find something soon. Note that: KVM IRQFD isn't enabled on the system I was doing experiments.

I'm not sure if there're further replies to this thread since then. My mailbox is broken for quite a while. Also, I don't know how Ben is missed from the cc list. Add him who might have more thoughts. Sorry for mail flooding to you, Ben :-)

The root cause of the problem would be specific to how MMIO regions are supported on KVM for book3s_hv, where invalid page table entries (PTEs) are built to trace the address mapping between guest virtual address and host physical address. Since they're marked as "invalid", accessing to the MMIO region will cause page fault in host kernel and then the PTE table is searched to locate the address mapping, the access is propogated to QEMU for emulation if the address mapping exits in PTE table. It's how the "slow path" works.

For the "fast path", KVM creates memory slot and update PTE table with the mappings upon page fault. Those PTEs are "valid" and seen by CPU to do address translation automatically. When the memory region for the "fast path" is disabled from QEMU, the host will purge TLB/PTEs for the mappings. So when the "fast path" regions are disabled, the PTE table doesn't have the entries required for "slow path" access any more. At later point, guest tries access to the region and the host just doesn't know how to handle the case.

Quoted 10 lines

I already have couple of patches to introduce addtional flag to identify the "fast path" region, which has properties that RAM region and MMIO region have. Once the region is disabled, host purges its mappings in PTEs/TLB, and then update PTEs with the mappings required by "slow path" region. With that, I didn't see the problem. Both host/QEMU needs changes. I'll remove this patch from the series and send out a new revision. The patches to address the "fast path" issue will be sent separately after checking with Ben or Paul they're worthy to be sent out.

Checked with Paul Mackerras. He already has patch fixing the issue in an different way :-)

Thanks,
Gavin

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 16 lines
hw/vfio/pci.c +5 -0
         QLIST_FOREACH(vbasedev, &group->device_list, next) {
             vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
@@ -3348,6 +3356,11 @@ int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
             }
 
             msix_reset(&vdev->pdev);
+
+            /* Disable INTx */
+            if (vdev->interrupt == VFIO_INT_INTx) {
+                vfio_disable_intx(vdev);
+            }
         }
 
         break;
author
#6 lore raw

PATCH v2 3/3 sPAPR: Reenable EEH functionality on reboot

In reply to Gavin Shan

When rebooting the guest, some PEs might be in frozen state. The contained PCI devices won't work properly if their frozen states aren't cleared in time. One case running into this situation would be maximal EEH error times encountered in the guest.

The patch reenables the EEH functinality on PEs on PHB's reset callback, which will clear their frozen states if needed.

---
 hw/ppc/spapr_pci_vfio.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci_vfio.c +13 -1
index 99a1be5..0cd96d3 100644
@@ -71,9 +71,21 @@ static void spapr_phb_vfio_finish_realize(sPAPRPHBState *sphb, Error **errp)
                                 spapr_tce_get_iommu(tcet));
 }
 
+/*
+ * The PE might be in frozen state. To reenable the EEH
+ * functionality on it will clean the frozen state, which
+ * ensures that the comtained PCI devices will work properly.
+ */
 static void spapr_phb_vfio_reset(DeviceState *qdev)
 {
-    /* Do nothing */
+    sPAPRPHBVFIOState *svphb = SPAPR_PCI_VFIO_HOST_BRIDGE(qdev);
+    struct vfio_eeh_pe_op op = {
+        .argsz = sizeof(op),
+        .op = VFIO_EEH_PE_ENABLE,
+    };
+
+    vfio_container_ioctl(&svphb->phb.iommu_as,
+                         svphb->iommugroupid, VFIO_EEH_PE_OP, &op);
 }
 
 static int spapr_phb_vfio_eeh_set_option(sPAPRPHBState *sphb,
Signature · 1 line
1.8.3.2
#7 lore raw
In reply to Gavin Shan
Quoted 69 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +7 -0
index 148eb53..ed07814 100644
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {
+            error_report("vfio: cannot handle EEH event on group %d\n",
+                         groupid);
+            return -1;
+        }
+
         break;
     default:
         /* Return an error on unknown requests */
hw/vfio/pci-stub.c new file +7 -0
new file mode 100644
index 0000000..7726a7a
@@ -0,0 +1,17 @@
+/*
+ * To include the file on !CONFIG_PCI
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+

hw/vfio/pci-stub.c line 17

Quoted 10 lines
hw/vfio/pci-stub.c new file +10 -0
+#include <linux/vfio.h>
+
+#include "exec/memory.h"
+#include "hw/vfio/vfio.h"
+
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    return -1;
+}

How about just a static inline in vfio.h?

Quoted 61 lines
hw/vfio/pci.c +38 -0
index 6b80539..fca1edc 100644
@@ -3319,6 +3319,44 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
     vdev->req_enabled = false;
 }
 
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    VFIOGroup *group;
+    VFIODevice *vbasedev;
+    VFIOPCIDevice *vdev;
+
+    group = vfio_get_group(groupid, as);
+    if (!group) {
+        error_report("vfio: group %d not found\n", groupid);
+        return -1;
+    }
+
+    switch (op->op) {
+    case VFIO_EEH_PE_RESET_HOT:
+    case VFIO_EEH_PE_RESET_FUNDAMENTAL:
+        /*
+         * The MSIx table will be cleaned out by reset. We need
+         * disable it so that it can be reenabled properly. Also,
+         * the cached MSIx table should be cleared as it's not
+         * reflecting the contents in hardware.
+         */
+        QLIST_FOREACH(vbasedev, &group->device_list, next) {
+            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+            if (msix_enabled(&vdev->pdev)) {
+                vfio_disable_msix(vdev);
+            }
+
+            msix_reset(&vdev->pdev);
+        }
+
+        break;
+    }
+
+    vfio_put_group(group);
+    return 0;
+}
+
 static int vfio_initfn(PCIDevice *pdev)
 {
     VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
include/hw/vfio/vfio.h +2 -0
index 0b26cd8..e9a3abb 100644
@@ -5,5 +5,7 @@
 
 extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
                                 int req, void *param);
+extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                                    struct vfio_eeh_pe_op *op);
 
 #endif
author
#8 lore raw
Quoted 74 lines · Alex Williamson
Quoted 73 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +7 -0
index 148eb53..ed07814 100644
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {
+            error_report("vfio: cannot handle EEH event on group %d\n",
+                         groupid);
+            return -1;
+        }
+
         break;
     default:
         /* Return an error on unknown requests */
hw/vfio/pci-stub.c new file +11 -0
new file mode 100644
index 0000000..7726a7a
@@ -0,0 +1,17 @@
+/*
+ * To include the file on !CONFIG_PCI
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <linux/vfio.h>
+
+#include "exec/memory.h"
+#include "hw/vfio/vfio.h"
Quoted 9 lines

hw/vfio/pci-stub.c line 17

Quoted 6 lines
hw/vfio/pci-stub.c new file +6 -0
+
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    return -1;
+}

How about just a static inline in vfio.h?

Yes, It would make things simpler to have something as follows, but I didn't find there is a header file, which includes "#define CONFIG_PCI 1" or similar thing. Do you know the header file containing CONFIG_PCI, or alternative macro for the purpose?

#ifdef CONFIG_PCI /* Or alternative macro */
extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,

				    struct vfio_eeh_pe_op *op);
#else
static ineline int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
                                            struct vfio_eeh_pe_op *op)
{
    return -1;
}

#endif /* CONFIG_PCI */

Thanks,
Gavin

Quoted 64 lines
Quoted 61 lines
hw/vfio/pci.c +38 -0
index 6b80539..fca1edc 100644
@@ -3319,6 +3319,44 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
     vdev->req_enabled = false;
 }
 
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    VFIOGroup *group;
+    VFIODevice *vbasedev;
+    VFIOPCIDevice *vdev;
+
+    group = vfio_get_group(groupid, as);
+    if (!group) {
+        error_report("vfio: group %d not found\n", groupid);
+        return -1;
+    }
+
+    switch (op->op) {
+    case VFIO_EEH_PE_RESET_HOT:
+    case VFIO_EEH_PE_RESET_FUNDAMENTAL:
+        /*
+         * The MSIx table will be cleaned out by reset. We need
+         * disable it so that it can be reenabled properly. Also,
+         * the cached MSIx table should be cleared as it's not
+         * reflecting the contents in hardware.
+         */
+        QLIST_FOREACH(vbasedev, &group->device_list, next) {
+            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+            if (msix_enabled(&vdev->pdev)) {
+                vfio_disable_msix(vdev);
+            }
+
+            msix_reset(&vdev->pdev);
+        }
+
+        break;
+    }
+
+    vfio_put_group(group);
+    return 0;
+}
+
 static int vfio_initfn(PCIDevice *pdev)
 {
     VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
include/hw/vfio/vfio.h +2 -0
index 0b26cd8..e9a3abb 100644
@@ -5,5 +5,7 @@
 
 extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
                                 int req, void *param);
+extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                                    struct vfio_eeh_pe_op *op);
 
 #endif
author
#9 lore raw
Quoted 92 lines · Gavin Shan
Quoted 74 lines · Alex Williamson
Quoted 73 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +7 -0
index 148eb53..ed07814 100644
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {
+            error_report("vfio: cannot handle EEH event on group %d\n",
+                         groupid);
+            return -1;
+        }
+
         break;
     default:
         /* Return an error on unknown requests */
hw/vfio/pci-stub.c new file +11 -0
new file mode 100644
index 0000000..7726a7a
@@ -0,0 +1,17 @@
+/*
+ * To include the file on !CONFIG_PCI
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <linux/vfio.h>
+
+#include "exec/memory.h"
+#include "hw/vfio/vfio.h"
Quoted 9 lines

hw/vfio/pci-stub.c line 17

Quoted 6 lines
hw/vfio/pci-stub.c new file +6 -0
+
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    return -1;
+}

How about just a static inline in vfio.h?

Yes, It would make things simpler to have something as follows, but I didn't find there is a header file, which includes "#define CONFIG_PCI 1" or similar thing. Do you know the header file containing CONFIG_PCI, or alternative macro for the purpose?

#ifdef CONFIG_PCI /* Or alternative macro */
extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,

Quoted 9 lines
				    struct vfio_eeh_pe_op *op);
#else
static ineline int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
                                           struct vfio_eeh_pe_op *op)
{
   return -1;
}

#endif /* CONFIG_PCI */

Alex.W, any idea on this? :-)

Thanks,
Gavin

Quoted 64 lines
Quoted 64 lines
Quoted 61 lines
hw/vfio/pci.c +38 -0
index 6b80539..fca1edc 100644
@@ -3319,6 +3319,44 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
     vdev->req_enabled = false;
 }
 
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    VFIOGroup *group;
+    VFIODevice *vbasedev;
+    VFIOPCIDevice *vdev;
+
+    group = vfio_get_group(groupid, as);
+    if (!group) {
+        error_report("vfio: group %d not found\n", groupid);
+        return -1;
+    }
+
+    switch (op->op) {
+    case VFIO_EEH_PE_RESET_HOT:
+    case VFIO_EEH_PE_RESET_FUNDAMENTAL:
+        /*
+         * The MSIx table will be cleaned out by reset. We need
+         * disable it so that it can be reenabled properly. Also,
+         * the cached MSIx table should be cleared as it's not
+         * reflecting the contents in hardware.
+         */
+        QLIST_FOREACH(vbasedev, &group->device_list, next) {
+            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+            if (msix_enabled(&vdev->pdev)) {
+                vfio_disable_msix(vdev);
+            }
+
+            msix_reset(&vdev->pdev);
+        }
+
+        break;
+    }
+
+    vfio_put_group(group);
+    return 0;
+}
+
 static int vfio_initfn(PCIDevice *pdev)
 {
     VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
include/hw/vfio/vfio.h +2 -0
index 0b26cd8..e9a3abb 100644
@@ -5,5 +5,7 @@
 
 extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
                                 int req, void *param);
+extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                                    struct vfio_eeh_pe_op *op);
 
 #endif
#10 lore raw
In reply to Gavin Shan
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 92 lines
hw/vfio/common.c +5 -0
+            error_report("vfio: cannot handle EEH event on group %d\n",
+                         groupid);
+            return -1;
+        }
+
         break;
     default:
         /* Return an error on unknown requests */
hw/vfio/pci-stub.c new file +17 -0
new file mode 100644
index 0000000..7726a7a
@@ -0,0 +1,17 @@
+/*
+ * To include the file on !CONFIG_PCI
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <linux/vfio.h>
+
+#include "exec/memory.h"
+#include "hw/vfio/vfio.h"
+
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    return -1;
+}
hw/vfio/pci.c +38 -0
index 6b80539..fca1edc 100644
@@ -3319,6 +3319,44 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
     vdev->req_enabled = false;
 }
 
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    VFIOGroup *group;
+    VFIODevice *vbasedev;
+    VFIOPCIDevice *vdev;
+
+    group = vfio_get_group(groupid, as);
+    if (!group) {
+        error_report("vfio: group %d not found\n", groupid);
+        return -1;
+    }
+
+    switch (op->op) {
+    case VFIO_EEH_PE_RESET_HOT:
+    case VFIO_EEH_PE_RESET_FUNDAMENTAL:
+        /*
+         * The MSIx table will be cleaned out by reset. We need
+         * disable it so that it can be reenabled properly. Also,
+         * the cached MSIx table should be cleared as it's not
+         * reflecting the contents in hardware.
+         */
+        QLIST_FOREACH(vbasedev, &group->device_list, next) {
+            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+            if (msix_enabled(&vdev->pdev)) {
+                vfio_disable_msix(vdev);
+            }
+
+            msix_reset(&vdev->pdev);
+        }
+
+        break;
+    }
+
+    vfio_put_group(group);
+    return 0;
+}
+
 static int vfio_initfn(PCIDevice *pdev)
 {
     VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
include/hw/vfio/vfio.h +2 -0
index 0b26cd8..e9a3abb 100644
@@ -5,5 +5,7 @@
 
 extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
                                 int req, void *param);
+extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                                    struct vfio_eeh_pe_op *op);
 
 #endif
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#11 lore raw
Quoted 45 lines · David Gibson
Quoted 44 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
Quoted 9 lines

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 4 lines
hw/vfio/common.c +2 -0
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl(). All those callers are implemtend in sPAPR platform (spapr_pci_vfio.c). I didn't put the logic there because:

- VFIOPCIDevice is invisible to sPAPR platform.
- We can't tell one particular PCI device attached to sPAPRPHBState is the basement of VFIOPCIDevice, or emulated PCI device.

Thanks,
Gavin

Quoted 99 lines
Quoted 93 lines
hw/vfio/common.c +5 -0
+            error_report("vfio: cannot handle EEH event on group %d\n",
+                         groupid);
+            return -1;
+        }
+
         break;
     default:
         /* Return an error on unknown requests */
hw/vfio/pci-stub.c new file +17 -0
new file mode 100644
index 0000000..7726a7a
@@ -0,0 +1,17 @@
+/*
+ * To include the file on !CONFIG_PCI
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <linux/vfio.h>
+
+#include "exec/memory.h"
+#include "hw/vfio/vfio.h"
+
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    return -1;
+}
hw/vfio/pci.c +38 -0
index 6b80539..fca1edc 100644
@@ -3319,6 +3319,44 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
     vdev->req_enabled = false;
 }
 
+int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                             struct vfio_eeh_pe_op *op)
+{
+    VFIOGroup *group;
+    VFIODevice *vbasedev;
+    VFIOPCIDevice *vdev;
+
+    group = vfio_get_group(groupid, as);
+    if (!group) {
+        error_report("vfio: group %d not found\n", groupid);
+        return -1;
+    }
+
+    switch (op->op) {
+    case VFIO_EEH_PE_RESET_HOT:
+    case VFIO_EEH_PE_RESET_FUNDAMENTAL:
+        /*
+         * The MSIx table will be cleaned out by reset. We need
+         * disable it so that it can be reenabled properly. Also,
+         * the cached MSIx table should be cleared as it's not
+         * reflecting the contents in hardware.
+         */
+        QLIST_FOREACH(vbasedev, &group->device_list, next) {
+            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+            if (msix_enabled(&vdev->pdev)) {
+                vfio_disable_msix(vdev);
+            }
+
+            msix_reset(&vdev->pdev);
+        }
+
+        break;
+    }
+
+    vfio_put_group(group);
+    return 0;
+}
+
 static int vfio_initfn(PCIDevice *pdev)
 {
     VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
include/hw/vfio/vfio.h +2 -0
index 0b26cd8..e9a3abb 100644
@@ -5,5 +5,7 @@
 
 extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
                                 int req, void *param);
+extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid,
+                                    struct vfio_eeh_pe_op *op);
 
 #endif
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#12 lore raw
Quoted 56 lines · Gavin Shan
Quoted 45 lines · David Gibson
Quoted 44 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
Quoted 9 lines

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 4 lines
hw/vfio/common.c +2 -0
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 4 lines

All those callers are implemtend in sPAPR
platform (spapr_pci_vfio.c). I didn't put the logic there because:

- VFIOPCIDevice is invisible to sPAPR platform.

It seems kind of silly that VFIOPCIDevice isn't visible to spapr_pci_vfio.c.

Quoted 2 lines

- We can't tell one particular PCI device attached to sPAPRPHBState is the basement of VFIOPCIDevice, or emulated PCI device.

I'm not sure what you mean by that.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#13 lore raw
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Thanks,
Gavin

Quoted 19 lines
Quoted 4 lines

All those callers are implemtend in sPAPR
platform (spapr_pci_vfio.c). I didn't put the logic there because:

- VFIOPCIDevice is invisible to sPAPR platform.

It seems kind of silly that VFIOPCIDevice isn't visible to spapr_pci_vfio.c.

Quoted 2 lines

- We can't tell one particular PCI device attached to sPAPRPHBState is the basement of VFIOPCIDevice, or emulated PCI device.

I'm not sure what you mean by that.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#14 lore raw
Quoted 67 lines · Gavin Shan
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 3 lines

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Well, I don't think your wrapper should be multiplexed. The multiplex works for the simple ioctl() wrapper, because there really is nothing that varies apart from the exact ioctl number called.

But now that you have different operations here, I think you want wrappers for each one - each one will call the ioctl(), then do the specific extra steps necessary for that operation. So vfio_container_event() will go away as well, split into various other functions.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#15 lore raw
Quoted 76 lines · David Gibson
Quoted 67 lines · Gavin Shan
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 3 lines

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Well, I don't think your wrapper should be multiplexed. The multiplex works for the simple ioctl() wrapper, because there really is nothing that varies apart from the exact ioctl number called.

Quoted 6 lines

But now that you have different operations here, I think you want wrappers for each one - each one will call the ioctl(), then do the specific extra steps necessary for that operation. So vfio_container_event() will go away as well, split into various other functions.

It wouldn't a good idea if I understand your proposal correctly. Currnetly, the global function vfio_container_ioctl() can be called from sPAPR platform for any ioctl commands handled in kernel source file vfio_iommu_spapr_tce.c, which means the function isn't called for EEH only. Other sPAPR TCE container ioctl commands are also routed by this function. There will be lots if having one global function for each ioctl commands, which just improve the cost to maintain the code.

Alternatively, we might expose another function vfio_container_eeh_ioctl(), which calls vfio_container_ioctl() after doing what we did in vfio_container_event() if necessary.

Thanks,
Gavin

Quoted 5 lines
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#16 lore raw
Quoted 84 lines · Gavin Shan
Quoted 76 lines · David Gibson
Quoted 67 lines · Gavin Shan
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 3 lines

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Well, I don't think your wrapper should be multiplexed. The multiplex works for the simple ioctl() wrapper, because there really is nothing that varies apart from the exact ioctl number called.

Quoted 6 lines

But now that you have different operations here, I think you want wrappers for each one - each one will call the ioctl(), then do the specific extra steps necessary for that operation. So vfio_container_event() will go away as well, split into various other functions.

Quoted 7 lines

It wouldn't a good idea if I understand your proposal correctly. Currnetly, the global function vfio_container_ioctl() can be called from sPAPR platform for any ioctl commands handled in kernel source file vfio_iommu_spapr_tce.c, which means the function isn't called for EEH only. Other sPAPR TCE container ioctl commands are also routed by this function. There will be lots if having one global function for each ioctl commands, which just improve the cost to maintain the code.

I don't really follow your objection. I'm only suggesting separate wrappers for things which require extra actions currently implemented in vfio_container_event(). Things which only ned the plain ioctl() can still use the simple vfio_container_ioctl() wrapper.

Quoted 9 lines

Alternatively, we might expose another function vfio_container_eeh_ioctl(), which calls vfio_container_ioctl() after doing what we did in vfio_container_event() if necessary.

Thanks,
Gavin

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#17 lore raw
Quoted 93 lines · David Gibson
Quoted 84 lines · Gavin Shan
Quoted 76 lines · David Gibson
Quoted 67 lines · Gavin Shan
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 3 lines

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Well, I don't think your wrapper should be multiplexed. The multiplex works for the simple ioctl() wrapper, because there really is nothing that varies apart from the exact ioctl number called.

Quoted 6 lines

But now that you have different operations here, I think you want wrappers for each one - each one will call the ioctl(), then do the specific extra steps necessary for that operation. So vfio_container_event() will go away as well, split into various other functions.

Quoted 7 lines

It wouldn't a good idea if I understand your proposal correctly. Currnetly, the global function vfio_container_ioctl() can be called from sPAPR platform for any ioctl commands handled in kernel source file vfio_iommu_spapr_tce.c, which means the function isn't called for EEH only. Other sPAPR TCE container ioctl commands are also routed by this function. There will be lots if having one global function for each ioctl commands, which just improve the cost to maintain the code.

Quoted 4 lines

I don't really follow your objection. I'm only suggesting separate wrappers for things which require extra actions currently implemented in vfio_container_event(). Things which only ned the plain ioctl() can still use the simple vfio_container_ioctl() wrapper.

vfio_container_ioctl() also filters to a limited set of ioctls, it clearly does not allow any ioctl.

Quoted 10 lines
Quoted 9 lines

Alternatively, we might expose another function vfio_container_eeh_ioctl(), which calls vfio_container_ioctl() after doing what we did in vfio_container_event() if necessary.

Thanks,
Gavin

author
#18 lore raw
Quoted 94 lines · Alex Williamson
Quoted 93 lines · David Gibson
Quoted 91 lines · Gavin Shan
Quoted 76 lines · David Gibson
Quoted 67 lines · Gavin Shan
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 3 lines

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Well, I don't think your wrapper should be multiplexed. The multiplex works for the simple ioctl() wrapper, because there really is nothing that varies apart from the exact ioctl number called.

Quoted 6 lines

But now that you have different operations here, I think you want wrappers for each one - each one will call the ioctl(), then do the specific extra steps necessary for that operation. So vfio_container_event() will go away as well, split into various other functions.

It wouldn't a good idea if I understand your proposal correctly. Currnetly, the global function vfio_container_ioctl() can be called from sPAPR platform for any ioctl commands handled in kernel source file vfio_iommu_spapr_tce.c, which means the function isn't called for EEH only. Other sPAPR TCE container ioctl commands are also routed by this function. There will be lots if having one global function for each ioctl commands, which just improve the cost to maintain the code.

Quoted 8 lines
Quoted 4 lines

I don't really follow your objection. I'm only suggesting separate wrappers for things which require extra actions currently implemented in vfio_container_event(). Things which only ned the plain ioctl() can still use the simple vfio_container_ioctl() wrapper.

vfio_container_ioctl() also filters to a limited set of ioctls, it clearly does not allow any ioctl.

Ok. I think your guys expect something like follows. Note that the following vfio_container_eeh_ioctl() will accept a limited set of EEH operations, similar to what's doing in vfio_contain_ioctl() to the ioctl commands:

If you agree to have the changes, I'll put another patch on top of this one to replace vfio_container_ioctl() in spapr_pci_vfio.c with vfio_container_eeh_ioctl() for EEH cases.

int vfio_container_eeh_ioctl(AddressSpace *as, int32_t groupid,
struct vfio_eeh_pe_op *op)

{
    switch (op->op) {
    case VFIO_EEH_PE_RESET_HOT:
    case VFIO_EEH_PE_RESET_FUNDAMENTAL: {
        VFIOGroup *group;
        VFIODevice *vbasedev;
        VFIOPCIDevice *vdev;

        /*
         * The MSIx table will be cleaned out by reset. We need
         * disable it so that it can be reenabled properly. Also,
         * the cached MSIx table should be cleared as it's not
         * reflecting the contents in hardware.
         */
        group = vfio_get_group(groupid, as);
        if (!group) {
            error_report("vfio: group %d not found\n", groupid);
            return -1;
        }

        QLIST_FOREACH(vbasedev, &group->device_list, next) {
            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
            if (msix_enabled(&vdev->pdev)) {
                vfio_disable_msix(vdev);
            }

            msix_reset(&vdev->pdev);
        }

        vfio_put_group(group);

        break;
    }
    case VFIO_EEH_PE_DISABLE:
    case VFIO_EEH_PE_ENABLE:
    case VFIO_EEH_PE_UNFREEZE_IO:
    case VFIO_EEH_PE_UNFREEZE_DMA:
    case VFIO_EEH_PE_GET_STATE:
    case VFIO_EEH_PE_RESET_DEACTIVATE:
    case VFIO_EEH_PE_CONFIGURE:
        break;
    default:
        error_report("vfio: unsupported EEH operation %X\n", op->op);
        return -1;
    }

    return vfio_container_ioctl(as, groupid, VFIO_EEH_PE_OP, op);
}

Thanks,
Gavin

Quoted 13 lines
Quoted 10 lines
Quoted 9 lines

Alternatively, we might expose another function vfio_container_eeh_ioctl(), which calls vfio_container_ioctl() after doing what we did in vfio_container_event() if necessary.

Thanks,
Gavin

#19 lore raw
Quoted 154 lines · Gavin Shan
Quoted 94 lines · Alex Williamson
Quoted 93 lines · David Gibson
Quoted 91 lines · Gavin Shan
Quoted 76 lines · David Gibson
Quoted 67 lines · Gavin Shan
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 3 lines

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Well, I don't think your wrapper should be multiplexed. The multiplex works for the simple ioctl() wrapper, because there really is nothing that varies apart from the exact ioctl number called.

Quoted 6 lines

But now that you have different operations here, I think you want wrappers for each one - each one will call the ioctl(), then do the specific extra steps necessary for that operation. So vfio_container_event() will go away as well, split into various other functions.

It wouldn't a good idea if I understand your proposal correctly. Currnetly, the global function vfio_container_ioctl() can be called from sPAPR platform for any ioctl commands handled in kernel source file vfio_iommu_spapr_tce.c, which means the function isn't called for EEH only. Other sPAPR TCE container ioctl commands are also routed by this function. There will be lots if having one global function for each ioctl commands, which just improve the cost to maintain the code.

Quoted 8 lines
Quoted 4 lines

I don't really follow your objection. I'm only suggesting separate wrappers for things which require extra actions currently implemented in vfio_container_event(). Things which only ned the plain ioctl() can still use the simple vfio_container_ioctl() wrapper.

vfio_container_ioctl() also filters to a limited set of ioctls, it clearly does not allow any ioctl.

Ok. I think your guys expect something like follows. Note that the following vfio_container_eeh_ioctl() will accept a limited set of EEH operations, similar to what's doing in vfio_contain_ioctl() to the ioctl commands:

If you agree to have the changes, I'll put another patch on top of this one to replace vfio_container_ioctl() in spapr_pci_vfio.c with vfio_container_eeh_ioctl() for EEH cases.

int vfio_container_eeh_ioctl(AddressSpace *as, int32_t groupid,
struct vfio_eeh_pe_op *op)

{
    switch (op->op) {
    case VFIO_EEH_PE_RESET_HOT:
    case VFIO_EEH_PE_RESET_FUNDAMENTAL: {
        VFIOGroup *group;
        VFIODevice *vbasedev;
        VFIOPCIDevice *vdev;

        /*
         * The MSIx table will be cleaned out by reset. We need
         * disable it so that it can be reenabled properly. Also,
         * the cached MSIx table should be cleared as it's not
         * reflecting the contents in hardware.
         */
        group = vfio_get_group(groupid, as);
        if (!group) {
            error_report("vfio: group %d not found\n", groupid);
            return -1;
        }

        QLIST_FOREACH(vbasedev, &group->device_list, next) {
            vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
            if (msix_enabled(&vdev->pdev)) {
                vfio_disable_msix(vdev);
            }

            msix_reset(&vdev->pdev);
        }

        vfio_put_group(group);

        break;
    }
    case VFIO_EEH_PE_DISABLE:
    case VFIO_EEH_PE_ENABLE:
    case VFIO_EEH_PE_UNFREEZE_IO:
    case VFIO_EEH_PE_UNFREEZE_DMA:
    case VFIO_EEH_PE_GET_STATE:
    case VFIO_EEH_PE_RESET_DEACTIVATE:
    case VFIO_EEH_PE_CONFIGURE:
Quoted 8 lines
        break;
    default:
        error_report("vfio: unsupported EEH operation %X\n", op->op);
        return -1;
    }

    return vfio_container_ioctl(as, groupid, VFIO_EEH_PE_OP, op);
}

No, extra operation specific logic inside the ioctl wrapper is exactly what I want to avoid. Instead I want to see vfio_container_eeh_ioctl() remain as it is now - doing nothing but verifying the ioctl() number, then passing the arguments on to ioctl().

What I'm expecting is then to add a new functions, along the lines of:

int vfio_eeh_pe_reset(...)

{
    VFIOGroup *group;
    VFIODevice *vbasedev;
    VFIOPCIDevice *vdev;

    /*
     * The MSIx table will be cleaned out by reset. We need
     * disable it so that it can be reenabled properly. Also,
     * the cached MSIx table should be cleared as it's not
     * reflecting the contents in hardware.
     */
    group = vfio_get_group(groupid, as);
    if (!group) {
        error_report("vfio: group %d not found\n", groupid);
        return -1;
    }

    QLIST_FOREACH(vbasedev, &group->device_list, next) {
        vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
        if (msix_enabled(&vdev->pdev)) {
            vfio_disable_msix(vdev);
        }

        msix_reset(&vdev->pdev);
    }

    vfio_put_group(group);

    return vfio_eeh_container_ioctl(as, groupid,
                                    VFIO_EEH_PE_RESET_FUNDAMENTAL, op);
}

I this function can build the op structure itself from sensible arguments, then that's even better.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#20 lore raw
Quoted 113 lines · David Gibson
Quoted 112 lines · Gavin Shan
Quoted 94 lines · Alex Williamson
Quoted 93 lines · David Gibson
Quoted 91 lines · Gavin Shan
Quoted 76 lines · David Gibson
Quoted 67 lines · Gavin Shan
Quoted 57 lines · David Gibson
Quoted 56 lines · Gavin Shan
Quoted 54 lines · David Gibson
Quoted 42 lines · Gavin Shan

The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.

The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.

---
v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate
error message for this function. Dropped vfio_put_group() on NULL group

---
 hw/vfio/Makefile.objs  |  6 +++++-
 hw/vfio/common.c       |  7 +++++++
 hw/vfio/pci-stub.c     | 17 +++++++++++++++++
 hw/vfio/pci.c          | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio.h |  2 ++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 hw/vfio/pci-stub.c
hw/vfio/Makefile.objs +5 -1
index e31f30e..1b8a065 100644
@@ -1,4 +1,8 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
-obj-$(CONFIG_PCI) += pci.o
+ifeq ($(CONFIG_PCI), y)
+obj-y += pci.o
+else
+obj-y += pci-stub.o
+endif
 endif
hw/vfio/common.c +0 -0
index 148eb53..ed07814 100644

hw/vfio/common.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 954

Quoted 6 lines
hw/vfio/common.c +2 -0
@@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
     switch (req) {
     case VFIO_CHECK_EXTENSION:
     case VFIO_IOMMU_SPAPR_TCE_GET_INFO:
+        break;
     case VFIO_EEH_PE_OP:
+        if (vfio_container_eeh_event(as, groupid, param) != 0) {

I really dislike the idea of having an arbitrarily complex side effect from a function whose name suggest's it's just a trivial wrapper around the ioctl().

Quoted 8 lines
Quoted 2 lines

Ok. I guess you would like putting the complex in the callers of vfio_container_ioctl().

Well.. maybe. I'd also be happy if helper functions were implemeneted which both called the ioctl() and did the other necessary pieces. They should just be called something that indicates their full function, not a name which suggests they're just an ioctl wrapper.

Quoted 3 lines

Indeed, vfio_container_ioctl() isn't indicating what the function is doing. How about renaming it to vfio_container_event_and_ioctl()? I'm always bad at giving a good function name :)

Well, I don't think your wrapper should be multiplexed. The multiplex works for the simple ioctl() wrapper, because there really is nothing that varies apart from the exact ioctl number called.

Quoted 6 lines

But now that you have different operations here, I think you want wrappers for each one - each one will call the ioctl(), then do the specific extra steps necessary for that operation. So vfio_container_event() will go away as well, split into various other functions.

It wouldn't a good idea if I understand your proposal correctly. Currnetly, the global function vfio_container_ioctl() can be called from sPAPR platform for any ioctl commands handled in kernel source file vfio_iommu_spapr_tce.c, which means the function isn't called for EEH only. Other sPAPR TCE container ioctl commands are also routed by this function. There will be lots if having one global function for each ioctl commands, which just improve the cost to maintain the code.

Quoted 8 lines
Quoted 4 lines

I don't really follow your objection. I'm only suggesting separate wrappers for things which require extra actions currently implemented in vfio_container_event(). Things which only ned the plain ioctl() can still use the simple vfio_container_ioctl() wrapper.

vfio_container_ioctl() also filters to a limited set of ioctls, it clearly does not allow any ioctl.

Ok. I think your guys expect something like follows. Note that the following vfio_container_eeh_ioctl() will accept a limited set of EEH operations, similar to what's doing in vfio_contain_ioctl() to the ioctl commands:

If you agree to have the changes, I'll put another patch on top of this one to replace vfio_container_ioctl() in spapr_pci_vfio.c with vfio_container_eeh_ioctl() for EEH cases.

[snip ...]

Quoted 7 lines

No, extra operation specific logic inside the ioctl wrapper is exactly what I want to avoid. Instead I want to see vfio_container_eeh_ioctl() remain as it is now - doing nothing but verifying the ioctl() number, then passing the arguments on to ioctl().

I think you were talking about vfio_container_ioctl() :)

Quoted 35 lines

What I'm expecting is then to add a new functions, along the lines of:

int vfio_eeh_pe_reset(...)

{
   VFIOGroup *group;
   VFIODevice *vbasedev;
   VFIOPCIDevice *vdev;

   /*
    * The MSIx table will be cleaned out by reset. We need
    * disable it so that it can be reenabled properly. Also,
    * the cached MSIx table should be cleared as it's not
    * reflecting the contents in hardware.
    */
   group = vfio_get_group(groupid, as);
   if (!group) {
       error_report("vfio: group %d not found\n", groupid);
       return -1;
   }

   QLIST_FOREACH(vbasedev, &group->device_list, next) {
       vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
       if (msix_enabled(&vdev->pdev)) {
           vfio_disable_msix(vdev);
       }

       msix_reset(&vdev->pdev);
   }

   vfio_put_group(group);

   return vfio_eeh_container_ioctl(as, groupid,
                                   VFIO_EEH_PE_RESET_FUNDAMENTAL, op);
}
Quoted 3 lines

I this function can build the op structure itself from sensible arguments, then that's even better.

Thanks, David. I assume that Alex doesn't object to this and I'll change the code according to your suggestion. I'll send next revision soon.

Thanks,
Gavin

Quoted 5 lines
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson