[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [RFC PATCH v3 08/18] spapr_iommu: Implement free_table() help
From: |
Alexey Kardashevskiy |
Subject: |
[Qemu-ppc] [RFC PATCH v3 08/18] spapr_iommu: Implement free_table() helper |
Date: |
Fri, 29 Aug 2014 20:12:12 +1000 |
Every sPAPRTCETable object holds an IOMMU memory region which holds
a referenced to the sPAPRTCETable instance. So if we want to free
an sPAPRTCETable instance, calling object_unref() will not be enough
as embedded memory region will hold the reference and we need to break
the loop.
This adds a spapr_tce_free_table() helper which destroys the embedded
memory region and then calls object_unref() on the sPAPRTCETable instance
which will succeed now. The helper adds a new child under unique name
derived from LIOBN.
As we are here, fix spapr_tce_new_table() callers.
At the moment spapr_tce_new_table() references sPAPRTCETable twice -
once in object_new() and second time in object_property_add_child().
The callers of spapr_tce_new_table() should take care of correct
referencing.
Signed-off-by: Alexey Kardashevskiy <address@hidden>
---
hw/ppc/spapr_iommu.c | 10 +++++++++-
hw/ppc/spapr_pci.c | 2 ++
hw/ppc/spapr_pci_vfio.c | 2 ++
include/hw/ppc/spapr.h | 1 +
4 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index a789ce1..bde4c1c 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -147,6 +147,7 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner,
uint32_t liobn,
bool vfio_accel)
{
sPAPRTCETable *tcet;
+ char buf[32];
if (spapr_tce_find_by_liobn(liobn)) {
fprintf(stderr, "Attempted to create TCE table with duplicate"
@@ -165,13 +166,20 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner,
uint32_t liobn,
tcet->nb_table = nb_table;
tcet->vfio_accel = vfio_accel;
- object_property_add_child(OBJECT(owner), "tce-table", OBJECT(tcet), NULL);
+ snprintf(buf, sizeof(buf) - 1, "tce-table-%08X", tcet->liobn);
+ object_property_add_child(OBJECT(owner), buf, OBJECT(tcet), NULL);
object_property_set_bool(OBJECT(tcet), true, "realized", NULL);
return tcet;
}
+void spapr_tce_free_table(sPAPRTCETable *tcet)
+{
+ object_unparent(OBJECT(&tcet->iommu));
+ object_unparent(OBJECT(tcet));
+}
+
static void spapr_tce_table_finalize(Object *obj)
{
sPAPRTCETable *tcet = SPAPR_TCE_TABLE(obj);
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 727d1fe..ea4b1bb 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -649,6 +649,8 @@ static void spapr_phb_finish_realize(sPAPRPHBState *sphb,
Error **errp)
/* Register default 32bit DMA window */
memory_region_add_subregion(&sphb->iommu_root, 0,
spapr_tce_get_iommu(tcet));
+
+ object_unref(OBJECT(tcet));
}
static int spapr_phb_children_reset(Object *child, void *opaque)
diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
index d3bddf2..51b4314 100644
--- a/hw/ppc/spapr_pci_vfio.c
+++ b/hw/ppc/spapr_pci_vfio.c
@@ -69,6 +69,8 @@ static void spapr_phb_vfio_finish_realize(sPAPRPHBState
*sphb, Error **errp)
/* Register default 32bit DMA window */
memory_region_add_subregion(&sphb->iommu_root, tcet->bus_offset,
spapr_tce_get_iommu(tcet));
+
+ object_unref(OBJECT(tcet));
}
static void spapr_phb_vfio_reset(DeviceState *qdev)
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index f3911a0..5a2a49f 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -475,6 +475,7 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner,
uint32_t liobn,
uint32_t page_shift,
uint32_t nb_table,
bool vfio_accel);
+void spapr_tce_free_table(sPAPRTCETable *tcet);
MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet);
void spapr_tce_set_bypass(sPAPRTCETable *tcet, bool bypass);
int spapr_dma_dt(void *fdt, int node_off, const char *propname,
--
2.0.0
- [Qemu-ppc] [RFC PATCH v3 00/18] spapr: vfio: Enable Dynamic DMA windows (DDW), Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 05/18] spapr_vio: Introduce a liobn number generating macros, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 03/18] spapr_iommu: Disable in-kernel IOMMU tables for >4GB windows, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 07/18] spapr_iommu: Make spapr_tce_find_by_liobn() public, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 01/18] spapr: Make machine naming conventions closer to those for PC, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 11/18] spapr_pci: Add windows counter, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 17/18] vfio: Enable DDW ioctls to VFIO IOMMU driver, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 04/18] spapr_pci: Introduce a liobn number generating macros, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 09/18] spapr_rtas: Reserve DDW RTAS token numbers, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 08/18] spapr_iommu: Implement free_table() helper,
Alexey Kardashevskiy <=
- [Qemu-ppc] [RFC PATCH v3 06/18] spapr_pci: Make find_phb()/find_dev() public, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 02/18] qom: Make object_child_foreach safe for objects removal, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 14/18] spapr_pci_vfio: Call spapr_pci::reset on reset, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 10/18] spapr_pci: Define DDW callbacks, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 18/18] spapr: Add pseries-2.2 machine, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 16/18] spapr_pci_vfio: Enable DDW, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 15/18] linux headers update for SPAPR (DDW + EEH), Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 12/18] spapr_rtas: Add Dynamic DMA windows (DDW) RTAS calls support, Alexey Kardashevskiy, 2014/08/29
- [Qemu-ppc] [RFC PATCH v3 13/18] spapr_pci: Enable DDW, Alexey Kardashevskiy, 2014/08/29