Skip to contentSkip to conversation

pc: pcihp: avoid adding ACPI_PCIHP_PROP_BSEL twice

PATCH In review Igor Mammedov 3 participants 4 messages Aug 3, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc: pcihp: avoid adding ACPI_PCIHP_PROP_BSEL twice

PCI hotplug for bridges was introduced only since 2.0 however
acpi_set_bsel()->object_property_add_uint32_ptr(bus, ACPI_PCIHP_PROP_BSEL)
didn't take in account that for legacy mode (1.7) when
PCI hotplug for bridges is unavailable and ACPI_PCIHP_PROP_BSEL property the only bus "PCI.0' has been created earlier at acpi_pcihp_init() time.

We managed to live with it only because of error rised by adding a duplicate property in acpi_set_bsel() has been ignored which resulted in useless leaking of just allocated (int)bus_bsel.

Issue affects only 1.7 machine type as ACPI tables supported by QEMU were introduced at that time, but there wasn't PCI hotplug for bridges till the next release (2.0).

Fix it by removing duplicate ACPI_PCIHP_PROP_BSEL intialization in acpi_pcihp_init() and doing it only in one place acpi_set_pci_info().

PS:
do not ignore error returned by object_property_add_uint32_ptr() and abort QEMU since it's programming error which should be fixed instead of being ignored.

---
 hw/acpi/pcihp.c      | 10 ----------
 hw/i386/acpi-build.c |  4 ++--
 2 files changed, 2 insertions(+), 12 deletions(-)
hw/acpi/pcihp.c +0 -10
index d957d1e..3298d94 100644
@@ -302,16 +302,6 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus,
     s->root= root_bus;
     s->legacy_piix = !bridges_enabled;
 
-    if (s->legacy_piix) {
-        unsigned *bus_bsel = g_malloc(sizeof *bus_bsel);
-
-        s->io_len = ACPI_PCIHP_LEGACY_SIZE;
-
-        *bus_bsel = ACPI_PCIHP_BSEL_DEFAULT;
-        object_property_add_uint32_ptr(OBJECT(root_bus), ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
-    }
-
     memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s,
                           "acpi-pci-hotplug", s->io_len);
     memory_region_add_subregion(address_space_io, s->io_base, &s->io);
hw/i386/acpi-build.c +2 -2
index a26a4bb..7174933 100644
@@ -438,7 +438,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 
         *bus_bsel = (*bsel_alloc)++;
         object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
+                                       bus_bsel, &error_abort);
     }
 
     return bsel_alloc;
@@ -447,7 +447,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 static void acpi_set_pci_info(void)
 {
     PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
-    unsigned bsel_alloc = 0;
+    unsigned bsel_alloc = ACPI_PCIHP_BSEL_DEFAULT;
 
     if (bus) {
         /* Scan all PCI buses. Set property to enable acpi based hotplug. */
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 55 lines · Igor Mammedov

PCI hotplug for bridges was introduced only since 2.0 however
acpi_set_bsel()->object_property_add_uint32_ptr(bus, ACPI_PCIHP_PROP_BSEL)
didn't take in account that for legacy mode (1.7) when
PCI hotplug for bridges is unavailable and ACPI_PCIHP_PROP_BSEL property the only bus "PCI.0' has been created earlier at acpi_pcihp_init() time.

We managed to live with it only because of error rised by adding a duplicate property in acpi_set_bsel() has been ignored which resulted in useless leaking of just allocated (int)bus_bsel.

Issue affects only 1.7 machine type as ACPI tables supported by QEMU were introduced at that time, but there wasn't PCI hotplug for bridges till the next release (2.0).

Fix it by removing duplicate ACPI_PCIHP_PROP_BSEL intialization in acpi_pcihp_init() and doing it only in one place acpi_set_pci_info().

PS:
do not ignore error returned by object_property_add_uint32_ptr() and abort QEMU since it's programming error which should be fixed instead of being ignored.

---
 hw/acpi/pcihp.c      | 10 ----------
 hw/i386/acpi-build.c |  4 ++--
 2 files changed, 2 insertions(+), 12 deletions(-)
hw/acpi/pcihp.c +0 -10
index d957d1e..3298d94 100644
@@ -302,16 +302,6 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus,
     s->root= root_bus;
     s->legacy_piix = !bridges_enabled;
 
-    if (s->legacy_piix) {
-        unsigned *bus_bsel = g_malloc(sizeof *bus_bsel);
-
-        s->io_len = ACPI_PCIHP_LEGACY_SIZE;
-
-        *bus_bsel = ACPI_PCIHP_BSEL_DEFAULT;
-        object_property_add_uint32_ptr(OBJECT(root_bus), ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
-    }
-
     memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s,
                           "acpi-pci-hotplug", s->io_len);
     memory_region_add_subregion(address_space_io, s->io_base, &s->io);
hw/i386/acpi-build.c +0 -0
index a26a4bb..7174933 100644

hw/i386/acpi-build.c static void *acpi_set_bsel(PCIBus *bus, void *opaque) · line 441

Quoted 5 lines
hw/i386/acpi-build.c +1 -1
@@ -438,7 +438,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 
         *bus_bsel = (*bsel_alloc)++;
         object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
+                                       bus_bsel, &error_abort);

Hi Igor,

I think the above hunk should be in a separate patch, but since the patch itself is small enough I am OK with it.

hw/i386/acpi-build.c static void *acpi_set_bsel(PCIBus *bus, void *opaque) · line 453

Quoted 13 lines
hw/i386/acpi-build.c +1 -1
     }
 
     return bsel_alloc;
@@ -447,7 +447,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 static void acpi_set_pci_info(void)
 {
     PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
-    unsigned bsel_alloc = 0;
+    unsigned bsel_alloc = ACPI_PCIHP_BSEL_DEFAULT;
 
     if (bus) {
         /* Scan all PCI buses. Set property to enable acpi based hotplug. */

Thanks,
Marcel

#2 lore raw
Quoted 64 lines · On Wed, 3 Aug 2016 11:17:11 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 55 lines · Igor Mammedov

PCI hotplug for bridges was introduced only since 2.0 however
acpi_set_bsel()->object_property_add_uint32_ptr(bus, ACPI_PCIHP_PROP_BSEL)
didn't take in account that for legacy mode (1.7) when
PCI hotplug for bridges is unavailable and ACPI_PCIHP_PROP_BSEL property the only bus "PCI.0' has been created earlier at acpi_pcihp_init() time.

We managed to live with it only because of error rised by adding a duplicate property in acpi_set_bsel() has been ignored which resulted in useless leaking of just allocated (int)bus_bsel.

Issue affects only 1.7 machine type as ACPI tables supported by QEMU were introduced at that time, but there wasn't PCI hotplug for bridges till the next release (2.0).

Fix it by removing duplicate ACPI_PCIHP_PROP_BSEL intialization in acpi_pcihp_init() and doing it only in one place acpi_set_pci_info().

PS:
do not ignore error returned by object_property_add_uint32_ptr() and abort QEMU since it's programming error which should be fixed instead of being ignored.

---
 hw/acpi/pcihp.c      | 10 ----------
 hw/i386/acpi-build.c |  4 ++--
 2 files changed, 2 insertions(+), 12 deletions(-)
hw/acpi/pcihp.c +0 -10
index d957d1e..3298d94 100644
@@ -302,16 +302,6 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus,
     s->root= root_bus;
     s->legacy_piix = !bridges_enabled;
 
-    if (s->legacy_piix) {
-        unsigned *bus_bsel = g_malloc(sizeof *bus_bsel);
-
-        s->io_len = ACPI_PCIHP_LEGACY_SIZE;
-
-        *bus_bsel = ACPI_PCIHP_BSEL_DEFAULT;
-        object_property_add_uint32_ptr(OBJECT(root_bus), ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
-    }
-
     memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s,
                           "acpi-pci-hotplug", s->io_len);
     memory_region_add_subregion(address_space_io, s->io_base, &s->io);
hw/i386/acpi-build.c +0 -0
index a26a4bb..7174933 100644

hw/i386/acpi-build.c static void *acpi_set_bsel(PCIBus *bus, void *opaque) · line 441

Quoted 5 lines
hw/i386/acpi-build.c +1 -1
@@ -438,7 +438,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 
         *bus_bsel = (*bsel_alloc)++;
         object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
+                                       bus_bsel, &error_abort);  

Hi Igor,

Quoted 2 lines

I think the above hunk should be in a separate patch, but since the patch itself is small enough I am OK with it.

I've been conflicted whether to split or not but decided not to as it exposes issue that the patch fixes and splitting could lead to bisection issues in case this part comes first.

Quoted 12 lines
Quoted 12 lines
hw/i386/acpi-build.c +1 -1
     }
 
     return bsel_alloc;
@@ -447,7 +447,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 static void acpi_set_pci_info(void)
 {
     PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
-    unsigned bsel_alloc = 0;
+    unsigned bsel_alloc = ACPI_PCIHP_BSEL_DEFAULT;
 
Quoted 7 lines

hw/i386/acpi-build.c static void *acpi_set_bsel(PCIBus *bus, void *opaque) · line 453

Quoted 3 lines
hw/i386/acpi-build.c +0 -0
     if (bus) {
         /* Scan all PCI buses. Set property to enable acpi based hotplug. */

Thanks!

Quoted 3 lines

Thanks,
Marcel

Reviewed-by on v1 1/1
#3 lore raw
In reply to Igor Mammedov

Hi

Quoted 40 lines · Igor Mammedov

PCI hotplug for bridges was introduced only since 2.0 however
acpi_set_bsel()->object_property_add_uint32_ptr(bus,
ACPI_PCIHP_PROP_BSEL)
didn't take in account that for legacy mode (1.7) when
PCI hotplug for bridges is unavailable and ACPI_PCIHP_PROP_BSEL property the only bus "PCI.0' has been created earlier at acpi_pcihp_init() time.

We managed to live with it only because of error rised by adding a duplicate property in acpi_set_bsel() has been ignored which resulted in useless leaking of just allocated (int)bus_bsel.

Issue affects only 1.7 machine type as ACPI tables supported by QEMU were introduced at that time, but there wasn't PCI hotplug for bridges till the next release (2.0).

Fix it by removing duplicate ACPI_PCIHP_PROP_BSEL intialization in acpi_pcihp_init() and doing it only in one place acpi_set_pci_info().

PS:
do not ignore error returned by object_property_add_uint32_ptr() and abort QEMU since it's programming error which should be fixed instead of being ignored.

---
 hw/acpi/pcihp.c      | 10 ----------
 hw/i386/acpi-build.c |  4 ++--
 2 files changed, 2 insertions(+), 12 deletions(-)
hw/acpi/pcihp.c +0 -1
index d957d1e..3298d94 100644
@@ -302,16 +302,6 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState
 *s, PCIBus *root_bus,
     s->root= root_bus;
     s->legacy_piix = !bridges_enabled;
 
-    if (s->legacy_piix) {

hw/acpi/pcihp.c void acpi_pcihp_init(Object *owner, AcpiPciHpState · line 307

Quoted 10 lines
hw/acpi/pcihp.c +0 -8
-        unsigned *bus_bsel = g_malloc(sizeof *bus_bsel);
-
-        s->io_len = ACPI_PCIHP_LEGACY_SIZE;
-
-        *bus_bsel = ACPI_PCIHP_BSEL_DEFAULT;
-        object_property_add_uint32_ptr(OBJECT(root_bus),
 ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
-    }
 

After this patch, ACPI_PCIHP_LEGACY_SIZE is unused. I suggest to remove it too.

thanks

Quoted 31 lines
hw/acpi/pcihp.c +0 -1
-
     memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s,
                           "acpi-pci-hotplug", s->io_len);
     memory_region_add_subregion(address_space_io, s->io_base, &s->io);
hw/i386/acpi-build.c +2 -2
index a26a4bb..7174933 100644
@@ -438,7 +438,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 
         *bus_bsel = (*bsel_alloc)++;
         object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
-                                       bus_bsel, NULL);
+                                       bus_bsel, &error_abort);
     }
 
     return bsel_alloc;
@@ -447,7 +447,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 static void acpi_set_pci_info(void)
 {
     PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
-    unsigned bsel_alloc = 0;
+    unsigned bsel_alloc = ACPI_PCIHP_BSEL_DEFAULT;
 
     if (bus) {
         /* Scan all PCI buses. Set property to enable acpi based hotplug.

*/
--
2.7.4

Quoted 1 line

--

Marc-André Lureau