qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] libqos: pci: Avoid fatal assert on zero-sized BARs in fuzz builds
@ 2025-10-08 19:19 Navid Emamdoost
  2025-10-08 19:19 ` [PATCH 2/2] tests/qtest/fuzz: Add generic fuzzer for pcie-pci-bridge Navid Emamdoost
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Navid Emamdoost @ 2025-10-08 19:19 UTC (permalink / raw)
  To: qemu-devel; +Cc: navidem, zsm, Fabiano Rosas, Laurent Vivier, Paolo Bonzini

The qpci_iomap() function fails with a fatal g_assert(addr) if it
probes a PCI BAR that has a size of zero. This is expected behavior
for certain devices, like the Q35 PCI Host Bridge, which have valid but
unimplemented BARs.
This assertion blocks the creation of fuzz targets for complex machine
types that include these devices.
Make the check conditional on !CONFIG_FUZZ. In fuzzing builds, a
zero-sized BAR is now handled gracefully by returning an empty BAR
struct, allowing fuzzing to proceed. The original assertion is kept for
all other builds to maintain strict checking for qtest and production
environments.

Signed-off-by: Navid Emamdoost <navidem@google.com>
---
 tests/qtest/libqos/pci.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tests/qtest/libqos/pci.c b/tests/qtest/libqos/pci.c
index a59197b992..df9e2a3993 100644
--- a/tests/qtest/libqos/pci.c
+++ b/tests/qtest/libqos/pci.c
@@ -541,6 +541,22 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr)
         addr &= PCI_BASE_ADDRESS_MEM_MASK;
     }
 
+#ifdef CONFIG_FUZZ
+    /*
+     * During fuzzing runs, an unimplemented BAR (addr=0) is not a fatal
+     * error. This occurs when probing devices like the Q35 host bridge. We
+     * return gracefully to allow fuzzing to continue. In non-fuzzing builds,
+     * we retain the original g_assert() to catch unexpected behavior.
+     */
+    if (!addr) {
+        if (sizeptr) {
+            *sizeptr = 0;
+        }
+        memset(&bar, 0, sizeof(bar));
+        return bar;
+    }
+#endif
+
     g_assert(addr); /* Must have *some* size bits */
 
     size = 1U << ctz32(addr);
-- 
2.51.0.710.ga91ca5db03-goog



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-13 14:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08 19:19 [PATCH 1/2] libqos: pci: Avoid fatal assert on zero-sized BARs in fuzz builds Navid Emamdoost
2025-10-08 19:19 ` [PATCH 2/2] tests/qtest/fuzz: Add generic fuzzer for pcie-pci-bridge Navid Emamdoost
2025-10-10 15:58 ` [PATCH 1/2] libqos: pci: Avoid fatal assert on zero-sized BARs in fuzz builds Alexander Bulekov
2025-10-14  1:14   ` Navid Emamdoost
2025-11-06 18:41     ` Navid Emamdoost
2025-11-13 14:02 ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).