spapr: fix PCI hotplug issue when PHBs don't have index
cover spapr: fix PCI hotplug issue when PHBs don't have index
While working on PHB hotplug for 2.11, a bug was discovered in the PCI DR logic in the PHB code: it relies on the PHB index property to be set but it doesn't enforce it. It is hence possible to create two PHBs with the same index (ie, the default value -1), even though this isn't expected by the rest of the PHB code. The most visible consequence, is that PCI hotplug doesn't work anymore.
It was agreed that the right fix would be to make the index property mandatory. This is too an intrusive change to do during soft/hard freeze though. It is postponed for 2.11.
In the meantime, we can at least have QEMU to detect the error early and to exit with an error message, instead of silently going on with half-broken PHBs.
David,
These patches were made with the future work on PHB hotplug in mind. If the series is too long, a similar result can be achieved with this single change in spapr_dr_connector_new():
- object_property_set_bool(OBJECT(drc), true, "realized", NULL);
+ object_property_set_bool(OBJECT(drc), true, "realized", &error_fatal);
Just tell me, if you prefer the shorter version.
--
Greg
---
Greg Kurz (3):
spapr_drc: abort if object_property_add_child() fails
spapr_drc: add Error ** argument to spapr_dr_connector_new()
spapr: error out if PHB fails to setup PCI DRCs
hw/ppc/spapr.c | 4 ++-- hw/ppc/spapr_drc.c | 6 +++--- hw/ppc/spapr_pci.c | 8 +++++++- include/hw/ppc/spapr_drc.h | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-)
PATCH 1/3 spapr_drc: abort if object_property_add_child() fails
object_property_add_child() can only fail in two cases:
- the child already has a parent, which shouldn't happen since the DRC was allocated a few lines above
- the parent already has a child with the same name, which would mean the caller tries to create a DRC that already exists
In both case, this is a QEMU bug and we should abort.
--- hw/ppc/spapr_drc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_drc.c +1 -1
@@ -541,7 +541,7 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type, drc->owner = owner; prop_name =g_strdup_printf ("dr-connector[%" PRIu32"]" ,spapr_drc_index (drc)); -object_property_add_child (owner, prop_name,OBJECT (drc),NULL ); +object_property_add_child (owner, prop_name,OBJECT (drc), &error_abort);object_property_set_bool (OBJECT (drc), true,"realized" ,NULL );g_free (prop_name);
Re: [Qemu-devel] [for-2.10 PATCH 1/3] spapr_drc: abort if object_property_add_child() fails
Quoted 9 lines · Greg Kurz
object_property_add_child()can only fail in two cases:
- the child already has a parent, which shouldn't happen since the DRC was allocated a few lines above
- the parent already has a child with the same name, which would mean the caller tries to create a DRC that already existsIn both case, this is a QEMU bug and we should abort.
Signed-off-by Greg Kurz <[email protected]>
This is definitely a fix, so applied for 2.10.
Quoted 18 lines
--- hw/ppc/spapr_drc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ppc/spapr_drc.c +1
-1@@ -541,7 +541,7 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type, drc->owner = owner; prop_name =g_strdup_printf ("dr-connector[%" PRIu32"]" ,spapr_drc_index (drc)); -object_property_add_child (owner, prop_name,OBJECT (drc),NULL ); +object_property_add_child (owner, prop_name,OBJECT (drc), &error_abort);object_property_set_bool (OBJECT (drc), true,"realized" ,NULL );g_free (prop_name);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 2/3 spapr_drc: add Error ** argument to spapr_dr_connector_new()
In reply to Greg KurzThis just allow spapr_dr_connector_new() to propagate errors to its callers. It doesn't change any functionality.
--- hw/ppc/spapr.c | 4 ++-- hw/ppc/spapr_drc.c | 4 ++-- hw/ppc/spapr_pci.c | 2 +- include/hw/ppc/spapr_drc.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +2 -2
@@ -2023,7 +2023,7 @@ static void spapr_create_lmb_dr_connectors(sPAPRMachineState *spapr) addr = i * lmb_size + spapr->hotplug_memory.base;spapr_dr_connector_new (OBJECT (spapr),TYPE_SPAPR_DRC_LMB , - addr / lmb_size); + addr / lmb_size,NULL ); } }
@@ -2118,7 +2118,7 @@ static void spapr_init_cpus(sPAPRMachineState *spapr)if (mc->has_hotpluggable_cpus) {spapr_dr_connector_new (OBJECT (spapr),TYPE_SPAPR_DRC_CPU , - (core_id / smp_threads) * smt); + (core_id / smp_threads) * smt,NULL ); }if (i < boot_cores_nr) {
hw/ppc/spapr_drc.c +2 -2
@@ -532,7 +532,7 @@ static void unrealize(DeviceState *d, Error **errp) }sPAPRDRConnector *spapr_dr_connector_new (Object *owner,const char *type, -uint32_t id) +uint32_t id,Error **errp) {sPAPRDRConnector *drc =SPAPR_DR_CONNECTOR (object_new (type));char *prop_name;
@@ -542,7 +542,7 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type, prop_name =g_strdup_printf ("dr-connector[%" PRIu32"]" ,spapr_drc_index (drc));object_property_add_child (owner, prop_name,OBJECT (drc), &error_abort); -object_property_set_bool (OBJECT (drc), true,"realized" ,NULL ); +object_property_set_bool (OBJECT (drc), true,"realized" , errp);g_free (prop_name);return drc;
hw/ppc/spapr_pci.c +1 -1
@@ -1733,7 +1733,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)if (sphb->dr_enabled) {for (i =0 ; i <PCI_SLOT_MAX *8 ; i++) {spapr_dr_connector_new (OBJECT (phb),TYPE_SPAPR_DRC_PCI , - (sphb->index <<16 ) | i); + (sphb->index <<16 ) | i,NULL ); } }
include/hw/ppc/spapr_drc.h +1 -1
@@ -248,7 +248,7 @@ uint32_t spapr_drc_index(sPAPRDRConnector *drc);sPAPRDRConnectorType spapr_drc_type (sPAPRDRConnector *drc);sPAPRDRConnector *spapr_dr_connector_new (Object *owner,const char *type, -uint32_t id); +uint32_t id,Error **errp);sPAPRDRConnector *spapr_drc_by_index (uint32_t index);sPAPRDRConnector *spapr_drc_by_id (const char *type,uint32_t id); int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
PATCH 3/3 spapr: error out if PHB fails to setup PCI DRCs
In reply to Greg KurzIt is currently possible to start QEMU with two PHBs without using the index property:
-device spapr-pci-host-bridge,id=pci1,\
buid=0x800000020000001,\
liobn=0x80000100,\
liobn64=0x80000101,\
mem_win_addr=0x200100000000,\
mem64_win_addr=0x220000000000,\
io_win_addr=0x200000010000 \
-device spapr-pci-host-bridge,id=pci2,\
buid=0x800000020000002,\
liobn=0x80000200,\
liobn64=0x80000201,\
mem_win_addr=0x200180000000,\
mem64_win_addr=0x230000000000,\
io_win_addr=0x200000020000 \Each PHB has its index property equal to -1. As a consequence, each PHB will want to create PCI DRCs with the same ids:
/* allocate connectors for child PCI devices */
if (sphb->dr_enabled) {
for (i = 0; i < PCI_SLOT_MAX * 8; i++) {
spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI,
(sphb->index << 16) | i);
}
}When DRC objects are added to the composition tree, an alias using the DRC id is created in the "/dr-connector" path. But DRC ids are supposed to be globally unique and the alias creation fails, leaving the DRC object unrealized, which isn't expected by the rest of the DR logic.
This has the effect of silently turning-off PCI hotplug support (ie, PCI hotplug no longer works on any PHB and no error message is printed).
This bug always existed and would even cause a non-fatal error to be reported on the console (until recent commit bf26ae32a92a). This patch causes the error message to be printed again and QEMU to exit.
--- hw/ppc/spapr_pci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci.c +8 -1
@@ -1731,9 +1731,16 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)/* allocate connectors for child PCI devices */ if (sphb->dr_enabled) { +Error *local_err =NULL ; +for (i =0 ; i <PCI_SLOT_MAX *8 ; i++) {spapr_dr_connector_new (OBJECT (phb),TYPE_SPAPR_DRC_PCI , - (sphb->index <<16 ) | i,NULL ); + (sphb->index <<16 ) | i, &local_err); +if (local_err) { +error_propagate (errp, local_err); +error_prepend (errp,"Failed to create DRC: " ); +return ; + } } }
Re: [Qemu-devel] [for-2.10 PATCH 3/3] spapr: error out if PHB fails to setup PCI DRCs
Quoted 34 lines · Greg Kurz
It is currently possible to start QEMU with two PHBs without using the index property:
(quoted diff) +0
-2-device spapr-pci-host-bridge,id=pci1,\ buid=0x800000020000001,\ liobn=0x80000100,\ liobn64=0x80000101,\ mem_win_addr=0x200100000000,\ mem64_win_addr=0x220000000000,\ io_win_addr=0x200000010000 \ -device spapr-pci-host-bridge,id=pci2,\ buid=0x800000020000002,\ liobn=0x80000200,\ liobn64=0x80000201,\ mem_win_addr=0x200180000000,\ mem64_win_addr=0x230000000000,\ io_win_addr=0x200000020000 \Each PHB has its index property equal to -1. As a consequence, each PHB will want to create PCI DRCs with the same ids:
/* allocate connectors for child PCI devices */ if (sphb->dr_enabled) { for (i = 0; i < PCI_SLOT_MAX * 8; i++) { spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI, (sphb->index << 16) | i); } }When DRC objects are added to the composition tree, an alias using the DRC id is created in the "/dr-connector" path. But DRC ids are supposed to be globally unique and the alias creation fails, leaving the DRC object unrealized, which isn't expected by the rest of the DR logic.
Quoted 8 lines
This has the effect of silently turning-off PCI hotplug support (ie, PCI hotplug no longer works on any PHB and no error message is printed).
This bug always existed and would even cause a non-fatal error to be reported on the console (until recent commit
bf26ae32a92a). This patch causes the error message to be printed again and QEMU to exit.Signed-off-by Greg Kurz <[email protected]>
Given that the bug isn't a regression, I'm a bit disinclined to merge patches 2&3 this late in 2.10.
It just seems bogus to have all this code to (supposedly) allow bridges without an index, but then have it error out if there's more than one of them.
I think skip straight to the real fix of making index madatory in 2.11.
Quoted 27 lines
--- hw/ppc/spapr_pci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)hw/ppc/spapr_pci.c +8
-1@@ -1731,9 +1731,16 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)/* allocate connectors for child PCI devices */ if (sphb->dr_enabled) { +Error *local_err =NULL ; +for (i =0 ; i <PCI_SLOT_MAX *8 ; i++) {spapr_dr_connector_new (OBJECT (phb),TYPE_SPAPR_DRC_PCI , - (sphb->index <<16 ) | i,NULL ); + (sphb->index <<16 ) | i, &local_err); +if (local_err) { +error_propagate (errp, local_err); +error_prepend (errp,"Failed to create DRC: " ); +return ; + } } }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [for-2.10 PATCH 3/3] spapr: error out if PHB fails to setup PCI DRCs
Quoted 38 lines · On Tue, 8 Aug 2017 16:16:36 +1000 David Gibson <[email protected]>…
Quoted 37 lines · Greg Kurz
It is currently possible to start QEMU with two PHBs without using the index property:
(quoted diff) +0
-2-device spapr-pci-host-bridge,id=pci1,\ buid=0x800000020000001,\ liobn=0x80000100,\ liobn64=0x80000101,\ mem_win_addr=0x200100000000,\ mem64_win_addr=0x220000000000,\ io_win_addr=0x200000010000 \ -device spapr-pci-host-bridge,id=pci2,\ buid=0x800000020000002,\ liobn=0x80000200,\ liobn64=0x80000201,\ mem_win_addr=0x200180000000,\ mem64_win_addr=0x230000000000,\ io_win_addr=0x200000020000 \Each PHB has its index property equal to -1. As a consequence, each PHB will want to create PCI DRCs with the same ids:
/* allocate connectors for child PCI devices */ if (sphb->dr_enabled) { for (i = 0; i < PCI_SLOT_MAX * 8; i++) { spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI, (sphb->index << 16) | i); } }When DRC objects are added to the composition tree, an alias using the DRC id is created in the "/dr-connector" path. But DRC ids are supposed to be globally unique and the alias creation fails, leaving the DRC object unrealized, which isn't expected by the rest of the DR logic.
This has the effect of silently turning-off PCI hotplug support (ie, PCI hotplug no longer works on any PHB and no error message is printed).
Quoted 7 lines
Quoted 5 lines
This bug always existed and would even cause a non-fatal error to be reported on the console (until recent commit
bf26ae32a92a). This patch causes the error message to be printed again and QEMU to exit.Signed-off-by Greg Kurz <[email protected]>Given that the bug isn't a regression, I'm a bit disinclined to merge
FWIW, 2.9 would at least print an error message, but 2.10 doesn't because of commit bf26ae32a92a.
Quoted 6 lines
patches 2&3 this late in 2.10.
It just seems bogus to have all this code to (supposedly) allow bridges without an index, but then have it error out if there's more than one of them.
I agree this is weird.
Quoted 2 lines
I think skip straight to the real fix of making index madatory in 2.11.
Ok.
Quoted 28 lines
Quoted 27 lines
--- hw/ppc/spapr_pci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)hw/ppc/spapr_pci.c +8
-1@@ -1731,9 +1731,16 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)/* allocate connectors for child PCI devices */ if (sphb->dr_enabled) { +Error *local_err =NULL ; +for (i =0 ; i <PCI_SLOT_MAX *8 ; i++) {spapr_dr_connector_new (OBJECT (phb),TYPE_SPAPR_DRC_PCI , - (sphb->index <<16 ) | i,NULL ); + (sphb->index <<16 ) | i, &local_err); +if (local_err) { +error_propagate (errp, local_err); +error_prepend (errp,"Failed to create DRC: " ); +return ; + } } }
Re: [Qemu-devel] [for-2.10 PATCH 3/3] spapr: error out if PHB fails to setup PCI DRCs
Quoted 45 lines · Greg Kurz
Quoted 42 lines · On Tue, 8 Aug 2017 16:16:36 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
It is currently possible to start QEMU with two PHBs without using the index property:
(quoted diff) +0
-2-device spapr-pci-host-bridge,id=pci1,\ buid=0x800000020000001,\ liobn=0x80000100,\ liobn64=0x80000101,\ mem_win_addr=0x200100000000,\ mem64_win_addr=0x220000000000,\ io_win_addr=0x200000010000 \ -device spapr-pci-host-bridge,id=pci2,\ buid=0x800000020000002,\ liobn=0x80000200,\ liobn64=0x80000201,\ mem_win_addr=0x200180000000,\ mem64_win_addr=0x230000000000,\ io_win_addr=0x200000020000 \Each PHB has its index property equal to -1. As a consequence, each PHB will want to create PCI DRCs with the same ids:
/* allocate connectors for child PCI devices */ if (sphb->dr_enabled) { for (i = 0; i < PCI_SLOT_MAX * 8; i++) { spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI, (sphb->index << 16) | i); } }When DRC objects are added to the composition tree, an alias using the DRC id is created in the "/dr-connector" path. But DRC ids are supposed to be globally unique and the alias creation fails, leaving the DRC object unrealized, which isn't expected by the rest of the DR logic.
This has the effect of silently turning-off PCI hotplug support (ie, PCI hotplug no longer works on any PHB and no error message is printed).
This bug always existed and would even cause a non-fatal error to be reported on the console (until recent commit
bf26ae32a92a). This patch causes the error message to be printed again and QEMU to exit.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Greg Kurz <[email protected]>Given that the bug isn't a regression, I'm a bit disinclined to merge
FWIW, 2.9 would at least print an error message, but 2.10 doesn't because of commit
bf26ae32a92a.
Ah, yeah that is a bit nasty. Still, I'm not comfortable with the complexity of patch required to fix it this late in 2.10.
Quoted 44 lines
Quoted 7 lines
patches 2&3 this late in 2.10.
It just seems bogus to have all this code to (supposedly) allow bridges without an index, but then have it error out if there's more than one of them.
I agree this is weird.
Quoted 2 lines
I think skip straight to the real fix of making index madatory in 2.11.
Ok.
Quoted 28 lines
Quoted 27 lines
--- hw/ppc/spapr_pci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)hw/ppc/spapr_pci.c +8
-1@@ -1731,9 +1731,16 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)/* allocate connectors for child PCI devices */ if (sphb->dr_enabled) { +Error *local_err =NULL ; +for (i =0 ; i <PCI_SLOT_MAX *8 ; i++) {spapr_dr_connector_new (OBJECT (phb),TYPE_SPAPR_DRC_PCI , - (sphb->index <<16 ) | i,NULL ); + (sphb->index <<16 ) | i, &local_err); +if (local_err) { +error_propagate (errp, local_err); +error_prepend (errp,"Failed to create DRC: " ); +return ; + } } }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson