Commit 11edf116 authored by Alexey Kardashevskiy's avatar Alexey Kardashevskiy Committed by Michael Ellerman

powerpc/iommu/vfio_spapr_tce: Cleanup iommu_table disposal

At the moment iommu_table can be disposed by either calling
iommu_table_free() directly or it_ops::free(); the only implementation
of free() is in IODA2 - pnv_ioda2_table_free() - and it calls
iommu_table_free() anyway.

As we are going to have reference counting on tables, we need an unified
way of disposing tables.

This moves it_ops::free() call into iommu_free_table() and makes use
of the latter. The free() callback now handles only platform-specific
data.

As from now on the iommu_free_table() calls it_ops->free(), we need
to have it_ops initialized before calling iommu_free_table() so this
moves this initialization in pnv_pci_ioda2_create_table().

This should cause no behavioral change.
Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
Acked-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent a540aa56
...@@ -719,6 +719,9 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name) ...@@ -719,6 +719,9 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
if (!tbl) if (!tbl)
return; return;
if (tbl->it_ops->free)
tbl->it_ops->free(tbl);
if (!tbl->it_map) { if (!tbl->it_map) {
kfree(tbl); kfree(tbl);
return; return;
...@@ -745,6 +748,7 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name) ...@@ -745,6 +748,7 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
/* free table */ /* free table */
kfree(tbl); kfree(tbl);
} }
EXPORT_SYMBOL_GPL(iommu_free_table);
/* Creates TCEs for a user provided buffer. The user buffer must be /* Creates TCEs for a user provided buffer. The user buffer must be
* contiguous real kernel storage (not vmalloc). The address passed here * contiguous real kernel storage (not vmalloc). The address passed here
......
...@@ -1424,7 +1424,6 @@ static void pnv_pci_ioda2_release_dma_pe(struct pci_dev *dev, struct pnv_ioda_pe ...@@ -1424,7 +1424,6 @@ static void pnv_pci_ioda2_release_dma_pe(struct pci_dev *dev, struct pnv_ioda_pe
iommu_group_put(pe->table_group.group); iommu_group_put(pe->table_group.group);
BUG_ON(pe->table_group.group); BUG_ON(pe->table_group.group);
} }
pnv_pci_ioda2_table_free_pages(tbl);
iommu_free_table(tbl, of_node_full_name(dev->dev.of_node)); iommu_free_table(tbl, of_node_full_name(dev->dev.of_node));
} }
...@@ -2040,7 +2039,6 @@ static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index, ...@@ -2040,7 +2039,6 @@ static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index,
static void pnv_ioda2_table_free(struct iommu_table *tbl) static void pnv_ioda2_table_free(struct iommu_table *tbl)
{ {
pnv_pci_ioda2_table_free_pages(tbl); pnv_pci_ioda2_table_free_pages(tbl);
iommu_free_table(tbl, "pnv");
} }
static struct iommu_table_ops pnv_ioda2_iommu_ops = { static struct iommu_table_ops pnv_ioda2_iommu_ops = {
...@@ -2317,6 +2315,8 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group, ...@@ -2317,6 +2315,8 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group,
if (!tbl) if (!tbl)
return -ENOMEM; return -ENOMEM;
tbl->it_ops = &pnv_ioda2_iommu_ops;
ret = pnv_pci_ioda2_table_alloc_pages(nid, ret = pnv_pci_ioda2_table_alloc_pages(nid,
bus_offset, page_shift, window_size, bus_offset, page_shift, window_size,
levels, tbl); levels, tbl);
...@@ -2325,8 +2325,6 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group, ...@@ -2325,8 +2325,6 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group,
return ret; return ret;
} }
tbl->it_ops = &pnv_ioda2_iommu_ops;
*ptbl = tbl; *ptbl = tbl;
return 0; return 0;
...@@ -2367,7 +2365,7 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe) ...@@ -2367,7 +2365,7 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe)
if (rc) { if (rc) {
pe_err(pe, "Failed to configure 32-bit TCE table, err %ld\n", pe_err(pe, "Failed to configure 32-bit TCE table, err %ld\n",
rc); rc);
pnv_ioda2_table_free(tbl); iommu_free_table(tbl, "");
return rc; return rc;
} }
...@@ -2455,7 +2453,7 @@ static void pnv_ioda2_take_ownership(struct iommu_table_group *table_group) ...@@ -2455,7 +2453,7 @@ static void pnv_ioda2_take_ownership(struct iommu_table_group *table_group)
pnv_pci_ioda2_unset_window(&pe->table_group, 0); pnv_pci_ioda2_unset_window(&pe->table_group, 0);
if (pe->pbus) if (pe->pbus)
pnv_ioda_setup_bus_dma(pe, pe->pbus, false); pnv_ioda_setup_bus_dma(pe, pe->pbus, false);
pnv_ioda2_table_free(tbl); iommu_free_table(tbl, "pnv");
} }
static void pnv_ioda2_release_ownership(struct iommu_table_group *table_group) static void pnv_ioda2_release_ownership(struct iommu_table_group *table_group)
......
...@@ -680,7 +680,7 @@ static void tce_iommu_free_table(struct tce_container *container, ...@@ -680,7 +680,7 @@ static void tce_iommu_free_table(struct tce_container *container,
unsigned long pages = tbl->it_allocated_size >> PAGE_SHIFT; unsigned long pages = tbl->it_allocated_size >> PAGE_SHIFT;
tce_iommu_userspace_view_free(tbl, container->mm); tce_iommu_userspace_view_free(tbl, container->mm);
tbl->it_ops->free(tbl); iommu_free_table(tbl, "");
decrement_locked_vm(container->mm, pages); decrement_locked_vm(container->mm, pages);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment