Skip to contentSkip to conversation

pc: limit 64 bit hole to 2G by default

PATCH Superseded Igor Mammedov 4 participants 29 messages Jul 28, 2013 – Jul 30, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover pc: limit 64 bit hole to 2G by default

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default.

v1-v2:
* redone using QOM properties to pass value around

git-tree for testing:
https://github.com/imammedo/qemu/commits/pcihole64_fix_v2

Igor Mammedov (5):
pc: add I440FX QOM cast macro
utils: add range_size() wrapper
pc: replace i440fx_common_init() with i440fx_init() as it isn't used
by anywhere else
pc: add Q35 to QOM composition tree under /machine
pc: limit 64 bit hole to 2G by default

Michael S. Tsirkin (1):
pc: move IO_APIC_DEFAULT_ADDRESS to include/hw/i386/ioapic.h

 hw/i386/pc.c              | 61 ++++++++++++++++++-------------
 hw/i386/pc_piix.c         | 14 +-------
 hw/i386/pc_q35.c          |  2 +-
 hw/pci-host/piix.c        | 91 ++++++++++++++++++++++++++---------------------
 hw/pci-host/q35.c         | 32 ++++++++++-------
 include/hw/i386/ioapic.h  |  1 +
 include/hw/i386/pc.h      |  5 ++-
 include/hw/pci-host/q35.h |  1 +
 include/qemu/range.h      |  6 ++++
 9 files changed, 119 insertions(+), 94 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/6 pc: move IO_APIC_DEFAULT_ADDRESS to include/hw/i386/ioapic.h

From: "Michael S. Tsirkin" <[email protected]>

---
 hw/i386/pc.c             | 2 --
 include/hw/i386/ioapic.h | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)
hw/i386/pc.c +0 -2
index 2a87563..b0b98a8 100644
@@ -75,8 +75,6 @@
 #define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 #define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
 
-#define IO_APIC_DEFAULT_ADDRESS 0xfec00000
-
 #define E820_NR_ENTRIES		16
 
 struct e820_entry {
include/hw/i386/ioapic.h +1 -0
index 86e63da..6245388 100644
@@ -21,6 +21,7 @@
 #define HW_IOAPIC_H
 
 #define IOAPIC_NUM_PINS 24
+#define IO_APIC_DEFAULT_ADDRESS 0xfec00000
 
 void ioapic_eoi_broadcast(int vector);
 
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: move IO_APIC_DEFAULT_ADDRESS to include/hw/i386/ioapic.h

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 4 lines

From: "Michael S. Tsirkin" <[email protected]>

Missing Reviewed-bys from Gerd and me.

Andreas

Quoted 32 lines
---
 hw/i386/pc.c             | 2 --
 include/hw/i386/ioapic.h | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)
hw/i386/pc.c +0 -2
index 2a87563..b0b98a8 100644
@@ -75,8 +75,6 @@
 #define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 #define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
 
-#define IO_APIC_DEFAULT_ADDRESS 0xfec00000
-
 #define E820_NR_ENTRIES		16
 
 struct e820_entry {
include/hw/i386/ioapic.h +1 -0
index 86e63da..6245388 100644
@@ -21,6 +21,7 @@
 #define HW_IOAPIC_H
 
 #define IOAPIC_NUM_PINS 24
+#define IO_APIC_DEFAULT_ADDRESS 0xfec00000
 
 void ioapic_eoi_broadcast(int vector);
 
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
#3 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: move IO_APIC_DEFAULT_ADDRESS to include/hw/i386/ioapic.h

Quoted 7 lines · On Sun, 28 Jul 2013 11:54:46 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 4 lines

From: "Michael S. Tsirkin" <[email protected]>

Missing Reviewed-bys from Gerd and me.

it changed file form apic.h to ioapic.h, so I haven't felt comfortble adding yours Reviewed-bys.
I sure can add it if it's ok.

Quoted 40 lines

Andreas

Quoted 32 lines
---
 hw/i386/pc.c             | 2 --
 include/hw/i386/ioapic.h | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)
hw/i386/pc.c +0 -2
index 2a87563..b0b98a8 100644
@@ -75,8 +75,6 @@
 #define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 #define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
 
-#define IO_APIC_DEFAULT_ADDRESS 0xfec00000
-
 #define E820_NR_ENTRIES		16
 
 struct e820_entry {
include/hw/i386/ioapic.h +1 -0
index 86e63da..6245388 100644
@@ -21,6 +21,7 @@
 #define HW_IOAPIC_H
 
 #define IOAPIC_NUM_PINS 24
+#define IO_APIC_DEFAULT_ADDRESS 0xfec00000
 
 void ioapic_eoi_broadcast(int vector);
 
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
Signature · 2 lines
Regards,
  Igor
Reviewed-by
#4 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: move IO_APIC_DEFAULT_ADDRESS to include/hw/i386/ioapic.h

Am 28.07.2013 19:19, schrieb Igor Mammedov:

Quoted 6 lines
Quoted 3 lines · On Sun, 28 Jul 2013 11:54:46 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 2 lines

From: "Michael S. Tsirkin" <[email protected]>

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Missing Reviewed-bys from Gerd and me.

it changed file form apic.h to ioapic.h, so I haven't felt comfortble adding yours Reviewed-bys.
I sure can add it if it's ok.

Oh, missed that! Still looks fine to me,

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
#5 lore raw

PATCH v2 2/6 pc: add I440FX QOM cast macro

In reply to Igor Mammedov
---
 hw/pci-host/piix.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +6 -2
index 3908860..bf879e7 100644
@@ -38,6 +38,10 @@
  * http://download.intel.com/design/chipsets/datashts/29054901.pdf
  */
 
+#define TYPE_I440FX_PCI_HOST "i440FX-pcihost"
+#define I440FX_PCI_HOST(obj) \
+    OBJECT_CHECK(I440FXState, (obj), TYPE_I440FX_PCI_HOST)
+
 typedef struct I440FXState {
     PCIHostState parent_obj;
 } I440FXState;
@@ -257,7 +261,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
     PCII440FXState *f;
     unsigned i;
 
-    dev = qdev_create(NULL, "i440FX-pcihost");
+    dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
     b = pci_bus_new(dev, NULL, pci_address_space,
                     address_space_io, 0, TYPE_PCI_BUS);
@@ -661,7 +665,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo i440fx_pcihost_info = {
-    .name          = "i440FX-pcihost",
+    .name          = TYPE_I440FX_PCI_HOST,
     .parent        = TYPE_PCI_HOST_BRIDGE,
     .instance_size = sizeof(I440FXState),
     .instance_init = i440fx_pcihost_initfn,
Signature · 1 line
1.8.3.1
#6 lore raw

Re: [Qemu-devel] [PATCH 2/6] pc: add I440FX QOM cast macro

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 10 lines
---
 hw/pci-host/piix.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +0 -0
index 3908860..bf879e7 100644

hw/pci-host/piix.c line 43

Quoted 6 lines
hw/pci-host/piix.c +3 -0
@@ -38,6 +38,10 @@
  * http://download.intel.com/design/chipsets/datashts/29054901.pdf
  */
 
+#define TYPE_I440FX_PCI_HOST "i440FX-pcihost"
+#define I440FX_PCI_HOST(obj) \
+    OBJECT_CHECK(I440FXState, (obj), TYPE_I440FX_PCI_HOST)

Either Anthony or mst had insisted on PCI_HOST_BRIDGE rather than PCI_HOST. Other than that looks good, thanks!

Andreas

Quoted 23 lines
hw/pci-host/piix.c +3 -2
+
 typedef struct I440FXState {
     PCIHostState parent_obj;
 } I440FXState;
@@ -257,7 +261,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
     PCII440FXState *f;
     unsigned i;
 
-    dev = qdev_create(NULL, "i440FX-pcihost");
+    dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
     b = pci_bus_new(dev, NULL, pci_address_space,
                     address_space_io, 0, TYPE_PCI_BUS);
@@ -661,7 +665,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo i440fx_pcihost_info = {
-    .name          = "i440FX-pcihost",
+    .name          = TYPE_I440FX_PCI_HOST,
     .parent        = TYPE_PCI_HOST_BRIDGE,
     .instance_size = sizeof(I440FXState),
     .instance_init = i440fx_pcihost_initfn,
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
#7 lore raw

Re: [Qemu-devel] [PATCH 2/6] pc: add I440FX QOM cast macro

Quoted 14 lines · On Sun, 28 Jul 2013 11:57:14 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 13 lines
---
 hw/pci-host/piix.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +0 -0
index 3908860..bf879e7 100644
@@ -38,6 +38,10 @@
  * http://download.intel.com/design/chipsets/datashts/29054901.pdf
  */
 
Quoted 6 lines

hw/pci-host/piix.c line 43

Quoted 3 lines
hw/pci-host/piix.c +3 -0
+#define TYPE_I440FX_PCI_HOST "i440FX-pcihost"
+#define I440FX_PCI_HOST(obj) \
+    OBJECT_CHECK(I440FXState, (obj), TYPE_I440FX_PCI_HOST)

Either Anthony or mst had insisted on PCI_HOST_BRIDGE rather than PCI_HOST. Other than that looks good, thanks!

it's the type cast macro that is missing, so adding it shouldn't hurt, and some day in future we might any way need to add it even if we don't use it now.

Quoted 30 lines

Andreas

Quoted 23 lines
hw/pci-host/piix.c +3 -2
+
 typedef struct I440FXState {
     PCIHostState parent_obj;
 } I440FXState;
@@ -257,7 +261,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
     PCII440FXState *f;
     unsigned i;
 
-    dev = qdev_create(NULL, "i440FX-pcihost");
+    dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
     b = pci_bus_new(dev, NULL, pci_address_space,
                     address_space_io, 0, TYPE_PCI_BUS);
@@ -661,7 +665,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo i440fx_pcihost_info = {
-    .name          = "i440FX-pcihost",
+    .name          = TYPE_I440FX_PCI_HOST,
     .parent        = TYPE_PCI_HOST_BRIDGE,
     .instance_size = sizeof(I440FXState),
     .instance_init = i440fx_pcihost_initfn,
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
Signature · 2 lines
Regards,
  Igor
#8 lore raw

Re: [Qemu-devel] [PATCH 2/6] pc: add I440FX QOM cast macro

Am 28.07.2013 19:21, schrieb Igor Mammedov:

Quoted 24 lines
Quoted 14 lines · On Sun, 28 Jul 2013 11:57:14 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 13 lines
---
 hw/pci-host/piix.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +0 -0
index 3908860..bf879e7 100644
@@ -38,6 +38,10 @@
  * http://download.intel.com/design/chipsets/datashts/29054901.pdf
  */
 
Quoted 6 lines

hw/pci-host/piix.c line 43

Quoted 3 lines
hw/pci-host/piix.c +3 -0
+#define TYPE_I440FX_PCI_HOST "i440FX-pcihost"
+#define I440FX_PCI_HOST(obj) \
+    OBJECT_CHECK(I440FXState, (obj), TYPE_I440FX_PCI_HOST)

Either Anthony or mst had insisted on PCI_HOST_BRIDGE rather than PCI_HOST. Other than that looks good, thanks!

Quoted 3 lines

it's the type cast macro that is missing, so adding it shouldn't hurt, and some day in future we might any way need to add it even if we don't use it now.

Maybe you misunderstood? Please add _BRIDGE to your macros. :)

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
#9 lore raw

Re: [Qemu-devel] [PATCH 2/6] pc: add I440FX QOM cast macro

Quoted 25 lines · On Sun, 28 Jul 2013 19:24:03 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 19:21, schrieb Igor Mammedov:

Quoted 24 lines
Quoted 20 lines · On Sun, 28 Jul 2013 11:57:14 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 10 lines
---
 hw/pci-host/piix.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +0 -0
index 3908860..bf879e7 100644

hw/pci-host/piix.c line 43

Quoted 6 lines
hw/pci-host/piix.c +3 -0
@@ -38,6 +38,10 @@
  * http://download.intel.com/design/chipsets/datashts/29054901.pdf
  */
 
+#define TYPE_I440FX_PCI_HOST "i440FX-pcihost"
+#define I440FX_PCI_HOST(obj) \
+    OBJECT_CHECK(I440FXState, (obj), TYPE_I440FX_PCI_HOST)

Either Anthony or mst had insisted on PCI_HOST_BRIDGE rather than PCI_HOST. Other than that looks good, thanks!

Quoted 5 lines
Quoted 3 lines

it's the type cast macro that is missing, so adding it shouldn't hurt, and some day in future we might any way need to add it even if we don't use it now.

Maybe you misunderstood? Please add _BRIDGE to your macros. :)

Yep, sure I'll do it.

Quoted 6 lines

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
Signature · 2 lines
Regards,
  Igor
#10 lore raw

PATCH v2 3/6 utils: add range_size() wrapper

In reply to Igor Mammedov
---
 include/qemu/range.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/qemu/range.h +6 -0
index b76cc0d..19b742c 100644
@@ -42,4 +42,10 @@ static inline int ranges_overlap(uint64_t first1, uint64_t len1,
     return !(last2 < first1 || last1 < first2);
 }
 
+/* Get range size */
+static inline uint64_t range_size(Range r)
+{
+    return r.end - r.begin;
+}
+
 #endif
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v2 4/6 pc: replace i440fx_common_init() with i440fx_init() as it isn't used by anywhere else

In reply to Igor Mammedov
---
 hw/pci-host/piix.c | 50 +++++++++++++-------------------------------------
 1 file changed, 13 insertions(+), 37 deletions(-)
hw/pci-host/piix.c +13 -37
index bf879e7..4624d04 100644
@@ -239,19 +239,18 @@ static int i440fx_initfn(PCIDevice *dev)
     return 0;
 }
 
-static PCIBus *i440fx_common_init(const char *device_name,
-                                  PCII440FXState **pi440fx_state,
-                                  int *piix3_devfn,
-                                  ISABus **isa_bus, qemu_irq *pic,
-                                  MemoryRegion *address_space_mem,
-                                  MemoryRegion *address_space_io,
-                                  ram_addr_t ram_size,
-                                  hwaddr pci_hole_start,
-                                  hwaddr pci_hole_size,
-                                  hwaddr pci_hole64_start,
-                                  hwaddr pci_hole64_size,
-                                  MemoryRegion *pci_address_space,
-                                  MemoryRegion *ram_memory)
+PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
+                    int *piix3_devfn,
+                    ISABus **isa_bus, qemu_irq *pic,
+                    MemoryRegion *address_space_mem,
+                    MemoryRegion *address_space_io,
+                    ram_addr_t ram_size,
+                    hwaddr pci_hole_start,
+                    hwaddr pci_hole_size,
+                    hwaddr pci_hole64_start,
+                    hwaddr pci_hole64_size,
+                    MemoryRegion *pci_address_space,
+                    MemoryRegion *ram_memory)
 {
     DeviceState *dev;
     PCIBus *b;
@@ -269,7 +268,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
     object_property_add_child(qdev_get_machine(), "i440fx", OBJECT(dev), NULL);
     qdev_init_nofail(dev);
 
-    d = pci_create_simple(b, 0, device_name);
+    d = pci_create_simple(b, 0, TYPE_I440FX_PCI_DEVICE);
     *pi440fx_state = I440FX_PCI_DEVICE(d);
     f = *pi440fx_state;
     f->system_memory = address_space_mem;
@@ -330,29 +329,6 @@ static PCIBus *i440fx_common_init(const char *device_name,
     return b;
 }
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
-                    ISABus **isa_bus, qemu_irq *pic,
-                    MemoryRegion *address_space_mem,
-                    MemoryRegion *address_space_io,
-                    ram_addr_t ram_size,
-                    hwaddr pci_hole_start,
-                    hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
-                    MemoryRegion *pci_memory, MemoryRegion *ram_memory)
-
-{
-    PCIBus *b;
-
-    b = i440fx_common_init(TYPE_I440FX_PCI_DEVICE, pi440fx_state,
-                           piix3_devfn, isa_bus, pic,
-                           address_space_mem, address_space_io, ram_size,
-                           pci_hole_start, pci_hole_size,
-                           pci_hole64_start, pci_hole64_size,
-                           pci_memory, ram_memory);
-    return b;
-}
-
 /* PIIX3 PCI to ISA bridge */
 static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
 {
Signature · 1 line
1.8.3.1
Reviewed-by on v2 4/6
#12 lore raw

Re: [Qemu-devel] [PATCH 4/6] pc: replace i440fx_common_init() with i440fx_init() as it isn't used by anywhere else

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 4 lines
---
 hw/pci-host/piix.c | 50 +++++++++++++-------------------------------------
 1 file changed, 13 insertions(+), 37 deletions(-)

Subject should probably be rebroken to have "It isn't ..." in the body.

I've confirmed that it's not used anywhere else currently, so

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
#13 lore raw

PATCH v2 5/6 pc: add Q35 to QOM composition tree under /machine

In reply to Igor Mammedov
---
 hw/i386/pc_q35.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/pc_q35.c +1 -1
index 0b1d2e3..5140caf 100644
@@ -130,7 +130,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 
     /* create pci host bus */
     q35_host = Q35_HOST_DEVICE(qdev_create(NULL, TYPE_Q35_HOST_DEVICE));
-
+    object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host), NULL);
     q35_host->mch.ram_memory = ram_memory;
     q35_host->mch.pci_address_space = pci_memory;
     q35_host->mch.system_memory = get_system_memory();
Signature · 1 line
1.8.3.1
Reviewed-by on v2 5/6
#14 lore raw

Re: [Qemu-devel] [PATCH 5/6] pc: add Q35 to QOM composition tree under /machine

Am 28.07.2013 09:29, schrieb Igor Mammedov:

Quoted 10 lines
---
 hw/i386/pc_q35.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/pc_q35.c +0 -0
index 0b1d2e3..5140caf 100644

hw/i386/pc_q35.c static void pc_q35_init(QEMUMachineInitArgs *args) · line 136

Quoted 8 lines
hw/i386/pc_q35.c +1 -1
@@ -130,7 +130,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 
     /* create pci host bus */
     q35_host = Q35_HOST_DEVICE(qdev_create(NULL, TYPE_Q35_HOST_DEVICE));
-
+    object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host), NULL);
     q35_host->mch.ram_memory = ram_memory;
     q35_host->mch.pci_address_space = pci_memory;
     q35_host->mch.system_memory = get_system_memory();

Thanks a lot, I was about to send the equivalent patch!

This is a Last Minute guest-visible change, but it matches what we have for i440fx, so I consider this fine.

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
#15 lore raw

PATCH v2 6/6 pc: limit 64 bit hole to 2G by default

In reply to Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +37 -22
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
+        }
+    }
 
     info = g_malloc(sizeof *info);
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
+    info->w64_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_start", NULL));
+    info->w64_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_end", NULL));
     /* Pass PCI hole info to guest via a side channel.
      * Required so guest PCI enumeration does the right thing. */
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
@@ -1037,29 +1050,31 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
-    guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
-    if (sizeof(hwaddr) == 4) {
-        guest_info->pci_info.w64.begin = 0;
-        guest_info->pci_info.w64.end = 0;
-    } else {
-        /*
-         * BIOS does not set MTRR entries for the 64 bit window, so no need to
-         * align address to power of two.  Align address at 1G, this makes sure
-         * it can be exactly covered with a PAT entry even when using huge
-         * pages.
-         */
-        guest_info->pci_info.w64.begin =
-            ROUND_UP((0x1ULL << 32) + above_4g_mem_size, 0x1ULL << 30);
-        guest_info->pci_info.w64.end = guest_info->pci_info.w64.begin +
-            (0x1ULL << 62);
-        assert(guest_info->pci_info.w64.begin <= guest_info->pci_info.w64.end);
-    }
-
     guest_info_state->machine_done.notify = pc_guest_info_machine_done;
     qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
     return guest_info;
 }
 
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start)
+{
+    if (sizeof(hwaddr) == 4) {
+        memset(&pci_info->w64, sizeof(pci_info->w64), 0);
+        return;
+    }
+    /*
+     * BIOS does not set MTRR entries for the 64 bit window, so no need to
+     * align address to power of two.  Align address at 1G, this makes sure
+     * it can be exactly covered with a PAT entry even when using huge
+     * pages.
+     */
+    pci_info->w64.begin = ROUND_UP(pci_hole64_start, 0x1ULL << 30);
+    if (!pci_info->w64.end) {
+        /* set default end if it wasn't specified, + 2 Gb past start */
+        pci_info->w64.end = pci_info->w64.begin + (0x1ULL << 31);
+    }
+    assert(pci_info->w64.begin < pci_info->w64.end);
+}
+
 void pc_acpi_init(const char *default_dsdt)
 {
     char *filename;
hw/i386/pc_piix.c +1 -13
index b58c255..ab25458 100644
@@ -129,15 +129,6 @@ static void pc_init1(MemoryRegion *system_memory,
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = has_pci_info;
 
-    /* Set PCI window size the way seabios has always done it. */
-    /* Power of 2 so bios can cover it with a single MTRR */
-    if (ram_size <= 0x80000000)
-        guest_info->pci_info.w32.begin = 0x80000000;
-    else if (ram_size <= 0xc0000000)
-        guest_info->pci_info.w32.begin = 0xc0000000;
-    else
-        guest_info->pci_info.w32.begin = 0xe0000000;
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         fw_cfg = pc_memory_init(system_memory,
@@ -160,10 +151,7 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
+                              above_4g_mem_size,
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
hw/pci-host/piix.c +33 -4
index 4624d04..59a42c5 100644
@@ -32,6 +32,7 @@
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/ioapic.h"
 
 /*
  * I440FX chipset data sheet.
@@ -44,6 +45,7 @@
 
 typedef struct I440FXState {
     PCIHostState parent_obj;
+    PcPciInfo pci_info;
 } I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
@@ -247,8 +249,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_address_space,
                     MemoryRegion *ram_memory)
 {
@@ -259,6 +260,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     PIIX3State *piix3;
     PCII440FXState *f;
     unsigned i;
+    I440FXState *i440fx;
+    uint64_t pci_hole64_size;
 
     dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
@@ -274,14 +277,30 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    i440fx = I440FX_PCI_HOST(dev);
+    /* Set PCI window size the way seabios has always done it. */
+    /* Power of 2 so bios can cover it with a single MTRR */
+    if (ram_size <= 0x80000000) {
+        i440fx->pci_info.w32.begin = 0x80000000;
+    } else if (ram_size <= 0xc0000000) {
+        i440fx->pci_info.w32.begin = 0xc0000000;
+    } else {
+        i440fx->pci_info.w32.begin = 0xe0000000;
+    }
+
     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);
+
+    pc_init_pci64_hole(&i440fx->pci_info, 0x100000000ULL + above_4g_mem_size);
+    pci_hole64_size = range_size(i440fx->pci_info.w64);
     memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64",
                              f->pci_address_space,
-                             pci_hole64_start, pci_hole64_size);
+                             i440fx->pci_info.w64.begin, pci_hole64_size);
     if (pci_hole64_size) {
-        memory_region_add_subregion(f->system_memory, pci_hole64_start,
+        memory_region_add_subregion(f->system_memory,
+                                    i440fx->pci_info.w64.begin,
                                     &f->pci_hole_64bit);
     }
     memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }
 
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -638,6 +666,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
     dc->realize = i440fx_pcihost_realize;
     dc->fw_name = "pci";
     dc->no_user = 1;
+    dc->props = i440fx_props;
 }
 
 static const TypeInfo i440fx_pcihost_info = {
hw/pci-host/q35.c +20 -12
index 6b1b3b7..a6936e6 100644
@@ -67,6 +67,21 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge,
 static Property mch_props[] = {
     DEFINE_PROP_UINT64("MCFG", Q35PCIHost, parent_obj.base_addr,
                         MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
+    DEFINE_PROP_UINT64("pci_hole64_start", Q35PCIHost,
+                       mch.pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", Q35PCIHost,
+                       mch.pci_info.w64.end, 0),
+    /* Leave enough space for the biggest MCFG BAR */
+    /* TODO: this matches current bios behaviour, but
+     * it's not a power of two, which means an MTRR
+     * can't cover it exactly.
+     */
+    DEFINE_PROP_UINT64("pci_hole_start", Q35PCIHost,
+                       mch.pci_info.w32.begin,
+                       MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
+                       MCH_HOST_BRIDGE_PCIEXBAR_MAX),
+    DEFINE_PROP_UINT64("pci_hole_end", Q35PCIHost,
+                       mch.pci_info.w32.end, IO_APIC_DEFAULT_ADDRESS),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -255,14 +270,6 @@ static int mch_init(PCIDevice *d)
     hwaddr pci_hole64_size;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
 
-    /* Leave enough space for the biggest MCFG BAR */
-    /* TODO: this matches current bios behaviour, but
-     * it's not a power of two, which means an MTRR
-     * can't cover it exactly.
-     */
-    mch->guest_info->pci_info.w32.begin = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
-        MCH_HOST_BRIDGE_PCIEXBAR_MAX;
-
     /* setup pci memory regions */
     memory_region_init_alias(&mch->pci_hole, OBJECT(mch), "pci-hole",
                              mch->pci_address_space,
@@ -270,15 +277,16 @@ static int mch_init(PCIDevice *d)
                              0x100000000ULL - mch->below_4g_mem_size);
     memory_region_add_subregion(mch->system_memory, mch->below_4g_mem_size,
                                 &mch->pci_hole);
-    pci_hole64_size = (sizeof(hwaddr) == 4 ? 0 :
-                       ((uint64_t)1 << 62));
+
+    pc_init_pci64_hole(&mch->pci_info, 0x100000000ULL + mch->above_4g_mem_size);
+    pci_hole64_size = range_size(mch->pci_info.w64);
     memory_region_init_alias(&mch->pci_hole_64bit, OBJECT(mch), "pci-hole64",
                              mch->pci_address_space,
-                             0x100000000ULL + mch->above_4g_mem_size,
+                             mch->pci_info.w64.begin,
                              pci_hole64_size);
     if (pci_hole64_size) {
         memory_region_add_subregion(mch->system_memory,
-                                    0x100000000ULL + mch->above_4g_mem_size,
+                                    mch->pci_info.w64.begin,
                                     &mch->pci_hole_64bit);
     }
     /* smram */
include/hw/i386/pc.h +2 -3
index 7fb97b0..ab747b7 100644
@@ -18,7 +18,6 @@ typedef struct PcPciInfo {
 } PcPciInfo;
 
 struct PcGuestInfo {
-    PcPciInfo pci_info;
     bool has_pci_info;
     FWCfgState *fw_cfg;
 };
@@ -100,6 +99,7 @@ void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
                                 ram_addr_t above_4g_mem_size);
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start);
 
 FWCfgState *pc_memory_init(MemoryRegion *system_memory,
                            const char *kernel_filename,
@@ -150,8 +150,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_memory,
                     MemoryRegion *ram_memory);
 
include/hw/pci-host/q35.h +1 -0
index 3cb631e..3a9e04b 100644
@@ -55,6 +55,7 @@ typedef struct MCHPCIState {
     MemoryRegion smram_region;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    PcPciInfo pci_info;
     uint8_t smm_enabled;
     ram_addr_t below_4g_mem_size;
     ram_addr_t above_4g_mem_size;
Signature · 1 line
1.8.3.1
#16 lore raw

Review

Quoted 10 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:

(quoted diff) +0 -2
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff
 
-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

Quoted 22 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +2 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 10 lines
hw/i386/pc.c +7 -0
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1023

Quoted 10 lines
hw/i386/pc.c +4 -4
     info = g_malloc(sizeof *info);
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

#define PCI_HOST_PROPS...
static inline get_

Quoted 164 lines
hw/i386/pc.c +24 -18
+    info->w64_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_start", NULL));
+    info->w64_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_end", NULL));
     /* Pass PCI hole info to guest via a side channel.
      * Required so guest PCI enumeration does the right thing. */
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
@@ -1037,29 +1050,31 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
-    guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
-    if (sizeof(hwaddr) == 4) {
-        guest_info->pci_info.w64.begin = 0;
-        guest_info->pci_info.w64.end = 0;
-    } else {
-        /*
-         * BIOS does not set MTRR entries for the 64 bit window, so no need to
-         * align address to power of two.  Align address at 1G, this makes sure
-         * it can be exactly covered with a PAT entry even when using huge
-         * pages.
-         */
-        guest_info->pci_info.w64.begin =
-            ROUND_UP((0x1ULL << 32) + above_4g_mem_size, 0x1ULL << 30);
-        guest_info->pci_info.w64.end = guest_info->pci_info.w64.begin +
-            (0x1ULL << 62);
-        assert(guest_info->pci_info.w64.begin <= guest_info->pci_info.w64.end);
-    }
-
     guest_info_state->machine_done.notify = pc_guest_info_machine_done;
     qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
     return guest_info;
 }
 
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start)
+{
+    if (sizeof(hwaddr) == 4) {
+        memset(&pci_info->w64, sizeof(pci_info->w64), 0);
+        return;
+    }
+    /*
+     * BIOS does not set MTRR entries for the 64 bit window, so no need to
+     * align address to power of two.  Align address at 1G, this makes sure
+     * it can be exactly covered with a PAT entry even when using huge
+     * pages.
+     */
+    pci_info->w64.begin = ROUND_UP(pci_hole64_start, 0x1ULL << 30);
+    if (!pci_info->w64.end) {
+        /* set default end if it wasn't specified, + 2 Gb past start */
+        pci_info->w64.end = pci_info->w64.begin + (0x1ULL << 31);
+    }
+    assert(pci_info->w64.begin < pci_info->w64.end);
+}
+
 void pc_acpi_init(const char *default_dsdt)
 {
     char *filename;
hw/i386/pc_piix.c +1 -13
index b58c255..ab25458 100644
@@ -129,15 +129,6 @@ static void pc_init1(MemoryRegion *system_memory,
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = has_pci_info;
 
-    /* Set PCI window size the way seabios has always done it. */
-    /* Power of 2 so bios can cover it with a single MTRR */
-    if (ram_size <= 0x80000000)
-        guest_info->pci_info.w32.begin = 0x80000000;
-    else if (ram_size <= 0xc0000000)
-        guest_info->pci_info.w32.begin = 0xc0000000;
-    else
-        guest_info->pci_info.w32.begin = 0xe0000000;
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         fw_cfg = pc_memory_init(system_memory,
@@ -160,10 +151,7 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
+                              above_4g_mem_size,
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
hw/pci-host/piix.c +23 -4
index 4624d04..59a42c5 100644
@@ -32,6 +32,7 @@
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/ioapic.h"
 
 /*
  * I440FX chipset data sheet.
@@ -44,6 +45,7 @@
 
 typedef struct I440FXState {
     PCIHostState parent_obj;
+    PcPciInfo pci_info;
 } I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
@@ -247,8 +249,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_address_space,
                     MemoryRegion *ram_memory)
 {
@@ -259,6 +260,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     PIIX3State *piix3;
     PCII440FXState *f;
     unsigned i;
+    I440FXState *i440fx;
+    uint64_t pci_hole64_size;
 
     dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
@@ -274,14 +277,30 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    i440fx = I440FX_PCI_HOST(dev);
+    /* Set PCI window size the way seabios has always done it. */
+    /* Power of 2 so bios can cover it with a single MTRR */
+    if (ram_size <= 0x80000000) {
+        i440fx->pci_info.w32.begin = 0x80000000;
+    } else if (ram_size <= 0xc0000000) {
+        i440fx->pci_info.w32.begin = 0xc0000000;
+    } else {
+        i440fx->pci_info.w32.begin = 0xe0000000;
+    }
+
     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);
+
+    pc_init_pci64_hole(&i440fx->pci_info, 0x100000000ULL + above_4g_mem_size);
+    pci_hole64_size = range_size(i440fx->pci_info.w64);
     memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64",
                              f->pci_address_space,
-                             pci_hole64_start, pci_hole64_size);
+                             i440fx->pci_info.w64.begin, pci_hole64_size);
     if (pci_hole64_size) {
-        memory_region_add_subregion(f->system_memory, pci_hole64_start,
+        memory_region_add_subregion(f->system_memory,
+                                    i440fx->pci_info.w64.begin,
                                     &f->pci_hole_64bit);
     }
     memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 10 lines
hw/pci-host/piix.c +9 -0
 
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 117 lines
hw/pci-host/piix.c +1 -0
 static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -638,6 +666,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
     dc->realize = i440fx_pcihost_realize;
     dc->fw_name = "pci";
     dc->no_user = 1;
+    dc->props = i440fx_props;
 }
 
 static const TypeInfo i440fx_pcihost_info = {
hw/pci-host/q35.c +20 -12
index 6b1b3b7..a6936e6 100644
@@ -67,6 +67,21 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge,
 static Property mch_props[] = {
     DEFINE_PROP_UINT64("MCFG", Q35PCIHost, parent_obj.base_addr,
                         MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
+    DEFINE_PROP_UINT64("pci_hole64_start", Q35PCIHost,
+                       mch.pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", Q35PCIHost,
+                       mch.pci_info.w64.end, 0),
+    /* Leave enough space for the biggest MCFG BAR */
+    /* TODO: this matches current bios behaviour, but
+     * it's not a power of two, which means an MTRR
+     * can't cover it exactly.
+     */
+    DEFINE_PROP_UINT64("pci_hole_start", Q35PCIHost,
+                       mch.pci_info.w32.begin,
+                       MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
+                       MCH_HOST_BRIDGE_PCIEXBAR_MAX),
+    DEFINE_PROP_UINT64("pci_hole_end", Q35PCIHost,
+                       mch.pci_info.w32.end, IO_APIC_DEFAULT_ADDRESS),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -255,14 +270,6 @@ static int mch_init(PCIDevice *d)
     hwaddr pci_hole64_size;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
 
-    /* Leave enough space for the biggest MCFG BAR */
-    /* TODO: this matches current bios behaviour, but
-     * it's not a power of two, which means an MTRR
-     * can't cover it exactly.
-     */
-    mch->guest_info->pci_info.w32.begin = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
-        MCH_HOST_BRIDGE_PCIEXBAR_MAX;
-
     /* setup pci memory regions */
     memory_region_init_alias(&mch->pci_hole, OBJECT(mch), "pci-hole",
                              mch->pci_address_space,
@@ -270,15 +277,16 @@ static int mch_init(PCIDevice *d)
                              0x100000000ULL - mch->below_4g_mem_size);
     memory_region_add_subregion(mch->system_memory, mch->below_4g_mem_size,
                                 &mch->pci_hole);
-    pci_hole64_size = (sizeof(hwaddr) == 4 ? 0 :
-                       ((uint64_t)1 << 62));
+
+    pc_init_pci64_hole(&mch->pci_info, 0x100000000ULL + mch->above_4g_mem_size);
+    pci_hole64_size = range_size(mch->pci_info.w64);
     memory_region_init_alias(&mch->pci_hole_64bit, OBJECT(mch), "pci-hole64",
                              mch->pci_address_space,
-                             0x100000000ULL + mch->above_4g_mem_size,
+                             mch->pci_info.w64.begin,
                              pci_hole64_size);
     if (pci_hole64_size) {
         memory_region_add_subregion(mch->system_memory,
-                                    0x100000000ULL + mch->above_4g_mem_size,
+                                    mch->pci_info.w64.begin,
                                     &mch->pci_hole_64bit);
     }
     /* smram */
include/hw/i386/pc.h +2 -3
index 7fb97b0..ab747b7 100644
@@ -18,7 +18,6 @@ typedef struct PcPciInfo {
 } PcPciInfo;
 
 struct PcGuestInfo {
-    PcPciInfo pci_info;
     bool has_pci_info;
     FWCfgState *fw_cfg;
 };
@@ -100,6 +99,7 @@ void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
                                 ram_addr_t above_4g_mem_size);
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start);
 
 FWCfgState *pc_memory_init(MemoryRegion *system_memory,
                            const char *kernel_filename,
@@ -150,8 +150,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_memory,
                     MemoryRegion *ram_memory);
 
include/hw/pci-host/q35.h +1 -0
index 3cb631e..3a9e04b 100644
@@ -55,6 +55,7 @@ typedef struct MCHPCIState {
     MemoryRegion smram_region;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    PcPciInfo pci_info;
     uint8_t smm_enabled;
     ram_addr_t below_4g_mem_size;
     ram_addr_t above_4g_mem_size;
Signature · 1 line
1.8.3.1
#17 lore raw
Quoted 10 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

Quoted 7 lines
Quoted 1 line

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

sure as convenience why not, on top of this patches.

Quoted 31 lines
Quoted 31 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +7 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
Quoted 8 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 2 lines
hw/i386/pc.c +2 -0
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

that drawback of dynamic lookup,
QOM paths supposed to be stable.

Quoted 3 lines

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

I've seen objections from afaerber about this approach, so dropped this idea.

Quoted 12 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1023

Quoted 11 lines
hw/i386/pc.c +4 -4
     info = g_malloc(sizeof *info);
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

Quoted 5 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 171 lines

#define PCI_HOST_PROPS...
static inline get_

Quoted 165 lines
hw/i386/pc.c +24 -18
+    info->w64_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_start", NULL));
+    info->w64_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_end", NULL));
     /* Pass PCI hole info to guest via a side channel.
      * Required so guest PCI enumeration does the right thing. */
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
@@ -1037,29 +1050,31 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
-    guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
-    if (sizeof(hwaddr) == 4) {
-        guest_info->pci_info.w64.begin = 0;
-        guest_info->pci_info.w64.end = 0;
-    } else {
-        /*
-         * BIOS does not set MTRR entries for the 64 bit window, so no need to
-         * align address to power of two.  Align address at 1G, this makes sure
-         * it can be exactly covered with a PAT entry even when using huge
-         * pages.
-         */
-        guest_info->pci_info.w64.begin =
-            ROUND_UP((0x1ULL << 32) + above_4g_mem_size, 0x1ULL << 30);
-        guest_info->pci_info.w64.end = guest_info->pci_info.w64.begin +
-            (0x1ULL << 62);
-        assert(guest_info->pci_info.w64.begin <= guest_info->pci_info.w64.end);
-    }
-
     guest_info_state->machine_done.notify = pc_guest_info_machine_done;
     qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
     return guest_info;
 }
 
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start)
+{
+    if (sizeof(hwaddr) == 4) {
+        memset(&pci_info->w64, sizeof(pci_info->w64), 0);
+        return;
+    }
+    /*
+     * BIOS does not set MTRR entries for the 64 bit window, so no need to
+     * align address to power of two.  Align address at 1G, this makes sure
+     * it can be exactly covered with a PAT entry even when using huge
+     * pages.
+     */
+    pci_info->w64.begin = ROUND_UP(pci_hole64_start, 0x1ULL << 30);
+    if (!pci_info->w64.end) {
+        /* set default end if it wasn't specified, + 2 Gb past start */
+        pci_info->w64.end = pci_info->w64.begin + (0x1ULL << 31);
+    }
+    assert(pci_info->w64.begin < pci_info->w64.end);
+}
+
 void pc_acpi_init(const char *default_dsdt)
 {
     char *filename;
hw/i386/pc_piix.c +1 -13
index b58c255..ab25458 100644
@@ -129,15 +129,6 @@ static void pc_init1(MemoryRegion *system_memory,
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = has_pci_info;
 
-    /* Set PCI window size the way seabios has always done it. */
-    /* Power of 2 so bios can cover it with a single MTRR */
-    if (ram_size <= 0x80000000)
-        guest_info->pci_info.w32.begin = 0x80000000;
-    else if (ram_size <= 0xc0000000)
-        guest_info->pci_info.w32.begin = 0xc0000000;
-    else
-        guest_info->pci_info.w32.begin = 0xe0000000;
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         fw_cfg = pc_memory_init(system_memory,
@@ -160,10 +151,7 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
+                              above_4g_mem_size,
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
hw/pci-host/piix.c +23 -4
index 4624d04..59a42c5 100644
@@ -32,6 +32,7 @@
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/ioapic.h"
 
 /*
  * I440FX chipset data sheet.
@@ -44,6 +45,7 @@
 
 typedef struct I440FXState {
     PCIHostState parent_obj;
+    PcPciInfo pci_info;
 } I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
@@ -247,8 +249,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_address_space,
                     MemoryRegion *ram_memory)
 {
@@ -259,6 +260,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     PIIX3State *piix3;
     PCII440FXState *f;
     unsigned i;
+    I440FXState *i440fx;
+    uint64_t pci_hole64_size;
 
     dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
@@ -274,14 +277,30 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    i440fx = I440FX_PCI_HOST(dev);
+    /* Set PCI window size the way seabios has always done it. */
+    /* Power of 2 so bios can cover it with a single MTRR */
+    if (ram_size <= 0x80000000) {
+        i440fx->pci_info.w32.begin = 0x80000000;
+    } else if (ram_size <= 0xc0000000) {
+        i440fx->pci_info.w32.begin = 0xc0000000;
+    } else {
+        i440fx->pci_info.w32.begin = 0xe0000000;
+    }
+
     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);
+
+    pc_init_pci64_hole(&i440fx->pci_info, 0x100000000ULL + above_4g_mem_size);
+    pci_hole64_size = range_size(i440fx->pci_info.w64);
     memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64",
                              f->pci_address_space,
-                             pci_hole64_start, pci_hole64_size);
+                             i440fx->pci_info.w64.begin, pci_hole64_size);
     if (pci_hole64_size) {
-        memory_region_add_subregion(f->system_memory, pci_hole64_start,
+        memory_region_add_subregion(f->system_memory,
+                                    i440fx->pci_info.w64.begin,
                                     &f->pci_hole_64bit);
     }
     memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }
 
Quoted 16 lines

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 9 lines
hw/pci-host/piix.c +9 -0
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

read-only properties are possible but we would have to drop
usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo, user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.

For user friendly property "pci_hole64_size" would be nice to have.

Quoted 119 lines
Quoted 118 lines
hw/pci-host/piix.c +1 -0
 static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -638,6 +666,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
     dc->realize = i440fx_pcihost_realize;
     dc->fw_name = "pci";
     dc->no_user = 1;
+    dc->props = i440fx_props;
 }
 
 static const TypeInfo i440fx_pcihost_info = {
hw/pci-host/q35.c +20 -12
index 6b1b3b7..a6936e6 100644
@@ -67,6 +67,21 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge,
 static Property mch_props[] = {
     DEFINE_PROP_UINT64("MCFG", Q35PCIHost, parent_obj.base_addr,
                         MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
+    DEFINE_PROP_UINT64("pci_hole64_start", Q35PCIHost,
+                       mch.pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", Q35PCIHost,
+                       mch.pci_info.w64.end, 0),
+    /* Leave enough space for the biggest MCFG BAR */
+    /* TODO: this matches current bios behaviour, but
+     * it's not a power of two, which means an MTRR
+     * can't cover it exactly.
+     */
+    DEFINE_PROP_UINT64("pci_hole_start", Q35PCIHost,
+                       mch.pci_info.w32.begin,
+                       MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
+                       MCH_HOST_BRIDGE_PCIEXBAR_MAX),
+    DEFINE_PROP_UINT64("pci_hole_end", Q35PCIHost,
+                       mch.pci_info.w32.end, IO_APIC_DEFAULT_ADDRESS),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -255,14 +270,6 @@ static int mch_init(PCIDevice *d)
     hwaddr pci_hole64_size;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
 
-    /* Leave enough space for the biggest MCFG BAR */
-    /* TODO: this matches current bios behaviour, but
-     * it's not a power of two, which means an MTRR
-     * can't cover it exactly.
-     */
-    mch->guest_info->pci_info.w32.begin = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
-        MCH_HOST_BRIDGE_PCIEXBAR_MAX;
-
     /* setup pci memory regions */
     memory_region_init_alias(&mch->pci_hole, OBJECT(mch), "pci-hole",
                              mch->pci_address_space,
@@ -270,15 +277,16 @@ static int mch_init(PCIDevice *d)
                              0x100000000ULL - mch->below_4g_mem_size);
     memory_region_add_subregion(mch->system_memory, mch->below_4g_mem_size,
                                 &mch->pci_hole);
-    pci_hole64_size = (sizeof(hwaddr) == 4 ? 0 :
-                       ((uint64_t)1 << 62));
+
+    pc_init_pci64_hole(&mch->pci_info, 0x100000000ULL + mch->above_4g_mem_size);
+    pci_hole64_size = range_size(mch->pci_info.w64);
     memory_region_init_alias(&mch->pci_hole_64bit, OBJECT(mch), "pci-hole64",
                              mch->pci_address_space,
-                             0x100000000ULL + mch->above_4g_mem_size,
+                             mch->pci_info.w64.begin,
                              pci_hole64_size);
     if (pci_hole64_size) {
         memory_region_add_subregion(mch->system_memory,
-                                    0x100000000ULL + mch->above_4g_mem_size,
+                                    mch->pci_info.w64.begin,
                                     &mch->pci_hole_64bit);
     }
     /* smram */
include/hw/i386/pc.h +2 -3
index 7fb97b0..ab747b7 100644
@@ -18,7 +18,6 @@ typedef struct PcPciInfo {
 } PcPciInfo;
 
 struct PcGuestInfo {
-    PcPciInfo pci_info;
     bool has_pci_info;
     FWCfgState *fw_cfg;
 };
@@ -100,6 +99,7 @@ void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
                                 ram_addr_t above_4g_mem_size);
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start);
 
 FWCfgState *pc_memory_init(MemoryRegion *system_memory,
                            const char *kernel_filename,
@@ -150,8 +150,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_memory,
                     MemoryRegion *ram_memory);
 
include/hw/pci-host/q35.h +1 -0
index 3cb631e..3a9e04b 100644
@@ -55,6 +55,7 @@ typedef struct MCHPCIState {
     MemoryRegion smram_region;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    PcPciInfo pci_info;
     uint8_t smm_enabled;
     ram_addr_t below_4g_mem_size;
     ram_addr_t above_4g_mem_size;
Signature · 1 line
1.8.3.1
Signature · 2 lines
Regards,
  Igor
#18 lore raw
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

sure as convenience why not, on top of this patches.

Well because you are specifying end as 0xffffffffffffffff so it's not a multiple of 1G?

Quoted 60 lines
Quoted 31 lines
Quoted 31 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +7 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
Quoted 8 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 2 lines
hw/i386/pc.c +2 -0
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

that drawback of dynamic lookup,
QOM paths supposed to be stable.

Quoted 3 lines

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

I've seen objections from afaerber about this approach, so dropped this idea.

Quoted 12 lines
Quoted 11 lines
hw/i386/pc.c +4 -4
     info = g_malloc(sizeof *info);
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 5 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

Quoted 194 lines
Quoted 5 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 171 lines

#define PCI_HOST_PROPS...
static inline get_

Quoted 165 lines
hw/i386/pc.c +24 -18
+    info->w64_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_start", NULL));
+    info->w64_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_end", NULL));
     /* Pass PCI hole info to guest via a side channel.
      * Required so guest PCI enumeration does the right thing. */
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
@@ -1037,29 +1050,31 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
-    guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
-    if (sizeof(hwaddr) == 4) {
-        guest_info->pci_info.w64.begin = 0;
-        guest_info->pci_info.w64.end = 0;
-    } else {
-        /*
-         * BIOS does not set MTRR entries for the 64 bit window, so no need to
-         * align address to power of two.  Align address at 1G, this makes sure
-         * it can be exactly covered with a PAT entry even when using huge
-         * pages.
-         */
-        guest_info->pci_info.w64.begin =
-            ROUND_UP((0x1ULL << 32) + above_4g_mem_size, 0x1ULL << 30);
-        guest_info->pci_info.w64.end = guest_info->pci_info.w64.begin +
-            (0x1ULL << 62);
-        assert(guest_info->pci_info.w64.begin <= guest_info->pci_info.w64.end);
-    }
-
     guest_info_state->machine_done.notify = pc_guest_info_machine_done;
     qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
     return guest_info;
 }
 
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start)
+{
+    if (sizeof(hwaddr) == 4) {
+        memset(&pci_info->w64, sizeof(pci_info->w64), 0);
+        return;
+    }
+    /*
+     * BIOS does not set MTRR entries for the 64 bit window, so no need to
+     * align address to power of two.  Align address at 1G, this makes sure
+     * it can be exactly covered with a PAT entry even when using huge
+     * pages.
+     */
+    pci_info->w64.begin = ROUND_UP(pci_hole64_start, 0x1ULL << 30);
+    if (!pci_info->w64.end) {
+        /* set default end if it wasn't specified, + 2 Gb past start */
+        pci_info->w64.end = pci_info->w64.begin + (0x1ULL << 31);
+    }
+    assert(pci_info->w64.begin < pci_info->w64.end);
+}
+
 void pc_acpi_init(const char *default_dsdt)
 {
     char *filename;
hw/i386/pc_piix.c +1 -13
index b58c255..ab25458 100644
@@ -129,15 +129,6 @@ static void pc_init1(MemoryRegion *system_memory,
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = has_pci_info;
 
-    /* Set PCI window size the way seabios has always done it. */
-    /* Power of 2 so bios can cover it with a single MTRR */
-    if (ram_size <= 0x80000000)
-        guest_info->pci_info.w32.begin = 0x80000000;
-    else if (ram_size <= 0xc0000000)
-        guest_info->pci_info.w32.begin = 0xc0000000;
-    else
-        guest_info->pci_info.w32.begin = 0xe0000000;
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         fw_cfg = pc_memory_init(system_memory,
@@ -160,10 +151,7 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
+                              above_4g_mem_size,
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
hw/pci-host/piix.c +23 -4
index 4624d04..59a42c5 100644
@@ -32,6 +32,7 @@
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/ioapic.h"
 
 /*
  * I440FX chipset data sheet.
@@ -44,6 +45,7 @@
 
 typedef struct I440FXState {
     PCIHostState parent_obj;
+    PcPciInfo pci_info;
 } I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
@@ -247,8 +249,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_address_space,
                     MemoryRegion *ram_memory)
 {
@@ -259,6 +260,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     PIIX3State *piix3;
     PCII440FXState *f;
     unsigned i;
+    I440FXState *i440fx;
+    uint64_t pci_hole64_size;
 
     dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
@@ -274,14 +277,30 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    i440fx = I440FX_PCI_HOST(dev);
+    /* Set PCI window size the way seabios has always done it. */
+    /* Power of 2 so bios can cover it with a single MTRR */
+    if (ram_size <= 0x80000000) {
+        i440fx->pci_info.w32.begin = 0x80000000;
+    } else if (ram_size <= 0xc0000000) {
+        i440fx->pci_info.w32.begin = 0xc0000000;
+    } else {
+        i440fx->pci_info.w32.begin = 0xe0000000;
+    }
+
     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);
+
+    pc_init_pci64_hole(&i440fx->pci_info, 0x100000000ULL + above_4g_mem_size);
+    pci_hole64_size = range_size(i440fx->pci_info.w64);
     memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64",
                              f->pci_address_space,
-                             pci_hole64_start, pci_hole64_size);
+                             i440fx->pci_info.w64.begin, pci_hole64_size);
     if (pci_hole64_size) {
-        memory_region_add_subregion(f->system_memory, pci_hole64_start,
+        memory_region_add_subregion(f->system_memory,
+                                    i440fx->pci_info.w64.begin,
                                     &f->pci_hole_64bit);
     }
     memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }
 
Quoted 16 lines

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 9 lines
hw/pci-host/piix.c +9 -0
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

Quoted 4 lines

user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.
For user friendly property "pci_hole64_size" would be nice to have.

So at the moment I do

qemu -device i440FX-pcihost,help

and this will get all properties.

If we add some properties that user can not set
they should not appear in this output.

Quoted 124 lines
Quoted 119 lines
Quoted 118 lines
hw/pci-host/piix.c +1 -0
 static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -638,6 +666,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
     dc->realize = i440fx_pcihost_realize;
     dc->fw_name = "pci";
     dc->no_user = 1;
+    dc->props = i440fx_props;
 }
 
 static const TypeInfo i440fx_pcihost_info = {
hw/pci-host/q35.c +20 -12
index 6b1b3b7..a6936e6 100644
@@ -67,6 +67,21 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge,
 static Property mch_props[] = {
     DEFINE_PROP_UINT64("MCFG", Q35PCIHost, parent_obj.base_addr,
                         MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
+    DEFINE_PROP_UINT64("pci_hole64_start", Q35PCIHost,
+                       mch.pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", Q35PCIHost,
+                       mch.pci_info.w64.end, 0),
+    /* Leave enough space for the biggest MCFG BAR */
+    /* TODO: this matches current bios behaviour, but
+     * it's not a power of two, which means an MTRR
+     * can't cover it exactly.
+     */
+    DEFINE_PROP_UINT64("pci_hole_start", Q35PCIHost,
+                       mch.pci_info.w32.begin,
+                       MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
+                       MCH_HOST_BRIDGE_PCIEXBAR_MAX),
+    DEFINE_PROP_UINT64("pci_hole_end", Q35PCIHost,
+                       mch.pci_info.w32.end, IO_APIC_DEFAULT_ADDRESS),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -255,14 +270,6 @@ static int mch_init(PCIDevice *d)
     hwaddr pci_hole64_size;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
 
-    /* Leave enough space for the biggest MCFG BAR */
-    /* TODO: this matches current bios behaviour, but
-     * it's not a power of two, which means an MTRR
-     * can't cover it exactly.
-     */
-    mch->guest_info->pci_info.w32.begin = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
-        MCH_HOST_BRIDGE_PCIEXBAR_MAX;
-
     /* setup pci memory regions */
     memory_region_init_alias(&mch->pci_hole, OBJECT(mch), "pci-hole",
                              mch->pci_address_space,
@@ -270,15 +277,16 @@ static int mch_init(PCIDevice *d)
                              0x100000000ULL - mch->below_4g_mem_size);
     memory_region_add_subregion(mch->system_memory, mch->below_4g_mem_size,
                                 &mch->pci_hole);
-    pci_hole64_size = (sizeof(hwaddr) == 4 ? 0 :
-                       ((uint64_t)1 << 62));
+
+    pc_init_pci64_hole(&mch->pci_info, 0x100000000ULL + mch->above_4g_mem_size);
+    pci_hole64_size = range_size(mch->pci_info.w64);
     memory_region_init_alias(&mch->pci_hole_64bit, OBJECT(mch), "pci-hole64",
                              mch->pci_address_space,
-                             0x100000000ULL + mch->above_4g_mem_size,
+                             mch->pci_info.w64.begin,
                              pci_hole64_size);
     if (pci_hole64_size) {
         memory_region_add_subregion(mch->system_memory,
-                                    0x100000000ULL + mch->above_4g_mem_size,
+                                    mch->pci_info.w64.begin,
                                     &mch->pci_hole_64bit);
     }
     /* smram */
include/hw/i386/pc.h +2 -3
index 7fb97b0..ab747b7 100644
@@ -18,7 +18,6 @@ typedef struct PcPciInfo {
 } PcPciInfo;
 
 struct PcGuestInfo {
-    PcPciInfo pci_info;
     bool has_pci_info;
     FWCfgState *fw_cfg;
 };
@@ -100,6 +99,7 @@ void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
                                 ram_addr_t above_4g_mem_size);
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start);
 
 FWCfgState *pc_memory_init(MemoryRegion *system_memory,
                            const char *kernel_filename,
@@ -150,8 +150,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_memory,
                     MemoryRegion *ram_memory);
 
include/hw/pci-host/q35.h +1 -0
index 3cb631e..3a9e04b 100644
@@ -55,6 +55,7 @@ typedef struct MCHPCIState {
     MemoryRegion smram_region;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    PcPciInfo pci_info;
     uint8_t smm_enabled;
     ram_addr_t below_4g_mem_size;
     ram_addr_t above_4g_mem_size;
Signature · 1 line
1.8.3.1
Signature · 2 lines
Regards,
  Igor
#19 lore raw

Am 28.07.2013 11:11, schrieb Michael S. Tsirkin:

Quoted 16 lines · Igor Mammedov
Quoted 15 lines
Quoted 12 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
 
     info = g_malloc(sizeof *info);
hw/i386/pc.c +4 -4
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

That's how QAPI works internally today for any uint64 visitor/property. uint64_t is cast to int64_t and back in visitors.

So I'd hope something like
uint64_t val = (uint64_t) object_property_get_int() would work equally well - CC'ing Michael.

Quoted 20 lines
Quoted 1 line

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

Quoted 9 lines
Quoted 4 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 3 lines

#define PCI_HOST_PROPS...
static inline get_

[...]

Quoted 30 lines
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
hw/pci-host/piix.c +0 -0
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }
 
Quoted 16 lines

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 9 lines
hw/pci-host/piix.c +9 -0
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

Quoted 4 lines

user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.
For user friendly property "pci_hole64_size" would be nice to have.

Quoted 8 lines

So at the moment I do

qemu -device i440FX-pcihost,help

and this will get all properties.

If we add some properties that user can not set
they should not appear in this output.

[snip]

Igor, you can simply use dynamic properties with NULL as setter argument for object_property_add*() to achieve that effect.

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
#20 lore raw
Quoted 84 lines · On Sun, 28 Jul 2013 12:17:47 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 11:11, schrieb Michael S. Tsirkin:

Quoted 16 lines · Igor Mammedov
Quoted 15 lines
Quoted 12 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
 
     info = g_malloc(sizeof *info);
hw/i386/pc.c +4 -4
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

That's how QAPI works internally today for any uint64 visitor/property. uint64_t is cast to int64_t and back in visitors.

So I'd hope something like
uint64_t val = (uint64_t) object_property_get_int() would work equally well - CC'ing Michael.

Quoted 20 lines
Quoted 1 line

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

Quoted 9 lines
Quoted 4 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 3 lines

#define PCI_HOST_PROPS...
static inline get_

[...]

Quoted 34 lines
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
hw/pci-host/piix.c +0 -0
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }
 
Quoted 16 lines

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 9 lines
hw/pci-host/piix.c +9 -0
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

Quoted 4 lines

user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.
For user friendly property "pci_hole64_size" would be nice to have.

So at the moment I do

qemu -device i440FX-pcihost,help

Quoted 8 lines
Quoted 4 lines

and this will get all properties.

If we add some properties that user can not set
they should not appear in this output.

[snip]

Igor, you can simply use dynamic properties with NULL as setter argument for object_property_add*() to achieve that effect.

Yes, I can but it's more boiler plate code just for restricting single property. And if we have "pci_hole64_size"/default then user set "pci_hole64_end" would not have any effect, since "pci_hole64_size" would override it.

Quoted 5 lines

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
Signature · 2 lines
Regards,
  Igor
#21 lore raw
Quoted 91 lines · Igor Mammedov
Quoted 88 lines · On Sun, 28 Jul 2013 12:17:47 +0200 Andreas Färber <[email protected]> wrote:

Am 28.07.2013 11:11, schrieb Michael S. Tsirkin:

Quoted 16 lines · Igor Mammedov
Quoted 15 lines
Quoted 12 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
 
     info = g_malloc(sizeof *info);
hw/i386/pc.c +4 -4
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

That's how QAPI works internally today for any uint64 visitor/property. uint64_t is cast to int64_t and back in visitors.

So I'd hope something like
uint64_t val = (uint64_t) object_property_get_int() would work equally well - CC'ing Michael.

Quoted 20 lines
Quoted 1 line

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

Quoted 9 lines
Quoted 4 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 3 lines

#define PCI_HOST_PROPS...
static inline get_

[...]

Quoted 38 lines
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
hw/pci-host/piix.c +0 -0
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }
 
Quoted 16 lines

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 9 lines
hw/pci-host/piix.c +9 -0
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

Quoted 4 lines

user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.
For user friendly property "pci_hole64_size" would be nice to have.

So at the moment I do

qemu -device i440FX-pcihost,help

and this will get all properties.

If we add some properties that user can not set
they should not appear in this output.

Quoted 8 lines
Quoted 4 lines

[snip]

Igor, you can simply use dynamic properties with NULL as setter argument for object_property_add*() to achieve that effect.

Yes, I can but it's more boiler plate code just for restricting single property. And if we have "pci_hole64_size"/default then user set "pci_hole64_end" would not have any effect, since "pci_hole64_size" would override it.

I don't think we want user to control low level properties such and _start and _end. _size might be unavoidable but let's limit it to that.

Quoted 10 lines
Quoted 5 lines

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
Signature · 2 lines
Regards,
  Igor
#22 lore raw
In reply to Andreas Färber

Quoting Andreas Färber (2013-07-28 05:17:47)

Quoted 22 lines

Am 28.07.2013 11:11, schrieb Michael S. Tsirkin:

Quoted 16 lines · Igor Mammedov
Quoted 15 lines
Quoted 12 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
 
     info = g_malloc(sizeof *info);
hw/i386/pc.c +4 -4
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

Quoted 6 lines

That's how QAPI works internally today for any uint64 visitor/property. uint64_t is cast to int64_t and back in visitors.

So I'd hope something like
uint64_t val = (uint64_t) object_property_get_int() would work equally well - CC'ing Michael.

It actually depends on the 'wire'/'serialized' encoding of the underlying visitor implementation. In this case we're 'serializing' into a QObject via QmpOutputVisitor, where all integers are actually stored as a QInt/int64 anyway, so this cast is unavoidable in this case regardless of what QAPI interface we use: we'll always end up storing as an int64, requiring us to re-cast to get back to original value. Best we can achieve is burying the cast deeper (or significantly re-working how QObject/QInt works)

There is additional bounds checking performed prior to serialization if the serialized type is less than 64 bits though, so we'd probably want to add fixed-width accessors if we found ourselves in a situation where we needed to cast to a smaller datatype than the original.

It's also worth noting that visiting uint64 types using int64 visitor interfaces isn't universally guaranteed to work: for certain visitor implementations the serialized encodings may not be compatible with one another. But in this case we should be good.

Quoted 69 lines
Quoted 20 lines
Quoted 2 lines

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 2 lines
Quoted 1 line
Quoted 1 line

but not need for extra API, with fixed property definition

i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

Quoted 9 lines
Quoted 4 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 3 lines

#define PCI_HOST_PROPS...
static inline get_

[...]

Quoted 30 lines
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
hw/pci-host/piix.c +0 -0
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }
 
Quoted 16 lines

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 9 lines
hw/pci-host/piix.c +9 -0
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

Quoted 4 lines

user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.
For user friendly property "pci_hole64_size" would be nice to have.

Quoted 8 lines

So at the moment I do

qemu -device i440FX-pcihost,help

and this will get all properties.

If we add some properties that user can not set
they should not appear in this output.

[snip]

Igor, you can simply use dynamic properties with NULL as setter argument for object_property_add*() to achieve that effect.

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
#23 lore raw
In reply to Michael S. Tsirkin
Quoted 92 lines · On Sun, 28 Jul 2013 12:11:42 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

sure as convenience why not, on top of this patches.

Well because you are specifying end as 0xffffffffffffffff so it's not a multiple of 1G?

Quoted 60 lines
Quoted 31 lines
Quoted 31 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +7 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
Quoted 8 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 2 lines
hw/i386/pc.c +2 -0
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

that drawback of dynamic lookup,
QOM paths supposed to be stable.

Quoted 3 lines

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

I've seen objections from afaerber about this approach, so dropped this idea.

Quoted 12 lines
Quoted 11 lines
hw/i386/pc.c +4 -4
     info = g_malloc(sizeof *info);
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 5 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Quoted 8 lines

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

does 32 bit PCI hole has right to be more than 4Gb?

Quoted 195 lines
Quoted 195 lines
Quoted 6 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 187 lines

#define PCI_HOST_PROPS...
static inline get_

Quoted 164 lines
hw/i386/pc.c +24 -18
+    info->w64_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_start", NULL));
+    info->w64_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_end", NULL));
     /* Pass PCI hole info to guest via a side channel.
      * Required so guest PCI enumeration does the right thing. */
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
@@ -1037,29 +1050,31 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
-    guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
-    if (sizeof(hwaddr) == 4) {
-        guest_info->pci_info.w64.begin = 0;
-        guest_info->pci_info.w64.end = 0;
-    } else {
-        /*
-         * BIOS does not set MTRR entries for the 64 bit window, so no need to
-         * align address to power of two.  Align address at 1G, this makes sure
-         * it can be exactly covered with a PAT entry even when using huge
-         * pages.
-         */
-        guest_info->pci_info.w64.begin =
-            ROUND_UP((0x1ULL << 32) + above_4g_mem_size, 0x1ULL << 30);
-        guest_info->pci_info.w64.end = guest_info->pci_info.w64.begin +
-            (0x1ULL << 62);
-        assert(guest_info->pci_info.w64.begin <= guest_info->pci_info.w64.end);
-    }
-
     guest_info_state->machine_done.notify = pc_guest_info_machine_done;
     qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
     return guest_info;
 }
 
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start)
+{
+    if (sizeof(hwaddr) == 4) {
+        memset(&pci_info->w64, sizeof(pci_info->w64), 0);
+        return;
+    }
+    /*
+     * BIOS does not set MTRR entries for the 64 bit window, so no need to
+     * align address to power of two.  Align address at 1G, this makes sure
+     * it can be exactly covered with a PAT entry even when using huge
+     * pages.
+     */
+    pci_info->w64.begin = ROUND_UP(pci_hole64_start, 0x1ULL << 30);
+    if (!pci_info->w64.end) {
+        /* set default end if it wasn't specified, + 2 Gb past start */
+        pci_info->w64.end = pci_info->w64.begin + (0x1ULL << 31);
+    }
+    assert(pci_info->w64.begin < pci_info->w64.end);
+}
+
 void pc_acpi_init(const char *default_dsdt)
 {
     char *filename;
hw/i386/pc_piix.c +1 -13
index b58c255..ab25458 100644
@@ -129,15 +129,6 @@ static void pc_init1(MemoryRegion *system_memory,
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = has_pci_info;
 
-    /* Set PCI window size the way seabios has always done it. */
-    /* Power of 2 so bios can cover it with a single MTRR */
-    if (ram_size <= 0x80000000)
-        guest_info->pci_info.w32.begin = 0x80000000;
-    else if (ram_size <= 0xc0000000)
-        guest_info->pci_info.w32.begin = 0xc0000000;
-    else
-        guest_info->pci_info.w32.begin = 0xe0000000;
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         fw_cfg = pc_memory_init(system_memory,
@@ -160,10 +151,7 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
+                              above_4g_mem_size,
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
hw/pci-host/piix.c +23 -4
index 4624d04..59a42c5 100644
@@ -32,6 +32,7 @@
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/ioapic.h"
 
 /*
  * I440FX chipset data sheet.
@@ -44,6 +45,7 @@
 
 typedef struct I440FXState {
     PCIHostState parent_obj;
+    PcPciInfo pci_info;
 } I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
@@ -247,8 +249,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_address_space,
                     MemoryRegion *ram_memory)
 {
@@ -259,6 +260,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     PIIX3State *piix3;
     PCII440FXState *f;
     unsigned i;
+    I440FXState *i440fx;
+    uint64_t pci_hole64_size;
 
     dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
@@ -274,14 +277,30 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    i440fx = I440FX_PCI_HOST(dev);
+    /* Set PCI window size the way seabios has always done it. */
+    /* Power of 2 so bios can cover it with a single MTRR */
+    if (ram_size <= 0x80000000) {
+        i440fx->pci_info.w32.begin = 0x80000000;
+    } else if (ram_size <= 0xc0000000) {
+        i440fx->pci_info.w32.begin = 0xc0000000;
+    } else {
+        i440fx->pci_info.w32.begin = 0xe0000000;
+    }
+
     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);
+
+    pc_init_pci64_hole(&i440fx->pci_info, 0x100000000ULL + above_4g_mem_size);
+    pci_hole64_size = range_size(i440fx->pci_info.w64);
     memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64",
                              f->pci_address_space,
-                             pci_hole64_start, pci_hole64_size);
+                             i440fx->pci_info.w64.begin, pci_hole64_size);
     if (pci_hole64_size) {
-        memory_region_add_subregion(f->system_memory, pci_hole64_start,
+        memory_region_add_subregion(f->system_memory,
+                                    i440fx->pci_info.w64.begin,
                                     &f->pci_hole_64bit);
     }
     memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 10 lines
hw/pci-host/piix.c +9 -0
 
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 4 lines
Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

it might be the way to do it.

Quoted 6 lines
Quoted 5 lines

user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.
For user friendly property "pci_hole64_size" would be nice to have.

Quoted 8 lines

So at the moment I do

qemu -device i440FX-pcihost,help

and this will get all properties.

If we add some properties that user can not set
they should not appear in this output.

with QOM all around I wouldn't say so, it could be property only for internal purposes and QOM properties do not care about whether they are visible or not to user so far. I guess we could document it in code like do not touch /internal or ...

Quoted 127 lines
Quoted 126 lines
Quoted 121 lines
Quoted 120 lines
hw/pci-host/piix.c +1 -0
 static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -638,6 +666,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
     dc->realize = i440fx_pcihost_realize;
     dc->fw_name = "pci";
     dc->no_user = 1;
+    dc->props = i440fx_props;
 }
 
 static const TypeInfo i440fx_pcihost_info = {
hw/pci-host/q35.c +20 -12
index 6b1b3b7..a6936e6 100644
@@ -67,6 +67,21 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge,
 static Property mch_props[] = {
     DEFINE_PROP_UINT64("MCFG", Q35PCIHost, parent_obj.base_addr,
                         MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
+    DEFINE_PROP_UINT64("pci_hole64_start", Q35PCIHost,
+                       mch.pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", Q35PCIHost,
+                       mch.pci_info.w64.end, 0),
+    /* Leave enough space for the biggest MCFG BAR */
+    /* TODO: this matches current bios behaviour, but
+     * it's not a power of two, which means an MTRR
+     * can't cover it exactly.
+     */
+    DEFINE_PROP_UINT64("pci_hole_start", Q35PCIHost,
+                       mch.pci_info.w32.begin,
+                       MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
+                       MCH_HOST_BRIDGE_PCIEXBAR_MAX),
+    DEFINE_PROP_UINT64("pci_hole_end", Q35PCIHost,
+                       mch.pci_info.w32.end, IO_APIC_DEFAULT_ADDRESS),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -255,14 +270,6 @@ static int mch_init(PCIDevice *d)
     hwaddr pci_hole64_size;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
 
-    /* Leave enough space for the biggest MCFG BAR */
-    /* TODO: this matches current bios behaviour, but
-     * it's not a power of two, which means an MTRR
-     * can't cover it exactly.
-     */
-    mch->guest_info->pci_info.w32.begin = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
-        MCH_HOST_BRIDGE_PCIEXBAR_MAX;
-
     /* setup pci memory regions */
     memory_region_init_alias(&mch->pci_hole, OBJECT(mch), "pci-hole",
                              mch->pci_address_space,
@@ -270,15 +277,16 @@ static int mch_init(PCIDevice *d)
                              0x100000000ULL - mch->below_4g_mem_size);
     memory_region_add_subregion(mch->system_memory, mch->below_4g_mem_size,
                                 &mch->pci_hole);
-    pci_hole64_size = (sizeof(hwaddr) == 4 ? 0 :
-                       ((uint64_t)1 << 62));
+
+    pc_init_pci64_hole(&mch->pci_info, 0x100000000ULL + mch->above_4g_mem_size);
+    pci_hole64_size = range_size(mch->pci_info.w64);
     memory_region_init_alias(&mch->pci_hole_64bit, OBJECT(mch), "pci-hole64",
                              mch->pci_address_space,
-                             0x100000000ULL + mch->above_4g_mem_size,
+                             mch->pci_info.w64.begin,
                              pci_hole64_size);
     if (pci_hole64_size) {
         memory_region_add_subregion(mch->system_memory,
-                                    0x100000000ULL + mch->above_4g_mem_size,
+                                    mch->pci_info.w64.begin,
                                     &mch->pci_hole_64bit);
     }
     /* smram */
include/hw/i386/pc.h +2 -3
index 7fb97b0..ab747b7 100644
@@ -18,7 +18,6 @@ typedef struct PcPciInfo {
 } PcPciInfo;
 
 struct PcGuestInfo {
-    PcPciInfo pci_info;
     bool has_pci_info;
     FWCfgState *fw_cfg;
 };
@@ -100,6 +99,7 @@ void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
                                 ram_addr_t above_4g_mem_size);
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start);
 
 FWCfgState *pc_memory_init(MemoryRegion *system_memory,
                            const char *kernel_filename,
@@ -150,8 +150,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_memory,
                     MemoryRegion *ram_memory);
 
include/hw/pci-host/q35.h +1 -0
index 3cb631e..3a9e04b 100644
@@ -55,6 +55,7 @@ typedef struct MCHPCIState {
     MemoryRegion smram_region;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    PcPciInfo pci_info;
     uint8_t smm_enabled;
     ram_addr_t below_4g_mem_size;
     ram_addr_t above_4g_mem_size;
Signature · 1 line
1.8.3.1
Signature · 2 lines
Regards,
  Igor
Signature · 2 lines
Regards,
  Igor
#24 lore raw
Quoted 98 lines · Igor Mammedov
Quoted 95 lines · On Sun, 28 Jul 2013 12:11:42 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

sure as convenience why not, on top of this patches.

Well because you are specifying end as 0xffffffffffffffff so it's not a multiple of 1G?

Quoted 60 lines
Quoted 31 lines
Quoted 31 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +7 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
Quoted 8 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 2 lines
hw/i386/pc.c +2 -0
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

that drawback of dynamic lookup,
QOM paths supposed to be stable.

Quoted 3 lines

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

I've seen objections from afaerber about this approach, so dropped this idea.

Quoted 12 lines
Quoted 11 lines
hw/i386/pc.c +4 -4
     info = g_malloc(sizeof *info);
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 5 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

does 32 bit PCI hole has right to be more than 4Gb?

No but the 64 bit one does. 32 one shouldn't be user controllable at all.

Quoted 353 lines
Quoted 195 lines
Quoted 195 lines
Quoted 6 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 187 lines

#define PCI_HOST_PROPS...
static inline get_

Quoted 164 lines
hw/i386/pc.c +24 -18
+    info->w64_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_start", NULL));
+    info->w64_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_end", NULL));
     /* Pass PCI hole info to guest via a side channel.
      * Required so guest PCI enumeration does the right thing. */
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
@@ -1037,29 +1050,31 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
-    guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
-    if (sizeof(hwaddr) == 4) {
-        guest_info->pci_info.w64.begin = 0;
-        guest_info->pci_info.w64.end = 0;
-    } else {
-        /*
-         * BIOS does not set MTRR entries for the 64 bit window, so no need to
-         * align address to power of two.  Align address at 1G, this makes sure
-         * it can be exactly covered with a PAT entry even when using huge
-         * pages.
-         */
-        guest_info->pci_info.w64.begin =
-            ROUND_UP((0x1ULL << 32) + above_4g_mem_size, 0x1ULL << 30);
-        guest_info->pci_info.w64.end = guest_info->pci_info.w64.begin +
-            (0x1ULL << 62);
-        assert(guest_info->pci_info.w64.begin <= guest_info->pci_info.w64.end);
-    }
-
     guest_info_state->machine_done.notify = pc_guest_info_machine_done;
     qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
     return guest_info;
 }
 
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start)
+{
+    if (sizeof(hwaddr) == 4) {
+        memset(&pci_info->w64, sizeof(pci_info->w64), 0);
+        return;
+    }
+    /*
+     * BIOS does not set MTRR entries for the 64 bit window, so no need to
+     * align address to power of two.  Align address at 1G, this makes sure
+     * it can be exactly covered with a PAT entry even when using huge
+     * pages.
+     */
+    pci_info->w64.begin = ROUND_UP(pci_hole64_start, 0x1ULL << 30);
+    if (!pci_info->w64.end) {
+        /* set default end if it wasn't specified, + 2 Gb past start */
+        pci_info->w64.end = pci_info->w64.begin + (0x1ULL << 31);
+    }
+    assert(pci_info->w64.begin < pci_info->w64.end);
+}
+
 void pc_acpi_init(const char *default_dsdt)
 {
     char *filename;
hw/i386/pc_piix.c +1 -13
index b58c255..ab25458 100644
@@ -129,15 +129,6 @@ static void pc_init1(MemoryRegion *system_memory,
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = has_pci_info;
 
-    /* Set PCI window size the way seabios has always done it. */
-    /* Power of 2 so bios can cover it with a single MTRR */
-    if (ram_size <= 0x80000000)
-        guest_info->pci_info.w32.begin = 0x80000000;
-    else if (ram_size <= 0xc0000000)
-        guest_info->pci_info.w32.begin = 0xc0000000;
-    else
-        guest_info->pci_info.w32.begin = 0xe0000000;
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         fw_cfg = pc_memory_init(system_memory,
@@ -160,10 +151,7 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
+                              above_4g_mem_size,
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
hw/pci-host/piix.c +23 -4
index 4624d04..59a42c5 100644
@@ -32,6 +32,7 @@
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/ioapic.h"
 
 /*
  * I440FX chipset data sheet.
@@ -44,6 +45,7 @@
 
 typedef struct I440FXState {
     PCIHostState parent_obj;
+    PcPciInfo pci_info;
 } I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
@@ -247,8 +249,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_address_space,
                     MemoryRegion *ram_memory)
 {
@@ -259,6 +260,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     PIIX3State *piix3;
     PCII440FXState *f;
     unsigned i;
+    I440FXState *i440fx;
+    uint64_t pci_hole64_size;
 
     dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
@@ -274,14 +277,30 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    i440fx = I440FX_PCI_HOST(dev);
+    /* Set PCI window size the way seabios has always done it. */
+    /* Power of 2 so bios can cover it with a single MTRR */
+    if (ram_size <= 0x80000000) {
+        i440fx->pci_info.w32.begin = 0x80000000;
+    } else if (ram_size <= 0xc0000000) {
+        i440fx->pci_info.w32.begin = 0xc0000000;
+    } else {
+        i440fx->pci_info.w32.begin = 0xe0000000;
+    }
+
     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);
+
+    pc_init_pci64_hole(&i440fx->pci_info, 0x100000000ULL + above_4g_mem_size);
+    pci_hole64_size = range_size(i440fx->pci_info.w64);
     memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64",
                              f->pci_address_space,
-                             pci_hole64_start, pci_hole64_size);
+                             i440fx->pci_info.w64.begin, pci_hole64_size);
     if (pci_hole64_size) {
-        memory_region_add_subregion(f->system_memory, pci_hole64_start,
+        memory_region_add_subregion(f->system_memory,
+                                    i440fx->pci_info.w64.begin,
                                     &f->pci_hole_64bit);
     }
     memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 10 lines
hw/pci-host/piix.c +9 -0
 
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 4 lines
Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

it might be the way to do it.

Quoted 6 lines
Quoted 5 lines

user better not to touch these properties since they are mostly internal API. but if we say it's internal properties then enforcing read-only might be overkill.
For user friendly property "pci_hole64_size" would be nice to have.

Quoted 8 lines

So at the moment I do

qemu -device i440FX-pcihost,help

and this will get all properties.

If we add some properties that user can not set
they should not appear in this output.

with QOM all around I wouldn't say so, it could be property only for internal purposes and QOM properties do not care about whether they are visible or not to user so far. I guess we could document it in code like do not touch /internal or ...

Quoted 127 lines
Quoted 126 lines
Quoted 121 lines
Quoted 120 lines
hw/pci-host/piix.c +1 -0
 static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -638,6 +666,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
     dc->realize = i440fx_pcihost_realize;
     dc->fw_name = "pci";
     dc->no_user = 1;
+    dc->props = i440fx_props;
 }
 
 static const TypeInfo i440fx_pcihost_info = {
hw/pci-host/q35.c +20 -12
index 6b1b3b7..a6936e6 100644
@@ -67,6 +67,21 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge,
 static Property mch_props[] = {
     DEFINE_PROP_UINT64("MCFG", Q35PCIHost, parent_obj.base_addr,
                         MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
+    DEFINE_PROP_UINT64("pci_hole64_start", Q35PCIHost,
+                       mch.pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", Q35PCIHost,
+                       mch.pci_info.w64.end, 0),
+    /* Leave enough space for the biggest MCFG BAR */
+    /* TODO: this matches current bios behaviour, but
+     * it's not a power of two, which means an MTRR
+     * can't cover it exactly.
+     */
+    DEFINE_PROP_UINT64("pci_hole_start", Q35PCIHost,
+                       mch.pci_info.w32.begin,
+                       MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
+                       MCH_HOST_BRIDGE_PCIEXBAR_MAX),
+    DEFINE_PROP_UINT64("pci_hole_end", Q35PCIHost,
+                       mch.pci_info.w32.end, IO_APIC_DEFAULT_ADDRESS),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -255,14 +270,6 @@ static int mch_init(PCIDevice *d)
     hwaddr pci_hole64_size;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
 
-    /* Leave enough space for the biggest MCFG BAR */
-    /* TODO: this matches current bios behaviour, but
-     * it's not a power of two, which means an MTRR
-     * can't cover it exactly.
-     */
-    mch->guest_info->pci_info.w32.begin = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +
-        MCH_HOST_BRIDGE_PCIEXBAR_MAX;
-
     /* setup pci memory regions */
     memory_region_init_alias(&mch->pci_hole, OBJECT(mch), "pci-hole",
                              mch->pci_address_space,
@@ -270,15 +277,16 @@ static int mch_init(PCIDevice *d)
                              0x100000000ULL - mch->below_4g_mem_size);
     memory_region_add_subregion(mch->system_memory, mch->below_4g_mem_size,
                                 &mch->pci_hole);
-    pci_hole64_size = (sizeof(hwaddr) == 4 ? 0 :
-                       ((uint64_t)1 << 62));
+
+    pc_init_pci64_hole(&mch->pci_info, 0x100000000ULL + mch->above_4g_mem_size);
+    pci_hole64_size = range_size(mch->pci_info.w64);
     memory_region_init_alias(&mch->pci_hole_64bit, OBJECT(mch), "pci-hole64",
                              mch->pci_address_space,
-                             0x100000000ULL + mch->above_4g_mem_size,
+                             mch->pci_info.w64.begin,
                              pci_hole64_size);
     if (pci_hole64_size) {
         memory_region_add_subregion(mch->system_memory,
-                                    0x100000000ULL + mch->above_4g_mem_size,
+                                    mch->pci_info.w64.begin,
                                     &mch->pci_hole_64bit);
     }
     /* smram */
include/hw/i386/pc.h +2 -3
index 7fb97b0..ab747b7 100644
@@ -18,7 +18,6 @@ typedef struct PcPciInfo {
 } PcPciInfo;
 
 struct PcGuestInfo {
-    PcPciInfo pci_info;
     bool has_pci_info;
     FWCfgState *fw_cfg;
 };
@@ -100,6 +99,7 @@ void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
                                 ram_addr_t above_4g_mem_size);
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start);
 
 FWCfgState *pc_memory_init(MemoryRegion *system_memory,
                            const char *kernel_filename,
@@ -150,8 +150,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_memory,
                     MemoryRegion *ram_memory);
 
include/hw/pci-host/q35.h +1 -0
index 3cb631e..3a9e04b 100644
@@ -55,6 +55,7 @@ typedef struct MCHPCIState {
     MemoryRegion smram_region;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
+    PcPciInfo pci_info;
     uint8_t smm_enabled;
     ram_addr_t below_4g_mem_size;
     ram_addr_t above_4g_mem_size;
Signature · 1 line
1.8.3.1
Signature · 2 lines
Regards,
  Igor
Signature · 2 lines
Regards,
  Igor
#25 lore raw
Quoted 102 lines · On Sun, 28 Jul 2013 22:51:57 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 101 lines · Igor Mammedov
Quoted 98 lines · On Sun, 28 Jul 2013 12:11:42 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

sure as convenience why not, on top of this patches.

Well because you are specifying end as 0xffffffffffffffff so it's not a multiple of 1G?

Quoted 60 lines
Quoted 31 lines
Quoted 31 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +7 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
Quoted 8 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 2 lines
hw/i386/pc.c +2 -0
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

that drawback of dynamic lookup,
QOM paths supposed to be stable.

Quoted 3 lines

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

I've seen objections from afaerber about this approach, so dropped this idea.

Quoted 12 lines
Quoted 11 lines
hw/i386/pc.c +4 -4
     info = g_malloc(sizeof *info);
-    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
-    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
-    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
-    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
+    info->w32_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_start", NULL));
+    info->w32_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole_end", NULL));
Quoted 5 lines
Quoted 4 lines

Looks wrong.
object_property_get_int returns a signed int64. w32 is unsigned.
Happens to work but I think we need an explicit API.

I guess it's copy-past error s/cpu_to_le64/cpu_to_le32/

Not these are 64 bit values, but they need to be
unsigned not signed.

Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

Quoted 207 lines
Quoted 3 lines
Quoted 2 lines

If you replace these with UINT32 you won't be able to specify values >4G.

does 32 bit PCI hole has right to be more than 4Gb?

No but the 64 bit one does. 32 one shouldn't be user controllable at all.

Quoted 200 lines
Quoted 195 lines
Quoted 195 lines
Quoted 6 lines

Property names are hard-coded string literals. Please add macros to set and get them
so we can avoid duplicating code.
E.g.

sure.

Quoted 187 lines

#define PCI_HOST_PROPS...
static inline get_

Quoted 164 lines
hw/i386/pc.c +24 -18
+    info->w64_min = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_start", NULL));
+    info->w64_max = cpu_to_le64(object_property_get_int(pci_info,
+                                "pci_hole64_end", NULL));
     /* Pass PCI hole info to guest via a side channel.
      * Required so guest PCI enumeration does the right thing. */
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
@@ -1037,29 +1050,31 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
-    guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
-    if (sizeof(hwaddr) == 4) {
-        guest_info->pci_info.w64.begin = 0;
-        guest_info->pci_info.w64.end = 0;
-    } else {
-        /*
-         * BIOS does not set MTRR entries for the 64 bit window, so no need to
-         * align address to power of two.  Align address at 1G, this makes sure
-         * it can be exactly covered with a PAT entry even when using huge
-         * pages.
-         */
-        guest_info->pci_info.w64.begin =
-            ROUND_UP((0x1ULL << 32) + above_4g_mem_size, 0x1ULL << 30);
-        guest_info->pci_info.w64.end = guest_info->pci_info.w64.begin +
-            (0x1ULL << 62);
-        assert(guest_info->pci_info.w64.begin <= guest_info->pci_info.w64.end);
-    }
-
     guest_info_state->machine_done.notify = pc_guest_info_machine_done;
     qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
     return guest_info;
 }
 
+void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start)
+{
+    if (sizeof(hwaddr) == 4) {
+        memset(&pci_info->w64, sizeof(pci_info->w64), 0);
+        return;
+    }
+    /*
+     * BIOS does not set MTRR entries for the 64 bit window, so no need to
+     * align address to power of two.  Align address at 1G, this makes sure
+     * it can be exactly covered with a PAT entry even when using huge
+     * pages.
+     */
+    pci_info->w64.begin = ROUND_UP(pci_hole64_start, 0x1ULL << 30);
+    if (!pci_info->w64.end) {
+        /* set default end if it wasn't specified, + 2 Gb past start */
+        pci_info->w64.end = pci_info->w64.begin + (0x1ULL << 31);
+    }
+    assert(pci_info->w64.begin < pci_info->w64.end);
+}
+
 void pc_acpi_init(const char *default_dsdt)
 {
     char *filename;
hw/i386/pc_piix.c +1 -13
index b58c255..ab25458 100644
@@ -129,15 +129,6 @@ static void pc_init1(MemoryRegion *system_memory,
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = has_pci_info;
 
-    /* Set PCI window size the way seabios has always done it. */
-    /* Power of 2 so bios can cover it with a single MTRR */
-    if (ram_size <= 0x80000000)
-        guest_info->pci_info.w32.begin = 0x80000000;
-    else if (ram_size <= 0xc0000000)
-        guest_info->pci_info.w32.begin = 0xc0000000;
-    else
-        guest_info->pci_info.w32.begin = 0xe0000000;
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         fw_cfg = pc_memory_init(system_memory,
@@ -160,10 +151,7 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
+                              above_4g_mem_size,
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
hw/pci-host/piix.c +23 -4
index 4624d04..59a42c5 100644
@@ -32,6 +32,7 @@
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/ioapic.h"
 
 /*
  * I440FX chipset data sheet.
@@ -44,6 +45,7 @@
 
 typedef struct I440FXState {
     PCIHostState parent_obj;
+    PcPciInfo pci_info;
 } I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
@@ -247,8 +249,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
                     ram_addr_t ram_size,
                     hwaddr pci_hole_start,
                     hwaddr pci_hole_size,
-                    hwaddr pci_hole64_start,
-                    hwaddr pci_hole64_size,
+                    ram_addr_t above_4g_mem_size,
                     MemoryRegion *pci_address_space,
                     MemoryRegion *ram_memory)
 {
@@ -259,6 +260,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     PIIX3State *piix3;
     PCII440FXState *f;
     unsigned i;
+    I440FXState *i440fx;
+    uint64_t pci_hole64_size;
 
     dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST);
     s = PCI_HOST_BRIDGE(dev);
@@ -274,14 +277,30 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    i440fx = I440FX_PCI_HOST(dev);
+    /* Set PCI window size the way seabios has always done it. */
+    /* Power of 2 so bios can cover it with a single MTRR */
+    if (ram_size <= 0x80000000) {
+        i440fx->pci_info.w32.begin = 0x80000000;
+    } else if (ram_size <= 0xc0000000) {
+        i440fx->pci_info.w32.begin = 0xc0000000;
+    } else {
+        i440fx->pci_info.w32.begin = 0xe0000000;
+    }
+
     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);
+
+    pc_init_pci64_hole(&i440fx->pci_info, 0x100000000ULL + above_4g_mem_size);
+    pci_hole64_size = range_size(i440fx->pci_info.w64);
     memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64",
                              f->pci_address_space,
-                             pci_hole64_start, pci_hole64_size);
+                             i440fx->pci_info.w64.begin, pci_hole64_size);
     if (pci_hole64_size) {
-        memory_region_add_subregion(f->system_memory, pci_hole64_start,
+        memory_region_add_subregion(f->system_memory,
+                                    i440fx->pci_info.w64.begin,
                                     &f->pci_hole_64bit);
     }
     memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
@@ -629,6 +648,15 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
     return "0000";
 }

hw/pci-host/piix.c static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, · line 659

Quoted 10 lines
hw/pci-host/piix.c +9 -0
 
+static Property i440fx_props[] = {
+    DEFINE_PROP_UINT64("pci_hole64_start", I440FXState, pci_info.w64.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole64_end", I440FXState, pci_info.w64.end, 0),
+    DEFINE_PROP_UINT64("pci_hole_start", I440FXState, pci_info.w32.begin, 0),
+    DEFINE_PROP_UINT64("pci_hole_end", I440FXState, pci_info.w32.end,
+                       IO_APIC_DEFAULT_ADDRESS),
+    DEFINE_PROP_END_OF_LIST(),
+};
+

So we have 4 properties. One of them pci_hole64_end is supposed to be set to a value.
Others should not be touched under any circuimstances. Of course if you query properties you have no way to know which is which and what are the legal values. Ouch.

Quoted 4 lines
Quoted 2 lines

read-only properties are possible but we would have to drop usage DEFINE_PROP_UINT64 of and explicitly use only setter in PropertyInfo,

Or add DEFINE_PROP_UINT64_RO for this?

it might be the way to do it.

I've meant to do it only for 32-bit PCI hole, I'm sorry for being unclear.

[...]

#26 lore raw
Quoted 9 lines · Igor Mammedov
Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

but not need for extra API, with fixed property definition i.e. s/UINT64/UNIT32/ property set code will take care about limits.

If you replace these with UINT32 you won't be able to specify values >4G.

does 32 bit PCI hole has right to be more than 4Gb?

No but the 64 bit one does. 32 one shouldn't be user controllable at all.

...

Quoted 3 lines

I've meant to do it only for 32-bit PCI hole, I'm sorry for being unclear.

[...]

That's OK then.

#27 lore raw
In reply to Igor Mammedov
Quoted 61 lines · Igor Mammedov
Quoted 10 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

Quoted 7 lines
Quoted 1 line

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

sure as convenience why not, on top of this patches.

Quoted 31 lines
Quoted 31 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +7 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
Quoted 8 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 2 lines
hw/i386/pc.c +2 -0
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

Quoted 8 lines

that drawback of dynamic lookup,
QOM paths supposed to be stable.

Quoted 3 lines

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

I've seen objections from afaerber about this approach, so dropped this idea.

Could we lookup TYPE_PCI_HOST? This will make pc code independent of specific machine.

Signature · 1 line
MST
#28 lore raw
Quoted 66 lines · On Sun, 28 Jul 2013 12:13:17 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 65 lines · Igor Mammedov
Quoted 10 lines · On Sun, 28 Jul 2013 10:57:12 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

It turns out that some 32 bit windows guests crash if 64 bit PCI hole size is >2G.
Limit it to 2G for piix and q35 by default. User may override default boundaries by using "pci_hole64_end " property.

Examples:
-global i440FX-pcihost.pci_hole64_end=0xffffffffffffffff

Quoted 7 lines
Quoted 1 line

-global q35-pcihost.pci_hole64_end=0xffffffffffffffff

IMO that's pretty bad as user interfaces go. In particular if you are not careful you can make end < start.
Why not set the size, and include a patch that let people write "1G" or "2G" for convenience?

sure as convenience why not, on top of this patches.

Quoted 31 lines
Quoted 31 lines
---
 hw/i386/pc.c              | 59 +++++++++++++++++++++++++++++------------------
 hw/i386/pc_piix.c         | 14 +----------
 hw/pci-host/piix.c        | 37 +++++++++++++++++++++++++----
 hw/pci-host/q35.c         | 32 +++++++++++++++----------
 include/hw/i386/pc.h      |  5 ++--
 include/hw/pci-host/q35.h |  1 +
 6 files changed, 94 insertions(+), 54 deletions(-)
hw/i386/pc.c +7 -0
index b0b98a8..acaeb6c 100644
@@ -1003,15 +1003,28 @@ typedef struct PcRomPciInfo {
 static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
 {
     PcRomPciInfo *info;
+    Object *pci_info;
+
     if (!guest_info->has_pci_info || !guest_info->fw_cfg) {
         return;
     }
+    pci_info = object_resolve_path("/machine/i440fx", NULL);
+    if (!pci_info) {
+        pci_info = object_resolve_path("/machine/q35", NULL);
+        if (!pci_info) {
+            return;
Quoted 8 lines

hw/i386/pc.c typedef struct PcRomPciInfo { · line 1017

Quoted 2 lines
hw/i386/pc.c +2 -0
+        }
+    }

So is the path /machine/i440fx? /machine/i440FX? /machine/i440FX-pcihost?
There's no way to check this code is right without actually running it.

that drawback of dynamic lookup,
QOM paths supposed to be stable.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

How about i44fx_get_pci_info so we can have this knowledge of paths localized in specific chipset code?

I've seen objections from afaerber about this approach, so dropped this idea.

Could we lookup TYPE_PCI_HOST? This will make pc code independent of specific machine.

sure, thanks for idea.

Quoted 3 lines
Signature · 2 lines
-- 
MST
Signature · 2 lines
Regards,
  Igor