From: Nicholas Piggin <npiggin@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Nicholas Piggin" <npiggin@gmail.com>,
"Akihiko Odaki" <akihiko.odaki@daynix.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"John Snow" <jsnow@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-block@nongnu.org, qemu-ppc@nongnu.org
Subject: [PATCH v5 03/11] tests/qtest: Add libqos function for testing msix interrupt status
Date: Fri, 2 May 2025 13:04:37 +1000 [thread overview]
Message-ID: <20250502030446.88310-4-npiggin@gmail.com> (raw)
In-Reply-To: <20250502030446.88310-1-npiggin@gmail.com>
This function is duplicated 3 times, with more potential future users.
Factor it into libqos, using qtest_memset instead of qtest_writel to
clear the message just because that looks nicer with the qtest_memread
used to read it.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
tests/qtest/libqos/pci.h | 2 ++
tests/qtest/libqos/pci.c | 48 ++++++++++++++++++++++++++
tests/qtest/libqos/virtio-pci-modern.c | 31 +++--------------
tests/qtest/libqos/virtio-pci.c | 40 ++++-----------------
4 files changed, 62 insertions(+), 59 deletions(-)
diff --git a/tests/qtest/libqos/pci.h b/tests/qtest/libqos/pci.h
index 83896145235..9f8f154c301 100644
--- a/tests/qtest/libqos/pci.h
+++ b/tests/qtest/libqos/pci.h
@@ -92,6 +92,8 @@ void qpci_msix_enable(QPCIDevice *dev);
void qpci_msix_disable(QPCIDevice *dev);
bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry);
bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry);
+bool qpci_msix_test_interrupt(QPCIDevice *dev, uint32_t msix_entry,
+ uint64_t msix_addr, uint32_t msix_data);
uint16_t qpci_msix_table_size(QPCIDevice *dev);
uint8_t qpci_config_readb(QPCIDevice *dev, uint8_t offset);
diff --git a/tests/qtest/libqos/pci.c b/tests/qtest/libqos/pci.c
index a59197b9922..773fd1fb6cf 100644
--- a/tests/qtest/libqos/pci.c
+++ b/tests/qtest/libqos/pci.c
@@ -351,6 +351,54 @@ bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry)
}
}
+/**
+ * qpci_msix_test_interrupt - test whether msix interrupt has been raised
+ * @dev: PCI device
+ * @msix_entry: msix entry to test
+ * @msix_addr: address of msix message
+ * @msix_data: expected msix message payload
+ *
+ * This tests whether the msix source has raised an interrupt. If the msix
+ * entry is masked, it tests the pending bit array for a pending message
+ * and @msix_addr and @msix_data need not be supplied. If the entry is not
+ * masked, it tests the address for corresponding data to see if the interrupt
+ * fired.
+ *
+ * Note that this does not lower the interrupt, however it does clear the
+ * msix message address to 0 if it is found set. This must be called with
+ * the msix address memory containing either 0 or the value of data, otherwise
+ * it will assert on incorrect message.
+ */
+bool qpci_msix_test_interrupt(QPCIDevice *dev, uint32_t msix_entry,
+ uint64_t msix_addr, uint32_t msix_data)
+{
+ uint32_t data;
+
+ g_assert(dev->msix_enabled);
+ g_assert_cmpint(msix_entry, !=, -1);
+
+ if (qpci_msix_masked(dev, msix_entry)) {
+ /* No ISR checking should be done if masked, but read anyway */
+ return qpci_msix_pending(dev, msix_entry);
+ }
+
+ g_assert_cmpint(msix_addr, !=, 0);
+ g_assert_cmpint(msix_data, !=, 0);
+
+ /* msix payload is written in little-endian format */
+ qtest_memread(dev->bus->qts, msix_addr, &data, 4);
+ data = le32_to_cpu(data);
+ if (data == 0) {
+ return false;
+ }
+
+ /* got a message, ensure it matches expected value then clear it. */
+ g_assert_cmphex(data, ==, msix_data);
+ qtest_memset(dev->bus->qts, msix_addr, 0, 4);
+
+ return true;
+}
+
uint16_t qpci_msix_table_size(QPCIDevice *dev)
{
uint8_t addr;
diff --git a/tests/qtest/libqos/virtio-pci-modern.c b/tests/qtest/libqos/virtio-pci-modern.c
index 5dae41e6d74..0d7d89bbcb1 100644
--- a/tests/qtest/libqos/virtio-pci-modern.c
+++ b/tests/qtest/libqos/virtio-pci-modern.c
@@ -126,28 +126,6 @@ static void set_status(QVirtioDevice *d, uint8_t status)
status);
}
-static bool get_msix_status(QVirtioPCIDevice *dev, uint32_t msix_entry,
- uint32_t msix_addr, uint32_t msix_data)
-{
- uint32_t data;
-
- g_assert_cmpint(msix_entry, !=, -1);
- if (qpci_msix_masked(dev->pdev, msix_entry)) {
- /* No ISR checking should be done if masked, but read anyway */
- return qpci_msix_pending(dev->pdev, msix_entry);
- }
-
- qtest_memread(dev->pdev->bus->qts, msix_addr, &data, 4);
- data = le32_to_cpu(data);
- if (data == 0) {
- return false;
- }
- /* got a message, ensure it matches expected value then clear it. */
- g_assert_cmphex(data, ==, msix_data);
- qtest_writel(dev->pdev->bus->qts, msix_addr, 0);
- return true;
-}
-
static bool get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
{
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
@@ -155,8 +133,8 @@ static bool get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
if (dev->pdev->msix_enabled) {
QVirtQueuePCI *vqpci = container_of(vq, QVirtQueuePCI, vq);
- return get_msix_status(dev, vqpci->msix_entry, vqpci->msix_addr,
- vqpci->msix_data);
+ return qpci_msix_test_interrupt(dev->pdev, vqpci->msix_entry,
+ vqpci->msix_addr, vqpci->msix_data);
}
return qpci_io_readb(dev->pdev, dev->bar, dev->isr_cfg_offset) & 1;
@@ -167,8 +145,9 @@ static bool get_config_isr_status(QVirtioDevice *d)
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
if (dev->pdev->msix_enabled) {
- return get_msix_status(dev, dev->config_msix_entry,
- dev->config_msix_addr, dev->config_msix_data);
+ return qpci_msix_test_interrupt(dev->pdev, dev->config_msix_entry,
+ dev->config_msix_addr,
+ dev->config_msix_data);
}
return qpci_io_readb(dev->pdev, dev->bar, dev->isr_cfg_offset) & 2;
diff --git a/tests/qtest/libqos/virtio-pci.c b/tests/qtest/libqos/virtio-pci.c
index 76ea1f45ba9..ea8114e2438 100644
--- a/tests/qtest/libqos/virtio-pci.c
+++ b/tests/qtest/libqos/virtio-pci.c
@@ -122,25 +122,12 @@ static void qvirtio_pci_set_status(QVirtioDevice *d, uint8_t status)
static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
{
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
- QVirtQueuePCI *vqpci = (QVirtQueuePCI *)vq;
- uint32_t data;
if (dev->pdev->msix_enabled) {
- g_assert_cmpint(vqpci->msix_entry, !=, -1);
- if (qpci_msix_masked(dev->pdev, vqpci->msix_entry)) {
- /* No ISR checking should be done if masked, but read anyway */
- return qpci_msix_pending(dev->pdev, vqpci->msix_entry);
- } else {
- qtest_memread(dev->pdev->bus->qts, vqpci->msix_addr, &data, 4);
- data = le32_to_cpu(data);
- if (data == 0) {
- return false;
- }
- /* got a message, ensure it matches expected value then clear it. */
- g_assert_cmphex(data, ==, vqpci->msix_data);
- qtest_writel(dev->pdev->bus->qts, vqpci->msix_addr, 0);
- return true;
- }
+ QVirtQueuePCI *vqpci = (QVirtQueuePCI *)vq;
+
+ return qpci_msix_test_interrupt(dev->pdev, vqpci->msix_entry,
+ vqpci->msix_addr, vqpci->msix_data);
} else {
return qpci_io_readb(dev->pdev, dev->bar, VIRTIO_PCI_ISR) & 1;
}
@@ -149,24 +136,11 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
{
QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
- uint32_t data;
if (dev->pdev->msix_enabled) {
- g_assert_cmpint(dev->config_msix_entry, !=, -1);
- if (qpci_msix_masked(dev->pdev, dev->config_msix_entry)) {
- /* No ISR checking should be done if masked, but read anyway */
- return qpci_msix_pending(dev->pdev, dev->config_msix_entry);
- } else {
- qtest_memread(dev->pdev->bus->qts, dev->config_msix_addr, &data, 4);
- data = le32_to_cpu(data);
- if (data == 0) {
- return false;
- }
- /* got a message, ensure it matches expected value then clear it. */
- g_assert_cmphex(data, ==, dev->config_msix_data);
- qtest_writel(dev->pdev->bus->qts, dev->config_msix_addr, 0);
- return true;
- }
+ return qpci_msix_test_interrupt(dev->pdev, dev->config_msix_entry,
+ dev->config_msix_addr,
+ dev->config_msix_data);
} else {
return qpci_io_readb(dev->pdev, dev->bar, VIRTIO_PCI_ISR) & 2;
}
--
2.47.1
next prev parent reply other threads:[~2025-05-02 3:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 3:04 [PATCH v5 00/11] tests/qtest: pci and msix fixes Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 01/11] tests/qtest: Enforce zero for the "un-fired" msix message value Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 02/11] tests/qtest: Fix virtio msix message endianness Nicholas Piggin
2025-05-05 5:05 ` Akihiko Odaki
2025-05-05 6:53 ` Nicholas Piggin
2025-05-02 3:04 ` Nicholas Piggin [this message]
2025-05-05 5:37 ` [PATCH v5 03/11] tests/qtest: Add libqos function for testing msix interrupt status Akihiko Odaki
2025-05-05 7:09 ` Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 04/11] tests/qtest: Enable spapr dma with linear iommu map Nicholas Piggin
2026-06-11 10:56 ` Alexander Mikhalitsyn
2025-05-02 3:04 ` [PATCH v5 05/11] tests/qtest/ahci: unmap pci bar before reusing device Nicholas Piggin
2025-05-05 5:03 ` Akihiko Odaki
2025-05-02 3:04 ` [PATCH v5 06/11] tests/qtest/ahci: don't unmap pci bar if it wasn't mapped Nicholas Piggin
2025-05-05 5:25 ` Akihiko Odaki
2025-05-05 6:54 ` Nicholas Piggin
2025-05-05 7:33 ` Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 07/11] tests/qtest/libquos/virtio: unmap pci bar when disabling device Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 08/11] tests/qtest/libquos/pci: Add migration fixup helper for pci devices Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 09/11] qtest/libqos/pci: Enforce balanced iomap/unmap Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 10/11] qtest/libqos/pci: Fix qpci_msix_enable sharing bar0 Nicholas Piggin
2025-05-02 3:04 ` [PATCH v5 11/11] qtest/libqos/pci: Factor msix entry helpers into pci common code Nicholas Piggin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250502030446.88310-4-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=akihiko.odaki@daynix.com \
--cc=farosas@suse.de \
--cc=harshpb@linux.ibm.com \
--cc=jsnow@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.