[Qemu-devel] [for-2.11 PATCH 06/26] spapr_pci: parent the MSI memory region to the PHB

Greg Kurz posted 26 patches 8 years, 3 months ago
[Qemu-devel] [for-2.11 PATCH 06/26] spapr_pci: parent the MSI memory region to the PHB
Posted by Greg Kurz 8 years, 3 months ago
This memory region should be owned by the PHB. This ensures the PHB
cannot be finalized as long as the the region is guest visible, or
used by a CPU or a device.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/spapr_pci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 3fe7f3145467..4e4165b44b9a 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1703,7 +1703,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
     }
 #endif
 
-    memory_region_init_io(&sphb->msiwindow, NULL, &spapr_msi_ops, spapr,
+    memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
                           "msi", msi_window_size);
     memory_region_add_subregion(&sphb->iommu_root, SPAPR_PCI_MSI_WINDOW,
                                 &sphb->msiwindow);


Re: [Qemu-devel] [for-2.11 PATCH 06/26] spapr_pci: parent the MSI memory region to the PHB
Posted by David Gibson 8 years, 3 months ago
On Tue, Jul 25, 2017 at 07:59:18PM +0200, Greg Kurz wrote:
> This memory region should be owned by the PHB. This ensures the PHB
> cannot be finalized as long as the the region is guest visible, or
> used by a CPU or a device.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>

Applied to ppc-for-2.11.

> ---
>  hw/ppc/spapr_pci.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 3fe7f3145467..4e4165b44b9a 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1703,7 +1703,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>      }
>  #endif
>  
> -    memory_region_init_io(&sphb->msiwindow, NULL, &spapr_msi_ops, spapr,
> +    memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
>                            "msi", msi_window_size);
>      memory_region_add_subregion(&sphb->iommu_root, SPAPR_PCI_MSI_WINDOW,
>                                  &sphb->msiwindow);
> 

-- 
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
Re: [Qemu-devel] [Qemu-ppc] [for-2.11 PATCH 06/26] spapr_pci: parent the MSI memory region to the PHB
Posted by Alexey Kardashevskiy 8 years, 3 months ago
On 26/07/17 03:59, Greg Kurz wrote:
> This memory region should be owned by the PHB. This ensures the PHB
> cannot be finalized as long as the the region is guest visible, or
> used by a CPU or a device.

Out of curiosity - does it really ensure this? Passing a parent to
memory_region_init_io() adds a reference to a child (i.e. "msi" region),
not to the PHB object. It is probably a good thing to have an owner for
every MR anyway, I am just not sure about the commit log, what does not
work if you do not do this?


> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>  hw/ppc/spapr_pci.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 3fe7f3145467..4e4165b44b9a 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1703,7 +1703,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>      }
>  #endif
>  
> -    memory_region_init_io(&sphb->msiwindow, NULL, &spapr_msi_ops, spapr,
> +    memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
>                            "msi", msi_window_size);
>      memory_region_add_subregion(&sphb->iommu_root, SPAPR_PCI_MSI_WINDOW,
>                                  &sphb->msiwindow);
> 
> 


-- 
Alexey

Re: [Qemu-devel] [Qemu-ppc] [for-2.11 PATCH 06/26] spapr_pci: parent the MSI memory region to the PHB
Posted by Greg Kurz 8 years, 3 months ago
On Wed, 26 Jul 2017 14:29:26 +1000
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:

> On 26/07/17 03:59, Greg Kurz wrote:
> > This memory region should be owned by the PHB. This ensures the PHB
> > cannot be finalized as long as the the region is guest visible, or
> > used by a CPU or a device.  
> 
> Out of curiosity - does it really ensure this? Passing a parent to
> memory_region_init_io() adds a reference to a child (i.e. "msi" region),
> not to the PHB object. 

You're right, being owner of the MR means the PHB is parent and takes
a reference on the MR. But it also means a reference on the PHB is
taken/dropped each time the MR gets referenced/unreferenced (ie, "guest
visible or used by a CPU or a device").

> It is probably a good thing to have an owner for
> every MR anyway, I am just not sure about the commit log, what does not
> work if you do not do this?
> 

The PHB could theorically get unrealized while the MSI region is still active.
But since the associated MMIO op spapr_msi_write() only uses the machine
object and not the PHB, I admit I don't have a scenario where this could
break something...

So even if doesn't fix anything obvious, as you say, it is probably a good
thing to have an owner for every MR anyway :)

> 
> > 
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> >  hw/ppc/spapr_pci.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> > index 3fe7f3145467..4e4165b44b9a 100644
> > --- a/hw/ppc/spapr_pci.c
> > +++ b/hw/ppc/spapr_pci.c
> > @@ -1703,7 +1703,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
> >      }
> >  #endif
> >  
> > -    memory_region_init_io(&sphb->msiwindow, NULL, &spapr_msi_ops, spapr,
> > +    memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
> >                            "msi", msi_window_size);
> >      memory_region_add_subregion(&sphb->iommu_root, SPAPR_PCI_MSI_WINDOW,
> >                                  &sphb->msiwindow);
> > 
> >   
> 
>