All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "Greg Kurz" <groug@kaod.org>,
	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>,
	"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 03/15] pci: allow cleanup/unregistration of PCI root buses
Date: Thu, 3 Jan 2019 14:41:59 +1100	[thread overview]
Message-ID: <20190103034159.GP10853@umbus.fritz.box> (raw)
In-Reply-To: <20190102222703-mutt-send-email-mst@kernel.org>

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

On Wed, Jan 02, 2019 at 10:27:14PM -0500, Michael S. Tsirkin wrote:
> On Thu, Jan 03, 2019 at 11:36:33AM +1100, David Gibson wrote:
> > On Fri, Dec 21, 2018 at 11:19:18AM -0500, Michael S. Tsirkin wrote:
> > > On Fri, Dec 21, 2018 at 01:35:30AM +0100, Greg Kurz wrote:
> > > > From: Michael Roth <mdroth@linux.vnet.ibm.com>
> > > > 
> > > > This adds cleanup counterparts to pci_register_root_bus(),
> > > > pci_root_bus_new(), and pci_bus_irqs().
> > > > 
> > > > These cleanup routines are needed in the case of hotpluggable
> > > > PCIHostBridge implementations. Currently we can rely on the
> > > > object_unparent()'ing of the PCIHostState recursively unparenting
> > > > and cleaning up it's child buses, but we need explicit calls
> > > > to also:
> > > > 
> > > >   1) remove the PCIHostState from pci_host_bridges global list.
> > > >      otherwise, we risk accessing freed memory when we access
> > > >      the list later
> > > >   2) clean up memory allocated in pci_bus_irqs()
> > > > 
> > > > Both are handled outside the context of any particular bus or
> > > > host bridge's init/realize functions, making it difficult to
> > > > avoid the need for explicit cleanup functions without remodeling
> > > > how PCIHostBridges are created. So keep it simple and just add
> > > > them for now.
> > > > 
> > > > Cc: Michael S. Tsirkin <mst@redhat.com>
> > > > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > > > Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> > > > Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> > > > Signed-off-by: Greg Kurz <groug@kaod.org>
> > > 
> > > Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > 
> > I've applied this tentatively to ppc-for-4.0.  Let me know, Michael,
> > if you'd prefer to take it through your tree.
> 
> 
> I think your tree makes sense for this.

Great, will do.

> 
> > > 
> > > > ---
> > > >  hw/pci/pci.c         |   33 +++++++++++++++++++++++++++++++++
> > > >  include/hw/pci/pci.h |    3 +++
> > > >  2 files changed, 36 insertions(+)
> > > > 
> > > > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > > > index efb5ce196ffb..16354f91206c 100644
> > > > --- a/hw/pci/pci.c
> > > > +++ b/hw/pci/pci.c
> > > > @@ -333,6 +333,13 @@ static void pci_host_bus_register(DeviceState *host)
> > > >      QLIST_INSERT_HEAD(&pci_host_bridges, host_bridge, next);
> > > >  }
> > > >  
> > > > +static void pci_host_bus_unregister(DeviceState *host)
> > > > +{
> > > > +    PCIHostState *host_bridge = PCI_HOST_BRIDGE(host);
> > > > +
> > > > +    QLIST_REMOVE(host_bridge, next);
> > > > +}
> > > > +
> > > >  PCIBus *pci_device_root_bus(const PCIDevice *d)
> > > >  {
> > > >      PCIBus *bus = pci_get_bus(d);
> > > > @@ -379,6 +386,11 @@ static void pci_root_bus_init(PCIBus *bus, DeviceState *parent,
> > > >      pci_host_bus_register(parent);
> > > >  }
> > > >  
> > > > +static void pci_bus_uninit(PCIBus *bus)
> > > > +{
> > > > +    pci_host_bus_unregister(BUS(bus)->parent);
> > > > +}
> > > > +
> > > >  bool pci_bus_is_express(PCIBus *bus)
> > > >  {
> > > >      return object_dynamic_cast(OBJECT(bus), TYPE_PCIE_BUS);
> > > > @@ -413,6 +425,12 @@ PCIBus *pci_root_bus_new(DeviceState *parent, const char *name,
> > > >      return bus;
> > > >  }
> > > >  
> > > > +void pci_root_bus_cleanup(PCIBus *bus)
> > > > +{
> > > > +    pci_bus_uninit(bus);
> > > > +    object_unparent(OBJECT(bus));
> > > > +}
> > > > +
> > > >  void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
> > > >                    void *irq_opaque, int nirq)
> > > >  {
> > > > @@ -423,6 +441,15 @@ void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
> > > >      bus->irq_count = g_malloc0(nirq * sizeof(bus->irq_count[0]));
> > > >  }
> > > >  
> > > > +void pci_bus_irqs_cleanup(PCIBus *bus)
> > > > +{
> > > > +    bus->set_irq = NULL;
> > > > +    bus->map_irq = NULL;
> > > > +    bus->irq_opaque = NULL;
> > > > +    bus->nirq = 0;
> > > > +    g_free(bus->irq_count);
> > > > +}
> > > > +
> > > >  PCIBus *pci_register_root_bus(DeviceState *parent, const char *name,
> > > >                                pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
> > > >                                void *irq_opaque,
> > > > @@ -439,6 +466,12 @@ PCIBus *pci_register_root_bus(DeviceState *parent, const char *name,
> > > >      return bus;
> > > >  }
> > > >  
> > > > +void pci_unregister_root_bus(PCIBus *bus)
> > > > +{
> > > > +    pci_bus_irqs_cleanup(bus);
> > > > +    pci_root_bus_cleanup(bus);
> > > > +}
> > > > +
> > > >  int pci_bus_num(PCIBus *s)
> > > >  {
> > > >      return PCI_BUS_GET_CLASS(s)->bus_num(s);
> > > > diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> > > > index e6514bba23aa..8998e3be3390 100644
> > > > --- a/include/hw/pci/pci.h
> > > > +++ b/include/hw/pci/pci.h
> > > > @@ -405,8 +405,10 @@ PCIBus *pci_root_bus_new(DeviceState *parent, const char *name,
> > > >                           MemoryRegion *address_space_mem,
> > > >                           MemoryRegion *address_space_io,
> > > >                           uint8_t devfn_min, const char *typename);
> > > > +void pci_root_bus_cleanup(PCIBus *bus);
> > > >  void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
> > > >                    void *irq_opaque, int nirq);
> > > > +void pci_bus_irqs_cleanup(PCIBus *bus);
> > > >  int pci_bus_get_irq_level(PCIBus *bus, int irq_num);
> > > >  /* 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD */
> > > >  int pci_swizzle_map_irq_fn(PCIDevice *pci_dev, int pin);
> > > > @@ -417,6 +419,7 @@ PCIBus *pci_register_root_bus(DeviceState *parent, const char *name,
> > > >                                MemoryRegion *address_space_io,
> > > >                                uint8_t devfn_min, int nirq,
> > > >                                const char *typename);
> > > > +void pci_unregister_root_bus(PCIBus *bus);
> > > >  void pci_bus_set_route_irq_fn(PCIBus *, pci_route_irq_fn);
> > > >  PCIINTxRoute pci_device_route_intx_to_irq(PCIDevice *dev, int pin);
> > > >  bool pci_intx_route_changed(PCIINTxRoute *old, PCIINTxRoute *new);
> > > 
> > 
> 
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

  reply	other threads:[~2019-01-03  4:32 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 [this message]
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
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=20190103034159.GP10853@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=clg@kaod.org \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=dmitry.fleytman@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=groug@kaod.org \
    --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.