qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Navid Emamdoost <navidem@google.com>
To: Alexander Bulekov <alxndr@bu.edu>
Cc: qemu-devel@nongnu.org, zsm@google.com,
	Fabiano Rosas <farosas@suse.de>,
	 Laurent Vivier <lvivier@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 1/2] libqos: pci: Avoid fatal assert on zero-sized BARs in fuzz builds
Date: Thu, 6 Nov 2025 10:41:27 -0800	[thread overview]
Message-ID: <CAGXevki76WoXWV8P3HSo9vq09FXzKBi+xQoxCLKWAU4AjXF39w@mail.gmail.com> (raw)
In-Reply-To: <CAGXevkjvVQE98WqE6-QcWc5jYvgycymhJYmVnEGUTdwNwNyH6w@mail.gmail.com>

On Mon, Oct 13, 2025 at 6:14 PM Navid Emamdoost <navidem@google.com> wrote:
>
> Hi Alexander,
>
> On Fri, Oct 10, 2025 at 8:59 AM Alexander Bulekov <alxndr@bu.edu> wrote:
> >
> > On 251008 1919, Navid Emamdoost wrote:
> > > 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.
> >
> > Is there a way to determine whether a BAR is unimplememnted from the
> > PCIDev in generic_fuzz.c:pci_enum so that we can skip the call to iomap?
> >
>
> Fair point. I don't think we have a reliable way to determine if a BAR
> is truly unimplemented from the PCIDevice model without probing it. If
> we moved that hardware probe into pci_enum, it would become
> inefficient for all the BARs that are implemented, as they would be
> probed twice: once in pci_enum just to check, and then again inside
> qpci_iomap to do the actual mapping. That's why I think delegating
> this check to qpci_iomap is the cleaner approach.
>

Friendly ping.

> > >
> > > 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
> > >
> > >
>
>
>
> --
> Thank you,
> Navid.



-- 
Thank you,
Navid.


  reply	other threads:[~2025-11-06 18:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-11-13 14:02 ` Peter Maydell

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=CAGXevki76WoXWV8P3HSo9vq09FXzKBi+xQoxCLKWAU4AjXF39w@mail.gmail.com \
    --to=navidem@google.com \
    --cc=alxndr@bu.edu \
    --cc=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zsm@google.com \
    /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 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).