qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-19  0:21 [Qemu-devel] [PATCH v3 00/12] spapr: add support for pci hotplug Michael Roth
@ 2014-08-19  0:21 ` Michael Roth
  2014-08-26  9:14   ` Alexey Kardashevskiy
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Michael Roth @ 2014-08-19  0:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: aik, agraf, ncmike, qemu-ppc, tyreld, nfont

Some kernels program a 0 address for io regions. PCI 3.0 spec
section 6.2.5.1 doesn't seem to disallow this.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 351d320..9578749 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1035,7 +1035,7 @@ static pcibus_t pci_bar_address(PCIDevice *d,
         /* Check if 32 bit BAR wraps around explicitly.
          * TODO: make priorities correct and remove this work around.
          */
-        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX) {
+        if (last_addr <= new_addr || last_addr >= UINT32_MAX) {
             return PCI_BAR_UNMAPPED;
         }
         return new_addr;
-- 
1.9.1

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-19  0:21 ` [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions Michael Roth
@ 2014-08-26  9:14   ` Alexey Kardashevskiy
  2014-08-26 11:55     ` Peter Maydell
  2014-08-26 18:34     ` Michael Roth
  2014-08-26 11:41   ` Alexander Graf
  2014-08-27 13:47   ` Michael S. Tsirkin
  2 siblings, 2 replies; 11+ messages in thread
From: Alexey Kardashevskiy @ 2014-08-26  9:14 UTC (permalink / raw)
  To: Michael Roth, qemu-devel; +Cc: ncmike, nfont, qemu-ppc, agraf, tyreld

On 08/19/2014 10:21 AM, Michael Roth wrote:
> Some kernels program a 0 address for io regions. PCI 3.0 spec
> section 6.2.5.1 doesn't seem to disallow this.


I remember there was discussion about it but I forgot :) Why does it have
to be a part of this patchset? Worth mentioning in the commit log I believe.


> 
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  hw/pci/pci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 351d320..9578749 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1035,7 +1035,7 @@ static pcibus_t pci_bar_address(PCIDevice *d,
>          /* Check if 32 bit BAR wraps around explicitly.
>           * TODO: make priorities correct and remove this work around.
>           */
> -        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX) {
> +        if (last_addr <= new_addr || last_addr >= UINT32_MAX) {
>              return PCI_BAR_UNMAPPED;
>          }
>          return new_addr;
> 


-- 
Alexey

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-19  0:21 ` [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions Michael Roth
  2014-08-26  9:14   ` Alexey Kardashevskiy
@ 2014-08-26 11:41   ` Alexander Graf
  2014-08-27 13:47   ` Michael S. Tsirkin
  2 siblings, 0 replies; 11+ messages in thread
From: Alexander Graf @ 2014-08-26 11:41 UTC (permalink / raw)
  To: Michael Roth, qemu-devel
  Cc: Michael S. Tsirkin, aik, ncmike, qemu-ppc, tyreld, nfont



On 19.08.14 02:21, Michael Roth wrote:
> Some kernels program a 0 address for io regions. PCI 3.0 spec
> section 6.2.5.1 doesn't seem to disallow this.
> 
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>

This patch does not need to be inside of this patch set. It also should
go via Michael's tree.


Alex

> ---
>  hw/pci/pci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 351d320..9578749 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1035,7 +1035,7 @@ static pcibus_t pci_bar_address(PCIDevice *d,
>          /* Check if 32 bit BAR wraps around explicitly.
>           * TODO: make priorities correct and remove this work around.
>           */
> -        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX) {
> +        if (last_addr <= new_addr || last_addr >= UINT32_MAX) {
>              return PCI_BAR_UNMAPPED;
>          }
>          return new_addr;
> 

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-26  9:14   ` Alexey Kardashevskiy
@ 2014-08-26 11:55     ` Peter Maydell
  2014-08-26 18:34     ` Michael Roth
  1 sibling, 0 replies; 11+ messages in thread
From: Peter Maydell @ 2014-08-26 11:55 UTC (permalink / raw)
  To: Alexey Kardashevskiy
  Cc: QEMU Developers, Alexander Graf, Michael Roth, Mike Day,
	qemu-ppc@nongnu.org, tyreld, nfont

On 26 August 2014 10:14, Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> On 08/19/2014 10:21 AM, Michael Roth wrote:
>> Some kernels program a 0 address for io regions. PCI 3.0 spec
>> section 6.2.5.1 doesn't seem to disallow this.
>
>
> I remember there was discussion about it but I forgot :)

I think the conclusion we came to was that there may have been
a note in the PCI 2.1 spec that implied that 0 addresses meant
"disabled" but this seems to have gone from later versions,
suggesting it was erroneous.

Personally I'm happy for us to remove the "0 means disabled"
check, but I'd prefer it if we do it consistently for both IO and
MMIO regions -- this patch only changes the IO BAR code.

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-26  9:14   ` Alexey Kardashevskiy
  2014-08-26 11:55     ` Peter Maydell
@ 2014-08-26 18:34     ` Michael Roth
  1 sibling, 0 replies; 11+ messages in thread
From: Michael Roth @ 2014-08-26 18:34 UTC (permalink / raw)
  To: Alexey Kardashevskiy, qemu-devel; +Cc: ncmike, nfont, qemu-ppc, agraf, tyreld

Quoting Alexey Kardashevskiy (2014-08-26 04:14:27)
> On 08/19/2014 10:21 AM, Michael Roth wrote:
> > Some kernels program a 0 address for io regions. PCI 3.0 spec
> > section 6.2.5.1 doesn't seem to disallow this.
> 
> 
> I remember there was discussion about it but I forgot :) Why does it have
> to be a part of this patchset? Worth mentioning in the commit log I believe.

Unfortunately with ppc guests the first bar allocation tends to be the
0-address case, so to me it seemed necessary for a testable series. Can
simply document this in the series and re-send separately though.

> 
> 
> > 
> > Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> > ---
> >  hw/pci/pci.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > index 351d320..9578749 100644
> > --- a/hw/pci/pci.c
> > +++ b/hw/pci/pci.c
> > @@ -1035,7 +1035,7 @@ static pcibus_t pci_bar_address(PCIDevice *d,
> >          /* Check if 32 bit BAR wraps around explicitly.
> >           * TODO: make priorities correct and remove this work around.
> >           */
> > -        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX) {
> > +        if (last_addr <= new_addr || last_addr >= UINT32_MAX) {
> >              return PCI_BAR_UNMAPPED;
> >          }
> >          return new_addr;
> > 
> 
> 
> -- 
> Alexey

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-19  0:21 ` [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions Michael Roth
  2014-08-26  9:14   ` Alexey Kardashevskiy
  2014-08-26 11:41   ` Alexander Graf
@ 2014-08-27 13:47   ` Michael S. Tsirkin
  2014-08-28 21:21     ` Michael Roth
  2 siblings, 1 reply; 11+ messages in thread
From: Michael S. Tsirkin @ 2014-08-27 13:47 UTC (permalink / raw)
  To: Michael Roth; +Cc: aik, qemu-devel, agraf, ncmike, qemu-ppc, tyreld, nfont

On Mon, Aug 18, 2014 at 07:21:54PM -0500, Michael Roth wrote:
> Some kernels program a 0 address for io regions. PCI 3.0 spec
> section 6.2.5.1 doesn't seem to disallow this.
> 
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>

Yes the PCI spec does not care.

But unfortunately as documented in the comment, at
least for PC (maybe others) priorities aren't
currently setup correctly, so programming PCI BAR at
address zero (during sizing) conflicts with
whatever else is there.

To make address 0 work, you'll have to fix up the prioriorities for a
bunch of machine types :(

> ---
>  hw/pci/pci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 351d320..9578749 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1035,7 +1035,7 @@ static pcibus_t pci_bar_address(PCIDevice *d,
>          /* Check if 32 bit BAR wraps around explicitly.
>           * TODO: make priorities correct and remove this work around.
>           */
> -        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX) {
> +        if (last_addr <= new_addr || last_addr >= UINT32_MAX) {
>              return PCI_BAR_UNMAPPED;
>          }
>          return new_addr;
> -- 
> 1.9.1
> 

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-27 13:47   ` Michael S. Tsirkin
@ 2014-08-28 21:21     ` Michael Roth
  2014-08-28 21:33       ` Peter Maydell
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Roth @ 2014-08-28 21:21 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: aik, qemu-devel, agraf, ncmike, qemu-ppc, tyreld, nfont

Quoting Michael S. Tsirkin (2014-08-27 08:47:51)
> On Mon, Aug 18, 2014 at 07:21:54PM -0500, Michael Roth wrote:
> > Some kernels program a 0 address for io regions. PCI 3.0 spec
> > section 6.2.5.1 doesn't seem to disallow this.
> > 
> > Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> 
> Yes the PCI spec does not care.
> 
> But unfortunately as documented in the comment, at
> least for PC (maybe others) priorities aren't
> currently setup correctly, so programming PCI BAR at
> address zero (during sizing) conflicts with
> whatever else is there.

I'm not sure I understand: that note was included as part of the following
fixup to 9f1a029abf15751e32a4b1df99ed2b8315f9072c:

-        if (last_addr <= new_addr || new_addr == 0) {
+        /* Check if BAR is being sized explicitly.
+         * TODO: make priorities correct and remove this work around.
+         */
+        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX)


which forces the BAR to PCI_BAR_UNMAPPED and unmaps the io region if the
address range extends beyond UINT32_MAX (which would happen during sizing
when guest writes -1...and I guess maybe last_addr <= new_addr covered the
same case back when we used uint32_t for pcibus_t?) ...

But the (new_addr == 0) seems to be something unrelated..., it means the
guest actually attempted to program a 0 address, or...

since pci_update_mappings unconditionally updates all IO regions for a
device whenever a particular BAR is written to, it would prevent us from
temporarily mapping all the IO regions to 0 (until guest re-assigns them)
...

You mentioned in the past this could lead to dispatch tables getting
permanantly corrupted, so maybe that's what the check was for?

But I guess there's still a separate issue, where there's a high liklihood that
a 0 address would conflict with some hard-wired IO address? Wouldn't this be a
guest bug though? Well, I guess it would be a QEMU bug if the above scenario
is a real one...but if we fix or verify that's not the case, would this be
an acceptable change?

> 
> To make address 0 work, you'll have to fix up the prioriorities for a
> bunch of machine types :(
> 
> > ---
> >  hw/pci/pci.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > index 351d320..9578749 100644
> > --- a/hw/pci/pci.c
> > +++ b/hw/pci/pci.c
> > @@ -1035,7 +1035,7 @@ static pcibus_t pci_bar_address(PCIDevice *d,
> >          /* Check if 32 bit BAR wraps around explicitly.
> >           * TODO: make priorities correct and remove this work around.
> >           */
> > -        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX) {
> > +        if (last_addr <= new_addr || last_addr >= UINT32_MAX) {
> >              return PCI_BAR_UNMAPPED;
> >          }
> >          return new_addr;
> > -- 
> > 1.9.1
> >

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-28 21:21     ` Michael Roth
@ 2014-08-28 21:33       ` Peter Maydell
  2014-08-28 21:46         ` Michael S. Tsirkin
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Maydell @ 2014-08-28 21:33 UTC (permalink / raw)
  To: Michael Roth
  Cc: Michael S. Tsirkin, Alexey Kardashevskiy, Alexander Graf,
	QEMU Developers, Mike Day, qemu-ppc@nongnu.org, tyreld, nfont

On 28 August 2014 22:21, Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> But I guess there's still a separate issue, where there's a high liklihood that
> a 0 address would conflict with some hard-wired IO address? Wouldn't this be a
> guest bug though?

Even if it's a guest bug, we should act like the hardware does
if the guest does this. If that differs between PCI controllers
then we need a flag so the host controller model can select
the required behaviour. (The versatile PB PCI controller we
model does have "address 0 is valid", and we'd need to have
this working if we implemented DMA accesses properly.)

-- PMM

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2014-08-28 21:33       ` Peter Maydell
@ 2014-08-28 21:46         ` Michael S. Tsirkin
  0 siblings, 0 replies; 11+ messages in thread
From: Michael S. Tsirkin @ 2014-08-28 21:46 UTC (permalink / raw)
  To: Peter Maydell
  Cc: QEMU Developers, Alexey Kardashevskiy, Alexander Graf,
	Michael Roth, Mike Day, qemu-ppc@nongnu.org, tyreld, nfont

On Thu, Aug 28, 2014 at 10:33:02PM +0100, Peter Maydell wrote:
> On 28 August 2014 22:21, Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> > But I guess there's still a separate issue, where there's a high liklihood that
> > a 0 address would conflict with some hard-wired IO address? Wouldn't this be a
> > guest bug though?

Real hardware behaves in a specific way.
the problem is we don't always emulate it properly, and PCI
has some work arounds for that.

> Even if it's a guest bug, we should act like the hardware does
> if the guest does this. If that differs between PCI controllers
> then we need a flag so the host controller model can select
> the required behaviour. (The versatile PB PCI controller we
> model does have "address 0 is valid", and we'd need to have
> this working if we implemented DMA accesses properly.)
> 
> -- PMM

Exactly.
Actually, I forgot that I might have already fixed it for PC:
83d08f2673504a299194dcac1657a13754b5932a
    pc: map PCI address space as catchall region for not mapped addresses

But need to go back and re-check other systems.


-- 
MST

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
@ 2015-01-09 14:57 Claudio Fontana
  2015-01-09 15:29 ` Michael Roth
  0 siblings, 1 reply; 11+ messages in thread
From: Claudio Fontana @ 2015-01-09 14:57 UTC (permalink / raw)
  To: peter.maydell, mdroth; +Cc: QEMU Developers, agraf, mst

Hello,

resurrecting an old thread.. I incurred in the same issue being
discussed before,
where QEMU silently ignores PCI BAR address programming attempts where
the I/O space offset is 0 (zero).

I think that from a QEMU "user" standpoint, beside this particular issue,
which can be easily worked around just using a minimum offset,
it would be good if QEMU would be a bit verbose in producing a warning
about this.

I think that at least it would be worth a message if DEBUG_PCI is set.

This silent discarding of BAR programming attempts has been painful
while doing early enablement
even for other cases (like the requirement to set I/O space bit before
hand etc), which are legitimate,
but are still worthy of a diagnostic I think, at the very least if
doing pci enablement (which to me translates in having DEBUG_PCI set).

What do you guys think, would a patch be welcome trying to address that?
Would you make the diagnostic dependent on DEBUG_PCI?

Thanks,

Claudio

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

* Re: [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions
  2015-01-09 14:57 [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions Claudio Fontana
@ 2015-01-09 15:29 ` Michael Roth
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Roth @ 2015-01-09 15:29 UTC (permalink / raw)
  To: Claudio Fontana, peter.maydell; +Cc: QEMU Developers, agraf, mst

Quoting Claudio Fontana (2015-01-09 08:57:39)
> Hello,
> 
> resurrecting an old thread.. I incurred in the same issue being
> discussed before,
> where QEMU silently ignores PCI BAR address programming attempts where
> the I/O space offset is 0 (zero).
> 
> I think that from a QEMU "user" standpoint, beside this particular issue,
> which can be easily worked around just using a minimum offset,
> it would be good if QEMU would be a bit verbose in producing a warning
> about this.
> 
> I think that at least it would be worth a message if DEBUG_PCI is set.
> 
> This silent discarding of BAR programming attempts has been painful
> while doing early enablement
> even for other cases (like the requirement to set I/O space bit before
> hand etc), which are legitimate,
> but are still worthy of a diagnostic I think, at the very least if
> doing pci enablement (which to me translates in having DEBUG_PCI set).
> 
> What do you guys think, would a patch be welcome trying to address that?
> Would you make the diagnostic dependent on DEBUG_PCI?

I've sent an updated patch (which allows 0-address MEM regions as well)
as a separate patchset. My hope is that we can simply allow the
programming of 0-address mem/io bars, but there are some concerns I
still don't quite understand but have attempted to summarize to
continue the discussion:

http://lists.gnu.org/archive/html/qemu-devel/2014-12/msg03453.html

Debugging would be useful, but there are undoubtedly cases where the
current behavior prevents proper initialization of guest devices on
existing guests which expect 0 to be valid, so at the very least I
think we should allow the behavior to be enabled on a
machine/host-bridge level of granularity, if not for all
machines/host-bridges as the patch above does.

> 
> Thanks,
> 
> Claudio

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

end of thread, other threads:[~2015-01-09 15:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-09 14:57 [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions Claudio Fontana
2015-01-09 15:29 ` Michael Roth
  -- strict thread matches above, loose matches on Subject: below --
2014-08-19  0:21 [Qemu-devel] [PATCH v3 00/12] spapr: add support for pci hotplug Michael Roth
2014-08-19  0:21 ` [Qemu-devel] [PATCH 08/12] pci: allow 0 address for PCI IO regions Michael Roth
2014-08-26  9:14   ` Alexey Kardashevskiy
2014-08-26 11:55     ` Peter Maydell
2014-08-26 18:34     ` Michael Roth
2014-08-26 11:41   ` Alexander Graf
2014-08-27 13:47   ` Michael S. Tsirkin
2014-08-28 21:21     ` Michael Roth
2014-08-28 21:33       ` Peter Maydell
2014-08-28 21:46         ` Michael S. Tsirkin

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).