[PATCH 0/6] hw: Log unassigned MMIO accesses with unassigned_mem_ops

Philippe Mathieu-Daudé posted 6 patches 2 weeks, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251027123644.63487-1-philmd@linaro.org
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Cédric Le Goater" <clg@kaod.org>, Peter Maydell <peter.maydell@linaro.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee <leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
include/system/memory.h    | 2 ++
system/memory-internal.h   | 2 --
hw/display/bochs-display.c | 2 +-
hw/display/vga-pci.c       | 4 ++--
hw/pci-host/aspeed_pcie.c  | 2 +-
hw/pci-host/astro.c        | 2 +-
hw/pci-host/gpex.c         | 2 +-
hw/sparc64/sun4u.c         | 2 +-
8 files changed, 9 insertions(+), 9 deletions(-)
[PATCH 0/6] hw: Log unassigned MMIO accesses with unassigned_mem_ops
Posted by Philippe Mathieu-Daudé 2 weeks, 4 days ago
Do not log unassigned MMIO accesses as I/O ones:
expose unassigned_mem_ops then use it instead of
unassigned_io_ops.

Philippe Mathieu-Daudé (6):
  system/memory: Expose unassigned_mem_ops symbol
  hw/display/vga: Log unassigned MMIO accesses with unassigned_mem_ops
  hw/pci-host/gpex: Log unassigned MMIO accesses with unassigned_mem_ops
  hw/pci-host/aspeed: Log unassigned MMIO accesses with
    unassigned_mem_ops
  hw/pci-host/astro: Log unassigned MMIO accesses with
    unassigned_mem_ops
  hw/sparc64/ebus: Log unassigned MMIO accesses with unassigned_mem_ops

 include/system/memory.h    | 2 ++
 system/memory-internal.h   | 2 --
 hw/display/bochs-display.c | 2 +-
 hw/display/vga-pci.c       | 4 ++--
 hw/pci-host/aspeed_pcie.c  | 2 +-
 hw/pci-host/astro.c        | 2 +-
 hw/pci-host/gpex.c         | 2 +-
 hw/sparc64/sun4u.c         | 2 +-
 8 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.51.0


Re: [PATCH 0/6] hw: Log unassigned MMIO accesses with unassigned_mem_ops
Posted by Alex Bennée 2 weeks, 4 days ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Do not log unassigned MMIO accesses as I/O ones:
> expose unassigned_mem_ops then use it instead of
> unassigned_io_ops.

But why? Is it because ioport.c is a x86 io thing?

>
> Philippe Mathieu-Daudé (6):
>   system/memory: Expose unassigned_mem_ops symbol
>   hw/display/vga: Log unassigned MMIO accesses with unassigned_mem_ops
>   hw/pci-host/gpex: Log unassigned MMIO accesses with unassigned_mem_ops
>   hw/pci-host/aspeed: Log unassigned MMIO accesses with
>     unassigned_mem_ops
>   hw/pci-host/astro: Log unassigned MMIO accesses with
>     unassigned_mem_ops
>   hw/sparc64/ebus: Log unassigned MMIO accesses with unassigned_mem_ops
>
>  include/system/memory.h    | 2 ++
>  system/memory-internal.h   | 2 --
>  hw/display/bochs-display.c | 2 +-
>  hw/display/vga-pci.c       | 4 ++--
>  hw/pci-host/aspeed_pcie.c  | 2 +-
>  hw/pci-host/astro.c        | 2 +-
>  hw/pci-host/gpex.c         | 2 +-
>  hw/sparc64/sun4u.c         | 2 +-
>  8 files changed, 9 insertions(+), 9 deletions(-)

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH 0/6] hw: Log unassigned MMIO accesses with unassigned_mem_ops
Posted by Peter Maydell 2 weeks, 4 days ago
On Mon, 27 Oct 2025 at 13:12, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
>
> > Do not log unassigned MMIO accesses as I/O ones:
> > expose unassigned_mem_ops then use it instead of
> > unassigned_io_ops.
>
> But why? Is it because ioport.c is a x86 io thing?


There is a behaviour difference: unassigned_mem_ops
will fault (because of unassigned_mem_accepts()),
but unassigned_io_ops will be "reads as -1, writes
are ignored". This patch series doesn't mention any
intention of introducing a behaviour difference, so
I suspect this is not intended...

There are a couple of different but related concepts
here that we need to keep straight:

(1) x86 I/O ops, which are different CPU instructions
that talk to a different memory-space than MMIO
accesses. In QEMU we model these as accesses to the
address_space_io AddressSpace. I believe no other
target CPU has an equivalent to this.

(2) PCI "I/O" BARs. PCI devices can have both MMIO
and IO BARs. A PCI controller on x86 maps IO BARs
into the IO space, I think. On non-x86 the IO BARs
typically appear in a different window for MMIO
accesses. Behaviour of PCI I/O accesses to unimplemented
regions is probably defined by the PCI spec somewhere.
Behaviour of PCI accesses to unimplemented MMIO
window areas is I think technically left unspecified
by the PCI standard, but "write ignore/read -1" is
what x86 does and what most software expects, so
hardware that implements something else is making
its life unnecessarily difficult.

I suspect we entangle the PCI IO BAR concept and
implementation a bit more with the x86 I/O ops
implementation than we ideally ought to.

-- PMM
Re: [PATCH 0/6] hw: Log unassigned MMIO accesses with unassigned_mem_ops
Posted by Philippe Mathieu-Daudé 2 weeks, 4 days ago
On 27/10/25 14:26, Peter Maydell wrote:
> On Mon, 27 Oct 2025 at 13:12, Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
>>
>>> Do not log unassigned MMIO accesses as I/O ones:
>>> expose unassigned_mem_ops then use it instead of
>>> unassigned_io_ops.
>>
>> But why? Is it because ioport.c is a x86 io thing?
> 
> 
> There is a behaviour difference: unassigned_mem_ops
> will fault (because of unassigned_mem_accepts()),
> but unassigned_io_ops will be "reads as -1, writes
> are ignored". This patch series doesn't mention any
> intention of introducing a behaviour difference, so
> I suspect this is not intended...

Oops... Good catch.

> There are a couple of different but related concepts
> here that we need to keep straight:
> 
> (1) x86 I/O ops, which are different CPU instructions
> that talk to a different memory-space than MMIO
> accesses. In QEMU we model these as accesses to the
> address_space_io AddressSpace. I believe no other
> target CPU has an equivalent to this.

This is also my understanding.

> (2) PCI "I/O" BARs. PCI devices can have both MMIO
> and IO BARs. A PCI controller on x86 maps IO BARs
> into the IO space, I think. On non-x86 the IO BARs
> typically appear in a different window for MMIO
> accesses. Behaviour of PCI I/O accesses to unimplemented
> regions is probably defined by the PCI spec somewhere.
> Behaviour of PCI accesses to unimplemented MMIO
> window areas is I think technically left unspecified
> by the PCI standard, but "write ignore/read -1" is
> what x86 does and what most software expects, so
> hardware that implements something else is making
> its life unnecessarily difficult.

Right, this is what I'd like to unify, ...

> I suspect we entangle the PCI IO BAR concept and
> implementation a bit more with the x86 I/O ops
> implementation than we ideally ought to.

... to disentangle that.

Re: [PATCH 0/6] hw: Log unassigned MMIO accesses with unassigned_mem_ops
Posted by Peter Maydell 2 weeks, 4 days ago
On Mon, 27 Oct 2025 at 13:33, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> On 27/10/25 14:26, Peter Maydell wrote:
> > (2) PCI "I/O" BARs. PCI devices can have both MMIO
> > and IO BARs. A PCI controller on x86 maps IO BARs
> > into the IO space, I think. On non-x86 the IO BARs
> > typically appear in a different window for MMIO
> > accesses. Behaviour of PCI I/O accesses to unimplemented
> > regions is probably defined by the PCI spec somewhere.
> > Behaviour of PCI accesses to unimplemented MMIO
> > window areas is I think technically left unspecified
> > by the PCI standard, but "write ignore/read -1" is
> > what x86 does and what most software expects, so
> > hardware that implements something else is making
> > its life unnecessarily difficult.
>
> Right, this is what I'd like to unify, ...
>
> > I suspect we entangle the PCI IO BAR concept and
> > implementation a bit more with the x86 I/O ops
> > implementation than we ideally ought to.
>
> ... to disentangle that.

I think my suggestion (based on about five minutes'
thought, so possibly wrong-headed ;-)) would be:

 * the individual PCI devices like bochs-display and
   vga-pci that currently use unassigned_io_ops should
   instead define their own local MemoryRegionOps that
   does what that specific device requires. (I actually
   suspect that having no I/O ops at all so that the
   accesses to holes in that MR fall through to the
   PCI controller's default behaviour for unassigned
   accesses would also produce correct behaviour, but that's
   trickier to verify and would require looking at a lot
   of individual pci-controller models, so the easy thing is
   a local MRO.)
 * patches 3, 4 and 5 are all defining the default behaviour
   for "access to some MMIO window provided by a PCI
   controller". If we want to disentangle this from the
   x86 IO port handling, then I guess that we could either
   have the generic PCI code provide a "reads as all-ones,
   writes ignored" MemoryRegionOps as a convenience for
   controller implementations; or we could have each
   controller do it separately. I guess I prefer the former.
 * I'm not sure about patch 6, but it looks like some kind
   of PCI-to-other-bus bridge. It should probably define its
   own MemoryRegionOps with the behaviour it wants. (Though
   again it's possible that letting unassigned addresses
   fall through the the PCI controller's implementation
   would be neater.)

Roughly, what's happened here is that various nominally
independent bits of code have borrowed unassigned_io_ops
as a convenient pre-existing "reads as all ones, writes
ignored" MemoryRegionOps; we can disentangle by having
them implement what they're after locally rather than
borrowing something that doesn't logically belong to them.

thanks
-- PMM
Re: [PATCH 0/6] hw: Log unassigned MMIO accesses with unassigned_mem_ops
Posted by Philippe Mathieu-Daudé 2 weeks, 4 days ago
On 27/10/25 14:12, Alex Bennée wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> Do not log unassigned MMIO accesses as I/O ones:
>> expose unassigned_mem_ops then use it instead of
>> unassigned_io_ops.
> 
> But why? Is it because ioport.c is a x86 io thing?

Mainly. But also because log is confusing.
This is part of a bigger PCI host-bridge address-spaces
rework.

> 
>>
>> Philippe Mathieu-Daudé (6):
>>    system/memory: Expose unassigned_mem_ops symbol
>>    hw/display/vga: Log unassigned MMIO accesses with unassigned_mem_ops
>>    hw/pci-host/gpex: Log unassigned MMIO accesses with unassigned_mem_ops
>>    hw/pci-host/aspeed: Log unassigned MMIO accesses with
>>      unassigned_mem_ops
>>    hw/pci-host/astro: Log unassigned MMIO accesses with
>>      unassigned_mem_ops
>>    hw/sparc64/ebus: Log unassigned MMIO accesses with unassigned_mem_ops
>>
>>   include/system/memory.h    | 2 ++
>>   system/memory-internal.h   | 2 --
>>   hw/display/bochs-display.c | 2 +-
>>   hw/display/vga-pci.c       | 4 ++--
>>   hw/pci-host/aspeed_pcie.c  | 2 +-
>>   hw/pci-host/astro.c        | 2 +-
>>   hw/pci-host/gpex.c         | 2 +-
>>   hw/sparc64/sun4u.c         | 2 +-
>>   8 files changed, 9 insertions(+), 9 deletions(-)
>