Skip to content

Commit 11edf11

Browse files
aikmpe
authored andcommitted
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: Alexey Kardashevskiy <[email protected]> Reviewed-by: David Gibson <[email protected]> Acked-by: Alex Williamson <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent a540aa5 commit 11edf11

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

arch/powerpc/kernel/iommu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
719719
if (!tbl)
720720
return;
721721

722+
if (tbl->it_ops->free)
723+
tbl->it_ops->free(tbl);
724+
722725
if (!tbl->it_map) {
723726
kfree(tbl);
724727
return;
@@ -745,6 +748,7 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
745748
/* free table */
746749
kfree(tbl);
747750
}
751+
EXPORT_SYMBOL_GPL(iommu_free_table);
748752

749753
/* Creates TCEs for a user provided buffer. The user buffer must be
750754
* contiguous real kernel storage (not vmalloc). The address passed here

arch/powerpc/platforms/powernv/pci-ioda.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,6 @@ static void pnv_pci_ioda2_release_dma_pe(struct pci_dev *dev, struct pnv_ioda_pe
14241424
iommu_group_put(pe->table_group.group);
14251425
BUG_ON(pe->table_group.group);
14261426
}
1427-
pnv_pci_ioda2_table_free_pages(tbl);
14281427
iommu_free_table(tbl, of_node_full_name(dev->dev.of_node));
14291428
}
14301429

@@ -2040,7 +2039,6 @@ static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index,
20402039
static void pnv_ioda2_table_free(struct iommu_table *tbl)
20412040
{
20422041
pnv_pci_ioda2_table_free_pages(tbl);
2043-
iommu_free_table(tbl, "pnv");
20442042
}
20452043

20462044
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,
23172315
if (!tbl)
23182316
return -ENOMEM;
23192317

2318+
tbl->it_ops = &pnv_ioda2_iommu_ops;
2319+
23202320
ret = pnv_pci_ioda2_table_alloc_pages(nid,
23212321
bus_offset, page_shift, window_size,
23222322
levels, tbl);
@@ -2325,8 +2325,6 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group,
23252325
return ret;
23262326
}
23272327

2328-
tbl->it_ops = &pnv_ioda2_iommu_ops;
2329-
23302328
*ptbl = tbl;
23312329

23322330
return 0;
@@ -2367,7 +2365,7 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe)
23672365
if (rc) {
23682366
pe_err(pe, "Failed to configure 32-bit TCE table, err %ld\n",
23692367
rc);
2370-
pnv_ioda2_table_free(tbl);
2368+
iommu_free_table(tbl, "");
23712369
return rc;
23722370
}
23732371

@@ -2455,7 +2453,7 @@ static void pnv_ioda2_take_ownership(struct iommu_table_group *table_group)
24552453
pnv_pci_ioda2_unset_window(&pe->table_group, 0);
24562454
if (pe->pbus)
24572455
pnv_ioda_setup_bus_dma(pe, pe->pbus, false);
2458-
pnv_ioda2_table_free(tbl);
2456+
iommu_free_table(tbl, "pnv");
24592457
}
24602458

24612459
static void pnv_ioda2_release_ownership(struct iommu_table_group *table_group)

drivers/vfio/vfio_iommu_spapr_tce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ static void tce_iommu_free_table(struct tce_container *container,
680680
unsigned long pages = tbl->it_allocated_size >> PAGE_SHIFT;
681681

682682
tce_iommu_userspace_view_free(tbl, container->mm);
683-
tbl->it_ops->free(tbl);
683+
iommu_free_table(tbl, "");
684684
decrement_locked_vm(container->mm, pages);
685685
}
686686

0 commit comments

Comments
 (0)