Skip to content

Commit

Permalink
powerpc/pseries/iommu: Use the iommu table[0] for IOV VF's DDW
Browse files Browse the repository at this point in the history
This patch basically brings consistency with PowerNV approach
to use the first freely available iommu table when the default
window is removed.

The pSeries iommu code convention has been that the table[0] is
for the default 32 bit DMA window and the table[1] is for the
64 bit DDW.

With VFs having only 1 DMA window, the default has to be removed
for creating the larger DMA window. The existing code uses the
table[1] for that, while marking the table[0] as NULL. This is
fine as long as the host driver itself uses the device.

For the VFIO user, on pSeries there is no way to skip table[0]
as the VFIO subdriver uses the first freely available table.
The window 0, when created as 64-bit DDW in that context would
still be on table[0], as the maximum number of windows is 1.

This won't have any impact for the host driver as the table is
fetched from the device's iommu_table_base.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
[mpe: Rebase and resolve conflicts]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/171923272328.1397.1817843961216868850.stgit@linux.ibm.com
  • Loading branch information
Shivaprasad G Bhat authored and Michael Ellerman committed Jun 28, 2024
1 parent 6af67f2 commit aed6e49
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions arch/powerpc/platforms/pseries/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void iommu_pseries_free_group(struct iommu_table_group *table_group,
#endif

/* Default DMA window table is at index 0, while DDW at 1. SR-IOV
* adapters only have table on index 1.
* adapters only have table on index 0(if not direct mapped).
*/
if (table_group->tables[0])
iommu_tce_table_put(table_group->tables[0]);
Expand Down Expand Up @@ -1555,6 +1555,11 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn)
clean_dma_window(pdn, win64->value);
goto out_del_list;
}
if (default_win_removed) {
iommu_tce_table_put(pci->table_group->tables[0]);
pci->table_group->tables[0] = NULL;
set_iommu_table_base(&dev->dev, NULL);
}
}

if (dynamic_mapping) {
Expand Down Expand Up @@ -1592,15 +1597,12 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn)
&iommu_table_lpar_multi_ops);
iommu_init_table(newtbl, pci->phb->node, start, end);

pci->table_group->tables[1] = newtbl;
pci->table_group->tables[default_win_removed ? 0 : 1] = newtbl;

set_iommu_table_base(&dev->dev, newtbl);
}

if (default_win_removed) {
iommu_tce_table_put(pci->table_group->tables[0]);
pci->table_group->tables[0] = NULL;

/* default_win is valid here because default_win_removed == true */
of_remove_property(pdn, default_win);
dev_info(&dev->dev, "Removed default DMA window for %pOF\n", pdn);
Expand Down

0 comments on commit aed6e49

Please sign in to comment.