powerpc/powernv: Fix stale iommu table base after VFIO
[linux-2.6-block.git] / arch / powerpc / platforms / powernv / pci-ioda.c
index 6b0caa2d0425a154acc98eb8eac06024fdec27c6..dc4a3c55044616d4d01798dd5e0127f039f36ff4 100644 (file)
@@ -2462,6 +2462,14 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe)
        if (!pnv_iommu_bypass_disabled)
                pnv_pci_ioda2_set_bypass(pe, true);
 
+       /*
+        * Set table base for the case of IOMMU DMA use. Usually this is done
+        * from dma_dev_setup() which is not called when a device is returned
+        * from VFIO so do it here.
+        */
+       if (pe->pdev)
+               set_iommu_table_base(&pe->pdev->dev, tbl);
+
        return 0;
 }
 
@@ -2549,6 +2557,8 @@ 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);
+       else if (pe->pdev)
+               set_iommu_table_base(&pe->pdev->dev, NULL);
        iommu_tce_table_put(tbl);
 }