From: Peter Maydell <peter.maydell@linaro.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: QEMU PCI subsystem: what code is responsible for making accesses to non-mapped addresses read as -1?
Date: Sat, 20 Mar 2021 20:40:13 +0000 [thread overview]
Message-ID: <CAFEAcA-TWsG8wbc8jtEHvnKU5RFJrif77miWDb76y937tmMyGw@mail.gmail.com> (raw)
In-Reply-To: <20210320144325-mutt-send-email-mst@kernel.org>
On Sat, 20 Mar 2021 at 18:59, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Fri, Mar 19, 2021 at 12:35:31PM +0000, Peter Maydell wrote:
> > I'm looking at a bug reported against the QEMU arm virt board's pci-gpex
> > PCI controller: https://bugs.launchpad.net/qemu/+bug/1918917
> > where an attempt to write to an address within the PCI IO window
> > where the guest hasn't mapped a BAR causes a CPU exception rather than
> > (what I believe is) the PCI-required behaviour of writes-ignored, reads
> > return -1.
> >
> > What in the QEMU PCI code is responsible for giving the PCI-spec
> > behaviour for accesses to the PCI IO and memory windows where there
> > is no BAR? I was expecting the generic PCI code to map a background
> > memory region over the whole window to do this, but it looks like it
> > doesn't...
> As far as I know, at the PCI level what happens is Master Abort
> on PCI/PCI-X and Unsupported Request on Express.
> PCI spec says:
> The host bus bridge, in PC compatible systems, must return all 1's on a read transaction and
> discard data on a write transaction when terminated with Master-Abort.
>
> We thus implement this per host e.g. on pc compatible systems by
> calling pc_pci_as_mapping_init.
Isn't pc_pci_as_mapping_init() "put the PCI space into the system
address space", rather than "define the default behaviour for
accesses in PCI space" ? IIRC x86 has -1/discard for everywhere,
though, so maybe you get that without having to do anything special.
Q: if PCI device A does a bus-mastering DMA read to a PCI address
where no other device has been mapped, does the spec require
it to (a) get back a "transaction failed" response or (b) get
back read-data of -1 ? It sounds like the answer based on what
you write above is (a), device A gets a Master Abort.
(Put another way, is the -1/discard behaviour general to PCI
transactions or is it strictly something that happens at the host
bridge where the host bridge turns host CPU transactions into PCI
transactions ?)
If this is host-bridge specific then I guess our current
implementation of "leave it up to the host bridge code" makes
sense, but it also seems like a recipe for all our host bridges
forgetting this corner case, in the absence of support from
the common code for making it easy/the default...
Anyway, I think that for hw/pci-host/gpex.c we would need
to change the current
memory_region_init(&s->io_mmio, OBJECT(s), "gpex_mmio", UINT64_MAX);
[...]
sysbus_init_mmio(sbd, &s->io_mmio);
[...]
pci->bus = pci_register_root_bus(dev, "pcie.0", gpex_set_irq,
pci_swizzle_map_irq_fn, s, &s->io_mmio,
&s->io_ioport, 0, 4, TYPE_PCIE_BUS);
to also create a container MR with a background set of io read/write
functions to give the -1/discard behaviour, map s->io_mmio into
that container, and return the container as the sysbus MMIO region.
(and same again for the IO window).
thanks
-- PMM
next prev parent reply other threads:[~2021-03-20 20:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-19 12:35 QEMU PCI subsystem: what code is responsible for making accesses to non-mapped addresses read as -1? Peter Maydell
2021-03-19 14:14 ` Philippe Mathieu-Daudé
2021-03-19 21:13 ` Laszlo Ersek
2021-03-20 18:58 ` Michael S. Tsirkin
2021-03-20 20:40 ` Peter Maydell [this message]
2021-03-20 21:50 ` Michael S. Tsirkin
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=CAFEAcA-TWsG8wbc8jtEHvnKU5RFJrif77miWDb76y937tmMyGw@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=mst@redhat.com \
--cc=qemu-devel@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 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).