diff options
author | Markus Armbruster <armbru@redhat.com> | 2020-05-05 17:29:24 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2020-05-15 07:08:14 +0200 |
commit | b69c3c21a5d11075d42100d5cfe0a736593fae6b (patch) | |
tree | b34284892cb90e420c8ec9cb909686664052dcde /hw/ppc | |
parent | 40c2281cc3342573bd72895997b5cfaddee36ef2 (diff) |
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
Diffstat (limited to 'hw/ppc')
-rw-r--r-- | hw/ppc/pnv_core.c | 2 | ||||
-rw-r--r-- | hw/ppc/spapr.c | 8 | ||||
-rw-r--r-- | hw/ppc/spapr_cpu_core.c | 2 | ||||
-rw-r--r-- | hw/ppc/spapr_drc.c | 14 | ||||
-rw-r--r-- | hw/ppc/spapr_iommu.c | 2 | ||||
-rw-r--r-- | hw/ppc/spapr_pci.c | 14 | ||||
-rw-r--r-- | hw/ppc/spapr_tpm_proxy.c | 2 |
7 files changed, 17 insertions, 27 deletions
diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index 7033104676..96a446f001 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -275,7 +275,7 @@ static void pnv_core_cpu_unrealize(PnvCore *pc, PowerPCCPU *cpu) object_unparent(OBJECT(cpu)); } -static void pnv_core_unrealize(DeviceState *dev, Error **errp) +static void pnv_core_unrealize(DeviceState *dev) { PnvCore *pc = PNV_CORE(dev); CPUCore *cc = CPU_CORE(dev); diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b73f4d94d3..c0bf8c8d4f 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3670,7 +3670,7 @@ static void spapr_memory_unplug(HotplugHandler *hotplug_dev, DeviceState *dev) SpaprDimmState *ds = spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(dev)); pc_dimm_unplug(PC_DIMM(dev), MACHINE(hotplug_dev)); - object_property_set_bool(OBJECT(dev), false, "realized", NULL); + object_property_set_bool(OBJECT(dev), false, "realized", &error_abort); spapr_pending_dimm_unplugs_remove(spapr, ds); } @@ -3763,7 +3763,7 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev) assert(core_slot); core_slot->cpu = NULL; - object_property_set_bool(OBJECT(dev), false, "realized", NULL); + object_property_set_bool(OBJECT(dev), false, "realized", &error_abort); } static @@ -4036,7 +4036,7 @@ void spapr_phb_release(DeviceState *dev) static void spapr_phb_unplug(HotplugHandler *hotplug_dev, DeviceState *dev) { - object_property_set_bool(OBJECT(dev), false, "realized", NULL); + object_property_set_bool(OBJECT(dev), false, "realized", &error_abort); } static void spapr_phb_unplug_request(HotplugHandler *hotplug_dev, @@ -4072,7 +4072,7 @@ static void spapr_tpm_proxy_unplug(HotplugHandler *hotplug_dev, DeviceState *dev { SpaprMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev)); - object_property_set_bool(OBJECT(dev), false, "realized", NULL); + object_property_set_bool(OBJECT(dev), false, "realized", &error_abort); object_unparent(OBJECT(dev)); spapr->tpm_proxy = NULL; } diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index df5c7742ca..e1f76c74f3 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -218,7 +218,7 @@ static void spapr_cpu_core_reset_handler(void *opaque) spapr_cpu_core_reset(opaque); } -static void spapr_cpu_core_unrealize(DeviceState *dev, Error **errp) +static void spapr_cpu_core_unrealize(DeviceState *dev) { SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc = CPU_CORE(dev); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 728307a992..8b2171f698 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -541,7 +541,7 @@ static void realize(DeviceState *d, Error **errp) trace_spapr_drc_realize_complete(spapr_drc_index(drc)); } -static void unrealize(DeviceState *d, Error **errp) +static void unrealize(DeviceState *d) { SpaprDrc *drc = SPAPR_DR_CONNECTOR(d); Object *root_container; @@ -551,7 +551,7 @@ static void unrealize(DeviceState *d, Error **errp) vmstate_unregister(VMSTATE_IF(drc), &vmstate_spapr_drc, drc); root_container = container_get(object_get_root(), DRC_CONTAINER_PATH); name = g_strdup_printf("%x", spapr_drc_index(drc)); - object_property_del(root_container, name, errp); + object_property_del(root_container, name, &error_abort); g_free(name); } @@ -650,17 +650,11 @@ static void realize_physical(DeviceState *d, Error **errp) qemu_register_reset(drc_physical_reset, drcp); } -static void unrealize_physical(DeviceState *d, Error **errp) +static void unrealize_physical(DeviceState *d) { SpaprDrcPhysical *drcp = SPAPR_DRC_PHYSICAL(d); - Error *local_err = NULL; - - unrealize(d, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } + unrealize(d); vmstate_unregister(VMSTATE_IF(drcp), &vmstate_spapr_drc_physical, drcp); qemu_unregister_reset(drc_physical_reset, drcp); } diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 601b896214..7e1d6d59ac 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -416,7 +416,7 @@ void spapr_tce_table_disable(SpaprTceTable *tcet) tcet->nb_table = 0; } -static void spapr_tce_table_unrealize(DeviceState *dev, Error **errp) +static void spapr_tce_table_unrealize(DeviceState *dev) { SpaprTceTable *tcet = SPAPR_TCE_TABLE(dev); diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 61b84a392d..616034222d 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1627,7 +1627,8 @@ static void spapr_pci_unplug(HotplugHandler *plug_handler, return; } - object_property_set_bool(OBJECT(plugged_dev), false, "realized", NULL); + object_property_set_bool(OBJECT(plugged_dev), false, "realized", + &error_abort); } static void spapr_pci_unplug_request(HotplugHandler *plug_handler, @@ -1715,7 +1716,7 @@ static void spapr_phb_finalizefn(Object *obj) sphb->dtbusname = NULL; } -static void spapr_phb_unrealize(DeviceState *dev, Error **errp) +static void spapr_phb_unrealize(DeviceState *dev) { SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); SysBusDevice *s = SYS_BUS_DEVICE(dev); @@ -1724,7 +1725,6 @@ static void spapr_phb_unrealize(DeviceState *dev, Error **errp) SpaprTceTable *tcet; int i; const unsigned windows_supported = spapr_phb_windows_supported(sphb); - Error *local_err = NULL; spapr_phb_nvgpu_free(sphb); @@ -1745,11 +1745,7 @@ static void spapr_phb_unrealize(DeviceState *dev, Error **errp) } } - remove_drcs(sphb, phb->bus, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } + remove_drcs(sphb, phb->bus, &error_abort); for (i = PCI_NUM_PINS - 1; i >= 0; i--) { if (sphb->lsi_table[i].irq) { @@ -2011,7 +2007,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) return; unrealize: - spapr_phb_unrealize(dev, NULL); + spapr_phb_unrealize(dev); } static int spapr_phb_children_reset(Object *child, void *opaque) diff --git a/hw/ppc/spapr_tpm_proxy.c b/hw/ppc/spapr_tpm_proxy.c index 991615d77a..a01f81f9e0 100644 --- a/hw/ppc/spapr_tpm_proxy.c +++ b/hw/ppc/spapr_tpm_proxy.c @@ -140,7 +140,7 @@ static void spapr_tpm_proxy_realize(DeviceState *d, Error **errp) qemu_register_reset(spapr_tpm_proxy_reset, tpm_proxy); } -static void spapr_tpm_proxy_unrealize(DeviceState *d, Error **errp) +static void spapr_tpm_proxy_unrealize(DeviceState *d) { SpaprTpmProxy *tpm_proxy = SPAPR_TPM_PROXY(d); |