tests/qtest: add some tests for virtio-net failover
v4 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
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 (3):
qtest/libqos: add a function to initialize secondary PCI buses tests/qtest: add some tests for virtio-net failover
failover: fix unplug pending detection
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 | 658 ++++++++++++++++++++++++++++++ 6 files changed, 815 insertions(+), 3 deletions(-) create mode 100644 tests/qtest/virtio-net-failover.c
Signature · 1 line
2.33.1
PATCH v4 1/3 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
@@ -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
@@ -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
PATCH v4 2/3 tests/qtest: add some tests for virtio-net failover
In reply to Laurent VivierAdd 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
@@ -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
PATCH v4 3/3 failover: fix unplug pending detection
In reply to Laurent VivierFailover 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
@@ -222,9 +222,27 @@ static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsigned sloPCIDevice *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
Hi,
I did something wrong and the last patch adding the test has been removed from the series.
I'm going to send a v5 with the test added correctly.
Sorry for the noise.
Laurent
Quoted 58 lines · Laurent Vivier
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_idtriggers an error
- check a primary device plugged on a bus that doesn't support hotplug triggers an errorWe 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
butfailover_pair_idis 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 hotplugThere 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
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 toqtest_qmp_eventwait()v3:
- fix a bug with ACPI unplug and add the related testv2:
- remove PATCH 1 that introduced a function that can be replaced byqobject_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 doLaurent Vivier (3):
qtest/libqos: add a function to initialize secondary PCI buses tests/qtest: add some tests for virtio-net failover
failover: fix unplug pending detectionhw/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 | 658 ++++++++++++++++++++++++++++++ 6 files changed, 815 insertions(+), 3 deletions(-)create mode 100644
tests/qtest/virtio-net-failover.c