From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: aik@ozlabs.ru, nfont@linux.vnet.ibm.com,
david@gibson.dropbear.id.au, qemu-ppc@nongnu.org,
bharata@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [RFC PATCH 05/15] spapr_pci: add PHB unrealize
Date: Thu, 30 Apr 2015 20:18:29 -0500 [thread overview]
Message-ID: <20150501011829.25451.23595@loki> (raw)
In-Reply-To: <5542369D.90801@redhat.com>
Quoting Paolo Bonzini (2015-04-30 09:05:17)
>
>
> On 29/04/2015 21:20, Michael Roth wrote:
> > To support PHB hotplug we need to clean up lingering references,
> > memory, child properties, etc. prior to the PHB object being
> > finalized. Generally this will be called as a result of calling
> > object_unref() on the PHB object, which in turn would normally
>
> s/object_unref/object_unparent/
>
> > be called as the result of an unplug() operation.
> >
> > When the PHB is finalized, child objects will be unparented in
> > turn, and finalized if the PHB was the only reference holder. so
> > we don't bother to explicitly unparent child objects of the PHB
> > (spapr_iommu, spapr_drc, etc).
> >
> > We do need to handle memory regions explicitly however, since
> > they also take a reference on the PHB, and won't allow it to
> > be finalized otherwise.
>
> They shouldn't hold a reference anymore as soon as the regions are not
> visible in an AddressSpace (and the RCU thread has picked up the changes).
Sorry, I mixed up memory regions with memory region alias. Memory region
aliases do a memory_region_ref() on the original MR, similar to
memory_region_add_subregion(), so that's what ends up creating the
reference to the owner/PHB.
So I think I do need to object_unparent() the 2 MR aliases in realize
(otherwise the PHB doesn't get finalized), but everything else can
get moved to instance_finalize() as you suggested and that seems to
do the trick.
>
> In fact, docs/memory.txt documents (!) that you must call
> object_unparent() for memory regions in the instance_finalize function,
> not in the unrealize function.
They seem to hint that creation should follow the same guidelines, so I
assume I should probably moved all the memory_region_init()'s to
instance_init()? I see a lot of counter-examples elsewhere, but not
sure if those are intended or not.
>
> > Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> > ---
> > hw/ppc/spapr_pci.c | 32 ++++++++++++++++++++++++++++++++
> > 1 file changed, 32 insertions(+)
> >
> > diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> > index 2e7590c..25a738c 100644
> > --- a/hw/ppc/spapr_pci.c
> > +++ b/hw/ppc/spapr_pci.c
> > @@ -1108,6 +1108,37 @@ static void spapr_phb_hot_unplug_child(HotplugHandler *plug_handler,
> > }
> > }
> >
> > +static void spapr_phb_unrealize(DeviceState *dev, Error **errp)
> > +{
> > + SysBusDevice *s = SYS_BUS_DEVICE(dev);
> > + PCIHostState *phb = PCI_HOST_BRIDGE(s);
> > + sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(phb);
> > + sPAPRTCETable *tcet;
> > +
> > + pci_unregister_bus(phb->bus);
> > +
> > + g_free(sphb->dtbusname);
> > + sphb->dtbusname = NULL;
>
> This g_free can probably also be moved for simplicity to instance_finalize.
>
> > + /* remove IO/MMIO subregions and aliases, rest should get cleaned
> > + * via PHB's unrealize->object_finalize
> > + */
> > + memory_region_del_subregion(get_system_memory(), &sphb->iowindow);
>
> ^^ You should indeed do this here.
>
> > + object_unparent(OBJECT(&sphb->iowindow));
> > + object_unparent(OBJECT(&sphb->iospace));
> > +
> > + memory_region_del_subregion(get_system_memory(), &sphb->memwindow);
>
> ^^ and this
>
> > + object_unparent(OBJECT(&sphb->memwindow));
> > + object_unparent(OBJECT(&sphb->memspace));
> > +
> > + tcet = spapr_tce_find_by_liobn(sphb->dma_liobn);
> > + memory_region_del_subregion(&sphb->iommu_root, &sphb->msiwindow);
> > + memory_region_del_subregion(&sphb->iommu_root, spapr_tce_get_iommu(tcet));
> > + address_space_destroy(&sphb->iommu_as);
>
> ^^ and these three. However, the object_unparents should be in
> instance_finalize.
>
> Paolo
>
> > + QLIST_REMOVE(sphb, list);
> > +}
> > +
> > static void spapr_phb_realize(DeviceState *dev, Error **errp)
> > {
> > SysBusDevice *s = SYS_BUS_DEVICE(dev);
> > @@ -1442,6 +1473,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data)
> >
> > hc->root_bus_path = spapr_phb_root_bus_path;
> > dc->realize = spapr_phb_realize;
> > + dc->unrealize = spapr_phb_unrealize;
> > dc->props = spapr_phb_properties;
> > dc->reset = spapr_phb_reset;
> > dc->vmsd = &vmstate_spapr_pci;
> >
>
next prev parent reply other threads:[~2015-05-01 1:18 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 ` [Qemu-devel] [RFC PATCH 02/15] qdev: store DeviceState's canonical path to use when unparenting Michael Roth
2015-04-30 13:35 ` 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 [this message]
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=20150501011829.25451.23595@loki \
--to=mdroth@linux.vnet.ibm.com \
--cc=aik@ozlabs.ru \
--cc=bharata@linux.vnet.ibm.com \
--cc=david@gibson.dropbear.id.au \
--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).