Skip to contentSkip to conversation

tests/qtest: add some tests for virtio-net failover

PATCH Superseded Laurent Vivier 4 participants 10 messages Nov 19, 2021 – Dec 8, 2021 Arm/Amlogic Meson SoC support

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover tests/qtest: add some tests for virtio-net failover

This series adds a qtest entry to test virtio-net failover feature.

We check following error cases:

- check missing id on device with failover_pair_id triggers an error
- check a primary device plugged on a bus that doesn't support hotplug triggers an error

We check the status of the machine before and after hotplugging cards and feature negotiation:

- check we don't see the primary device at boot if failover is on
- check we see the primary device at boot if failover is off
- check we don't see the primary device if failover is on
but failover_pair_id is not the one with on (I think this should be changed)
- check the primary device is plugged after the feature negotiation
- check the result if the primary device is plugged before standby device and vice-versa
- check the if the primary device is coldplugged and the standy device hotplugged and vice-versa
- check the migration triggers the unplug and the hotplug

There is one preliminary patch in the series:

- PATCH 1 introduces a function to enable PCI bridge. Failover needs to be plugged on a pcie-root-port and while the root port is not configured the cards behind it are not available

v5:
- re-add the wait-unplug test that has been removed from v4 by mistake.

v4:
- rely on query-migrate status to know the migration state rather than to wait the STOP event.
- remove the patch to add time out to qtest_qmp_eventwait()

v3:
- fix a bug with ACPI unplug and add the related test

v2:
- remove PATCH 1 that introduced a function that can be replaced by qobject_to_json_pretty() (Markus)
- Add migration to a file and from the file to check the card is correctly unplugged on the source, and hotplugged on the dest
- Add an ACPI call to eject the card as the kernel would do

Laurent Vivier (4):
qtest/libqos: add a function to initialize secondary PCI buses tests/qtest: add some tests for virtio-net failover
failover: fix unplug pending detection tests/libqtest: update virtio-net failover test

 hw/acpi/pcihp.c                   |  30 +-
 include/hw/pci/pci_bridge.h       |   8 +
 tests/qtest/libqos/pci.c          | 118 ++++++
 tests/qtest/libqos/pci.h          |   1 +
 tests/qtest/meson.build           |   3 +
 tests/qtest/virtio-net-failover.c | 681 ++++++++++++++++++++++++++++++
 6 files changed, 838 insertions(+), 3 deletions(-)
 create mode 100644 tests/qtest/virtio-net-failover.c
Signature · 1 line
2.33.1
#1 lore raw

PATCH v5 1/4 qtest/libqos: add a function to initialize secondary PCI buses

Scan the PCI devices to find bridge and set PCI_SECONDARY_BUS and PCI_SUBORDINATE_BUS (algorithm from seabios)

---
 include/hw/pci/pci_bridge.h |   8 +++
 tests/qtest/libqos/pci.c    | 118 ++++++++++++++++++++++++++++++++++++
 tests/qtest/libqos/pci.h    |   1 +
 3 files changed, 127 insertions(+)
include/hw/pci/pci_bridge.h +8 -0
index a94d350034bf..30691a6e5728 100644
@@ -138,6 +138,7 @@ typedef struct PCIBridgeQemuCap {
     uint64_t mem_pref_64; /* Prefetchable memory to reserve (64-bit MMIO) */
 } PCIBridgeQemuCap;
 
+#define REDHAT_PCI_CAP_TYPE_OFFSET      3
 #define REDHAT_PCI_CAP_RESOURCE_RESERVE 1
 
 /*
@@ -152,6 +153,13 @@ typedef struct PCIResReserve {
     uint64_t mem_pref_64;
 } PCIResReserve;
 
+#define REDHAT_PCI_CAP_RES_RESERVE_BUS_RES     4
+#define REDHAT_PCI_CAP_RES_RESERVE_IO          8
+#define REDHAT_PCI_CAP_RES_RESERVE_MEM         16
+#define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_32 20
+#define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_64 24
+#define REDHAT_PCI_CAP_RES_RESERVE_CAP_SIZE    32
+
 int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,
                                PCIResReserve res_reserve, Error **errp);
 
tests/qtest/libqos/pci.c +118 -0

130 lines not on this page · raw message

tests/qtest/libqos/pci.h +1 -0
index ee64fdecbda8..becb800f9e6a 100644
@@ -81,6 +81,7 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
                          void *data);
 QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn);
 void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr);
+int qpci_secondary_buses_init(QPCIBus *bus);
 
 bool qpci_has_buggy_msi(QPCIDevice *dev);
 bool qpci_check_buggy_msi(QPCIDevice *dev);
Signature · 1 line
2.33.1
#2 lore raw

PATCH v5 2/4 tests/qtest: add some tests for virtio-net failover

In reply to Laurent Vivier

Add test cases to test several error cases that must be generated by invalid failover configuration.

Add a combination of coldplug and hotplug test cases to be sure the primary is correctly managed according the presence or not of the STANDBY feature.

---
 tests/qtest/meson.build           |   3 +
 tests/qtest/virtio-net-failover.c | 658 ++++++++++++++++++++++++++++++
 2 files changed, 661 insertions(+)
 create mode 100644 tests/qtest/virtio-net-failover.c
tests/qtest/meson.build +3 -0
index c9d8458062ff..6d66bf522156 100644
@@ -22,6 +22,9 @@ qtests_generic = \
   (config_all_devices.has_key('CONFIG_VIRTIO_SCSI') ? ['fuzz-virtio-scsi-test'] : []) + \
   (config_all_devices.has_key('CONFIG_SB16') ? ['fuzz-sb16-test'] : []) + \
   (config_all_devices.has_key('CONFIG_SDHCI_PCI') ? ['fuzz-sdcard-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_VIRTIO_NET') and \
+   config_all_devices.has_key('CONFIG_Q35') and \
+   config_all_devices.has_key('CONFIG_VIRTIO_PCI') ? ['virtio-net-failover'] : []) + \
   [
   'cdrom-test',
   'device-introspect-test',
tests/qtest/virtio-net-failover.c new file +658 -0

658 lines not on this page · raw message

Signature · 1 line
2.33.1
#3 lore raw

PATCH v5 3/4 failover: fix unplug pending detection

In reply to Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

    17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

---
 hw/acpi/pcihp.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
hw/acpi/pcihp.c +27 -3
index f610a25d2ef9..30405b5113d7 100644
@@ -222,9 +222,27 @@ static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsigned slo
         PCIDevice *dev = PCI_DEVICE(qdev);
         if (PCI_SLOT(dev->devfn) == slot) {
             if (!acpi_pcihp_pc_no_hotplug(s, dev)) {
-                hotplug_ctrl = qdev_get_hotplug_handler(qdev);
-                hotplug_handler_unplug(hotplug_ctrl, qdev, &error_abort);
-                object_unparent(OBJECT(qdev));
+                /*
+                 * partially_hotplugged is used by virtio-net failover:
+                 * failover has asked the guest OS to unplug the device
+                 * but we need to keep some references to the device
+                 * to be able to plug it back in case of failure so
+                 * we don't execute hotplug_handler_unplug().
+                 */
+                if (dev->partially_hotplugged) {
+                    /*
+                     * pending_deleted_event is set to true when
+                     * virtio-net failover asks to unplug the device,
+                     * and set to false here when the operation is done
+                     * This is used by the migration loop to detect the
+                     * end of the operation and really start the migration.
+                     */
+                    qdev->pending_deleted_event = false;
+                } else {
+                    hotplug_ctrl = qdev_get_hotplug_handler(qdev);
+                    hotplug_handler_unplug(hotplug_ctrl, qdev, &error_abort);
+                    object_unparent(OBJECT(qdev));
+                }
             }
         }
     }
@@ -396,6 +414,12 @@ void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
         return;
     }
 
+    /*
+     * pending_deleted_event is used by virtio-net failover to detect the
+     * end of the unplug operation, the flag is set to false in
+     * acpi_pcihp_eject_slot() when the operation is completed.
+     */
+    pdev->qdev.pending_deleted_event = true;
     s->acpi_pcihp_pci_status[bsel].down |= (1U << slot);
     acpi_send_event(DEVICE(hotplug_dev), ACPI_PCI_HOTPLUG_STATUS);
 }
Signature · 1 line
2.33.1
#4 lore raw

Re: [PATCH v5 3/4] failover: fix unplug pending detection

Quoted 16 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

    17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

Quoted 5 lines

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Hmm. I think this one may be needed for this release actually. Isolate from testing changes and repost?

Quoted 54 lines
---
 hw/acpi/pcihp.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
hw/acpi/pcihp.c +27 -3
index f610a25d2ef9..30405b5113d7 100644
@@ -222,9 +222,27 @@ static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsigned slo
         PCIDevice *dev = PCI_DEVICE(qdev);
         if (PCI_SLOT(dev->devfn) == slot) {
             if (!acpi_pcihp_pc_no_hotplug(s, dev)) {
-                hotplug_ctrl = qdev_get_hotplug_handler(qdev);
-                hotplug_handler_unplug(hotplug_ctrl, qdev, &error_abort);
-                object_unparent(OBJECT(qdev));
+                /*
+                 * partially_hotplugged is used by virtio-net failover:
+                 * failover has asked the guest OS to unplug the device
+                 * but we need to keep some references to the device
+                 * to be able to plug it back in case of failure so
+                 * we don't execute hotplug_handler_unplug().
+                 */
+                if (dev->partially_hotplugged) {
+                    /*
+                     * pending_deleted_event is set to true when
+                     * virtio-net failover asks to unplug the device,
+                     * and set to false here when the operation is done
+                     * This is used by the migration loop to detect the
+                     * end of the operation and really start the migration.
+                     */
+                    qdev->pending_deleted_event = false;
+                } else {
+                    hotplug_ctrl = qdev_get_hotplug_handler(qdev);
+                    hotplug_handler_unplug(hotplug_ctrl, qdev, &error_abort);
+                    object_unparent(OBJECT(qdev));
+                }
             }
         }
     }
@@ -396,6 +414,12 @@ void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
         return;
     }
 
+    /*
+     * pending_deleted_event is used by virtio-net failover to detect the
+     * end of the unplug operation, the flag is set to false in
+     * acpi_pcihp_eject_slot() when the operation is completed.
+     */
+    pdev->qdev.pending_deleted_event = true;
     s->acpi_pcihp_pci_status[bsel].down |= (1U << slot);
     acpi_send_event(DEVICE(hotplug_dev), ACPI_PCI_HOTPLUG_STATUS);
 }
Signature · 1 line
2.33.1
#5 lore raw

Re: [PATCH v5 3/4] failover: fix unplug pending detection

Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

     17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

Quoted 8 lines
Quoted 5 lines

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Hmm. I think this one may be needed for this release actually. Isolate from testing changes and repost?

You merged it already here:

https://gitlab.com/qemu-project/qemu/-/commit/9323f892b39d133eb6

so we should be fine :-)

Thomas

#6 lore raw

Re: [PATCH v5 3/4] failover: fix unplug pending detection

Quoted 25 lines · Thomas Huth
Quoted 23 lines · Michael S. Tsirkin
Quoted 21 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

     17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Quoted 6 lines
Quoted 2 lines

Hmm. I think this one may be needed for this release actually. Isolate from testing changes and repost?

You merged it already here:

https://gitlab.com/qemu-project/qemu/-/commit/9323f892b39d133eb6

Yes I pointed this out in the other thread. Michael was not CC'd there somehow ...

Quoted 5 lines

so we should be fine :-)

Thomas

#7 lore raw

Re: [PATCH v5 3/4] failover: fix unplug pending detection

In reply to Thomas Huth
Quoted 24 lines · Thomas Huth
Quoted 23 lines · Michael S. Tsirkin
Quoted 21 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

     17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Quoted 6 lines
Quoted 2 lines

Hmm. I think this one may be needed for this release actually. Isolate from testing changes and repost?

You merged it already here:

https://gitlab.com/qemu-project/qemu/-/commit/9323f892b39d133eb6

Oh, good. Forgot to drop the tag.

Quoted 3 lines

so we should be fine :-)

Thomas

#8 lore raw

PATCH v5 4/4 tests/libqtest: update virtio-net failover test

In reply to Laurent Vivier

Update the migration test to check we correctly wait the end of the card unplug before doing the migration.

---
 tests/qtest/virtio-net-failover.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
tests/qtest/virtio-net-failover.c +23 -0
index 11fa0b21f8bf..9a81133154d6 100644
@@ -541,6 +541,29 @@ static void test_outmigrate(gconstpointer opaque)
 
     qobject_unref(resp);
 
+    /* wait the end of the migration setup phase */
+    while (true) {
+        const gchar *status;
+
+        ret = migrate_status(qts);
+
+        status = qdict_get_str(ret, "status");
+        if (strcmp(status, "wait-unplug") == 0) {
+            break;
+        }
+
+        /* The migration must not start if the card is not ejected */
+        g_assert_cmpstr(status, !=, "active");
+        g_assert_cmpstr(status, !=, "completed");
+        g_assert_cmpstr(status, !=, "failed");
+        g_assert_cmpstr(status, !=, "cancelling");
+        g_assert_cmpstr(status, !=, "cancelled");
+
+        qobject_unref(ret);
+    }
+    qobject_unref(ret);
+
+    /* OS unplugs the cards, QEMU can move from wait-unplug state */
     qtest_outl(qts, ACPI_PCIHP_ADDR_ICH9 + PCI_EJ_BASE, 1);
 
     qtest_qmp_eventwait(qts, "STOP");
Signature · 1 line
2.33.1
Reviewed-by on the v5 series
#9 lore raw
In reply to Laurent Vivier
Quoted 1 line · Laurent Vivier

This series adds a qtest entry to test virtio-net failover feature.

Quoted 63 lines

We check following error cases:

- check missing id on device with failover_pair_id triggers an error
- check a primary device plugged on a bus that doesn't support hotplug triggers an error

We check the status of the machine before and after hotplugging cards and feature negotiation:

- check we don't see the primary device at boot if failover is on
- check we see the primary device at boot if failover is off
- check we don't see the primary device if failover is on
but failover_pair_id is not the one with on (I think this should be changed)
- check the primary device is plugged after the feature negotiation
- check the result if the primary device is plugged before standby device and vice-versa
- check the if the primary device is coldplugged and the standy device hotplugged and vice-versa
- check the migration triggers the unplug and the hotplug

There is one preliminary patch in the series:

- PATCH 1 introduces a function to enable PCI bridge. Failover needs to be plugged on a pcie-root-port and while the root port is not configured the cards behind it are not available

v5:
- re-add the wait-unplug test that has been removed from v4 by mistake.

v4:
- rely on query-migrate status to know the migration state rather than to wait the STOP event.
- remove the patch to add time out to qtest_qmp_eventwait()

v3:
- fix a bug with ACPI unplug and add the related test

v2:
- remove PATCH 1 that introduced a function that can be replaced by qobject_to_json_pretty() (Markus)
- Add migration to a file and from the file to check the card is correctly unplugged on the source, and hotplugged on the dest
- Add an ACPI call to eject the card as the kernel would do

Laurent Vivier (4):
qtest/libqos: add a function to initialize secondary PCI buses tests/qtest: add some tests for virtio-net failover
failover: fix unplug pending detection tests/libqtest: update virtio-net failover test

 hw/acpi/pcihp.c                   |  30 +-
 include/hw/pci/pci_bridge.h       |   8 +
 tests/qtest/libqos/pci.c          | 118 ++++++
 tests/qtest/libqos/pci.h          |   1 +
 tests/qtest/meson.build           |   3 +
 tests/qtest/virtio-net-failover.c | 681 ++++++++++++++++++++++++++++++
 6 files changed, 838 insertions(+), 3 deletions(-)
 create mode 100644 tests/qtest/virtio-net-failover.c
Signature · 1 line
2.33.1