[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 28/29] qdev: defer DEVICE_DEL event until instance_fi
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 28/29] qdev: defer DEVICE_DEL event until instance_finalize() |
Date: |
Wed, 18 Oct 2017 18:12:20 +0200 |
From: Michael Roth <address@hidden>
DEVICE_DEL is currently emitted when a Device is unparented, as
opposed to when it is finalized. The main design motivation for this
seems to be that after unparent()/unrealize(), the Device is no
longer visible to the guest, and thus the operation is complete
from the perspective of management.
However, there are cases where remaining host-side cleanup is also
pertinent to management. The is generally handled by treating these
resources as aspects of the "backend", which can be managed via
separate interfaces/events, such as blockdev_add/del, netdev_add/del,
object_add/del, etc, but some devices do not have this level of
compartmentalization, namely vfio-pci, and possibly to lend themselves
well to it.
In the case of vfio-pci, the "backend" cleanup happens as part of
the finalization of the vfio-pci device itself, in particular the
cleanup of the VFIO group FD. Failing to wait for this cleanup can
result in tools like libvirt attempting to rebind the device to
the host while it's still being used by VFIO, which can result in
host crashes or other misbehavior depending on the host driver.
Deferring DEVICE_DEL still affords us the ability to manage backends
explicitly, while also addressing cases like vfio-pci's, so we
implement that approach here.
An alternative proposal involving having VFIO emit a separate event
to denote completion of host-side cleanup was discussed, but the
prevailing opinion seems to be that it is not worth the added
complexity, and leaves the issue open for other Device implementations
to solve in the future.
Signed-off-by: Michael Roth <address@hidden>
Reviewed-by: Greg Kurz <address@hidden>
Tested-by: Eric Auger <address@hidden>
Reviewed-by: David Gibson <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/core/qdev.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 418cdac..1111295 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -1069,7 +1069,6 @@ static void device_finalize(Object *obj)
NamedGPIOList *ngl, *next;
DeviceState *dev = DEVICE(obj);
- qemu_opts_del(dev->opts);
QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {
QLIST_REMOVE(ngl, node);
@@ -1080,6 +1079,18 @@ static void device_finalize(Object *obj)
* here
*/
}
+
+ /* Only send event if the device had been completely realized */
+ if (dev->pending_deleted_event) {
+ g_assert(dev->canonical_path);
+
+ qapi_event_send_device_deleted(!!dev->id, dev->id, dev->canonical_path,
+ &error_abort);
+ g_free(dev->canonical_path);
+ dev->canonical_path = NULL;
+ }
+
+ qemu_opts_del(dev->opts);
}
static void device_class_base_init(ObjectClass *class, void *data)
@@ -1109,16 +1120,6 @@ static void device_unparent(Object *obj)
object_unref(OBJECT(dev->parent_bus));
dev->parent_bus = NULL;
}
-
- /* Only send event if the device had been completely realized */
- if (dev->pending_deleted_event) {
- g_assert(dev->canonical_path);
-
- qapi_event_send_device_deleted(!!dev->id, dev->id, dev->canonical_path,
- &error_abort);
- g_free(dev->canonical_path);
- dev->canonical_path = NULL;
- }
}
static void device_class_init(ObjectClass *class, void *data)
--
1.8.3.1
- [Qemu-devel] [PULL 18/29] kvm: tolerate non-existing slot for log_start/log_stop/log_sync, (continued)
- [Qemu-devel] [PULL 18/29] kvm: tolerate non-existing slot for log_start/log_stop/log_sync, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 22/29] memory: reuse section_from_flat_range(), Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 21/29] kvm: simplify kvm_align_section(), Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 20/29] kvm: region_add and region_del is not called on updates, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 24/29] watch_mem_write: implement 8-byte accesses, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 25/29] qemu-pr-helper: use new libmultipath API, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 27/29] Revert "qdev: Free QemuOpts when the QOM path goes away", Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 29/29] scsi: reject configurations with logical block size > physical block size, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 26/29] qdev: store DeviceState's canonical path to use when unparenting, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 23/29] notdirty_mem_write: implement 8-byte accesses, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 28/29] qdev: defer DEVICE_DEL event until instance_finalize(),
Paolo Bonzini <=
- Re: [Qemu-devel] [PULL 00/29] Misc patches for 2017-10-18, no-reply, 2017/10/18
- Re: [Qemu-devel] [PULL 00/29] Misc patches for 2017-10-18, Peter Maydell, 2017/10/19