All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	qemu-s390x@nongnu.org, "Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Michael Roth" <mdroth@linux.vnet.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Marcel Apfelbaum" <marcel@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Dmitry Fleytman" <dmitry.fleytman@gmail.com>
Subject: Re: [Qemu-devel] [PATCH 04/15] spapr_pci: add proper rollback on PHB realize error path
Date: Mon, 7 Jan 2019 17:40:22 +0100	[thread overview]
Message-ID: <20190107174022.625b3c78@bahia.lan> (raw)
In-Reply-To: <20190103015906.GJ10853@umbus.fritz.box>

[-- Attachment #1: Type: text/plain, Size: 4722 bytes --]

On Thu, 3 Jan 2019 12:59:06 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Fri, Dec 21, 2018 at 01:35:52AM +0100, Greg Kurz wrote:
> > The current realize code assumes the PHB is coldplugged, ie, QEMU will
> > terminate if an error is detected, and does not bother to free anything
> > it has already allocated.
> > 
> > In order to support PHB hotplug, let's first ensure spapr_phb_realize()
> > doesn't leak anything in case of error.
> > 
> > Signed-off-by: Greg Kurz <groug@kaod.org>  
> 
> This looks ok as far as it goes.  However, it looks like there will be
> a lot of fragments duplicated between the rollback paths and
> unrealize() when it's added in the next patch.
> 
> A common pattern to avoid that is to make unrealize() safe to call on
> a partially realized object, then call that from the realize() failure
> paths.  Is it possible to do that here?  I imagine that would involve
> folding this patch with the next as well.
> 

Makes sense. I'll give a try.

> > ---
> >  hw/ppc/spapr_pci.c |   40 +++++++++++++++++++++++++++++++++++-----
> >  1 file changed, 35 insertions(+), 5 deletions(-)
> > 
> > diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> > index e59adbe706bb..46d7062dd143 100644
> > --- a/hw/ppc/spapr_pci.c
> > +++ b/hw/ppc/spapr_pci.c
> > @@ -1570,6 +1570,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
> >      sPAPRTCETable *tcet;
> >      const unsigned windows_supported =
> >          sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1;
> > +    Object *drcs[PCI_SLOT_MAX * 8];
> >  
> >      if (!spapr) {
> >          error_setg(errp, TYPE_SPAPR_PCI_HOST_BRIDGE " needs a pseries machine");
> > @@ -1733,7 +1734,10 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
> >          spapr_irq_claim(spapr, irq, true, &local_err);
> >          if (local_err) {
> >              error_propagate_prepend(errp, local_err, "can't allocate LSIs: ");
> > -            return;
> > +            while (--i >= 0) {
> > +                spapr_irq_free(spapr, sphb->lsi_table[i].irq, 1);
> > +            }
> > +            goto fail_del_msiwindow;
> >          }
> >  
> >          sphb->lsi_table[i].irq = irq;
> > @@ -1741,9 +1745,10 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
> >  
> >      /* allocate connectors for child PCI devices */
> >      if (sphb->dr_enabled) {
> > -        for (i = 0; i < PCI_SLOT_MAX * 8; i++) {
> > -            spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI,
> > -                                   (sphb->index << 16) | i);
> > +        for (i = 0; i < ARRAY_SIZE(drcs); i++) {
> > +            drcs[i] =
> > +                OBJECT(spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI,
> > +                                              (sphb->index << 16) | i));
> >          }
> >      }
> >  
> > @@ -1753,13 +1758,38 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
> >          if (!tcet) {
> >              error_setg(errp, "Creating window#%d failed for %s",
> >                         i, sphb->dtbusname);
> > -            return;
> > +            while (--i >= 0) {
> > +                tcet = spapr_tce_find_by_liobn(sphb->dma_liobn[i]);
> > +                assert(tcet);
> > +                memory_region_del_subregion(&sphb->iommu_root,
> > +                                            spapr_tce_get_iommu(tcet));
> > +                object_unparent(OBJECT(tcet));
> > +            }
> > +            goto fail_free_drcs;
> >          }
> >          memory_region_add_subregion(&sphb->iommu_root, 0,
> >                                      spapr_tce_get_iommu(tcet));
> >      }
> >  
> >      sphb->msi = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
> > +    return;
> > +
> > +fail_free_drcs:
> > +    if (sphb->dr_enabled) {
> > +        for (i = 0; i < ARRAY_SIZE(drcs); i++) {
> > +            object_unparent(drcs[i]);
> > +        }
> > +    }
> > +fail_del_msiwindow:
> > +    memory_region_del_subregion(&sphb->iommu_root, &sphb->msiwindow);
> > +    address_space_destroy(&sphb->iommu_as);
> > +    qbus_set_hotplug_handler(BUS(phb->bus), NULL, &error_abort);
> > +    pci_unregister_root_bus(phb->bus);
> > +    memory_region_del_subregion(get_system_memory(), &sphb->iowindow);
> > +    if (sphb->mem64_win_pciaddr != (hwaddr)-1) {
> > +        memory_region_del_subregion(get_system_memory(), &sphb->mem64window);
> > +    }
> > +    memory_region_del_subregion(get_system_memory(), &sphb->mem32window);
> >  }
> >  
> >  static int spapr_phb_children_reset(Object *child, void *opaque)
> >   
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-01-07 16:40 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-21  0:34 [Qemu-devel] [PATCH 00/15] spapr: Add support for PHB hotplug Greg Kurz
2018-12-21  0:34 ` [Qemu-devel] [PATCH 01/15] ppc/spapr: Receive and store device tree blob from SLOF Greg Kurz
2018-12-21 17:39   ` [Qemu-devel] [Qemu-ppc] " Murilo Opsfelder Araujo
2019-01-02  3:25     ` David Gibson
2019-01-03  0:32   ` [Qemu-devel] " David Gibson
2018-12-21  0:35 ` [Qemu-devel] [PATCH 02/15] spapr: move spapr_create_phb() to core machine code Greg Kurz
2019-01-03  0:33   ` David Gibson
2018-12-21  0:35 ` [Qemu-devel] [PATCH 03/15] pci: allow cleanup/unregistration of PCI root buses Greg Kurz
2018-12-21 16:19   ` Michael S. Tsirkin
2019-01-03  0:36     ` David Gibson
2019-01-03  3:27       ` Michael S. Tsirkin
2019-01-03  3:41         ` David Gibson
2018-12-21  0:35 ` [Qemu-devel] [PATCH 04/15] spapr_pci: add proper rollback on PHB realize error path Greg Kurz
2019-01-03  1:59   ` David Gibson
2019-01-07 16:40     ` Greg Kurz [this message]
2018-12-21  0:36 ` [Qemu-devel] [PATCH 05/15] spapr_pci: add PHB unrealize Greg Kurz
2018-12-21  0:36 ` [Qemu-devel] [PATCH 06/15] spapr: enable PHB hotplug for default pseries machine type Greg Kurz
2019-01-03  2:00   ` David Gibson
2019-01-08  9:55     ` Greg Kurz
2018-12-21  0:36 ` [Qemu-devel] [PATCH 07/15] spapr_pci: Define SPAPR_MAX_PHBS in hw/pci-host/spapr.h Greg Kurz
2018-12-21  8:03   ` Cédric Le Goater
2018-12-21  9:50     ` Greg Kurz
2019-01-03  2:07   ` David Gibson
2018-12-21  0:37 ` [Qemu-devel] [PATCH 08/15] spapr: create DR connectors for PHBs Greg Kurz
2018-12-21  0:37 ` [Qemu-devel] [PATCH 09/15] spapr: populate PHB DRC entries for root DT node Greg Kurz
2018-12-21  0:37 ` [Qemu-devel] [PATCH 10/15] spapr_events: add support for phb hotplug events Greg Kurz
2018-12-21  0:38 ` [Qemu-devel] [PATCH 11/15] qdev: pass an Object * to qbus_set_hotplug_handler() Greg Kurz
2018-12-21  0:38 ` [Qemu-devel] [PATCH 12/15] spapr_pci: provide node start offset via spapr_populate_pci_dt() Greg Kurz
2018-12-21  0:38 ` [Qemu-devel] [PATCH 13/15] spapr_pci: add ibm, my-drc-index property for PHB hotplug Greg Kurz
2018-12-21  6:35 ` [Qemu-devel] [PATCH 14/15] spapr: Expose the name of the interrupt controller node Greg Kurz
2018-12-21  8:12   ` Cédric Le Goater
2018-12-21  9:53     ` Greg Kurz
2019-01-03  2:13       ` David Gibson
2018-12-21  6:36 ` [Qemu-devel] [PATCH 15/15] spapr: add hotplug hooks for PHB hotplug Greg Kurz
2019-01-03  2:17   ` David Gibson
2019-01-08 10:18     ` Greg Kurz

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=20190107174022.625b3c78@bahia.lan \
    --to=groug@kaod.org \
    --cc=aik@ozlabs.ru \
    --cc=clg@kaod.org \
    --cc=cohuck@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=dmitry.fleytman@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcel@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.