Skip to contentSkip to conversation

qtest/libqos/pci: pci and msix fixes

PATCH Superseded Nicholas Piggin 2 participants 10 messages Apr 11, 2025 – Apr 19, 2025

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover qtest/libqos/pci: pci and msix fixes

Since v3:
https://lore.kernel.org/qemu-devel/[email protected]/

- Split out the preparation patches for the ahci and virtio tests into their own patches as suggested by Phil.
- Added an extra assertion that qpci_iounmap() must only be called for a bar that was previously mapped, which required a bunch more prep work in ahci including adding a qpci migration helper.

Thanks,
Nick

Nicholas Piggin (7):
tests/qtest/ahci: unmap pci bar before reusing device tests/qtest/ahci: don't unmap pci bar if it wasn't mapped tests/qtest/libquos/virtio: unmap pci bar when disabling device tests/qtest/libquos/pci: Add migration fixup helper for pci devices qtest/libqos/pci: Enforce balanced iomap/unmap qtest/libqos/pci: Fix qpci_msix_enable sharing bar0 qtest/libqos/pci: Factor msix entry helpers into pci common code

 tests/qtest/libqos/ahci.h       |   2 +
 tests/qtest/libqos/pci.h        |  14 +++
 tests/qtest/libqos/virtio-pci.h |   1 +
 tests/qtest/ahci-test.c         |  38 +++++---
 tests/qtest/libqos/ahci.c       |  11 +++
 tests/qtest/libqos/pci.c        | 148 +++++++++++++++++++++++++++++---
 tests/qtest/libqos/virtio-pci.c |  59 ++++---------
 7 files changed, 208 insertions(+), 65 deletions(-)
Signature · 1 line
2.47.1
#2 lore raw

PATCH v4 2/7 tests/qtest/ahci: don't unmap pci bar if it wasn't mapped

ahci-test has a bunch of tests where the pci bar was not mapped. Avoid unmapping it in these cases, to keep iomaps balanced.

Cc Michael S. Tsirkin <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Akihiko Odaki <[email protected]>
Cc Akihiko Odaki <[email protected]>
Cc Fabiano Rosas <[email protected]>
---
 tests/qtest/ahci-test.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)
tests/qtest/ahci-test.c +24 -11
index 7cae6b58e0c..02c9d54f898 100644
@@ -85,6 +85,8 @@ static void verify_state(AHCIQState *ahci, uint64_t hba_old)
     uint64_t hba_base;
     AHCICommandHeader cmd;
 
+    g_assert_cmphex(ahci->hba_bar.addr, ==, hba_old);
+
     ahci_fingerprint = qpci_config_readl(ahci->dev, PCI_VENDOR_ID);
     g_assert_cmphex(ahci_fingerprint, ==, ahci->fingerprint);
 
@@ -193,18 +195,28 @@ static AHCIQState *ahci_boot(const char *cli, ...)
 
 /**
  * Clean up the PCI device, then terminate the QEMU instance.
+ * Should be called if ahci_pci_enable (or ahci_boot_and_enable)
+ * was not used, or device/pci was disabled later.
  */
-static void ahci_shutdown(AHCIQState *ahci)
+static void ahci_shutdown_pci_disabled(AHCIQState *ahci)
 {
     QOSState *qs = ahci->parent;
 
-    ahci_pci_disable(ahci);
     ahci_clean_mem(ahci);
     free_ahci_device(ahci->dev);
     g_free(ahci);
     qtest_shutdown(qs);
 }
 
+/**
+ * Clean up the PCI device, then terminate the QEMU instance.
+ */
+static void ahci_shutdown(AHCIQState *ahci)
+{
+    ahci_pci_disable(ahci);
+    ahci_shutdown_pci_disabled(ahci);
+}
+
 /**
  * Boot and fully enable the HBA device.
  * @see ahci_boot, ahci_pci_enable and ahci_hba_enable.
@@ -945,7 +957,7 @@ static void test_sanity(void)
 {
     AHCIQState *ahci;
     ahci = ahci_boot(NULL);
-    ahci_shutdown(ahci);
+    ahci_shutdown_pci_disabled(ahci);
 }
 
 /**
@@ -957,7 +969,7 @@ static void test_pci_spec(void)
     AHCIQState *ahci;
     ahci = ahci_boot(NULL);
     ahci_test_pci_spec(ahci);
-    ahci_shutdown(ahci);
+    ahci_shutdown_pci_disabled(ahci);
 }
 
 /**
@@ -1143,8 +1155,8 @@ static void test_migrate_sanity(void)
 
     ahci_migrate(src, dst, uri);
 
-    ahci_shutdown(src);
-    ahci_shutdown(dst);
+    ahci_shutdown_pci_disabled(src);
+    ahci_shutdown_pci_disabled(dst);
     g_free(uri);
 }
 
@@ -1182,7 +1194,7 @@ static void ahci_migrate_simple(uint8_t cmd_read, uint8_t cmd_write)
     /* Verify pattern */
     g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);
 
-    ahci_shutdown(src);
+    ahci_shutdown_pci_disabled(src);
     ahci_shutdown(dst);
     g_free(rx);
     g_free(tx);
@@ -1324,7 +1336,7 @@ static void ahci_migrate_halted_io(uint8_t cmd_read, uint8_t cmd_write)
     g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);
 
     /* Cleanup and go home. */
-    ahci_shutdown(src);
+    ahci_shutdown_pci_disabled(src);
     ahci_shutdown(dst);
     g_free(rx);
     g_free(tx);
@@ -1388,8 +1400,8 @@ static void test_flush_migrate(void)
     ahci_command_verify(dst, cmd);
 
     ahci_command_free(cmd);
-    ahci_shutdown(src);
-    ahci_shutdown(dst);
+    ahci_shutdown_pci_disabled(src);
+    ahci_shutdown_pci_disabled(dst);
     g_free(uri);
 }
 
@@ -1421,6 +1433,7 @@ static void test_reset(void)
         ahci_set(ahci, AHCI_GHC, AHCI_GHC_HR);
         stop_ahci_device(ahci);
         ahci_clean_mem(ahci);
+        start_ahci_device(ahci);
     }
 
     ahci_shutdown(ahci);
@@ -1508,7 +1521,7 @@ static void test_reset_pending_callback(void)
     stop_ahci_device(ahci);
     ahci_clean_mem(ahci);
 
-    ahci_shutdown(ahci);
+    ahci_shutdown_pci_disabled(ahci);
 }
 
 static void test_ncq_simple(void)
Signature · 1 line
2.47.1
#4 lore raw

PATCH v4 3/7 tests/qtest/libquos/virtio: unmap pci bar when disabling device

In reply to Nicholas Piggin

Unmap the virtio-pci bar in qvirtio_pci_disable_device() to keep iomap/iounmap balanced.

---
 tests/qtest/libqos/virtio-pci.h |  1 +
 tests/qtest/libqos/virtio-pci.c | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
tests/qtest/libqos/virtio-pci.h +1 -0
index f5115cacba2..efdf904b254 100644
@@ -26,6 +26,7 @@ typedef struct QVirtioPCIDevice {
     uint64_t config_msix_addr;
     uint32_t config_msix_data;
 
+    bool enabled;
     int bar_idx;
 
     /* VIRTIO 1.0 */
tests/qtest/libqos/virtio-pci.c +10 -1
index 002bf8b8c2d..cb52a7c3f2e 100644
@@ -300,13 +300,22 @@ static const QVirtioPCIMSIXOps qvirtio_pci_msix_ops_legacy = {
 
 void qvirtio_pci_device_enable(QVirtioPCIDevice *d)
 {
+    g_assert(!d->enabled);
+    d->enabled = true;
     qpci_device_enable(d->pdev);
     d->bar = qpci_iomap(d->pdev, d->bar_idx, NULL);
 }
 
 void qvirtio_pci_device_disable(QVirtioPCIDevice *d)
 {
-    qpci_iounmap(d->pdev, d->bar);
+    /*
+     * Test for "enabled" device state because some paths can call
+     * qvirtio_pci_disable_device() on devices that have not been enabled.
+     */
+    if (d->enabled) {
+        qpci_iounmap(d->pdev, d->bar);
+        d->enabled = false;
+    }
 }
 
 void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci,
Signature · 1 line
2.47.1
#7 lore raw

PATCH v4 5/7 qtest/libqos/pci: Enforce balanced iomap/unmap

In reply to Nicholas Piggin

Add assertions to ensure a BAR is not mapped twice, and that only previously mapped BARs are unmapped. This can help catch bugs and fragile coding.

---
 tests/qtest/libqos/pci.h |  9 +++++++
 tests/qtest/libqos/pci.c | 51 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 55 insertions(+), 5 deletions(-)
tests/qtest/libqos/pci.h +9 -0
index fd195ac4e6f..5c7ebad4270 100644
@@ -61,10 +61,19 @@ struct QPCIBar {
     bool is_io;
 };
 
+/*
+ * hw/pci permits 7 (PCI_NUM_REGIONS) regions, the last for PCI_ROM_SLOT.
+ * libqos does not implement PCI_ROM_SLOT at the moment, and as such it
+ * permits 6.
+ */
+#define QPCI_NUM_REGIONS 6
+
 struct QPCIDevice
 {
     QPCIBus *bus;
     int devfn;
+    bool bars_mapped[QPCI_NUM_REGIONS];
+    QPCIBar bars[QPCI_NUM_REGIONS];
     bool msix_enabled;
     QPCIBar msix_table_bar, msix_pba_bar;
     uint64_t msix_table_off, msix_pba_off;
tests/qtest/libqos/pci.c +46 -5

97 lines not on this page · raw message

Signature · 1 line
2.47.1
#1 lore raw

PATCH v4 1/7 tests/qtest/ahci: unmap pci bar before reusing device

In reply to Nicholas Piggin

ahci-test double-maps the hba bar in the pending_callback test. Unmap it first, to keep iomaps balanced.

---
 tests/qtest/libqos/ahci.h |  2 ++
 tests/qtest/ahci-test.c   |  4 ++++
 tests/qtest/libqos/ahci.c | 11 +++++++++++
 3 files changed, 17 insertions(+)
tests/qtest/libqos/ahci.h +2 -0
index a0487a1557d..f610bd32a5f 100644
@@ -574,7 +574,9 @@ void ahci_clean_mem(AHCIQState *ahci);
 QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint);
 void free_ahci_device(QPCIDevice *dev);
 void ahci_pci_enable(AHCIQState *ahci);
+void ahci_pci_disable(AHCIQState *ahci);
 void start_ahci_device(AHCIQState *ahci);
+void stop_ahci_device(AHCIQState *ahci);
 void ahci_hba_enable(AHCIQState *ahci);
 
 /* Port Management */
tests/qtest/ahci-test.c +4 -0
index 88ac6c66ce3..7cae6b58e0c 100644
@@ -198,6 +198,7 @@ static void ahci_shutdown(AHCIQState *ahci)
 {
     QOSState *qs = ahci->parent;
 
+    ahci_pci_disable(ahci);
     ahci_clean_mem(ahci);
     free_ahci_device(ahci->dev);
     g_free(ahci);
@@ -1418,6 +1419,7 @@ static void test_reset(void)
                                CMD_READ_DMA_EXT,
                                CMD_WRITE_DMA_EXT);
         ahci_set(ahci, AHCI_GHC, AHCI_GHC_HR);
+        stop_ahci_device(ahci);
         ahci_clean_mem(ahci);
     }
 
@@ -1484,6 +1486,7 @@ static void test_reset_pending_callback(void)
     sleep(1);
 
     /* Start again. */
+    stop_ahci_device(ahci);
     ahci_clean_mem(ahci);
     ahci_pci_enable(ahci);
     ahci_hba_enable(ahci);
@@ -1502,6 +1505,7 @@ static void test_reset_pending_callback(void)
     ahci_free(ahci, ptr1);
     ahci_free(ahci, ptr2);
 
+    stop_ahci_device(ahci);
     ahci_clean_mem(ahci);
 
     ahci_shutdown(ahci);
tests/qtest/libqos/ahci.c +11 -0
index 34a75b7f43b..bd1994a9208 100644
@@ -205,6 +205,11 @@ void ahci_pci_enable(AHCIQState *ahci)
 
 }
 
+void ahci_pci_disable(AHCIQState *ahci)
+{
+    stop_ahci_device(ahci);
+}
+
 /**
  * Map BAR5/ABAR, and engage the PCI device.
  */
@@ -217,6 +222,12 @@ void start_ahci_device(AHCIQState *ahci)
     qpci_device_enable(ahci->dev);
 }
 
+void stop_ahci_device(AHCIQState *ahci)
+{
+    /* Unmap AHCI's ABAR */
+    qpci_iounmap(ahci->dev, ahci->hba_bar);
+}
+
 /**
  * Test and initialize the AHCI's HBA memory areas.
  * Initialize and start any ports with devices attached.
Signature · 1 line
2.47.1
#5 lore raw

PATCH v4 4/7 tests/qtest/libquos/pci: Add migration fixup helper for pci devices

In reply to Nicholas Piggin

Migration tests can create new QPCI devices for the destination machine which may need to take on some state of the source machine after destination is complete.

Add a migration fixup helper and call it from ahci migration tests. This is currently a noop and will be used subsequently.

---
 tests/qtest/libqos/pci.h | 1 +
 tests/qtest/ahci-test.c  | 1 +
 tests/qtest/libqos/pci.c | 4 ++++
 3 files changed, 6 insertions(+)
tests/qtest/libqos/pci.h +1 -0
index 83896145235..fd195ac4e6f 100644
@@ -122,6 +122,7 @@ void qpci_memwrite(QPCIDevice *bus, QPCIBar token, uint64_t off,
                    const void *buf, size_t len);
 QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);
 void qpci_iounmap(QPCIDevice *dev, QPCIBar addr);
+void qpci_migrate_fixup(QPCIDevice *to, QPCIDevice *from);
 QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
 
 void qpci_unplug_acpi_device_test(QTestState *qs, const char *id, uint8_t slot);
tests/qtest/ahci-test.c +1 -0
index 02c9d54f898..6fd6063b971 100644
@@ -137,6 +137,7 @@ static void ahci_migrate(AHCIQState *from, AHCIQState *to, const char *uri)
     memcpy(to, from, sizeof(AHCIQState));
     to->parent = tmp;
     to->dev = dev;
+    qpci_migrate_fixup(to->dev, from->dev);
 
     tmp = from->parent;
     dev = from->dev;
tests/qtest/libqos/pci.c +4 -0
index a59197b9922..14581178c79 100644
@@ -586,6 +586,10 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr)
     return bar;
 }
 
+void qpci_migrate_fixup(QPCIDevice *to, QPCIDevice *from)
+{
+}
+
 void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr)
 {
     g_assert(addr);
Signature · 1 line
2.47.1
#8 lore raw

PATCH v4 6/7 qtest/libqos/pci: Fix qpci_msix_enable sharing bar0

In reply to Nicholas Piggin

Devices where the MSI-X addresses are shared with other MMIO on BAR0 can not use msi_enable because it unmaps and remaps BAR0, which interferes with device MMIO mappings. xhci-nec is one such device we would like to test with msix.

Use the BAR iomap tracking structure introduced in the previous change to have qpci_misx_enable() use existing iomaps if msix bars are already mapped.

---
 tests/qtest/libqos/pci.h |  1 +
 tests/qtest/libqos/pci.c | 40 ++++++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)
tests/qtest/libqos/pci.h +1 -0
index 5c7ebad4270..d334d9c0837 100644
@@ -75,6 +75,7 @@ struct QPCIDevice
     bool bars_mapped[QPCI_NUM_REGIONS];
     QPCIBar bars[QPCI_NUM_REGIONS];
     bool msix_enabled;
+    bool msix_table_bar_iomap, msix_pba_bar_iomap;
     QPCIBar msix_table_bar, msix_pba_bar;
     uint64_t msix_table_off, msix_pba_off;
 };
tests/qtest/libqos/pci.c +34 -6
index 02d88acd500..72adf81ddd6 100644
@@ -288,15 +288,21 @@ void qpci_msix_enable(QPCIDevice *dev)
 
     table = qpci_config_readl(dev, addr + PCI_MSIX_TABLE);
     bir_table = table & PCI_MSIX_FLAGS_BIRMASK;
-    dev->msix_table_bar = qpci_iomap(dev, bir_table, NULL);
+    if (dev->bars_mapped[bir_table]) {
+        dev->msix_table_bar = dev->bars[bir_table];
+    } else {
+        dev->msix_table_bar_iomap = true;
+        dev->msix_table_bar = qpci_iomap(dev, bir_table, NULL);
+    }
     dev->msix_table_off = table & ~PCI_MSIX_FLAGS_BIRMASK;
 
     table = qpci_config_readl(dev, addr + PCI_MSIX_PBA);
     bir_pba = table & PCI_MSIX_FLAGS_BIRMASK;
-    if (bir_pba != bir_table) {
-        dev->msix_pba_bar = qpci_iomap(dev, bir_pba, NULL);
+    if (dev->bars_mapped[bir_pba]) {
+        dev->msix_pba_bar = dev->bars[bir_pba];
     } else {
-        dev->msix_pba_bar = dev->msix_table_bar;
+        dev->msix_pba_bar_iomap = true;
+        dev->msix_pba_bar = qpci_iomap(dev, bir_pba, NULL);
     }
     dev->msix_pba_off = table & ~PCI_MSIX_FLAGS_BIRMASK;
 
@@ -307,6 +313,7 @@ void qpci_msix_disable(QPCIDevice *dev)
 {
     uint8_t addr;
     uint16_t val;
+    uint32_t table;
 
     g_assert(dev->msix_enabled);
     addr = qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0);
@@ -315,10 +322,31 @@ void qpci_msix_disable(QPCIDevice *dev)
     qpci_config_writew(dev, addr + PCI_MSIX_FLAGS,
                                                 val & ~PCI_MSIX_FLAGS_ENABLE);
 
-    if (dev->msix_pba_bar.addr != dev->msix_table_bar.addr) {
+    if (dev->msix_pba_bar_iomap) {
+        dev->msix_pba_bar_iomap = false;
         qpci_iounmap(dev, dev->msix_pba_bar);
+    } else {
+        /*
+         * If we had reused an existing iomap, ensure it is still mapped
+         * otherwise it would be a bug if it were unmapped before msix is
+         * disabled. A refcounting iomap implementation could avoid this
+         * issue entirely, but let's wait until that's needed.
+         */
+        uint8_t bir_pba;
+        table = qpci_config_readl(dev, addr + PCI_MSIX_PBA);
+        bir_pba = table & PCI_MSIX_FLAGS_BIRMASK;
+        g_assert(dev->bars_mapped[bir_pba]);
+    }
+
+    if (dev->msix_table_bar_iomap) {
+        dev->msix_table_bar_iomap = false;
+        qpci_iounmap(dev, dev->msix_table_bar);
+    } else {
+        uint8_t bir_table;
+        table = qpci_config_readl(dev, addr + PCI_MSIX_TABLE);
+        bir_table = table & PCI_MSIX_FLAGS_BIRMASK;
+        g_assert(dev->bars_mapped[bir_table]);
     }
-    qpci_iounmap(dev, dev->msix_table_bar);
 
     dev->msix_enabled = 0;
     dev->msix_table_off = 0;
Signature · 1 line
2.47.1
#9 lore raw

PATCH v4 7/7 qtest/libqos/pci: Factor msix entry helpers into pci common code

In reply to Nicholas Piggin

Setting msix entry address and data and masking is moved into common code helpers from virtio tests.

For now that remains the only user, but there are changes under development to enable msix vectors for msix, e1000e, and xhci tests, which can make use of them.

---
 tests/qtest/libqos/pci.h        |  3 ++
 tests/qtest/libqos/pci.c        | 53 +++++++++++++++++++++++++++++++++
 tests/qtest/libqos/virtio-pci.c | 48 ++++-------------------------
 3 files changed, 61 insertions(+), 43 deletions(-)
tests/qtest/libqos/pci.h +3 -0
index d334d9c0837..c63342d8c72 100644
@@ -100,8 +100,11 @@ void qpci_device_enable(QPCIDevice *dev);
 uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id, uint8_t start_addr);
 void qpci_msix_enable(QPCIDevice *dev);
 void qpci_msix_disable(QPCIDevice *dev);
+void qpci_msix_set_entry(QPCIDevice *dev, uint16_t entry,
+                         uint64_t guest_addr, uint32_t data);
 bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry);
 bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry);
+void qpci_msix_set_masked(QPCIDevice *dev, uint16_t entry, bool masked);
 uint16_t qpci_msix_table_size(QPCIDevice *dev);
 
 uint8_t qpci_config_readb(QPCIDevice *dev, uint8_t offset);
tests/qtest/libqos/pci.c +53 -0

77 lines not on this page · raw message

tests/qtest/libqos/virtio-pci.c +5 -43

69 lines not on this page · raw message

Signature · 1 line
2.47.1
#3 lore raw

Re: [PATCH v4 2/7] tests/qtest/ahci: don't unmap pci bar if it wasn't mapped

In reply to Nicholas Piggin
Quoted 7 lines · Nicholas Piggin

ahci-test has a bunch of tests where the pci bar was not mapped. Avoid unmapping it in these cases, to keep iomaps balanced.

Cc Michael S. Tsirkin <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Akihiko Odaki <[email protected]>
Cc Akihiko Odaki <[email protected]>

My address is duplicated.

Quoted 37 lines
---
  tests/qtest/ahci-test.c | 35 ++++++++++++++++++++++++-----------
  1 file changed, 24 insertions(+), 11 deletions(-)
tests/qtest/ahci-test.c +5 -2
index 7cae6b58e0c..02c9d54f898 100644
@@ -85,6 +85,8 @@ static void verify_state(AHCIQState *ahci, uint64_t hba_old)
      uint64_t hba_base;
      AHCICommandHeader cmd;
 
+    g_assert_cmphex(ahci->hba_bar.addr, ==, hba_old);
+
      ahci_fingerprint = qpci_config_readl(ahci->dev, PCI_VENDOR_ID);
      g_assert_cmphex(ahci_fingerprint, ==, ahci->fingerprint);
 
@@ -193,18 +195,28 @@ static AHCIQState *ahci_boot(const char *cli, ...)
 
  /**
   * Clean up the PCI device, then terminate the QEMU instance.
+ * Should be called if ahci_pci_enable (or ahci_boot_and_enable)
+ * was not used, or device/pci was disabled later.
   */
-static void ahci_shutdown(AHCIQState *ahci)
+static void ahci_shutdown_pci_disabled(AHCIQState *ahci)
  {
      QOSState *qs = ahci->parent;
 
-    ahci_pci_disable(ahci);
      ahci_clean_mem(ahci);
      free_ahci_device(ahci->dev);
      g_free(ahci);
      qtest_shutdown(qs);
  }

tests/qtest/ahci-test.c static AHCIQState *ahci_boot(const char *cli, ...) · line 219

Quoted 10 lines
tests/qtest/ahci-test.c +9 -0
 
+/**
+ * Clean up the PCI device, then terminate the QEMU instance.
+ */
+static void ahci_shutdown(AHCIQState *ahci)
+{
+    ahci_pci_disable(ahci);
+    ahci_shutdown_pci_disabled(ahci);
+}
+

I rather want to keep one unified function that performs all cleanup operations since it's error-prone to choose an appropriate cleanup function. ahci_shutdown() also calls ahci_clean_mem(), which checks if its cleanup operation is necessary before actually performing it so we can do the same for the BAR unmapping for consistency.

Quoted 78 lines
tests/qtest/ahci-test.c +10 -9
  /**
   * Boot and fully enable the HBA device.
   * @see ahci_boot, ahci_pci_enable and ahci_hba_enable.
@@ -945,7 +957,7 @@ static void test_sanity(void)
  {
      AHCIQState *ahci;
      ahci = ahci_boot(NULL);
-    ahci_shutdown(ahci);
+    ahci_shutdown_pci_disabled(ahci);
  }
 
  /**
@@ -957,7 +969,7 @@ static void test_pci_spec(void)
      AHCIQState *ahci;
      ahci = ahci_boot(NULL);
      ahci_test_pci_spec(ahci);
-    ahci_shutdown(ahci);
+    ahci_shutdown_pci_disabled(ahci);
  }
 
  /**
@@ -1143,8 +1155,8 @@ static void test_migrate_sanity(void)
 
      ahci_migrate(src, dst, uri);
 
-    ahci_shutdown(src);
-    ahci_shutdown(dst);
+    ahci_shutdown_pci_disabled(src);
+    ahci_shutdown_pci_disabled(dst);
      g_free(uri);
  }
 
@@ -1182,7 +1194,7 @@ static void ahci_migrate_simple(uint8_t cmd_read, uint8_t cmd_write)
      /* Verify pattern */
      g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);
 
-    ahci_shutdown(src);
+    ahci_shutdown_pci_disabled(src);
      ahci_shutdown(dst);
      g_free(rx);
      g_free(tx);
@@ -1324,7 +1336,7 @@ static void ahci_migrate_halted_io(uint8_t cmd_read, uint8_t cmd_write)
      g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);
 
      /* Cleanup and go home. */
-    ahci_shutdown(src);
+    ahci_shutdown_pci_disabled(src);
      ahci_shutdown(dst);
      g_free(rx);
      g_free(tx);
@@ -1388,8 +1400,8 @@ static void test_flush_migrate(void)
      ahci_command_verify(dst, cmd);
 
      ahci_command_free(cmd);
-    ahci_shutdown(src);
-    ahci_shutdown(dst);
+    ahci_shutdown_pci_disabled(src);
+    ahci_shutdown_pci_disabled(dst);
      g_free(uri);
  }
 
@@ -1421,6 +1433,7 @@ static void test_reset(void)
          ahci_set(ahci, AHCI_GHC, AHCI_GHC_HR);
          stop_ahci_device(ahci);
          ahci_clean_mem(ahci);
+        start_ahci_device(ahci);
      }
 
      ahci_shutdown(ahci);
@@ -1508,7 +1521,7 @@ static void test_reset_pending_callback(void)
      stop_ahci_device(ahci);
      ahci_clean_mem(ahci);
 
-    ahci_shutdown(ahci);
+    ahci_shutdown_pci_disabled(ahci);
  }
 
  static void test_ncq_simple(void)
Reviewed-by on v4 4/7
#6 lore raw

Re: [PATCH v4 4/7] tests/qtest/libquos/pci: Add migration fixup helper for pci devices

In reply to Nicholas Piggin
Quoted 8 lines · Nicholas Piggin

Migration tests can create new QPCI devices for the destination machine which may need to take on some state of the source machine after destination is complete.

Add a migration fixup helper and call it from ahci migration tests. This is currently a noop and will be used subsequently.