qemu-e2k/target/i386
Markus Armbruster b69c3c21a5 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>
2020-05-15 07:08:14 +02:00
..
hvf i386: hvf: Reset IRQ inhibition after moving RIP 2020-04-02 14:55:45 -04:00
Makefile.objs target-i386: add kvm stubs to user-mode emulators 2019-03-11 16:33:49 +01:00
TODO Move target-* CPU file into a target/ folder 2016-12-20 21:52:12 +01:00
arch_dump.c dump: add kernel_gs_base to QEMU CPU state 2018-07-16 16:13:34 +02:00
arch_memory_mapping.c exec,dump,i386,ppc,s390x: don't include exec/cpu-all.h explicitly 2017-09-19 18:21:33 +02:00
bpt_helper.c target/i386: Use env_cpu, env_archcpu 2019-06-10 07:03:42 -07:00
cc_helper.c target-i386: Use ctpop helper 2017-01-10 08:49:59 -08:00
cc_helper_template.h Move target-* CPU file into a target/ folder 2016-12-20 21:52:12 +01:00
cpu-param.h tcg: Split out target/arch/cpu-param.h 2019-06-10 07:03:34 -07:00
cpu-qom.h cpu: Use DeviceClass reset instead of a special CPUClass reset 2020-03-17 19:48:10 -04:00
cpu.c qdev: Unrealize must not fail 2020-05-15 07:08:14 +02:00
cpu.h target-arm: kvm64: handle SIGBUS signal from kernel or KVM 2020-05-14 15:03:09 +01:00
excp_helper.c sysemu: Split sysemu/runstate.h off sysemu/sysemu.h 2019-08-16 13:37:36 +02:00
fpu_helper.c target/i386: check for empty register in FXAM 2020-02-25 09:18:01 +01:00
gdbstub.c gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb 2020-04-15 11:38:23 +01:00
hax-all.c Avoid cpu_physical_memory_rw() with a constant is_write argument 2020-02-20 14:47:08 +01:00
hax-i386.h Clean up ill-advised or unusual header guards 2019-05-13 08:58:55 +02:00
hax-interface.h Clean up ill-advised or unusual header guards 2019-05-13 08:58:55 +02:00
hax-mem.c qemu/queue.h: leave head structs anonymous unless necessary 2019-01-11 15:46:55 +01:00
hax-posix.c i386: Fix GCC warning with snprintf when HAX is enabled 2020-03-16 23:02:24 +01:00
hax-posix.h Clean up header guards that don't match their file name 2019-05-13 08:58:55 +02:00
hax-windows.c hax: Windows doesn't like posix device names 2020-04-14 10:37:42 -04:00
hax-windows.h hax: Support guest RAM sizes of 4GB or more 2018-02-13 11:44:13 +01:00
helper.c Fix wrong behavior of cpu_memory_rw_debug() function in SMM 2019-10-04 18:49:18 +02:00
helper.h target/i386: Implement CPUID_EXT_RDRAND 2019-05-22 12:38:54 -04:00
hyperv-proto.h i386/kvm: add NoNonArchitecturalCoreSharing Hyper-V enlightenment 2019-10-22 09:38:42 +02:00
hyperv-stub.c target/i386: fix feature check in hyperv-stub.c 2019-07-05 22:16:46 +02:00
hyperv.c i386/kvm: convert hyperv enlightenments properties from bools to bits 2019-06-21 02:29:38 +02:00
hyperv.h hyperv: qom-ify SynIC 2018-10-19 13:44:14 +02:00
int_helper.c target/i386: Implement CPUID_EXT_RDRAND 2019-05-22 12:38:54 -04:00
kvm-stub.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
kvm.c KVM: Move hwpoison page related functions into kvm-all.c 2020-05-14 15:03:09 +01:00
kvm_i386.h target/i386: kvm: initialize feature MSRs very early 2020-01-24 20:59:09 +01:00
machine.c Fix some comment spelling errors. 2019-12-18 02:34:11 +01:00
mem_helper.c tcg: Search includes from the project root source directory 2020-01-15 15:13:10 -10:00
misc_helper.c target/i386: fix TCG UCODE_REV access 2020-02-12 16:29:30 +01:00
monitor.c hw: replace hw/i386/pc.h with a header just for the i8259 2019-12-17 19:33:49 +01:00
mpx_helper.c target/i386: move cpu_sync_bndcs_hflags() function 2017-07-05 09:12:44 +02:00
ops_sse.h target/i386: Return 'indefinite integer value' for invalid SSE fp->int conversions 2019-08-20 17:26:20 +02:00
ops_sse_header.h target-i386: Use ctpop helper 2017-01-10 08:49:59 -08:00
seg_helper.c target/i386: Use cpu_*_mmuidx_ra instead of templates 2020-01-15 15:13:10 -10:00
sev-stub.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
sev.c qom: Drop parameter @errp of object_property_add() & friends 2020-05-15 07:07:58 +02:00
sev_i386.h Include generated QAPI headers less 2019-08-16 13:31:51 +02:00
shift_helper_template.h Move target-* CPU file into a target/ folder 2016-12-20 21:52:12 +01:00
smm_helper.c target/i386: Use env_cpu, env_archcpu 2019-06-10 07:03:42 -07:00
svm.h target-i386: Add NPT support 2018-07-02 15:41:18 +02:00
svm_helper.c target/i386: Use env_cpu, env_archcpu 2019-06-10 07:03:42 -07:00
trace-events trace-events: Shorten file names in comments 2019-03-22 16:18:07 +00:00
translate.c linux-user/i386: Emulate x86_64 vsyscalls 2020-03-26 08:08:54 +01:00
whp-dispatch.h WHPX: TSC get and set should be dependent on VM state 2020-03-16 23:02:21 +01:00
whpx-all.c WHPX: Use proper synchronization primitives while processing 2020-03-16 23:02:24 +01:00
xsave_helper.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00