]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
powerpc/iommu/vfio_spapr_tce: Cleanup iommu_table disposal
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Mon, 7 Aug 2017 15:45:00 +0000 (17:45 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Thu, 24 Aug 2017 08:03:22 +0000 (10:03 +0200)
BugLink: http://bugs.launchpad.net/bugs/1686019
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 <aik@ozlabs.ru>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
(cherry picked from commit 11edf116e3a6352cfee6b1437d41603c9aff79c9)
Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
arch/powerpc/kernel/iommu.c
arch/powerpc/platforms/powernv/pci-ioda.c
drivers/vfio/vfio_iommu_spapr_tce.c

index 685a4767b72238e7264d13fb3f5a8b1021efb467..a3689fdedd4ae25768d5d3b1ca041e1658f7b6be 100644 (file)
@@ -719,6 +719,9 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
        if (!tbl)
                return;
 
+       if (tbl->it_ops->free)
+               tbl->it_ops->free(tbl);
+
        if (!tbl->it_map) {
                kfree(tbl);
                return;
@@ -745,6 +748,7 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
        /* free table */
        kfree(tbl);
 }
+EXPORT_SYMBOL_GPL(iommu_free_table);
 
 /* Creates TCEs for a user provided buffer.  The user buffer must be
  * contiguous real kernel storage (not vmalloc).  The address passed here
index 3c44a792c0b7f574b9006b8362c0a0ec2b1f94a8..0b1bb56a30b8dda7a2fcc7461ee31c2bb2c145ee 100644 (file)
@@ -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);
                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));
 }
 
@@ -2049,7 +2048,6 @@ static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index,
 static void pnv_ioda2_table_free(struct iommu_table *tbl)
 {
        pnv_pci_ioda2_table_free_pages(tbl);
-       iommu_free_table(tbl, "pnv");
 }
 
 static struct iommu_table_ops pnv_ioda2_iommu_ops = {
@@ -2326,6 +2324,8 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group,
        if (!tbl)
                return -ENOMEM;
 
+       tbl->it_ops = &pnv_ioda2_iommu_ops;
+
        ret = pnv_pci_ioda2_table_alloc_pages(nid,
                        bus_offset, page_shift, window_size,
                        levels, tbl);
@@ -2334,8 +2334,6 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group,
                return ret;
        }
 
-       tbl->it_ops = &pnv_ioda2_iommu_ops;
-
        *ptbl = tbl;
 
        return 0;
@@ -2376,7 +2374,7 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe)
        if (rc) {
                pe_err(pe, "Failed to configure 32-bit TCE table, err %ld\n",
                                rc);
-               pnv_ioda2_table_free(tbl);
+               iommu_free_table(tbl, "");
                return rc;
        }
 
@@ -2464,7 +2462,7 @@ static void pnv_ioda2_take_ownership(struct iommu_table_group *table_group)
        pnv_pci_ioda2_unset_window(&pe->table_group, 0);
        if (pe->pbus)
                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)
index 59b3f62a2d64ebd85be990630e09a48c7c7f2f1c..ffab01874a22bb7ede5affdb879e1d57c23c7fcd 100644 (file)
@@ -677,7 +677,7 @@ static void tce_iommu_free_table(struct tce_container *container,
        unsigned long pages = tbl->it_allocated_size >> PAGE_SHIFT;
 
        tce_iommu_userspace_view_free(tbl, container->mm);
-       tbl->it_ops->free(tbl);
+       iommu_free_table(tbl, "");
        decrement_locked_vm(container->mm, pages);
 }