Skip to contentSkip to conversation

pci: complete master abort protocol

RFC PATCH Superseded Marcel Apfelbaum 4 participants 25 messages Sep 2, 2013 – Sep 9, 2013

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover pci: complete master abort protocol

Note: The series is incomplete, for review only

PCI spec requires that a transaction that has not been claimed by any PCI bus devices will be terminated by the initiator with "master abort". For read transactions -1(FFFFFFFF) is returned and writes are silently dropped. (already implemented in quemu)

The series deals with the other aspect of the master abort scenario:
Upon completion the master has to raise MASTER ABORT BIT in i initiator's STATUS register.

Implementation:
Allowed the MemoryRegion priority to be negative so a subregion will be visible on all the addresses not covered by the parent MemoryRegion or other subregions.
Added a memory region with negative priority that extends over all the pci address space. This region catches all the accesses
to the unassigned pci addresses.
The MeomoryRegion's ops callbacks emulate the master abort scenario.

Note:
For the moment the code assumes that all the reads/writes on pci address space are done by the cpu.

Marcel Apfelbaum (3):
memory: allow MemoryRegion's priority field to accept negative values hw/pci: add MemoryRegion ops for unassigned pci addresses hw/pci-host: catch acesses to unassigned pci addresses

 hw/pci-host/piix.c        |  8 ++++++++
 hw/pci-host/q35.c         | 19 ++++++++++++++++---
 hw/pci/pci.c              | 18 ++++++++++++++++++
 include/exec/memory.h     |  6 +++---
 include/hw/pci-host/q35.h |  1 +
 include/hw/pci/pci.h      |  3 +++
 memory.c                  |  2 +-
 7 files changed, 50 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

RFC PATCH 1/3 memory: allow MemoryRegion's priority field to accept negative values

Priority is used to make visible some subregions by obscuring the parent MemoryRegion addresses overlapping with the subregion.

By allowing the priority to be negative the opposite can be done:
Allow a subregion to be visible on all the addresses not covered by the parent MemoryRegion or other subregions.

---
 include/exec/memory.h | 6 +++---
 memory.c              | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
include/exec/memory.h +3 -3
index ebe0d24..6995087 100644
@@ -153,7 +153,7 @@ struct MemoryRegion {
     bool flush_coalesced_mmio;
     MemoryRegion *alias;
     hwaddr alias_offset;
-    unsigned priority;
+    int priority;
     bool may_overlap;
     QTAILQ_HEAD(subregions, MemoryRegion) subregions;
     QTAILQ_ENTRY(MemoryRegion) subregions_link;
@@ -193,7 +193,7 @@ struct MemoryListener {
     void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
                                hwaddr addr, hwaddr len);
     /* Lower = earlier (during add), later (during del) */
-    unsigned priority;
+    int priority;
     AddressSpace *address_space_filter;
     QTAILQ_ENTRY(MemoryListener) link;
 };
@@ -779,7 +779,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority);
+                                         int priority);
 
 /**
  * memory_region_get_ram_addr: Get the ram address associated with a memory
memory.c +1 -1
index 886f838..dfb3ae6 100644
@@ -1473,7 +1473,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority)
+                                         int priority)
 {
     subregion->may_overlap = true;
     subregion->priority = priority;
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [Qemu-devel] [PATCH RFC 1/3] memory: allow MemoryRegion's priority field to accept negative values

Quoted 6 lines · Marcel Apfelbaum

Priority is used to make visible some subregions by obscuring the parent MemoryRegion addresses overlapping with the subregion.

By allowing the priority to be negative the opposite can be done:
Allow a subregion to be visible on all the addresses not covered by the parent MemoryRegion or other subregions.

This comment is not exactly accurate. Allowing priority to be signed is just a convenience: you can achieve exactly the same effect by specifying some positive priority for everything you map into the region and having the background region be priority zero. (If you care at all about priorities then everything being mapped into the region should be happening under the control of your code anyway.)

Quoted 20 lines
---
 include/exec/memory.h | 6 +++---
 memory.c              | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
include/exec/memory.h +1 -1
index ebe0d24..6995087 100644
@@ -153,7 +153,7 @@ struct MemoryRegion {
     bool flush_coalesced_mmio;
     MemoryRegion *alias;
     hwaddr alias_offset;
-    unsigned priority;
+    int priority;
     bool may_overlap;
     QTAILQ_HEAD(subregions, MemoryRegion) subregions;
     QTAILQ_ENTRY(MemoryRegion) subregions_link;

include/exec/memory.h struct MemoryListener { · line 196

Quoted 5 lines
include/exec/memory.h +1 -1
@@ -193,7 +193,7 @@ struct MemoryListener {
     void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
                                hwaddr addr, hwaddr len);
     /* Lower = earlier (during add), later (during del) */
-    unsigned priority;
+    int priority;

This is unrelated to MemoryRegion priorities -- it controls the order in which listener callbacks are called. Don't try to change both at once (and you only need the MR priorities anyway.)

Quoted 17 lines
include/exec/memory.h +1 -1
     AddressSpace *address_space_filter;
     QTAILQ_ENTRY(MemoryListener) link;
 };
@@ -779,7 +779,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority);
+                                         int priority);
 
 /**
  * memory_region_get_ram_addr: Get the ram address associated with a memory
memory.c +0 -0
index 886f838..dfb3ae6 100644

memory.c void memory_region_add_subregion(MemoryRegion *mr, · line 1479

Quoted 8 lines
memory.c +1 -1
@@ -1473,7 +1473,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority)
+                                         int priority)
 {
     subregion->may_overlap = true;
     subregion->priority = priority;

This isn't a complete set of changes. For instance memory_region_set_address() has a local variable 'priority' which should be signed now.

sysbus_mmio_map_common() and sysbus_mmio_map_overlap() have priority arguments which need to change to match.

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH RFC 1/3] memory: allow MemoryRegion's priority field to accept negative values

Quoted 8 lines · Peter Maydell
Quoted 6 lines · Marcel Apfelbaum

Priority is used to make visible some subregions by obscuring the parent MemoryRegion addresses overlapping with the subregion.

By allowing the priority to be negative the opposite can be done:
Allow a subregion to be visible on all the addresses not covered by the parent MemoryRegion or other subregions.

Quoted 7 lines

This comment is not exactly accurate. Allowing priority to be signed is just a convenience: you can achieve exactly the same effect by specifying some positive priority for everything you map into the region and having the background region be priority zero. (If you care at all about priorities then everything being mapped into the region should be happening under the control of your code anyway.)

It seems (to me) that having the default priority 0 and expanding on both directions depending on what you want to achieve is an elegant solution. That being said, what you proposed would work too.

Quoted 22 lines
Quoted 22 lines
---
 include/exec/memory.h | 6 +++---
 memory.c              | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
include/exec/memory.h +1 -1
index ebe0d24..6995087 100644
@@ -153,7 +153,7 @@ struct MemoryRegion {
     bool flush_coalesced_mmio;
     MemoryRegion *alias;
     hwaddr alias_offset;
-    unsigned priority;
+    int priority;
     bool may_overlap;
     QTAILQ_HEAD(subregions, MemoryRegion) subregions;
     QTAILQ_ENTRY(MemoryRegion) subregions_link;
@@ -193,7 +193,7 @@ struct MemoryListener {
     void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
Quoted 8 lines

include/exec/memory.h struct MemoryListener { · line 196

Quoted 4 lines
include/exec/memory.h +1 -1
                                hwaddr addr, hwaddr len);
     /* Lower = earlier (during add), later (during del) */
-    unsigned priority;
+    int priority;

This is unrelated to MemoryRegion priorities -- it controls the order in which listener callbacks are called. Don't try to change both at once (and you only need the MR priorities anyway.)

I found that one :). I didn't updated the patches, thanks anyway Marcel

Quoted 37 lines
Quoted 18 lines
include/exec/memory.h +1 -1
     AddressSpace *address_space_filter;
     QTAILQ_ENTRY(MemoryListener) link;
 };
@@ -779,7 +779,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority);
+                                         int priority);
 
 /**
  * memory_region_get_ram_addr: Get the ram address associated with a memory
memory.c +0 -0
index 886f838..dfb3ae6 100644

memory.c void memory_region_add_subregion(MemoryRegion *mr, · line 1479

Quoted 8 lines
memory.c +1 -1
@@ -1473,7 +1473,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority)
+                                         int priority)
 {
     subregion->may_overlap = true;
     subregion->priority = priority;

This isn't a complete set of changes. For instance memory_region_set_address() has a local variable 'priority' which should be signed now.

sysbus_mmio_map_common() and sysbus_mmio_map_overlap() have priority arguments which need to change to match.

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH RFC 1/3] memory: allow MemoryRegion's priority field to accept negative values

In reply to Peter Maydell
Quoted 77 lines · Peter Maydell
Quoted 6 lines · Marcel Apfelbaum

Priority is used to make visible some subregions by obscuring the parent MemoryRegion addresses overlapping with the subregion.

By allowing the priority to be negative the opposite can be done:
Allow a subregion to be visible on all the addresses not covered by the parent MemoryRegion or other subregions.

This comment is not exactly accurate. Allowing priority to be signed is just a convenience: you can achieve exactly the same effect by specifying some positive priority for everything you map into the region and having the background region be priority zero. (If you care at all about priorities then everything being mapped into the region should be happening under the control of your code anyway.)

Quoted 20 lines
---
 include/exec/memory.h | 6 +++---
 memory.c              | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
include/exec/memory.h +1 -1
index ebe0d24..6995087 100644
@@ -153,7 +153,7 @@ struct MemoryRegion {
     bool flush_coalesced_mmio;
     MemoryRegion *alias;
     hwaddr alias_offset;
-    unsigned priority;
+    int priority;
     bool may_overlap;
     QTAILQ_HEAD(subregions, MemoryRegion) subregions;
     QTAILQ_ENTRY(MemoryRegion) subregions_link;

include/exec/memory.h struct MemoryListener { · line 196

Quoted 5 lines
include/exec/memory.h +1 -1
@@ -193,7 +193,7 @@ struct MemoryListener {
     void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
                                hwaddr addr, hwaddr len);
     /* Lower = earlier (during add), later (during del) */
-    unsigned priority;
+    int priority;

This is unrelated to MemoryRegion priorities -- it controls the order in which listener callbacks are called. Don't try to change both at once (and you only need the MR priorities anyway.)

Quoted 17 lines
include/exec/memory.h +1 -1
     AddressSpace *address_space_filter;
     QTAILQ_ENTRY(MemoryListener) link;
 };
@@ -779,7 +779,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority);
+                                         int priority);
 
 /**
  * memory_region_get_ram_addr: Get the ram address associated with a memory
memory.c +0 -0
index 886f838..dfb3ae6 100644

memory.c void memory_region_add_subregion(MemoryRegion *mr, · line 1479

Quoted 8 lines
memory.c +1 -1
@@ -1473,7 +1473,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          hwaddr offset,
                                          MemoryRegion *subregion,
-                                         unsigned priority)
+                                         int priority)
 {
     subregion->may_overlap = true;
     subregion->priority = priority;

This isn't a complete set of changes. For instance memory_region_set_address() has a local variable 'priority' which should be signed now.

Quoted 2 lines

sysbus_mmio_map_common() and sysbus_mmio_map_overlap() have priority arguments which need to change to match.

Missed that :(
Making necessary changes and send a new version
Thanks,
Marcel

Quoted 4 lines

thanks
-- PMM

#5 lore raw

RFC PATCH 2/3 hw/pci: add MemoryRegion ops for unassigned pci addresses

In reply to Marcel Apfelbaum

The MemoryRegions assigned with this ops shall "intercept" the accesses to unassigned pci address space and the associated callback will set MASTER ABORT bit in the STATUS register of the device that initiated the transaction as defined in PCI spec.

Note: This implementation assumes that all the reads/writes to the pci address space are done by the cpu.

---
 hw/pci/pci.c         | 18 ++++++++++++++++++
 include/hw/pci/pci.h |  3 +++
 2 files changed, 21 insertions(+)
hw/pci/pci.c +18 -0
index 4c004f5..f0289fc 100644
@@ -2229,6 +2229,24 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
     return dev->bus->address_space_io;
 }
 
+static bool pci_unassigned_mem_accepts(void *opaque, hwaddr addr,
+                                       unsigned size, bool is_write)
+{
+    PCIDevice *d = opaque;
+
+    /* FIXME assumption: the cpu initiated the pci transaction
+     * and not another pci device */
+    pci_word_test_and_set_mask(d->config + PCI_STATUS,
+                               PCI_STATUS_REC_MASTER_ABORT);
+
+    return false;
+}
+
+const MemoryRegionOps pci_unassigned_mem_ops = {
+    .valid.accepts = pci_unassigned_mem_accepts,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 static void pci_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
include/hw/pci/pci.h +3 -0
index ccec2ba..854681c 100644
@@ -329,6 +329,9 @@ int pci_device_load(PCIDevice *s, QEMUFile *f);
 MemoryRegion *pci_address_space(PCIDevice *dev);
 MemoryRegion *pci_address_space_io(PCIDevice *dev);
 
+#define PCI_UNASSIGNED_MEM_PRIORITY -1
+extern const MemoryRegionOps pci_unassigned_mem_ops;
+
 typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
 typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
 typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);
Signature · 1 line
1.8.3.1
#6 lore raw

Re: [Qemu-devel] [PATCH RFC 2/3] hw/pci: add MemoryRegion ops for unassigned pci addresses

hw/pci/pci.c MemoryRegion *pci_address_space_io(PCIDevice *dev) · line 2248

Quoted 4 lines · Marcel Apfelbaum
hw/pci/pci.c +4 -0
+const MemoryRegionOps pci_unassigned_mem_ops = {
+    .valid.accepts = pci_unassigned_mem_accepts,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};

This is wrong -- you want reads and writes to result in your PCI-spec-defined behaviour, but if you provide an accepts callback and it returns false then you get "machine dependent behaviour such as a machine check exception". What you want is to provide .read and .write callbacks which behave as the PCI spec mandates.

Also this should probably be static, not global, and you should put it in the same patch as the one which actually creates the memory region.

-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH RFC 2/3] hw/pci: add MemoryRegion ops for unassigned pci addresses

Quoted 12 lines · Peter Maydell

hw/pci/pci.c MemoryRegion *pci_address_space_io(PCIDevice *dev) · line 2248

Quoted 4 lines · Marcel Apfelbaum
hw/pci/pci.c +4 -0
+const MemoryRegionOps pci_unassigned_mem_ops = {
+    .valid.accepts = pci_unassigned_mem_accepts,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};

This is wrong -- you want reads and writes to result in your PCI-spec-defined behaviour, but if you provide an accepts callback and it returns false then you get "machine dependent behaviour such as a machine check exception". What you want is to provide .read and .write callbacks which behave as the PCI spec mandates.

That makes sense. It was already a bug.Thanks!

Quoted 2 lines

Also this should probably be static, not global, and you

If it will be implemented in the "pci core layer", sure Marcel

Quoted 5 lines

should put it in the same patch as the one which actually creates the memory region.

-- PMM

#8 lore raw

Re: [Qemu-devel] [PATCH RFC 2/3] hw/pci: add MemoryRegion ops for unassigned pci addresses

In reply to Marcel Apfelbaum
Quoted 20 lines · Marcel Apfelbaum

The MemoryRegions assigned with this ops shall "intercept" the accesses to unassigned pci address space and the associated callback will set MASTER ABORT bit in the STATUS register of the device that initiated the transaction as defined in PCI spec.

Note: This implementation assumes that all the reads/writes to the pci address space are done by the cpu.

---
 hw/pci/pci.c         | 18 ++++++++++++++++++
 include/hw/pci/pci.h |  3 +++
 2 files changed, 21 insertions(+)
hw/pci/pci.c +0 -0
index 4c004f5..f0289fc 100644

hw/pci/pci.c MemoryRegion *pci_address_space_io(PCIDevice *dev) · line 2238

Quoted 10 lines
hw/pci/pci.c +7 -0
@@ -2229,6 +2229,24 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
     return dev->bus->address_space_io;
 }
 
+static bool pci_unassigned_mem_accepts(void *opaque, hwaddr addr,
+                                       unsigned size, bool is_write)
+{
+    PCIDevice *d = opaque;
+
+    /* FIXME assumption: the cpu initiated the pci transaction
+     * and not another pci device */

/*
* Multiline
* comments
*/

Quoted 30 lines
hw/pci/pci.c +11 -0
+    pci_word_test_and_set_mask(d->config + PCI_STATUS,
+                               PCI_STATUS_REC_MASTER_ABORT);
+
+    return false;
+}
+
+const MemoryRegionOps pci_unassigned_mem_ops = {
+    .valid.accepts = pci_unassigned_mem_accepts,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 static void pci_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
include/hw/pci/pci.h +3 -0
index ccec2ba..854681c 100644
@@ -329,6 +329,9 @@ int pci_device_load(PCIDevice *s, QEMUFile *f);
 MemoryRegion *pci_address_space(PCIDevice *dev);
 MemoryRegion *pci_address_space_io(PCIDevice *dev);
 
+#define PCI_UNASSIGNED_MEM_PRIORITY -1
+extern const MemoryRegionOps pci_unassigned_mem_ops;
+
 typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
 typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
 typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);
Signature · 1 line
1.8.3.1
#9 lore raw

Re: [Qemu-devel] [PATCH RFC 2/3] hw/pci: add MemoryRegion ops for unassigned pci addresses

Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Marcel Apfelbaum

The MemoryRegions assigned with this ops shall "intercept" the accesses to unassigned pci address space and the associated callback will set MASTER ABORT bit in the STATUS register of the device that initiated the transaction as defined in PCI spec.

Note: This implementation assumes that all the reads/writes to the pci address space are done by the cpu.

---
 hw/pci/pci.c         | 18 ++++++++++++++++++
 include/hw/pci/pci.h |  3 +++
 2 files changed, 21 insertions(+)
hw/pci/pci.c +0 -0
index 4c004f5..f0289fc 100644
@@ -2229,6 +2229,24 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
     return dev->bus->address_space_io;
 }
 
Quoted 12 lines

hw/pci/pci.c MemoryRegion *pci_address_space_io(PCIDevice *dev) · line 2238

Quoted 7 lines
hw/pci/pci.c +7 -0
+static bool pci_unassigned_mem_accepts(void *opaque, hwaddr addr,
+                                       unsigned size, bool is_write)
+{
+    PCIDevice *d = opaque;
+
+    /* FIXME assumption: the cpu initiated the pci transaction
+     * and not another pci device */

/*
* Multiline
* comments
*/

Got it. Thanks!
Marcel

Quoted 33 lines
Quoted 32 lines
hw/pci/pci.c +11 -0
+    pci_word_test_and_set_mask(d->config + PCI_STATUS,
+                               PCI_STATUS_REC_MASTER_ABORT);
+
+    return false;
+}
+
+const MemoryRegionOps pci_unassigned_mem_ops = {
+    .valid.accepts = pci_unassigned_mem_accepts,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 static void pci_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
include/hw/pci/pci.h +3 -0
index ccec2ba..854681c 100644
@@ -329,6 +329,9 @@ int pci_device_load(PCIDevice *s, QEMUFile *f);
 MemoryRegion *pci_address_space(PCIDevice *dev);
 MemoryRegion *pci_address_space_io(PCIDevice *dev);
 
+#define PCI_UNASSIGNED_MEM_PRIORITY -1
+extern const MemoryRegionOps pci_unassigned_mem_ops;
+
 typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
 typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
 typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);
Signature · 1 line
1.8.3.1
#10 lore raw

RFC PATCH 3/3 hw/pci-host: catch acesses to unassigned pci addresses

In reply to Marcel Apfelbaum

Added a memory region that has negative priority and extends over all the pci adddress space. This region will "catch" all the accesses to the unassigned pci addresses and it will be possible to emulate the master abort scenario (When no device on the bus claims the transaction).

---
 hw/pci-host/piix.c        |  8 ++++++++
 hw/pci-host/q35.c         | 19 ++++++++++++++++---
 include/hw/pci-host/q35.h |  1 +
 3 files changed, 25 insertions(+), 3 deletions(-)
hw/pci-host/piix.c +8 -0
index dc1718f..27b04a6 100644
@@ -104,6 +104,7 @@ struct PCII440FXState {
     MemoryRegion *ram_memory;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    MemoryRegion pci_unassigned_memory;
     PAMMemoryRegion pam_regions[13];
     MemoryRegion smram_region;
     uint8_t smm_enabled;
@@ -347,6 +348,13 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
         i440fx->pci_info.w32.begin = 0xe0000000;
     }
 
+    memory_region_init_io(&f->pci_unassigned_memory, OBJECT(d),
+                          &pci_unassigned_mem_ops, d,
+                          "pci-hole-unassigned", pci_hole_size);
+    memory_region_add_subregion_overlap(f->pci_address_space, pci_hole_start,
+                                        &f->pci_unassigned_memory,
+                                        PCI_UNASSIGNED_MEM_PRIORITY);
+
     memory_region_init_alias(&f->pci_hole, OBJECT(d), "pci-hole", f->pci_address_space,
                              pci_hole_start, pci_hole_size);
     memory_region_add_subregion(f->system_memory, pci_hole_start, &f->pci_hole);
hw/pci-host/q35.c +16 -3
index 12314d8..ee4a4f9 100644
@@ -320,13 +320,26 @@ static int mch_init(PCIDevice *d)
 {
     int i;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
+    hwaddr pci_hole_start;
+    uint64_t pci_hole_size;
+
+    pci_hole_start = mch->below_4g_mem_size;
+    pci_hole_size = 0x100000000ULL - pci_hole_start;
+
+    memory_region_init_io(&mch->pci_unassigned_memory, OBJECT(d),
+                          &pci_unassigned_mem_ops, d,
+                          "pci-hole-unassigned", pci_hole_size);
+    memory_region_add_subregion_overlap(mch->pci_address_space, pci_hole_start,
+                                        &mch->pci_unassigned_memory,
+                                        PCI_UNASSIGNED_MEM_PRIORITY);
+
 
     /* setup pci memory regions */
     memory_region_init_alias(&mch->pci_hole, OBJECT(mch), "pci-hole",
                              mch->pci_address_space,
-                             mch->below_4g_mem_size,
-                             0x100000000ULL - mch->below_4g_mem_size);
-    memory_region_add_subregion(mch->system_memory, mch->below_4g_mem_size,
+                             pci_hole_start,
+                             pci_hole_size);
+    memory_region_add_subregion(mch->system_memory, pci_hole_start,
                                 &mch->pci_hole);
 
     pc_init_pci64_hole(&mch->pci_info, 0x100000000ULL + mch->above_4g_mem_size,
include/hw/pci-host/q35.h +1 -0
index 6eb7ab6..c42fba3 100644
@@ -55,6 +55,7 @@ typedef struct MCHPCIState {
     MemoryRegion smram_region;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    MemoryRegion pci_unassigned_memory;
     PcPciInfo pci_info;
     uint8_t smm_enabled;
     ram_addr_t below_4g_mem_size;
Signature · 1 line
1.8.3.1
#11 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

Quoted 7 lines · Marcel Apfelbaum

Added a memory region that has negative priority and extends over all the pci adddress space. This region will "catch" all the accesses to the unassigned pci addresses and it will be possible to emulate the master abort scenario (When no device on the bus claims the transaction).

Quoted 5 lines
---
 hw/pci-host/piix.c        |  8 ++++++++
 hw/pci-host/q35.c         | 19 ++++++++++++++++---
 include/hw/pci-host/q35.h |  1 +

This is happening at the wrong layer -- you want this memory region to be created and managed in the PCI core code so that we get correct PCI-spec behaviour for all our PCI controllers, not just the two x86 ones you've changed here.

-- PMM

#12 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

Quoted 14 lines · Peter Maydell
Quoted 7 lines · Marcel Apfelbaum

Added a memory region that has negative priority and extends over all the pci adddress space. This region will "catch" all the accesses to the unassigned pci addresses and it will be possible to emulate the master abort scenario (When no device on the bus claims the transaction).

Quoted 5 lines
---
 hw/pci-host/piix.c        |  8 ++++++++
 hw/pci-host/q35.c         | 19 ++++++++++++++++---
 include/hw/pci-host/q35.h |  1 +
Quoted 4 lines

This is happening at the wrong layer -- you want this memory region to be created and managed in the PCI core code so that we get correct PCI-spec behaviour for all our PCI controllers, not just the two x86 ones you've changed here.pci_address_space

I saw that the memory regions are part of the Host state and duplicated for each host type(like pci_address_space). Question, why are not pci_address_space and pci_hole present in a core layer?

I followed the existing code; from what you are saying I understand that also the existing memory regions like the one mentioned above should be moved in the core layer, right?
Marcel

Quoted 3 lines

-- PMM

#13 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

Am 02.09.2013 17:42, schrieb Marcel Apfelbaum:

Quoted 15 lines · Peter Maydell
Quoted 14 lines · Marcel Apfelbaum
Quoted 12 lines

Added a memory region that has negative priority and extends over all the pci adddress space. This region will "catch" all the accesses to the unassigned pci addresses and it will be possible to emulate the master abort scenario (When no device on the bus claims the transaction).

---
 hw/pci-host/piix.c        |  8 ++++++++
 hw/pci-host/q35.c         | 19 ++++++++++++++++---
 include/hw/pci-host/q35.h |  1 +
Quoted 8 lines
Quoted 4 lines

This is happening at the wrong layer -- you want this memory region to be created and managed in the PCI core code so that we get correct PCI-spec behaviour for all our PCI controllers, not just the two x86 ones you've changed here.pci_address_space

I saw that the memory regions are part of the Host state and duplicated for each host type(like pci_address_space). Question, why are not pci_address_space and pci_hole present in a core layer?

I would say, because that core layer didn't exist before I added it not too long ago. My focus was on fixing bugs at the time and getting PReP Raven PHB into shape for QOM.

Quoted 4 lines

I followed the existing code; from what you are saying I understand that also the existing memory regions like the one mentioned above should be moved in the core layer, right?

Consider it all Work In Progress :) and feel free to move more fields and code there as you guys see fit.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#14 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

In reply to Marcel Apfelbaum
Quoted 10 lines · Marcel Apfelbaum
Quoted 4 lines · Peter Maydell

This is happening at the wrong layer -- you want this memory region to be created and managed in the PCI core code so that we get correct PCI-spec behaviour for all our PCI controllers, not just the two x86 ones you've changed here.pci_address_space

I saw that the memory regions are part of the Host state and duplicated for each host type(like pci_address_space). Question, why are not pci_address_space and pci_hole present in a core layer?

Quoted 4 lines

I followed the existing code; from what you are saying I understand that also the existing memory regions like the one mentioned above should be moved in the core layer, right?

Ideally, yes, I think so. However that's not particularly a requirement for the changes you're trying to make here:
at the moment what happens is that the pci controller creates the PCI memory and io memory regions (or cheats by reusing the system memory space[*]), passes them to the PCI core code (via pci_bus_new) and then they're the PCI code's responsibility to manage. So in the PCI code you can ignore where they came from when you're deciding how to manage these containers (and in this case what you do is just create your default region and map it in to the container at a suitable priority).

[*] I'm pretty sure this is a bug in all platforms that do it.

-- PMM

#15 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

Quoted 28 lines · Peter Maydell
Quoted 10 lines · Marcel Apfelbaum
Quoted 4 lines · Peter Maydell

This is happening at the wrong layer -- you want this memory region to be created and managed in the PCI core code so that we get correct PCI-spec behaviour for all our PCI controllers, not just the two x86 ones you've changed here.pci_address_space

I saw that the memory regions are part of the Host state and duplicated for each host type(like pci_address_space). Question, why are not pci_address_space and pci_hole present in a core layer?

Quoted 4 lines

I followed the existing code; from what you are saying I understand that also the existing memory regions like the one mentioned above should be moved in the core layer, right?

Ideally, yes, I think so. However that's not particularly a requirement for the changes you're trying to make here:
at the moment what happens is that the pci controller creates the PCI memory and io memory regions (or cheats by reusing the system memory space[*]), passes them to the PCI core code (via pci_bus_new) and then they're the PCI code's responsibility to manage. So in the PCI code you can ignore where they came from when you're deciding how to manage these containers (and in this case what you do is just create your default region and map it in to the container at a suitable priority).

Quoted 3 lines

[*] I'm pretty sure this is a bug in all platforms that do it.

-- PMM

Well as usual this cheat originated with PIIX. AFAIK PIIX actually has a shared bus for memory and PCI so this is not a bug there, I think.

Signature · 1 line
MST
#16 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Peter Maydell

at the moment what happens is that the pci controller creates the PCI memory and io memory regions (or cheats by reusing the system memory space[*]),

[*] I'm pretty sure this is a bug in all platforms that do it.

Well as usual this cheat originated with PIIX. AFAIK PIIX actually has a shared bus for memory and PCI so this is not a bug there, I think.

It will be when you introduce this "return -1 for unassigned addresses", though, since you only want that to happen for PCI accesses, not system memory accesses, right?

thanks
-- PMM

#17 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

Quoted 12 lines · Peter Maydell
Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Peter Maydell

at the moment what happens is that the pci controller creates the PCI memory and io memory regions (or cheats by reusing the system memory space[*]),

[*] I'm pretty sure this is a bug in all platforms that do it.

Well as usual this cheat originated with PIIX. AFAIK PIIX actually has a shared bus for memory and PCI so this is not a bug there, I think.

Quoted 6 lines

It will be when you introduce this "return -1 for unassigned addresses", though, since you only want that to happen for PCI accesses, not system memory accesses, right?

thanks
-- PMM

What happens with PIIX is that everything that is not in system memory is PCI.
So there's no such thing as "unassigned system memory address": all unassigned addresses are PCI addresses.

Signature · 1 line
MST
#18 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

In reply to Peter Maydell
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Marcel Apfelbaum

Question, why are not pci_address_space and pci_hole present in a core layer?

I followed the existing code; from what you are saying I understand that also the existing memory regions like the one mentioned above should be moved in the core layer, right?

Ideally, yes, I think so.

...but I didn't notice you mentioned pci_hole there. That is a PCI-controller specific concept (there's no such thing for the versatilepb PCI controller, for instance) and so it should remain at the PCI controller level, not the PCI core code.

-- PMM

#19 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

In reply to Peter Maydell
Quoted 16 lines · Peter Maydell
Quoted 10 lines · Marcel Apfelbaum
Quoted 4 lines · Peter Maydell

This is happening at the wrong layer -- you want this memory region to be created and managed in the PCI core code so that we get correct PCI-spec behaviour for all our PCI controllers, not just the two x86 ones you've changed here.pci_address_space

I saw that the memory regions are part of the Host state and duplicated for each host type(like pci_address_space). Question, why are not pci_address_space and pci_hole present in a core layer?

Quoted 4 lines

I followed the existing code; from what you are saying I understand that also the existing memory regions like the one mentioned above should be moved in the core layer, right?

Quoted 11 lines

Ideally, yes, I think so. However that's not particularly a requirement for the changes you're trying to make here:
at the moment what happens is that the pci controller creates the PCI memory and io memory regions (or cheats by reusing the system memory space[*]), passes them to the PCI core code (via pci_bus_new) and then they're the PCI code's responsibility to manage. So in the PCI code you can ignore where they came from when you're deciding how to manage these containers (and in this case what you do is just create your default region and map it in to the container at a suitable priority).

Thanks, I am going to follow this path
Marcel

Quoted 4 lines

[*] I'm pretty sure this is a bug in all platforms that do it.

-- PMM

#20 lore raw

Re: [Qemu-devel] [PATCH RFC 3/3] hw/pci-host: catch acesses to unassigned pci addresses

In reply to Marcel Apfelbaum
Quoted 15 lines · Marcel Apfelbaum
Quoted 14 lines · Peter Maydell
Quoted 12 lines · Marcel Apfelbaum

Added a memory region that has negative priority and extends over all the pci adddress space. This region will "catch" all the accesses to the unassigned pci addresses and it will be possible to emulate the master abort scenario (When no device on the bus claims the transaction).

---
 hw/pci-host/piix.c        |  8 ++++++++
 hw/pci-host/q35.c         | 19 ++++++++++++++++---
 include/hw/pci-host/q35.h |  1 +
Quoted 8 lines
Quoted 4 lines

This is happening at the wrong layer -- you want this memory region to be created and managed in the PCI core code so that we get correct PCI-spec behaviour for all our PCI controllers, not just the two x86 ones you've changed here.pci_address_space

I saw that the memory regions are part of the Host state and duplicated for each host type(like pci_address_space). Question, why are not pci_address_space and pci_hole present in a core layer?

I think we can move them out to core.

Quoted 6 lines

I followed the existing code; from what you are saying I understand that also the existing memory regions like the one mentioned above should be moved in the core layer, right?
Marcel

pci hole is a PC thing.

Quoted 4 lines
Quoted 3 lines

-- PMM

#21 lore raw
In reply to Marcel Apfelbaum
Quoted 6 lines · Marcel Apfelbaum

Note: The series is incomplete, for review only

PCI spec requires that a transaction that has not been claimed by any PCI bus devices will be terminated by the initiator with "master abort". For read transactions -1(FFFFFFFF) is returned and writes are silently dropped. (already implemented in quemu)

...but only erroneously and by breaking a pile of other boards.

Quoted 3 lines

Note:
For the moment the code assumes that all the reads/writes on pci address space are done by the cpu.

This is a bogus assumption in the presence of bus mastering PCI devices, which aren't exactly uncommon.

-- PMM

#22 lore raw
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Marcel Apfelbaum

Note: The series is incomplete, for review only

PCI spec requires that a transaction that has not been claimed by any PCI bus devices will be terminated by the initiator with "master abort". For read transactions -1(FFFFFFFF) is returned and writes are silently dropped. (already implemented in quemu)

...but only erroneously and by breaking a pile of other boards.

:(
Let's find a way to fix it... Please suggest

Quoted 7 lines
Quoted 4 lines

Note:
For the moment the code assumes that all the reads/writes on pci address space are done by the cpu.

This is a bogus assumption in the presence of bus mastering PCI devices, which aren't exactly uncommon.

As I said, the series is work in progress. Tracking down the real initiator of a read/write to the pci address space seems to be difficult. I am looking into it and opened to suggestions.
Marcel

Quoted 3 lines

-- PMM

#23 lore raw
Quoted 4 lines · Marcel Apfelbaum
Quoted 3 lines · Peter Maydell
Quoted 2 lines · Marcel Apfelbaum

Note: The series is incomplete, for review only

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

PCI spec requires that a transaction that has not been claimed by any PCI bus devices will be terminated by the initiator with "master abort". For read transactions -1(FFFFFFFF) is returned and writes are silently dropped. (already implemented in quemu)

...but only erroneously and by breaking a pile of other boards.

:(
Let's find a way to fix it... Please suggest

We need to apply Jan's two patches which revert the breakage and give us back 1.5 behaviour for unassigned memory. Then you can work on this patchset and we can commit it when it works OK.

-- PMM

#24 lore raw
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Marcel Apfelbaum
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Marcel Apfelbaum

Note: The series is incomplete, for review only

PCI spec requires that a transaction that has not been claimed by any PCI bus devices will be terminated by the initiator with "master abort". For read transactions -1(FFFFFFFF) is returned and writes are silently dropped. (already implemented in quemu)

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

...but only erroneously and by breaking a pile of other boards.

:(
Let's find a way to fix it... Please suggest

We need to apply Jan's two patches which revert the breakage and give us back 1.5 behaviour for unassigned memory. Then you can work on this patchset and we can commit it when it works OK.

I am going to have a look on those patches, thanks Marcel

Quoted 3 lines

-- PMM