qemu-patch-raspberry4/hw
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
..
9pfs xen: re-name XenDevice to XenLegacyDevice... 2019-01-14 13:45:40 +00:00
acpi qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
adc Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
alpha hw/alpha/Makefile.objs: Create CONFIG_* for alpha 2019-02-05 16:50:20 +01:00
arm hw/arm/stellaris: Implement watchdog timer 2019-03-05 15:55:09 +00:00
audio i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
block block/pflash_cfi02: Fix memory leak and potential use-after-free 2019-03-06 10:37:23 +01:00
bt char: allow specifying a GMainContext at opening time 2019-02-13 14:23:39 +01:00
char hw/char/pl011: Use '0x' prefix when logging hex numbers 2019-02-21 18:17:46 +00:00
core qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
cpu hw/cpu/cluster: Mark the cpu-cluster device with user_creatable = false 2019-02-06 15:55:56 +01:00
cris hw/cris/Makefile.objs: Create CONFIG_* for cris 2019-02-05 16:50:20 +01:00
display i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
dma hw/dma/i8257: Use qemu_log_mask(UNIMP) instead of fprintf 2019-02-14 11:46:30 +01:00
gpio i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
hppa hw/hppa/dino: mask out lower 2 bits of PCI config addr 2019-02-21 10:16:19 -08:00
hyperv hw/hyperv: fix NULL dereference with pure-kvm SynIC 2018-11-26 14:14:38 -02:00
i2c i2c: Verify that the count passed in to smbus_eeprom_init() is valid 2019-02-27 21:06:08 -06:00
i386 qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
ide hw/ide: drop iov field from IDEDMA 2019-02-22 09:42:13 +00:00
input i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
intc hw/ppc: Use object_initialize_child for correct reference counting 2019-02-26 09:21:25 +11:00
ipack hw/ipack: Use the IEC binary prefix definitions 2018-07-02 15:41:12 +02:00
ipmi ipmi: Use proper struct reference for BT vmstate 2018-08-23 18:46:25 +02:00
isa i2c: Split smbus into parts 2019-02-27 21:06:08 -06:00
lm32 hw/lm32/Makefile.objs: Conditionally build lm32 and milkmyst 2019-02-05 16:50:20 +01:00
m68k hw/m68k/mcf5208: Support loading of bios images 2019-02-28 12:18:18 +01:00
mem pc-dimm: use same mechanism for [get|set]_addr 2019-02-21 12:28:41 -05:00
microblaze hw/microblaze/Makefile.objs: Create configs for petalogix and xilinx boards 2019-02-05 16:50:19 +01:00
mips i2c: Split smbus into parts 2019-02-27 21:06:08 -06:00
misc This has been out there long enough, I need to get this in. 2019-03-01 11:20:49 +00:00
moxie hw/moxie/Makefile.objs: Conditionally build moxie 2019-02-05 16:50:20 +01:00
net virtio-net: Allow qemu_announce_self to trigger virtio announcements 2019-03-05 11:27:41 +08:00
nios2 hw/nios2/Makefile.objs: Conditionally build nios2 2019-02-05 16:50:20 +01:00
nvram i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
openrisc hw/openrisc/Makefile.objs: Create CONFIG_* for openrisc 2019-02-05 16:50:21 +01:00
pci qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
pci-bridge pci/shpc: perform unplug via the hotplug handler 2018-12-20 11:19:12 -05:00
pci-host hw/pci-host/bonito.c: Add PCI mem region mapped at the correct address 2019-02-21 19:36:47 +01:00
pcmcia hw: Clean up includes 2016-01-29 15:07:25 +00:00
ppc qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
rdma hw/rdma: modify struct initialization 2019-01-19 11:01:33 +02:00
riscv riscv: Ensure the kernel start address is correctly cast 2019-02-11 15:56:22 -08:00
s390x qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
scsi qdev: pass an Object * to qbus_set_hotplug_handler() 2019-02-17 21:54:02 +11:00
sd hw: sd: set category of the sd memory card 2019-01-30 10:24:20 +01:00
sh4 * cpu-exec fixes (Emilio, Laurent) 2019-02-05 19:39:22 +00:00
smbios hw/smbios: fix offset of type 3 sku field 2019-02-22 10:51:31 -05:00
sparc qemu-sparc queue 2019-02-07 16:49:30 +00:00
sparc64 hw/sparc64: Explicitly set default_display = "std" 2019-02-14 11:46:30 +01:00
ssi aspeed/smc: snoop SPI transfers to fake dummy cycles 2019-01-29 11:46:05 +00:00
timer i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
tpm tpm_tis: convert tpm_tis_show_buffer() to use trace event 2019-02-24 14:46:14 -05:00
tricore hw/tricore/Makefile.objs: Create CONFIG_* for tricore 2019-02-05 16:50:21 +01:00
unicore32 hw/unicore32/puv3: Drop useless inclusion of "hw/i386/pc.h" 2019-02-06 15:54:12 +01:00
usb hw/usb: switch MTP to use new inotify APIs 2019-02-26 15:25:58 +00:00
vfio s390x updates: 2019-03-04 13:38:54 +00:00
virtio pci, pc, virtio: fixes, cleanups, tests 2019-03-04 11:04:31 +00:00
watchdog hw/arm/stellaris: Implement watchdog timer 2019-03-05 15:55:09 +00:00
xen xen: fix xen-bus state model to allow frontend re-connection 2019-02-04 11:04:49 +00:00
xenpv xen: Replace few mentions of xend by libxl 2019-01-14 13:45:40 +00:00
xtensa hw/xtensa/Makefile.objs: Build xtensa_sim and xtensa_fpga conditionally 2019-02-05 16:50:20 +01:00
Makefile.objs hw/vfio/Makefile.objs: Create new CONFIG_* variables for VFIO core and PCI 2019-02-05 16:50:21 +01:00