Skip to contentSkip to conversation

hw/pci: SR-IOV related fixes and improvements

PATCH Superseded Akihiko Odaki 4 participants 30 messages Aug 23, 2024 – Sep 12, 2024

v15 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
#0 lore raw

v15 cover hw/pci: SR-IOV related fixes and improvements

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

[1]: https://patchew.org/QEMU/[email protected]/

---
Changes in v15:
- Fixed variable shadowing in patch
"pcie_sriov: Remove num_vfs from PCIESriovPF"
- Link to v14: https://lore.kernel.org/r/[email protected]

Changes in v14:
- Dropped patch "pcie_sriov: Ensure VF function number does not overflow" as I found the restriction it imposes is unnecessary.
- Link to v13: https://lore.kernel.org/r/[email protected]

Changes in v13:
- Added patch "s390x/pci: Check for multifunction after device realization". I found SR-IOV devices, which are multifunction devices, are not supposed to work at all with s390x on QEMU.
- Link to v12: https://lore.kernel.org/r/[email protected]

Changes in v12:
- Changed to ignore invalid PCI_SRIOV_NUM_VF writes as done for PCI_SRIOV_CTRL_VFE.
- Updated the message for patch "hw/pci: Use -1 as the default value for rombar". (Markus Armbruster)
- Link to v11: https://lore.kernel.org/r/[email protected]

Changes in v11:
- Rebased.
- Dropped patch "hw/pci: Convert rom_bar into OnOffAuto".
- Added patch "hw/pci: Use -1 as the default value for rombar".
- Added for-9.2 to give a testing period for possible breakage with libvirt/s390x.
- Link to v10: https://lore.kernel.org/r/[email protected]

Changes in v10:
- Added patch "hw/ppc/spapr_pci: Do not reject VFs created after a PF".
- Added patch "hw/ppc/spapr_pci: Do not create DT for disabled PCI device".
- Added patch "hw/pci: Convert rom_bar into OnOffAuto".
- Dropped patch "hw/pci: Determine if rombar is explicitly enabled".
- Dropped patch "hw/qdev: Remove opts member".
- Link to v9: https://lore.kernel.org/r/[email protected]

Changes in v9:
- Rebased.
- Restored '#include "qapi/error.h"' (Michael S. Tsirkin)
- Added patch "pcie_sriov: Ensure VF function number does not overflow" to fix abortion with wrong PF addr.
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Clarified that "hw/pci: Replace -1 with UINT32_MAX for romsize" is not a bug fix. (Markus Armbruster)
- Squashed patch "vfio: Avoid inspecting option QDict for rombar" into "hw/pci: Determine if rombar is explicitly enabled".
(Markus Armbruster)
- Noted the minor semantics change for patch "hw/pci: Determine if rombar is explicitly enabled". (Markus Armbruster)
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Replaced -1 with UINT32_MAX when expressing uint32_t.
(Markus Armbruster)
- Added patch "hw/pci: Replace -1 with UINT32_MAX for romsize".
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Fixed migration.
- Added patch "pcie_sriov: Do not manually unrealize".
- Restored patch "pcie_sriov: Release VFs failed to realize" that was missed in v5.
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Added patch "hw/pci: Always call pcie_sriov_pf_reset()".
- Added patch "pcie_sriov: Reset SR-IOV extended capability".
- Removed a reference to PCI_SRIOV_CTRL_VFE in hw/nvme.
(Michael S. Tsirkin)
- Noted the impact on the guest of patch "pcie_sriov: Do not reset NumVFs after unregistering VFs". (Michael S. Tsirkin)
- Changed to use pcie_sriov_num_vfs().
- Restored pci_set_power() and changed it to call pci_set_enabled() only for PFs with an expalanation. (Michael S. Tsirkin)
- Reordered patches.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Reverted the change to pci_rom_bar_explicitly_enabled().
(Michael S. Tsirkin)
- Added patch "pcie_sriov: Do not reset NumVFs after unregistering VFs".
- Added patch "hw/nvme: Refer to dev->exp.sriov_pf.num_vfs".
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Extracted patch "hw/pci: Use -1 as a default value for rombar" from patch "hw/pci: Determine if rombar is explicitly enabled"
(Philippe Mathieu-Daudé)
- Added an audit result of PCIDevice::rom_bar to the message of patch "hw/pci: Use -1 as a default value for rombar"
(Philippe Mathieu-Daudé)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Reset after enabling a function so that NVMe VF state gets updated.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Akihiko Odaki (11):
hw/pci: Rename has_power to enabled hw/ppc/spapr_pci: Do not create DT for disabled PCI device hw/ppc/spapr_pci: Do not reject VFs created after a PF s390x/pci: Check for multifunction after device realization
pcie_sriov: Do not manually unrealize
pcie_sriov: Reuse SR-IOV VF device instances
pcie_sriov: Release VFs failed to realize
pcie_sriov: Remove num_vfs from PCIESriovPF
pcie_sriov: Register VFs after migration
hw/pci: Use -1 as the default value for rombar hw/qdev: Remove opts member

 docs/pcie_sriov.txt         |   8 ++-
 include/hw/pci/pci.h        |   2 +-
 include/hw/pci/pci_device.h |  19 +++++-
 include/hw/pci/pcie_sriov.h |   9 +--
 include/hw/qdev-core.h      |   4 --
 hw/core/qdev.c              |   1 -
 hw/net/igb.c                |  13 +++-
 hw/nvme/ctrl.c              |  24 ++++---
 hw/pci/pci.c                |  23 ++++---
 hw/pci/pci_host.c           |   4 +-
 hw/pci/pcie_sriov.c         | 153 +++++++++++++++++++++++---------------------
 hw/ppc/spapr_pci.c          |   8 ++-
 hw/s390x/s390-pci-bus.c     |  14 ++--
 hw/vfio/pci.c               |   5 +-
 system/qdev-monitor.c       |  12 ++--
 hw/pci/trace-events         |   2 +-
 16 files changed, 175 insertions(+), 126 deletions(-)

---
base-commit: 31669121a01a14732f57c49400bc239cf9fd505f
change-id: 20240129-reuse-faae22b11934

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>
#1 lore raw

PATCH v15 1/11 hw/pci: Rename has_power to enabled

The renamed state will not only represent powering state of PFs, but also represent SR-IOV VF enablement in the future.

---
 include/hw/pci/pci.h        |  7 ++++++-
 include/hw/pci/pci_device.h |  2 +-
 hw/pci/pci.c                | 14 +++++++-------
 hw/pci/pci_host.c           |  4 ++--
 4 files changed, 16 insertions(+), 11 deletions(-)
include/hw/pci/pci.h +6 -1
index eb26cac81098..fe04b4fafd04 100644
@@ -678,6 +678,11 @@ static inline void pci_irq_pulse(PCIDevice *pci_dev)
 }
 
 MSIMessage pci_get_msi_message(PCIDevice *dev, int vector);
-void pci_set_power(PCIDevice *pci_dev, bool state);
+void pci_set_enabled(PCIDevice *pci_dev, bool state);
+
+static inline void pci_set_power(PCIDevice *pci_dev, bool state)
+{
+    pci_set_enabled(pci_dev, state);
+}
 
 #endif
include/hw/pci/pci_device.h +1 -1
index 15694f248948..f38fb3111954 100644
@@ -57,7 +57,7 @@ typedef struct PCIReqIDCache PCIReqIDCache;
 struct PCIDevice {
     DeviceState qdev;
     bool partially_hotplugged;
-    bool has_power;
+    bool enabled;
 
     /* PCI config space */
     uint8_t *config;
hw/pci/pci.c +7 -7
index fab86d056721..b532888e8f6c 100644
@@ -1525,7 +1525,7 @@ static void pci_update_mappings(PCIDevice *d)
             continue;
 
         new_addr = pci_bar_address(d, i, r->type, r->size);
-        if (!d->has_power) {
+        if (!d->enabled) {
             new_addr = PCI_BAR_UNMAPPED;
         }
 
@@ -1613,7 +1613,7 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int
         pci_update_irq_disabled(d, was_irq_disabled);
         memory_region_set_enabled(&d->bus_master_enable_region,
                                   (pci_get_word(d->config + PCI_COMMAND)
-                                   & PCI_COMMAND_MASTER) && d->has_power);
+                                   & PCI_COMMAND_MASTER) && d->enabled);
     }
 
     msi_write_config(d, addr, val_in, l);
@@ -2884,18 +2884,18 @@ MSIMessage pci_get_msi_message(PCIDevice *dev, int vector)
     return msg;
 }
 
-void pci_set_power(PCIDevice *d, bool state)
+void pci_set_enabled(PCIDevice *d, bool state)
 {
-    if (d->has_power == state) {
+    if (d->enabled == state) {
         return;
     }
 
-    d->has_power = state;
+    d->enabled = state;
     pci_update_mappings(d);
     memory_region_set_enabled(&d->bus_master_enable_region,
                               (pci_get_word(d->config + PCI_COMMAND)
-                               & PCI_COMMAND_MASTER) && d->has_power);
-    if (!d->has_power) {
+                               & PCI_COMMAND_MASTER) && d->enabled);
+    if (!d->enabled) {
         pci_device_reset(d);
     }
 }
hw/pci/pci_host.c +2 -2
index dfe6fe618401..0d82727cc9dd 100644
@@ -86,7 +86,7 @@ void pci_host_config_write_common(PCIDevice *pci_dev, uint32_t addr,
      * allowing direct removal of unexposed functions.
      */
     if ((pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) ||
-        !pci_dev->has_power || is_pci_dev_ejected(pci_dev)) {
+        !pci_dev->enabled || is_pci_dev_ejected(pci_dev)) {
         return;
     }
 
@@ -111,7 +111,7 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr,
      * allowing direct removal of unexposed functions.
      */
     if ((pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) ||
-        !pci_dev->has_power || is_pci_dev_ejected(pci_dev)) {
+        !pci_dev->enabled || is_pci_dev_ejected(pci_dev)) {
         return ~0x0;
     }
 
Signature · 1 line
2.46.0
#2 lore raw

PATCH v15 2/11 hw/ppc/spapr_pci: Do not create DT for disabled PCI device

In reply to Akihiko Odaki

Disabled means it is a disabled SR-IOV VF or it is powered off, and hidden from the guest.

---
 hw/ppc/spapr_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/ppc/spapr_pci.c +4 -0
index 7cf9904c3546..f63182a03c41 100644
@@ -1296,6 +1296,10 @@ static void spapr_dt_pci_device_cb(PCIBus *bus, PCIDevice *pdev,
         return;
     }
 
+    if (!pdev->enabled) {
+        return;
+    }
+
     err = spapr_dt_pci_device(p->sphb, pdev, p->fdt, p->offset);
     if (err < 0) {
         p->err = err;
Signature · 1 line
2.46.0
#3 lore raw

PATCH v15 3/11 hw/ppc/spapr_pci: Do not reject VFs created after a PF

In reply to Akihiko Odaki

A PF may automatically create VFs and the PF may be function 0.

---
 hw/ppc/spapr_pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci.c +3 -1
index f63182a03c41..ed4454bbf79e 100644
@@ -1573,7 +1573,9 @@ static void spapr_pci_pre_plug(HotplugHandler *plug_handler,
      * hotplug, we do not allow functions to be hotplugged to a
      * slot that already has function 0 present
      */
-    if (plugged_dev->hotplugged && bus->devices[PCI_DEVFN(slotnr, 0)] &&
+    if (plugged_dev->hotplugged &&
+        !pci_is_vf(pdev) &&
+        bus->devices[PCI_DEVFN(slotnr, 0)] &&
         PCI_FUNC(pdev->devfn) != 0) {
         error_setg(errp, "PCI: slot %d function 0 already occupied by %s,"
                    " additional functions can no longer be exposed to guest.",
Signature · 1 line
2.46.0
#4 lore raw

PATCH v15 4/11 s390x/pci: Check for multifunction after device realization

In reply to Akihiko Odaki

The SR-IOV PFs set the multifunction bits during device realization so check them after that. This forbids adding SR-IOV devices to s390x.

---
 hw/s390x/s390-pci-bus.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
hw/s390x/s390-pci-bus.c +6 -8
index 3e57d5faca18..00b2c1f6157b 100644
@@ -971,14 +971,7 @@ static void s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                     "this device");
     }
 
-    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
-        PCIDevice *pdev = PCI_DEVICE(dev);
-
-        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
-            error_setg(errp, "multifunction not supported in s390");
-            return;
-        }
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
         S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
 
         if (!s390_pci_alloc_idx(s, pbdev)) {
@@ -1069,6 +1062,11 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
         pdev = PCI_DEVICE(dev);
 
+        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+            error_setg(errp, "multifunction not supported in s390");
+            return;
+        }
+
         if (!dev->id) {
             /* In the case the PCI device does not define an id */
             /* we generate one based on the PCI address         */
Signature · 1 line
2.46.0
Tested-by Reviewed-by on v15 4/11
#5 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

Quoted 4 lines · Akihiko Odaki

The SR-IOV PFs set the multifunction bits during device realization so check them after that. This forbids adding SR-IOV devices to s390x.

May be add :

Fixes 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

?

Anyhow,

Thanks,

C.

Quoted 37 lines
---
  hw/s390x/s390-pci-bus.c | 14 ++++++--------
  1 file changed, 6 insertions(+), 8 deletions(-)
hw/s390x/s390-pci-bus.c +6 -8
index 3e57d5faca18..00b2c1f6157b 100644
@@ -971,14 +971,7 @@ static void s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                      "this device");
      }
 
-    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
-        PCIDevice *pdev = PCI_DEVICE(dev);
-
-        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
-            error_setg(errp, "multifunction not supported in s390");
-            return;
-        }
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
          S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
 
          if (!s390_pci_alloc_idx(s, pbdev)) {
@@ -1069,6 +1062,11 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
      } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
          pdev = PCI_DEVICE(dev);
 
+        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+            error_setg(errp, "multifunction not supported in s390");
+            return;
+        }
+
          if (!dev->id) {
              /* In the case the PCI device does not define an id */
              /* we generate one based on the PCI address         */
#6 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

In reply to Akihiko Odaki

+Matthew +Eric

Side note for the maintainers :

Before this change, the igb device, which is multifunction, was working fine under Linux.

Was there a fix in Linux since :

57da367b9ec4 ("s390x/pci: forbid multifunction pci device") 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

?

s390 PCI devices do not have extended capabilities, so the igb device does not expose the SRIOV capability and only the PF is accessible but it doesn't seem to be an issue. (Btw, CONFIG_PCI_IOV is set to y in the default Linux config which is unexpected)

Thanks,

C.

Quoted 41 lines · Akihiko Odaki

The SR-IOV PFs set the multifunction bits during device realization so check them after that. This forbids adding SR-IOV devices to s390x.

---
  hw/s390x/s390-pci-bus.c | 14 ++++++--------
  1 file changed, 6 insertions(+), 8 deletions(-)
hw/s390x/s390-pci-bus.c +6 -8
index 3e57d5faca18..00b2c1f6157b 100644
@@ -971,14 +971,7 @@ static void s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                      "this device");
      }
 
-    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
-        PCIDevice *pdev = PCI_DEVICE(dev);
-
-        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
-            error_setg(errp, "multifunction not supported in s390");
-            return;
-        }
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
          S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
 
          if (!s390_pci_alloc_idx(s, pbdev)) {
@@ -1069,6 +1062,11 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
      } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
          pdev = PCI_DEVICE(dev);
 
+        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+            error_setg(errp, "multifunction not supported in s390");
+            return;
+        }
+
          if (!dev->id) {
              /* In the case the PCI device does not define an id */
              /* we generate one based on the PCI address         */
#7 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

Quoted 13 lines · Cédric Le Goater

+Matthew +Eric

Side note for the maintainers :

Before this change, the igb device, which is multifunction, was working fine under Linux.

Was there a fix in Linux since :

  57da367b9ec4 ("s390x/pci: forbid multifunction pci device") 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug
handler")

Quoted 6 lines

?

s390 PCI devices do not have extended capabilities, so the igb device does not expose the SRIOV capability and only the PF is accessible but it doesn't seem to be an issue. (Btw, CONFIG_PCI_IOV is set to y in the default Linux config which is unexpected)

Doesn't s390x really see extended capabilities? hw/s390x/s390-pci-inst.c has a call pci_config_size() and pci_host_config_write_common(), which means it is exposing the whole PCI Express configuration space. Why can't s390x use extended capabilities then?

The best option for fix would be to replace the SR-IOV implementation with stub if s390x cannot use the SR-IOV capability. However I still need to know at what level I should change the implementation (e.g., is it fine to remove the entire capability, or should I keep the capability while writes to its registers no-op?)

Regards,
Akihiko Odaki

Quoted 49 lines

Thanks,

C.

Quoted 40 lines · Akihiko Odaki

The SR-IOV PFs set the multifunction bits during device realization so check them after that. This forbids adding SR-IOV devices to s390x.

---
  hw/s390x/s390-pci-bus.c | 14 ++++++--------

  1 file changed, 6 insertions(+), 8 deletions(-)
hw/s390x/s390-pci-bus.c +6 -8
index 3e57d5faca18..00b2c1f6157b 100644
@@ -971,14 +971,7 @@ static void s390_pcihost_pre_plug(HotplugHandler 
 *hotplug_dev, DeviceState *dev,
                       "this device");
       }
-    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
-        PCIDevice *pdev = PCI_DEVICE(dev);
-
-        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
-            error_setg(errp, "multifunction not supported in s390");
-            return;
-        }
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
           S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
           if (!s390_pci_alloc_idx(s, pbdev)) {
@@ -1069,6 +1062,11 @@ static void s390_pcihost_plug(HotplugHandler 
 *hotplug_dev, DeviceState *dev,
       } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
           pdev = PCI_DEVICE(dev);
+        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+            error_setg(errp, "multifunction not supported in s390");
+            return;
+        }
+
           if (!dev->id) {
               /* In the case the PCI device does not define an id */
               /* we generate one based on the PCI address         */
#8 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

Quoted 26 lines · Akihiko Odaki
Quoted 13 lines · Cédric Le Goater

+Matthew +Eric

Side note for the maintainers :

Before this change, the igb device, which is multifunction, was working fine under Linux.

Was there a fix in Linux since :

  57da367b9ec4 ("s390x/pci: forbid multifunction pci device") 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug
handler")

Quoted 6 lines

?

s390 PCI devices do not have extended capabilities, so the igb device does not expose the SRIOV capability and only the PF is accessible but it doesn't seem to be an issue. (Btw, CONFIG_PCI_IOV is set to y in the default Linux config which is unexpected)

Doesn't s390x really see extended capabilities? hw/s390x/s390-pci-inst.c has a call pci_config_size() and pci_host_config_write_common(), which means it is exposing the whole PCI Express configuration space. Why can't s390x use extended capabilities then?

Quoted 8 lines

The best option for fix would be to replace the SR-IOV implementation with stub if s390x cannot use the SR-IOV capability. However I still need to know at what level I should change the implementation (e.g., is it fine to remove the entire capability, or should I keep the capability while writes to its registers no-op?)

Regards,
Akihiko Odaki

Note changing caps needs compat hacks for cross version migration to work.

Quoted 49 lines
Quoted 49 lines

Thanks,

C.

Quoted 40 lines · Akihiko Odaki

The SR-IOV PFs set the multifunction bits during device realization so check them after that. This forbids adding SR-IOV devices to s390x.

---
  hw/s390x/s390-pci-bus.c | 14 ++++++--------

  1 file changed, 6 insertions(+), 8 deletions(-)
hw/s390x/s390-pci-bus.c +6 -8
index 3e57d5faca18..00b2c1f6157b 100644
@@ -971,14 +971,7 @@ static void
 s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                       "this device");
       }
-    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
-        PCIDevice *pdev = PCI_DEVICE(dev);
-
-        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
-            error_setg(errp, "multifunction not supported in s390");
-            return;
-        }
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
           S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
           if (!s390_pci_alloc_idx(s, pbdev)) {
@@ -1069,6 +1062,11 @@ static void s390_pcihost_plug(HotplugHandler
 *hotplug_dev, DeviceState *dev,
       } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
           pdev = PCI_DEVICE(dev);
+        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+            error_setg(errp, "multifunction not supported in s390");
+            return;
+        }
+
           if (!dev->id) {
               /* In the case the PCI device does not define an id */
               /* we generate one based on the PCI address         */
#9 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

In reply to Akihiko Odaki
Quoted 8 lines · Akihiko Odaki
Quoted 7 lines · Cédric Le Goater

+Matthew +Eric

Side note for the maintainers :

Before this change, the igb device, which is multifunction, was working fine under Linux.

Quoted 6 lines
Quoted 6 lines

Was there a fix in Linux since :

   57da367b9ec4 ("s390x/pci: forbid multifunction pci device") 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

?

The timing of those particular commits predates the linux s390 kernel support of multifunction/SR-IOV. At that time it was simply not possible on s390.

Quoted 5 lines
Quoted 5 lines

s390 PCI devices do not have extended capabilities, so the igb device does not expose the SRIOV capability and only the PF is accessible but it doesn't seem to be an issue. (Btw, CONFIG_PCI_IOV is set to y in the default Linux config which is unexpected)

The linux config option makes sense because the s390 kernel now supports SR-IOV/multifunction.

Quoted 3 lines

Doesn't s390x really see extended capabilities? hw/s390x/s390-pci-inst.c has a call pci_config_size() and pci_host_config_write_common(), which means it is exposing the whole PCI Express configuration space. Why can't s390x use extended capabilities then?

So, rather than poking around in config space, s390 (and thus the s390 kernel) has an extra layer of 'capabilities' that it generally relies on to determine device functionality called 'CLP'. Basically, there are pieces of CLP that are not currently generated (or forwarded from the host in the case of passthrough) by QEMU that would be needed by the guest to recognize the SRIOV/multifunction capability of a device, despite what config space has in it. I suspect this is exactly why only the PF was available to your igb device then (missing CLP info made the device appear to not have multifunction capability as far as the s390 guest is concerned - fwiw adding CLP emulation to enable that is on our todo list).

Sounds like the short-term solution here would be to continue allowing the PF without multifunction being visible to the guest (so as to not regress prior functionality) and then aim for proper support after with the necessary CLP pieces.

Thanks,
Matt

#10 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

Quoted 9 lines · Matthew Rosato
Quoted 8 lines · Akihiko Odaki
Quoted 7 lines · Cédric Le Goater

+Matthew +Eric

Side note for the maintainers :

Before this change, the igb device, which is multifunction, was working fine under Linux.

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

Was there a fix in Linux since :

   57da367b9ec4 ("s390x/pci: forbid multifunction pci device") 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

?

The timing of those particular commits predates the linux s390 kernel support of multifunction/SR-IOV. At that time it was simply not possible on s390.

Is it OK to remove this check of multifunction now?

This code is not working properly with SR-IOV and misleading. It is better to remove the code if it does no good.

It would be nice if anyone confirms multifunction works for s390x with the code removed.

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

s390 PCI devices do not have extended capabilities, so the igb device does not expose the SRIOV capability and only the PF is accessible but it doesn't seem to be an issue. (Btw, CONFIG_PCI_IOV is set to y in the default Linux config which is unexpected)

Quoted 7 lines

The linux config option makes sense because the s390 kernel now supports SR-IOV/multifunction.

Quoted 3 lines

Doesn't s390x really see extended capabilities? hw/s390x/s390-pci-inst.c has a call pci_config_size() and pci_host_config_write_common(), which means it is exposing the whole PCI Express configuration space. Why can't s390x use extended capabilities then?

So, rather than poking around in config space, s390 (and thus the s390 kernel) has an extra layer of 'capabilities' that it generally relies on to determine device functionality called 'CLP'. Basically, there are pieces of CLP that are not currently generated (or forwarded from the host in the case of passthrough) by QEMU that would be needed by the guest to recognize the SRIOV/multifunction capability of a device, despite what config space has in it. I suspect this is exactly why only the PF was available to your igb device then (missing CLP info made the device appear to not have multifunction capability as far as the s390 guest is concerned - fwiw adding CLP emulation to enable that is on our todo list).

What is expected to happen if you poke the configuration space anyway? I also wonder if there is some public documentation of CLP and relevant aspect of PCI support in s390x.

Quoted 2 lines

Sounds like the short-term solution here would be to continue allowing the PF without multifunction being visible to the guest (so as to not regress prior functionality) and then aim for proper support after with the necessary CLP pieces.

I agree; we can keep the PF working.

Regards,
Akihiko Odaki

#11 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

Quoted 12 lines · Akihiko Odaki
Quoted 11 lines · Matthew Rosato
Quoted 10 lines · Akihiko Odaki
Quoted 9 lines · Cédric Le Goater

+Matthew +Eric

Side note for the maintainers :

Before this change, the igb device, which is multifunction, was working fine under Linux.

Was there a fix in Linux since :

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

    57da367b9ec4 ("s390x/pci: forbid multifunction pci device") 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

?

The timing of those particular commits predates the linux s390 kernel support of multifunction/SR-IOV.  At that time it was simply not possible on s390.

Is it OK to remove this check of multifunction now?

Yes, I think removing the check (which AFAIU was broken since 6069bcdeacee) will get us back to the behavior Cedric was seeing, where a device that reports multifunction in the config space is still allowed through but only the PF will be usable in the guest.

Quoted 4 lines

This code is not working properly with SR-IOV and misleading. It is better to remove the code if it does no good.

It would be nice if anyone confirms multifunction works for s390x with the code removed.

Even if you remove the check, multifunction itself won't work in the s390x guest without these missing CLP pieces too. When I have some time I'll hack something together to fabricate some CLP data and try it out, but it sounds like Cedric could use his setup to right now at least verify that the PF itself should remain usable in the guest (current behavior).

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 7 lines

s390 PCI devices do not have extended capabilities, so the igb device does not expose the SRIOV capability and only the PF is accessible but it doesn't seem to be an issue. (Btw, CONFIG_PCI_IOV is set to y in the default Linux config which is unexpected)

The linux config option makes sense because the s390 kernel now supports SR-IOV/multifunction.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Doesn't s390x really see extended capabilities? hw/s390x/s390-pci-inst.c has a call pci_config_size() and pci_host_config_write_common(), which means it is exposing the whole PCI Express configuration space. Why can't s390x use extended capabilities then?

So, rather than poking around in config space, s390 (and thus the s390 kernel) has an extra layer of 'capabilities' that it generally relies on to determine device functionality called 'CLP'.  Basically, there are pieces of CLP that are not currently generated (or forwarded from the host in the case of passthrough) by QEMU that would be needed by the guest to recognize the SRIOV/multifunction capability of a device, despite what config space has in it.  I suspect this is exactly why only the PF was available to your igb device then (missing CLP info made the device appear to not have multifunction capability as far as the s390 guest is concerned - fwiw adding CLP emulation to enable that is on our todo list).

What is expected to happen if you poke the configuration space anyway? I also wonder if there is some public documentation of CLP and relevant aspect of PCI support in s390x.

On s390, the contents of config space might be what is directly reported by the device or may have been modified by a firmware layer in between the device and the LPAR (logical partition that is the closest thing to bare-metal on s390 where you could run a linux host). It's not that config space can't be read on s390 or anything like that, rather that the base s390 PCI kernel layer makes its decisions about multifunction based specifically on what is reported via CLP. If CLP doesn't report that the device is multifunction capable (which it never does for a s390x QEMU guest today) then it is treated as not having multifunction support.

Unfortunately, the CLP details are not publicly documented.

Quoted 5 lines
Quoted 3 lines

Sounds like the short-term solution here would be to continue allowing the PF without multifunction being visible to the guest (so as to not regress prior functionality) and then aim for proper support after with the necessary CLP pieces.

I agree; we can keep the PF working.

Thanks!

Matt

#12 lore raw

Re: [PATCH for-9.2 v15 04/11] s390x/pci: Check for multifunction after device realization

Quoted 16 lines · Matthew Rosato
Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Matthew Rosato
Quoted 13 lines · Akihiko Odaki
Quoted 12 lines · Cédric Le Goater

+Matthew +Eric

Side note for the maintainers :

Before this change, the igb device, which is multifunction, was working fine under Linux.

Was there a fix in Linux since :

    57da367b9ec4 ("s390x/pci: forbid multifunction pci device") 6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

?

The timing of those particular commits predates the linux s390 kernel support of multifunction/SR-IOV.  At that time it was simply not possible on s390.

Is it OK to remove this check of multifunction now?

Yes, I think removing the check (which AFAIU was broken since 6069bcdeacee) will get us back to the behavior Cedric was seeing, where a device that reports multifunction in the config space is still allowed through but only the PF will be usable in the guest.

Commit 6069bcdeacee predates the introduction of SR-IOV (commit 7c0fa8dff811 ["pcie: Add support for Single Root I/O Virtualization (SR/IOV)"]) so it did not break anything, strictly speaking. Ideally, we should have taken care of the check when introducing SR-IOV.

Quoted 7 lines
Quoted 5 lines

This code is not working properly with SR-IOV and misleading. It is better to remove the code if it does no good.

It would be nice if anyone confirms multifunction works for s390x with the code removed.

Even if you remove the check, multifunction itself won't work in the s390x guest without these missing CLP pieces too. When I have some time I'll hack something together to fabricate some CLP data and try it out, but it sounds like Cedric could use his setup to right now at least verify that the PF itself should remain usable in the guest (current behavior).

Well, it seems better to keep the check for non-SR-IOV multifunction devices while not enforcing the restriction for SR-IOV.

Multifunction devices without SR-IOV are created with explicit requests by specifying multifunction=on for PCI devices. Such requests cannot be fulfilled without multifunction CLP so we should reject them.

The situation is different for SR-IOV. SR-IOV is a feature inherent to specific type of devices and gets automatically enabled for these devices. It may make more sense to ignore just the SR-IOV part of such devices and keep the other functionalities working.

The current code implements such a behavior, but it is accidental and semantically wrong. I will correct the code to explicitly allow multifunction for SR-IOV.

Regards,
Akihiko Odaki

#13 lore raw

PATCH v15 5/11 pcie_sriov: Do not manually unrealize

In reply to Akihiko Odaki

A device gets automatically unrealized when being unparented.

---
 hw/pci/pcie_sriov.c | 4 ----
 1 file changed, 4 deletions(-)
hw/pci/pcie_sriov.c +0 -4
index e9b23221d713..499becd5273f 100644
@@ -204,11 +204,7 @@ static void unregister_vfs(PCIDevice *dev)
     trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn),
                                PCI_FUNC(dev->devfn), num_vfs);
     for (i = 0; i < num_vfs; i++) {
-        Error *err = NULL;
         PCIDevice *vf = dev->exp.sriov_pf.vf[i];
-        if (!object_property_set_bool(OBJECT(vf), "realized", false, &err)) {
-            error_reportf_err(err, "Failed to unplug: ");
-        }
         object_unparent(OBJECT(vf));
         object_unref(OBJECT(vf));
     }
Signature · 1 line
2.46.0
#14 lore raw

PATCH v15 6/11 pcie_sriov: Reuse SR-IOV VF device instances

In reply to Akihiko Odaki

Disable SR-IOV VF devices by reusing code to power down PCI devices instead of removing them when the guest requests to disable VFs. This allows to realize devices and report VF realization errors at PF realization time.

---
 docs/pcie_sriov.txt         |   8 ++--
 include/hw/pci/pci.h        |   5 ---
 include/hw/pci/pci_device.h |  15 +++++++
 include/hw/pci/pcie_sriov.h |   6 +--
 hw/net/igb.c                |  13 ++++--
 hw/nvme/ctrl.c              |  24 +++++++----
 hw/pci/pci.c                |   2 +-
 hw/pci/pcie_sriov.c         | 102 +++++++++++++++++++-------------------------
 8 files changed, 95 insertions(+), 80 deletions(-)
docs/pcie_sriov.txt +5 -3
index a47aad0bfab0..ab2142807f79 100644
@@ -52,9 +52,11 @@ setting up a BAR for a VF.
       ...
 
       /* Add and initialize the SR/IOV capability */
-      pcie_sriov_pf_init(d, 0x200, "your_virtual_dev",
-                       vf_devid, initial_vfs, total_vfs,
-                       fun_offset, stride);
+      if (!pcie_sriov_pf_init(d, 0x200, "your_virtual_dev",
+                              vf_devid, initial_vfs, total_vfs,
+                              fun_offset, stride, errp)) {
+         return;
+      }
 
       /* Set up individual VF BARs (parameters as for normal BARs) */
       pcie_sriov_pf_init_vf_bar( ... )
include/hw/pci/pci.h +0 -5
index fe04b4fafd04..14a869eeaa71 100644
@@ -680,9 +680,4 @@ static inline void pci_irq_pulse(PCIDevice *pci_dev)
 MSIMessage pci_get_msi_message(PCIDevice *dev, int vector);
 void pci_set_enabled(PCIDevice *pci_dev, bool state);
 
-static inline void pci_set_power(PCIDevice *pci_dev, bool state)
-{
-    pci_set_enabled(pci_dev, state);
-}
-
 #endif
include/hw/pci/pci_device.h +15 -0
index f38fb3111954..1ff3ce94e25b 100644
@@ -212,6 +212,21 @@ static inline uint16_t pci_get_bdf(PCIDevice *dev)
     return PCI_BUILD_BDF(pci_bus_num(pci_get_bus(dev)), dev->devfn);
 }
 
+static inline void pci_set_power(PCIDevice *pci_dev, bool state)
+{
+    /*
+     * Don't change the enabled state of VFs when powering on/off the device.
+     *
+     * When powering on, VFs must not be enabled immediately but they must
+     * wait until the guest configures SR-IOV.
+     * When powering off, their corresponding PFs will be reset and disable
+     * VFs.
+     */
+    if (!pci_is_vf(pci_dev)) {
+        pci_set_enabled(pci_dev, state);
+    }
+}
+
 uint16_t pci_requester_id(PCIDevice *dev);
 
 /* DMA access functions */
include/hw/pci/pcie_sriov.h +3 -3
index 450cbef6c201..70649236c18a 100644
@@ -18,7 +18,6 @@
 typedef struct PCIESriovPF {
     uint16_t num_vfs;   /* Number of virtual functions created */
     uint8_t vf_bar_type[PCI_NUM_REGIONS];   /* Store type for each VF bar */
-    const char *vfname; /* Reference to the device type used for the VFs */
     PCIDevice **vf;     /* Pointer to an array of num_vfs VF devices */
 } PCIESriovPF;
 
@@ -27,10 +26,11 @@ typedef struct PCIESriovVF {
     uint16_t vf_number; /* Logical VF number of this function */
 } PCIESriovVF;
 
-void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
+bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
                         const char *vfname, uint16_t vf_dev_id,
                         uint16_t init_vfs, uint16_t total_vfs,
-                        uint16_t vf_offset, uint16_t vf_stride);
+                        uint16_t vf_offset, uint16_t vf_stride,
+                        Error **errp);
 void pcie_sriov_pf_exit(PCIDevice *dev);
 
 /* Set up a VF bar in the SR/IOV bar area */
hw/net/igb.c +10 -3
index b92bba402e0d..b6ca2f1b8aee 100644
@@ -446,9 +446,16 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
 
     pcie_ari_init(pci_dev, 0x150);
 
-    pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, TYPE_IGBVF,
-        IGB_82576_VF_DEV_ID, IGB_MAX_VF_FUNCTIONS, IGB_MAX_VF_FUNCTIONS,
-        IGB_VF_OFFSET, IGB_VF_STRIDE);
+    if (!pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET,
+                            TYPE_IGBVF, IGB_82576_VF_DEV_ID,
+                            IGB_MAX_VF_FUNCTIONS, IGB_MAX_VF_FUNCTIONS,
+                            IGB_VF_OFFSET, IGB_VF_STRIDE,
+                            errp)) {
+        pcie_cap_exit(pci_dev);
+        igb_cleanup_msix(s);
+        msi_uninit(pci_dev);
+        return;
+    }
 
     pcie_sriov_pf_init_vf_bar(pci_dev, IGBVF_MMIO_BAR_IDX,
         PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH,
hw/nvme/ctrl.c +16 -8
index c6d4f61a47f9..e86ea2e7ce57 100644
@@ -8271,7 +8271,8 @@ out:
     return pow2ceil(bar_size);
 }
 
-static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset)
+static bool nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset,
+                            Error **errp)
 {
     uint16_t vf_dev_id = n->params.use_intel_id ?
                          PCI_DEVICE_ID_INTEL_NVME : PCI_DEVICE_ID_REDHAT_NVME;
@@ -8280,12 +8281,17 @@ static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset)
                                       le16_to_cpu(cap->vifrsm),
                                       NULL, NULL);
 
-    pcie_sriov_pf_init(pci_dev, offset, "nvme", vf_dev_id,
-                       n->params.sriov_max_vfs, n->params.sriov_max_vfs,
-                       NVME_VF_OFFSET, NVME_VF_STRIDE);
+    if (!pcie_sriov_pf_init(pci_dev, offset, "nvme", vf_dev_id,
+                            n->params.sriov_max_vfs, n->params.sriov_max_vfs,
+                            NVME_VF_OFFSET, NVME_VF_STRIDE,
+                            errp)) {
+        return false;
+    }
 
     pcie_sriov_pf_init_vf_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY |
                               PCI_BASE_ADDRESS_MEM_TYPE_64, bar_size);
+
+    return true;
 }
 
 static int nvme_add_pm_capability(PCIDevice *pci_dev, uint8_t offset)
@@ -8410,6 +8416,12 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp)
         return false;
     }
 
+    if (!pci_is_vf(pci_dev) && n->params.sriov_max_vfs &&
+        !nvme_init_sriov(n, pci_dev, 0x120, errp)) {
+        msix_uninit(pci_dev, &n->bar0, &n->bar0);
+        return false;
+    }
+
     nvme_update_msixcap_ts(pci_dev, n->conf_msix_qsize);
 
     pcie_cap_deverr_init(pci_dev);
@@ -8439,10 +8451,6 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp)
         nvme_init_pmr(n, pci_dev);
     }
 
-    if (!pci_is_vf(pci_dev) && n->params.sriov_max_vfs) {
-        nvme_init_sriov(n, pci_dev, 0x120);
-    }
-
     return true;
 }
 
hw/pci/pci.c +1 -1
index b532888e8f6c..5c0050e1786a 100644
@@ -2895,7 +2895,7 @@ void pci_set_enabled(PCIDevice *d, bool state)
     memory_region_set_enabled(&d->bus_master_enable_region,
                               (pci_get_word(d->config + PCI_COMMAND)
                                & PCI_COMMAND_MASTER) && d->enabled);
-    if (!d->enabled) {
+    if (d->qdev.realized) {
         pci_device_reset(d);
     }
 }
hw/pci/pcie_sriov.c +45 -57

162 lines not on this page · raw message

Signature · 1 line
2.46.0
#15 lore raw

PATCH v15 7/11 pcie_sriov: Release VFs failed to realize

In reply to Akihiko Odaki

Release VFs failed to realize just as we do in unregister_vfs().

Fixes 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)")
---
 hw/pci/pcie_sriov.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci/pcie_sriov.c +2 -0
index 4bffe6c97f66..ac8c4013bc88 100644
@@ -87,6 +87,8 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
         vf->exp.sriov_vf.vf_number = i;
 
         if (!qdev_realize(&vf->qdev, bus, errp)) {
+            object_unparent(OBJECT(vf));
+            object_unref(vf);
             unparent_vfs(dev, i);
             return false;
         }
Signature · 1 line
2.46.0
#16 lore raw

PATCH v15 8/11 pcie_sriov: Remove num_vfs from PCIESriovPF

In reply to Akihiko Odaki

num_vfs is not migrated so use PCI_SRIOV_CTRL_VFE and PCI_SRIOV_NUM_VF instead.

---
 include/hw/pci/pcie_sriov.h |  1 -
 hw/pci/pcie_sriov.c         | 38 +++++++++++++++++++++++++++-----------
 hw/pci/trace-events         |  2 +-
 3 files changed, 28 insertions(+), 13 deletions(-)
include/hw/pci/pcie_sriov.h +0 -1
index 70649236c18a..5148c5b77dd1 100644
@@ -16,7 +16,6 @@
 #include "hw/pci/pci.h"
 
 typedef struct PCIESriovPF {
-    uint16_t num_vfs;   /* Number of virtual functions created */
     uint8_t vf_bar_type[PCI_NUM_REGIONS];   /* Store type for each VF bar */
     PCIDevice **vf;     /* Pointer to an array of num_vfs VF devices */
 } PCIESriovPF;
hw/pci/pcie_sriov.c +27 -11
index ac8c4013bc88..47028e150eac 100644
@@ -45,7 +45,6 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
     pcie_add_capability(dev, PCI_EXT_CAP_ID_SRIOV, 1,
                         offset, PCI_EXT_CAP_SRIOV_SIZEOF);
     dev->exp.sriov_cap = offset;
-    dev->exp.sriov_pf.num_vfs = 0;
     dev->exp.sriov_pf.vf = NULL;
 
     pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset);
@@ -182,29 +181,28 @@ static void register_vfs(PCIDevice *dev)
 
     assert(sriov_cap > 0);
     num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF);
-    if (num_vfs > pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_VF)) {
-        return;
-    }
 
     trace_sriov_register_vfs(dev->name, PCI_SLOT(dev->devfn),
                              PCI_FUNC(dev->devfn), num_vfs);
     for (i = 0; i < num_vfs; i++) {
         pci_set_enabled(dev->exp.sriov_pf.vf[i], true);
     }
-    dev->exp.sriov_pf.num_vfs = num_vfs;
+
+    pci_set_word(dev->wmask + sriov_cap + PCI_SRIOV_NUM_VF, 0);
 }
 
 static void unregister_vfs(PCIDevice *dev)
 {
-    uint16_t num_vfs = dev->exp.sriov_pf.num_vfs;
+    uint8_t *cfg = dev->config + dev->exp.sriov_cap;
     uint16_t i;
 
     trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn),
-                               PCI_FUNC(dev->devfn), num_vfs);
-    for (i = 0; i < num_vfs; i++) {
+                               PCI_FUNC(dev->devfn));
+    for (i = 0; i < pci_get_word(cfg + PCI_SRIOV_TOTAL_VF); i++) {
         pci_set_enabled(dev->exp.sriov_pf.vf[i], false);
     }
-    dev->exp.sriov_pf.num_vfs = 0;
+
+    pci_set_word(dev->wmask + dev->exp.sriov_cap + PCI_SRIOV_NUM_VF, 0xffff);
 }
 
 void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
@@ -230,6 +228,17 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
         } else {
             unregister_vfs(dev);
         }
+    } else if (range_covers_byte(off, len, PCI_SRIOV_NUM_VF)) {
+        uint8_t *cfg = dev->config + sriov_cap;
+        uint8_t *wmask = dev->wmask + sriov_cap;
+        uint16_t num_vfs = pci_get_word(cfg + PCI_SRIOV_NUM_VF);
+        uint16_t wmask_val = PCI_SRIOV_CTRL_MSE | PCI_SRIOV_CTRL_ARI;
+
+        if (num_vfs <= pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)) {
+            wmask_val |= PCI_SRIOV_CTRL_VFE;
+        }
+
+        pci_set_word(wmask + PCI_SRIOV_CTRL, wmask_val);
     }
 }
 
@@ -246,6 +255,8 @@ void pcie_sriov_pf_reset(PCIDevice *dev)
     unregister_vfs(dev);
 
     pci_set_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF, 0);
+    pci_set_word(dev->wmask + sriov_cap + PCI_SRIOV_CTRL,
+                 PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE | PCI_SRIOV_CTRL_ARI);
 
     /*
      * Default is to use 4K pages, software can modify it
@@ -292,7 +303,7 @@ PCIDevice *pcie_sriov_get_pf(PCIDevice *dev)
 PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, int n)
 {
     assert(!pci_is_vf(dev));
-    if (n < dev->exp.sriov_pf.num_vfs) {
+    if (n < pcie_sriov_num_vfs(dev)) {
         return dev->exp.sriov_pf.vf[n];
     }
     return NULL;
@@ -300,5 +311,10 @@ PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, int n)
 
 uint16_t pcie_sriov_num_vfs(PCIDevice *dev)
 {
-    return dev->exp.sriov_pf.num_vfs;
+    uint16_t sriov_cap = dev->exp.sriov_cap;
+    uint8_t *cfg = dev->config + sriov_cap;
+
+    return sriov_cap &&
+           (pci_get_word(cfg + PCI_SRIOV_CTRL) & PCI_SRIOV_CTRL_VFE) ?
+           pci_get_word(cfg + PCI_SRIOV_NUM_VF) : 0;
 }
hw/pci/trace-events +1 -1
index 19643aa8c6b0..e98f575a9d19 100644
@@ -14,7 +14,7 @@ msix_write_config(char *name, bool enabled, bool masked) "dev %s enabled %d mask
 
 # hw/pci/pcie_sriov.c
 sriov_register_vfs(const char *name, int slot, int function, int num_vfs) "%s %02x:%x: creating %d vf devs"
-sriov_unregister_vfs(const char *name, int slot, int function, int num_vfs) "%s %02x:%x: Unregistering %d vf devs"
+sriov_unregister_vfs(const char *name, int slot, int function) "%s %02x:%x: Unregistering vf devs"
 sriov_config_write(const char *name, int slot, int fun, uint32_t offset, uint32_t val, uint32_t len) "%s %02x:%x: sriov offset 0x%x val 0x%x len %d"
 
 # pcie.c
Signature · 1 line
2.46.0
#17 lore raw

PATCH v15 9/11 pcie_sriov: Register VFs after migration

In reply to Akihiko Odaki

pcie_sriov doesn't have code to restore its state after migration, but igb, which uses pcie_sriov, naively claimed its migration capability.

Add code to register VFs after migration and fix igb migration.

Fixes 3a977deebe6b ("Intrdocue igb device emulation")
---
 include/hw/pci/pcie_sriov.h | 2 ++
 hw/pci/pci.c                | 7 +++++++
 hw/pci/pcie_sriov.c         | 7 +++++++
 3 files changed, 16 insertions(+)
include/hw/pci/pcie_sriov.h +2 -0
index 5148c5b77dd1..c5d2d318d330 100644
@@ -57,6 +57,8 @@ void pcie_sriov_pf_add_sup_pgsize(PCIDevice *dev, uint16_t opt_sup_pgsize);
 void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
                              uint32_t val, int len);
 
+void pcie_sriov_pf_post_load(PCIDevice *dev);
+
 /* Reset SR/IOV */
 void pcie_sriov_pf_reset(PCIDevice *dev);
 
hw/pci/pci.c +7 -0
index 5c0050e1786a..4c7be5295110 100644
@@ -733,10 +733,17 @@ static bool migrate_is_not_pcie(void *opaque, int version_id)
     return !pci_is_express((PCIDevice *)opaque);
 }
 
+static int pci_post_load(void *opaque, int version_id)
+{
+    pcie_sriov_pf_post_load(opaque);
+    return 0;
+}
+
 const VMStateDescription vmstate_pci_device = {
     .name = "PCIDevice",
     .version_id = 2,
     .minimum_version_id = 1,
+    .post_load = pci_post_load,
     .fields = (const VMStateField[]) {
         VMSTATE_INT32_POSITIVE_LE(version_id, PCIDevice),
         VMSTATE_BUFFER_UNSAFE_INFO_TEST(config, PCIDevice,
hw/pci/pcie_sriov.c +7 -0
index 47028e150eac..a1cb1214af27 100644
@@ -242,6 +242,13 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
     }
 }
 
+void pcie_sriov_pf_post_load(PCIDevice *dev)
+{
+    if (dev->exp.sriov_cap) {
+        register_vfs(dev);
+    }
+}
+
 
 /* Reset SR/IOV */
 void pcie_sriov_pf_reset(PCIDevice *dev)
Signature · 1 line
2.46.0
#18 lore raw

PATCH v15 10/11 hw/pci: Use -1 as the default value for rombar

In reply to Akihiko Odaki

vfio_pci_size_rom() distinguishes whether rombar is explicitly set to 1 by checking dev->opts, bypassing the QOM property infrastructure.

Use -1 as the default value for rombar to tell if the user explicitly set it to 1. The property is also converted from unsigned to signed. -1 is signed so it is safe to give it a new meaning. The values in [2 ^ 31, 2 ^ 32) become invalid, but nobody should have typed these values by chance.

---
 include/hw/pci/pci_device.h | 2 +-
 hw/pci/pci.c                | 2 +-
 hw/vfio/pci.c               | 5 ++---
 3 files changed, 4 insertions(+), 5 deletions(-)
include/hw/pci/pci_device.h +1 -1
index 1ff3ce94e25b..8fa845beee5e 100644
@@ -148,7 +148,7 @@ struct PCIDevice {
     uint32_t romsize;
     bool has_rom;
     MemoryRegion rom;
-    uint32_t rom_bar;
+    int32_t rom_bar;
 
     /* INTx routing notifier */
     PCIINTxRoutingNotifier intx_routing_notifier;
hw/pci/pci.c +1 -1
index 4c7be5295110..d2eaf0c51dde 100644
@@ -71,7 +71,7 @@ static Property pci_props[] = {
     DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
     DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
     DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, UINT32_MAX),
-    DEFINE_PROP_UINT32("rombar",  PCIDevice, rom_bar, 1),
+    DEFINE_PROP_INT32("rombar",  PCIDevice, rom_bar, -1),
     DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
                     QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
     DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present,
hw/vfio/pci.c +2 -3
index 2407720c3530..dc53837eac73 100644
@@ -1012,7 +1012,6 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
 {
     uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);
     off_t offset = vdev->config_offset + PCI_ROM_ADDRESS;
-    DeviceState *dev = DEVICE(vdev);
     char *name;
     int fd = vdev->vbasedev.fd;
 
@@ -1046,12 +1045,12 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
     }
 
     if (vfio_opt_rom_in_denylist(vdev)) {
-        if (dev->opts && qdict_haskey(dev->opts, "rombar")) {
+        if (vdev->pdev.rom_bar > 0) {
             warn_report("Device at %s is known to cause system instability"
                         " issues during option rom execution",
                         vdev->vbasedev.name);
             error_printf("Proceeding anyway since user specified"
-                         " non zero value for rombar\n");
+                         " positive value for rombar\n");
         } else {
             warn_report("Rom loading for device at %s has been disabled"
                         " due to system instability issues",
Signature · 1 line
2.46.0
#19 lore raw

PATCH v15 11/11 hw/qdev: Remove opts member

In reply to Akihiko Odaki

It is no longer used.

---
 include/hw/qdev-core.h |  4 ----
 hw/core/qdev.c         |  1 -
 system/qdev-monitor.c  | 12 +++++++-----
 3 files changed, 7 insertions(+), 10 deletions(-)
include/hw/qdev-core.h +0 -4
index 77bfcbdf732a..a3757e6769f8 100644
@@ -237,10 +237,6 @@ struct DeviceState {
      * @pending_deleted_expires_ms: optional timeout for deletion events
      */
     int64_t pending_deleted_expires_ms;
-    /**
-     * @opts: QDict of options for the device
-     */
-    QDict *opts;
     /**
      * @hotplugged: was device added after PHASE_MACHINE_READY?
      */
hw/core/qdev.c +0 -1
index f3a996f57dee..2fc84699d432 100644
@@ -706,7 +706,6 @@ static void device_finalize(Object *obj)
         dev->canonical_path = NULL;
     }
 
-    qobject_unref(dev->opts);
     g_free(dev->id);
 }
 
system/qdev-monitor.c +7 -5
index 6af6ef7d667f..3551989d5153 100644
@@ -624,6 +624,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
     char *id;
     DeviceState *dev = NULL;
     BusState *bus = NULL;
+    QDict *properties;
 
     driver = qdict_get_try_str(opts, "driver");
     if (!driver) {
@@ -705,13 +706,14 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
     }
 
     /* set properties */
-    dev->opts = qdict_clone_shallow(opts);
-    qdict_del(dev->opts, "driver");
-    qdict_del(dev->opts, "bus");
-    qdict_del(dev->opts, "id");
+    properties = qdict_clone_shallow(opts);
+    qdict_del(properties, "driver");
+    qdict_del(properties, "bus");
+    qdict_del(properties, "id");
 
-    object_set_properties_from_keyval(&dev->parent_obj, dev->opts, from_json,
+    object_set_properties_from_keyval(&dev->parent_obj, properties, from_json,
                                       errp);
+    qobject_unref(properties);
     if (*errp) {
         goto err_del_dev;
     }
Signature · 1 line
2.46.0
#20 lore raw
In reply to Akihiko Odaki
Quoted 9 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

Quoted 3 lines

[1]: https://patchew.org/QEMU/[email protected]/

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

Quoted 141 lines

---
Changes in v15:
- Fixed variable shadowing in patch
"pcie_sriov: Remove num_vfs from PCIESriovPF"
- Link to v14: https://lore.kernel.org/r/[email protected]

Changes in v14:
- Dropped patch "pcie_sriov: Ensure VF function number does not overflow" as I found the restriction it imposes is unnecessary.
- Link to v13: https://lore.kernel.org/r/[email protected]

Changes in v13:
- Added patch "s390x/pci: Check for multifunction after device realization". I found SR-IOV devices, which are multifunction devices, are not supposed to work at all with s390x on QEMU.
- Link to v12: https://lore.kernel.org/r/[email protected]

Changes in v12:
- Changed to ignore invalid PCI_SRIOV_NUM_VF writes as done for PCI_SRIOV_CTRL_VFE.
- Updated the message for patch "hw/pci: Use -1 as the default value for rombar". (Markus Armbruster)
- Link to v11: https://lore.kernel.org/r/[email protected]

Changes in v11:
- Rebased.
- Dropped patch "hw/pci: Convert rom_bar into OnOffAuto".
- Added patch "hw/pci: Use -1 as the default value for rombar".
- Added for-9.2 to give a testing period for possible breakage with libvirt/s390x.
- Link to v10: https://lore.kernel.org/r/[email protected]

Changes in v10:
- Added patch "hw/ppc/spapr_pci: Do not reject VFs created after a PF".
- Added patch "hw/ppc/spapr_pci: Do not create DT for disabled PCI device".
- Added patch "hw/pci: Convert rom_bar into OnOffAuto".
- Dropped patch "hw/pci: Determine if rombar is explicitly enabled".
- Dropped patch "hw/qdev: Remove opts member".
- Link to v9: https://lore.kernel.org/r/[email protected]

Changes in v9:
- Rebased.
- Restored '#include "qapi/error.h"' (Michael S. Tsirkin)
- Added patch "pcie_sriov: Ensure VF function number does not overflow" to fix abortion with wrong PF addr.
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Clarified that "hw/pci: Replace -1 with UINT32_MAX for romsize" is not a bug fix. (Markus Armbruster)
- Squashed patch "vfio: Avoid inspecting option QDict for rombar" into "hw/pci: Determine if rombar is explicitly enabled".
(Markus Armbruster)
- Noted the minor semantics change for patch "hw/pci: Determine if rombar is explicitly enabled". (Markus Armbruster)
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Replaced -1 with UINT32_MAX when expressing uint32_t.
(Markus Armbruster)
- Added patch "hw/pci: Replace -1 with UINT32_MAX for romsize".
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Fixed migration.
- Added patch "pcie_sriov: Do not manually unrealize".
- Restored patch "pcie_sriov: Release VFs failed to realize" that was missed in v5.
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Added patch "hw/pci: Always call pcie_sriov_pf_reset()".
- Added patch "pcie_sriov: Reset SR-IOV extended capability".
- Removed a reference to PCI_SRIOV_CTRL_VFE in hw/nvme.
(Michael S. Tsirkin)
- Noted the impact on the guest of patch "pcie_sriov: Do not reset NumVFs after unregistering VFs". (Michael S. Tsirkin)
- Changed to use pcie_sriov_num_vfs().
- Restored pci_set_power() and changed it to call pci_set_enabled() only for PFs with an expalanation. (Michael S. Tsirkin)
- Reordered patches.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Reverted the change to pci_rom_bar_explicitly_enabled().
(Michael S. Tsirkin)
- Added patch "pcie_sriov: Do not reset NumVFs after unregistering VFs".
- Added patch "hw/nvme: Refer to dev->exp.sriov_pf.num_vfs".
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Extracted patch "hw/pci: Use -1 as a default value for rombar" from patch "hw/pci: Determine if rombar is explicitly enabled"
(Philippe Mathieu-Daudé)
- Added an audit result of PCIDevice::rom_bar to the message of patch "hw/pci: Use -1 as a default value for rombar"
(Philippe Mathieu-Daudé)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Reset after enabling a function so that NVMe VF state gets updated.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Akihiko Odaki (11):
hw/pci: Rename has_power to enabled hw/ppc/spapr_pci: Do not create DT for disabled PCI device hw/ppc/spapr_pci: Do not reject VFs created after a PF s390x/pci: Check for multifunction after device realization
pcie_sriov: Do not manually unrealize
pcie_sriov: Reuse SR-IOV VF device instances
pcie_sriov: Release VFs failed to realize
pcie_sriov: Remove num_vfs from PCIESriovPF
pcie_sriov: Register VFs after migration
hw/pci: Use -1 as the default value for rombar hw/qdev: Remove opts member

 docs/pcie_sriov.txt         |   8 ++-
 include/hw/pci/pci.h        |   2 +-
 include/hw/pci/pci_device.h |  19 +++++-
 include/hw/pci/pcie_sriov.h |   9 +--
 include/hw/qdev-core.h      |   4 --
 hw/core/qdev.c              |   1 -
 hw/net/igb.c                |  13 +++-
 hw/nvme/ctrl.c              |  24 ++++---
 hw/pci/pci.c                |  23 ++++---
 hw/pci/pci_host.c           |   4 +-
 hw/pci/pcie_sriov.c         | 153 +++++++++++++++++++++++---------------------
 hw/ppc/spapr_pci.c          |   8 ++-
 hw/s390x/s390-pci-bus.c     |  14 ++--
 hw/vfio/pci.c               |   5 +-
 system/qdev-monitor.c       |  12 ++--
 hw/pci/trace-events         |   2 +-
 16 files changed, 175 insertions(+), 126 deletions(-)

---
base-commit: 31669121a01a14732f57c49400bc239cf9fd505f
change-id: 20240129-reuse-faae22b11934

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>
#21 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

Quoted 6 lines
Quoted 3 lines

[1]: https://patchew.org/QEMU/[email protected]/

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

Regards,
Akihiko Odaki

#22 lore raw
Quoted 28 lines · Akihiko Odaki
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

Quoted 6 lines
Quoted 3 lines

[1]: https://patchew.org/QEMU/[email protected]/

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

Quoted 2 lines

Regards,
Akihiko Odaki

Cédric would appreciate your Tested-by/Reviewed-by.

Signature · 1 line
MST
#23 lore raw
In reply to Akihiko Odaki
Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

[1]: https://patchew.org/QEMU/[email protected]/

Quoted 7 lines
Quoted 2 lines

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

yes, indeed and it seems to fix :

6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

I will update patch 4.

Thanks,

C.

That said, the igb device worked perfectly fine under the s390x machine.

#24 lore raw
Quoted 31 lines · Cédric Le Goater
Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

[1]: https://patchew.org/QEMU/[email protected]/

Quoted 7 lines
Quoted 2 lines

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

yes, indeed and it seems to fix :

6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

I will update patch 4.

Quoted 6 lines

Thanks,

C.

That said, the igb device worked perfectly fine under the s390x machine.

And it works for you after this patchset, yes?

#25 lore raw
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Cédric Le Goater
Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

[1]: https://patchew.org/QEMU/[email protected]/

Quoted 7 lines
Quoted 2 lines

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

yes, indeed and it seems to fix :

6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

I will update patch 4.

Quoted 8 lines
Quoted 6 lines

Thanks,

C.

That said, the igb device worked perfectly fine under the s390x machine.

And it works for you after this patchset, yes?

ah no, IGB is not an available device for the s390x machine anymore :

qemu-system-s390x: -device igb,netdev=net1,mac=C0:FF:EE:00:00:13: multifunction not supported in s390

This is what commit 57da367b9ec4 ("s390x/pci: forbid multifunction pci device") initially required (and later broken by 6069bcdeacee). So I guess we are fine with the expected behavior.

Thanks,

C.

#26 lore raw
Quoted 38 lines · Cédric Le Goater
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Cédric Le Goater
Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

[1]: https://patchew.org/QEMU/[email protected]/

Quoted 7 lines
Quoted 2 lines

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

yes, indeed and it seems to fix :

6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

I will update patch 4.

Thanks,

C.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

That said, the igb device worked perfectly fine under the s390x machine.

And it works for you after this patchset, yes?

ah no, IGB is not an available device for the s390x machine anymore :

qemu-system-s390x: -device igb,netdev=net1,mac=C0:FF:EE:00:00:13: multifunction not supported in s390

So patch 4 didn't relly help.

Quoted 7 lines

This is what commit 57da367b9ec4 ("s390x/pci: forbid multifunction pci device") initially required (and later broken by 6069bcdeacee). So I guess we are fine with the expected behavior.

Thanks,

C.

Better to fix than to guess if there are users, I think.

Signature · 1 line
MST
#27 lore raw
Quoted 55 lines · Michael S. Tsirkin
Quoted 38 lines · Cédric Le Goater
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Cédric Le Goater
Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

[1]: https://patchew.org/QEMU/[email protected]/

Quoted 7 lines
Quoted 2 lines

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

yes, indeed and it seems to fix :

    6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

I will update patch 4.

Thanks,

C.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

That said, the igb device worked perfectly fine under the s390x machine.

And it works for you after this patchset, yes?

ah no, IGB is not an available device for the s390x machine anymore :

   qemu-system-s390x: -device igb,netdev=net1,mac=C0:FF:EE:00:00:13: multifunction not supported in s390

So patch 4 didn't relly help.

Quoted 4 lines

This is what commit 57da367b9ec4 ("s390x/pci: forbid multifunction pci device") initially required (and later broken by 6069bcdeacee). So I guess we are fine with the expected behavior.

Quoted 5 lines
Quoted 3 lines

Thanks,

C.

Better to fix than to guess if there are users, I think.

Yes, but it will require some knowledge of s390x, which I cannot provide.

Commit 57da367b9ec4 ("s390x/pci: forbid multifunction pci device") says having a multifunction device will make the guest spin forever. That is not what Cédric observed with igb so it may no longer be relevant, but I cannot be sure that the problem is resolved without understanding how multifunction devices are supposed to work with s390x.

Ideally someone with s390x expertise should check relevant hardware documentation and confirm QEMU properly implements mutlifunction devices. Let's keep the restriction until then.

Regards,
Akihiko Odaki

#28 lore raw
Quoted 64 lines · Akihiko Odaki
Quoted 55 lines · Michael S. Tsirkin
Quoted 38 lines · Cédric Le Goater
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Cédric Le Goater
Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2 0/4] hw/pci: Convert rom_bar into OnOffAuto")

I submitted a RFC series[1] to add support for SR-IOV emulation to virtio-net-pci. During the development of the series, I fixed some trivial bugs and made improvements that I think are independently useful. This series extracts those fixes and improvements from the RFC series.

[1]: https://patchew.org/QEMU/[email protected]/

Quoted 7 lines
Quoted 2 lines

I don't think Cédric's issues have been addressed, am I wrong? Cédric, what is your take?

I put the URI to Cédric's report here:
https://lore.kernel.org/r/[email protected]

This issue was dealt with patch "s390x/pci: Check for multifunction after device realization". I found that s390x on QEMU does not support multifunction and SR-IOV devices accidentally circumvent this restriction, which means igb was never supposed to work with s390x. The patch prevents adding SR-IOV devices to s390x to ensure the restriction is properly enforced.

yes, indeed and it seems to fix :

    6069bcdeacee ("s390x/pci: Move some hotplug checks to the pre_plug handler")

I will update patch 4.

Thanks,

C.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

That said, the igb device worked perfectly fine under the s390x machine.

And it works for you after this patchset, yes?

ah no, IGB is not an available device for the s390x machine anymore :

   qemu-system-s390x: -device igb,netdev=net1,mac=C0:FF:EE:00:00:13: multifunction not supported in s390

So patch 4 didn't relly help.

Quoted 4 lines

This is what commit 57da367b9ec4 ("s390x/pci: forbid multifunction pci device") initially required (and later broken by 6069bcdeacee). So I guess we are fine with the expected behavior.

Quoted 5 lines
Quoted 3 lines

Thanks,

C.

Better to fix than to guess if there are users, I think.

Yes, but it will require some knowledge of s390x, which I cannot provide.

Quoted 8 lines

Commit 57da367b9ec4 ("s390x/pci: forbid multifunction pci device") says having a multifunction device will make the guest spin forever. That is not what Cédric observed with igb so it may no longer be relevant, but I cannot be sure that the problem is resolved without understanding how multifunction devices are supposed to work with s390x.

Ideally someone with s390x expertise should check relevant hardware documentation and confirm QEMU properly implements mutlifunction devices.

The fact is, QEMU already does what most users want from it. So the first rule whenever adding a new feature is not breaking old functionality. I know, it's annoying, as some of it is held together by duct tape. We have a friendly community so if you ask nicely, you usually can get help. You'd probably have to be a bit more specific with your questions.

Quoted 4 lines

Let's keep the restriction until then.

Regards,
Akihiko Odaki

Not introducing regressions is a hard rule, sorry.

Signature · 1 line
MST
#29 lore raw
In reply to Akihiko Odaki
Quoted 7 lines
Quoted 1 line

Better to fix than to guess if there are users, I think.

Yes, but it will require some knowledge of s390x, which I cannot provide.

Commit 57da367b9ec4 ("s390x/pci: forbid multifunction pci device") says having a multifunction device will make the guest spin forever. That is not what Cédric observed with igb so it may no longer be relevant, but I cannot be sure that the problem is resolved without understanding how multifunction devices are supposed to work with s390x.

Ideally someone with s390x expertise should check relevant hardware documentation and confirm QEMU properly implements mutlifunction devices.

I just cc'ed the s390x PCI maintainers on patch 4. Let's see.

Thanks,

C.