Skip to contentSkip to conversation

hw/pci: Use correct bus aperture for device container size

PATCH In review Philippe Mathieu-Daudé 4 participants 7 messages Nov 24, 2025 – Feb 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/pci: Use correct bus aperture for device container size

Before commit 3716d5902d7 ("pci: introduce a bus master container") device view of the bus address space was correctly sized to the bus aperture, but then it always used a 64-bit aperture. Restore the previous behavior, so devices on 32-bit PCI only see 32-bit address space.

---
 hw/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +2 -1
index b1eba348e06..64f33b9de04 100644
@@ -1375,7 +1375,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
     pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
 
     memory_region_init(&pci_dev->bus_master_container_region, OBJECT(pci_dev),
-                       "bus master container", UINT64_MAX);
+                       "bus master container",
+                       memory_region_size(bus->address_space_mem));
     address_space_init(&pci_dev->bus_master_as,
                        &pci_dev->bus_master_container_region, pci_dev->name);
     pci_dev->bus_master_as.max_bounce_buffer_size =
Signature · 1 line
2.51.0
Acked-by Yodel Eldar on v1 1/1
#1 lore raw

Hi, Philippe!

Quoted 16 lines · Philippe Mathieu-Daudé

Before commit 3716d5902d7 ("pci: introduce a bus master container") device view of the bus address space was correctly sized to the bus aperture, but then it always used a 64-bit aperture. Restore the previous behavior, so devices on 32-bit PCI only see 32-bit address space.

---
  hw/pci/pci.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +0 -0
index b1eba348e06..64f33b9de04 100644

hw/pci/pci.c static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, · line 1382

Quoted 9 lines
hw/pci/pci.c +2 -1
@@ -1375,7 +1375,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
      pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
 
      memory_region_init(&pci_dev->bus_master_container_region, OBJECT(pci_dev),
-                       "bus master container", UINT64_MAX);
+                       "bus master container",
+                       memory_region_size(bus->address_space_mem));
      address_space_init(&pci_dev->bus_master_as,
                         &pci_dev->bus_master_container_region, pci_dev->name);
      pci_dev->bus_master_as.max_bounce_buffer_size =

Thanks,
Yodel

#2 lore raw
In reply to Philippe Mathieu-Daudé

ping?

Quoted 25 lines · Philippe Mathieu-Daudé

Before commit 3716d5902d7 ("pci: introduce a bus master container") device view of the bus address space was correctly sized to the bus aperture, but then it always used a 64-bit aperture. Restore the previous behavior, so devices on 32-bit PCI only see 32-bit address space.

---
  hw/pci/pci.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +2 -1
index b1eba348e06..64f33b9de04 100644
@@ -1375,7 +1375,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
      pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
 
      memory_region_init(&pci_dev->bus_master_container_region, OBJECT(pci_dev),
-                       "bus master container", UINT64_MAX);
+                       "bus master container",
+                       memory_region_size(bus->address_space_mem));
      address_space_init(&pci_dev->bus_master_as,
                         &pci_dev->bus_master_container_region, pci_dev->name);
      pci_dev->bus_master_as.max_bounce_buffer_size =
#3 lore raw
Quoted 1 line · Philippe Mathieu-Daudé

ping?

picked it up.

Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines

Before commit 3716d5902d7 ("pci: introduce a bus master container") device view of the bus address space was correctly sized to the bus aperture, but then it always used a 64-bit aperture. Restore the previous behavior, so devices on 32-bit PCI only see 32-bit address space.

---
  hw/pci/pci.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +2 -1
index b1eba348e06..64f33b9de04 100644
@@ -1375,7 +1375,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
      pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
      memory_region_init(&pci_dev->bus_master_container_region, OBJECT(pci_dev),
-                       "bus master container", UINT64_MAX);
+                       "bus master container",
+                       memory_region_size(bus->address_space_mem));
      address_space_init(&pci_dev->bus_master_as,
                         &pci_dev->bus_master_container_region, pci_dev->name);
      pci_dev->bus_master_as.max_bounce_buffer_size =
#4 lore raw
Quoted 5 lines · Michael S. Tsirkin
Quoted 1 line · Philippe Mathieu-Daudé

ping?

picked it up.

Thank you :)

Quoted 12 lines
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines

Before commit 3716d5902d7 ("pci: introduce a bus master container") device view of the bus address space was correctly sized to the bus aperture, but then it always used a 64-bit aperture. Restore the previous behavior, so devices on 32-bit PCI only see 32-bit address space.

---
   hw/pci/pci.c | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
#5 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Before commit 3716d5902d7 ("pci: introduce a bus master container") device view of the bus address space was correctly sized to the bus aperture, but then it always used a 64-bit aperture. Restore the previous behavior, so devices on 32-bit PCI only see 32-bit address space.

Wait I am confused. Is there a problem this is trying to fix?

Quoted 9 lines
---
 hw/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +0 -0
index b1eba348e06..64f33b9de04 100644

hw/pci/pci.c static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, · line 1379

Quoted 6 lines
hw/pci/pci.c +2 -1
@@ -1375,7 +1375,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
     pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
 
     memory_region_init(&pci_dev->bus_master_container_region, OBJECT(pci_dev),
-                       "bus master container", UINT64_MAX);
+                       "bus master container",
+                       memory_region_size(bus->address_space_mem));

as far as I can tell this does more than it says it does.

Look at raven.c:

h->bus = pci_register_root_bus(d, NULL, raven_set_irq, raven_map_irq,

                                 s, &s->pci_memory, &s->pci_io, 0, 4,                                                                    
                                 TYPE_PCI_BUS);                                                                                          

The bus is created with &s->pci_memory (1G) as the address space.

But the actual bus master space (&s->bm at line 285) is 4 G.

Your patch limits DMA to 1G. No?

failures here (definitely the ppc one)

https://gitlab.com/mstredhat/qemu/-/jobs/12984084992

reverting fixed it:

https://gitlab.com/mstredhat/qemu/-/jobs/12984187692

Quoted 5 lines
hw/pci/pci.c +0 -0
     address_space_init(&pci_dev->bus_master_as,
                        &pci_dev->bus_master_container_region, pci_dev->name);
     pci_dev->bus_master_as.max_bounce_buffer_size =
Signature · 1 line
2.51.0
#6 lore raw
Quoted 44 lines · Michael S. Tsirkin
Quoted 7 lines · Philippe Mathieu-Daudé

Before commit 3716d5902d7 ("pci: introduce a bus master container") device view of the bus address space was correctly sized to the bus aperture, but then it always used a 64-bit aperture. Restore the previous behavior, so devices on 32-bit PCI only see 32-bit address space.

Wait I am confused. Is there a problem this is trying to fix?

Quoted 9 lines
---
  hw/pci/pci.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +0 -0
index b1eba348e06..64f33b9de04 100644

hw/pci/pci.c static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, · line 1379

Quoted 6 lines
hw/pci/pci.c +2 -1
@@ -1375,7 +1375,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
      pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
 
      memory_region_init(&pci_dev->bus_master_container_region, OBJECT(pci_dev),
-                       "bus master container", UINT64_MAX);
+                       "bus master container",
+                       memory_region_size(bus->address_space_mem));

as far as I can tell this does more than it says it does.

Look at raven.c:

h->bus = pci_register_root_bus(d, NULL, raven_set_irq, raven_map_irq,

                                  s, &s->pci_memory, &s->pci_io, 0, 4,
                                  TYPE_PCI_BUS);

The bus is created with &s->pci_memory (1G) as the address space.

But the actual bus master space (&s->bm at line 285) is 4 G.

Your patch limits DMA to 1G. No?

Quoted 11 lines

failures here (definitely the ppc one)

https://gitlab.com/mstredhat/qemu/-/jobs/12984084992

reverting fixed it:

https://gitlab.com/mstredhat/qemu/-/jobs/12984187692

Thanks for the catch, Michael.

Sorry, I wasn't aware of this quirk in raven when I acked. Looking into it now, it seems that prior to 97db0466788 its pci_memory had size 0xff000000 as a workaround, and that would indeed "fix" the regression here, too, but is probably not preferable to leaving the bus master container maxed out. What do you think, Philippe?

Quoted 7 lines
Quoted 5 lines
hw/pci/pci.c +0 -0
      address_space_init(&pci_dev->bus_master_as,
                         &pci_dev->bus_master_container_region, pci_dev->name);
      pci_dev->bus_master_as.max_bounce_buffer_size =
Signature · 1 line
2.51.0