From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
aik@ozlabs.ru, Paolo Bonzini <pbonzini@redhat.com>,
qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com,
nfont@linux.vnet.ibm.com, david@gibson.dropbear.id.au
Subject: [Qemu-devel] [RFC PATCH 02/15] qdev: store DeviceState's canonical path to use when unparenting
Date: Wed, 29 Apr 2015 14:20:11 -0500 [thread overview]
Message-ID: <1430335224-6716-3-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1430335224-6716-1-git-send-email-mdroth@linux.vnet.ibm.com>
device_unparent(dev, ...) is called when a device is unparented,
either directly, or as a result of a parent device being
finalized, and handles some final cleanup for the device. Part
of this includes emiting a DEVICE_DELETED QMP event to notify
management, which includes the device's path in the composition
tree as provided by object_get_canonical_path().
object_get_canonical_path() assumes the device is still connected
to the machine/root container, and will assert otherwise, but
in some situations this isn't the case:
If the parent is finalized as a result of object_unparent(), it
will still be attached to the composition tree at the time any
children are unparented as a result of that same call to
object_unparent(). However, in some cases, object_unparent()
will complete without finalizing the parent device, due to
lingering references that won't be released till some time later.
One such example is if the parent has MemoryRegion children (which
take a ref on their parent), who in turn have AddressSpace's (which
take a ref on their regions), since those AddressSpaces get cleaned
up asynchronously by the RCU thread.
In this case qdev:device_unparent() may be called for a child Device
that no longer has a path to the root/machine container, causing
object_get_canonical_path() to assert.
Fix this by storing the canonical path during realize() so the
information will still be available for device_unparent() in such
cases.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
hw/core/qdev.c | 15 ++++++++++++---
include/hw/qdev-core.h | 1 +
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 6be5866..fda1d2f 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -1072,6 +1072,12 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
goto post_realize_fail;
}
+ /* always re-initialize since we clean up in device_unparent() instead
+ * of unrealize()
+ */
+ g_free(dev->canonical_path);
+ dev->canonical_path = object_get_canonical_path(OBJECT(dev));
+
if (qdev_get_vmsd(dev)) {
vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
dev->instance_id_alias,
@@ -1125,6 +1131,7 @@ child_realize_fail:
}
post_realize_fail:
+ g_free(dev->canonical_path);
if (dc->unrealize) {
dc->unrealize(dev, NULL);
}
@@ -1248,10 +1255,12 @@ static void device_unparent(Object *obj)
/* Only send event if the device had been completely realized */
if (dev->pending_deleted_event) {
- gchar *path = object_get_canonical_path(OBJECT(dev));
+ g_assert(dev->canonical_path);
- qapi_event_send_device_deleted(!!dev->id, dev->id, path, &error_abort);
- g_free(path);
+ qapi_event_send_device_deleted(!!dev->id, dev->id, dev->canonical_path,
+ &error_abort);
+ g_free(dev->canonical_path);
+ dev->canonical_path = NULL;
}
}
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 4e673f9..17f805e 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -153,6 +153,7 @@ struct DeviceState {
/*< public >*/
const char *id;
+ char *canonical_path;
bool realized;
bool pending_deleted_event;
QemuOpts *opts;
--
1.9.1
next prev parent reply other threads:[~2015-04-29 19:21 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-29 19:20 [Qemu-devel] [RFC PATCH 00/15] spapr: add support for PHB hotplug Michael Roth
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 01/15] pci: allow cleanup/unregistration of PCI buses Michael Roth
2015-05-05 7:56 ` David Gibson
2015-04-29 19:20 ` Michael Roth [this message]
2015-04-30 13:35 ` [Qemu-devel] [RFC PATCH 02/15] qdev: store DeviceState's canonical path to use when unparenting Paolo Bonzini
2015-04-30 23:03 ` Michael Roth
2015-05-01 20:43 ` Paolo Bonzini
2015-05-01 22:54 ` Michael Roth
2015-05-04 9:35 ` Paolo Bonzini
2015-05-05 15:48 ` Michael Roth
2015-05-19 9:41 ` Paolo Bonzini
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 03/15] spapr_drc: pass object ownership to parent/owner Michael Roth
2015-04-30 14:00 ` Paolo Bonzini
2015-05-05 9:57 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 04/15] spapr_iommu: " Michael Roth
2015-04-30 14:00 ` Paolo Bonzini
2015-05-05 9:58 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 05/15] spapr_pci: add PHB unrealize Michael Roth
2015-04-30 14:05 ` Paolo Bonzini
2015-05-01 1:18 ` Michael Roth
2015-05-04 9:29 ` Paolo Bonzini
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 06/15] spapr_pci: also use 'index' property as DRC index for PHBs Michael Roth
2015-05-05 11:34 ` David Gibson
2015-05-05 15:54 ` Michael Roth
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 07/15] spapr: enable PHB hotplug for pseries-2.4 Michael Roth
2015-05-05 11:35 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 08/15] spapr: create DR connectors for PHBs and register reset hooks Michael Roth
2015-04-30 14:08 ` Paolo Bonzini
2015-05-01 1:25 ` Michael Roth
2015-05-05 11:37 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 09/15] spapr: populate PHB DRC entries for root DT node Michael Roth
2015-05-05 11:39 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 10/15] spapr_events: add support for phb hotplug events Michael Roth
2015-05-05 11:39 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 11/15] qdev: add qbus_set_hotplug_handler_generic() Michael Roth
2015-04-30 14:09 ` Paolo Bonzini
2015-05-05 11:42 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 12/15] spapr: stub implementation of machine-level HotplugHandler interface Michael Roth
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 13/15] spapr_pci: provide node start offset via spapr_populate_pci_dt() Michael Roth
2015-05-05 11:44 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 14/15] spapr_pci: add ibm, my-drc-index property for PHB hotplug Michael Roth
2015-05-05 11:44 ` David Gibson
2015-04-29 19:20 ` [Qemu-devel] [RFC PATCH 15/15] spapr: add hotplug hooks " Michael Roth
2015-05-05 11:46 ` David Gibson
2015-04-30 14:10 ` [Qemu-devel] [RFC PATCH 00/15] spapr: add support " Paolo Bonzini
2015-05-01 1:27 ` Michael Roth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430335224-6716-3-git-send-email-mdroth@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=aik@ozlabs.ru \
--cc=bharata@linux.vnet.ibm.com \
--cc=david@gibson.dropbear.id.au \
--cc=mst@redhat.com \
--cc=nfont@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).