qemu-patch-raspberry4/hw/i386
David Hildenbrand 07578b0ad6 qdev: Let the hotplug_handler_unplug() caller delete the device
When unplugging a device, at one point the device will be destroyed
via object_unparent(). This will, one the one hand, unrealize the
removed device hierarchy, and on the other hand, destroy/free the
device hierarchy.

When chaining hotplug handlers, we want to overwrite a bus hotplug
handler by the machine hotplug handler, to be able to perform
some part of the plug/unplug and to forward the calls to the bus hotplug
handler.

For now, the bus hotplug handler would trigger an object_unparent(), not
allowing us to perform some unplug action on a device after we forwarded
the call to the bus hotplug handler. The device would be gone at that
point.

machine_unplug_handler(dev)
    /* eventually do unplug stuff */
    bus_unplug_handler(dev)
    /* dev is gone, we can't do more unplug stuff */

So move the object_unparent() to the original caller of the unplug. For
now, keep the unrealize() at the original places of the
object_unparent(). For implicitly chained hotplug handlers (e.g. pc
code calling acpi hotplug handlers), the object_unparent() has to be
done by the outermost caller. So when calling hotplug_handler_unplug()
from inside an unplug handler, nothing is to be done.

hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
    machine_unplug_handler(dev) {
        /* eventually do unplug stuff */
        bus_unplug_handler(dev) -> calls unrealize(dev)
        /* we can do more unplug stuff but device already unrealized */
    }
object_unparent(dev)

In the long run, every unplug action should be factored out of the
unrealize() function into the unplug handler (especially for PCI). Then
we can get rid of the additonal unrealize() calls and object_unparent()
will properly unrealize the device hierarchy after the device has been
unplugged.

hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
    machine_unplug_handler(dev) {
        /* eventually do unplug stuff */
        bus_unplug_handler(dev) -> only unplugs, does not unrealize
        /* we can do more unplug stuff */
    }
object_unparent(dev) -> will unrealize

The original approach was suggested by Igor Mammedov for the PCI
part, but I extended it to all hotplug handlers. I consider this one
step into the right direction.

To summarize:
- object_unparent() on synchronous unplugs is done by common code
-- "Caller of hotplug_handler_unplug"
- object_unparent() on asynchronous unplugs ("unplug requests") has to
  be done manually
-- "Caller of hotplug_handler_unplug"

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20190228122849.4296-2-david@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-03-06 11:51:08 -03:00
..
kvm ioapic: use TYPE_FOO MACRO than constant string 2019-01-09 11:33:47 +01:00
xen xen: introduce new 'XenBus' and 'XenDevice' object hierarchy 2019-01-14 13:45:40 +00:00
acpi-build.c i386, acpi: cleanup build_facs by removing second unused argument 2019-02-05 10:58:33 -05:00
acpi-build.h Use scripts/clean-includes to drop redundant qemu/typedefs.h 2016-03-22 22:20:16 +01:00
amd_iommu.c x86-iommu: switch intr_supported to OnOffAuto type 2018-12-20 13:25:11 -05:00
amd_iommu.h x86_iommu/amd: Enable Guest virtual APIC support 2018-11-05 13:24:02 -05:00
intel_iommu.c intel_iommu: reset intr_enabled when system reset 2019-02-05 10:58:33 -05:00
intel_iommu_internal.h intel_iommu: dma read/write draining support 2018-12-19 16:48:16 -05:00
kvmvapic.c target: Do not include "exec/exec-all.h" if it is not necessary 2018-06-01 14:15:10 +02:00
Makefile.objs hw/i386/Makefile.objs: Build pc_piix* and pc_q35 boards 2019-02-05 16:50:19 +01:00
multiboot.c elf: Add optional function ptr to load_elf() to parse ELF notes 2019-02-05 16:50:16 +01:00
multiboot.h refer to FWCfgState explicitly 2013-06-02 18:14:02 +03:00
pc.c qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
pc_piix.c boards.h: Ignore migration for SMBus devices on older machines 2019-02-27 21:06:08 -06:00
pc_q35.c boards.h: Ignore migration for SMBus devices on older machines 2019-02-27 21:06:08 -06:00
pc_sysfw.c hw/i386: Use the IEC binary prefix definitions 2018-07-02 15:41:16 +02:00
trace-events intel_iommu: convert invalid traces into error reports 2018-12-19 16:48:16 -05:00
vmmouse.c hw/input/i8042: Extract declarations from i386/pc.h into input/i8042.h 2018-03-12 16:12:48 +01:00
vmport.c hw/input/i8042: Extract declarations from i386/pc.h into input/i8042.h 2018-03-12 16:12:48 +01:00
x86-iommu.c x86-iommu: turn on IR by default if proper 2018-12-20 13:25:11 -05:00