Skip to content

Commit 1f7aacc

Browse files
Gaurav Batrampe
authored andcommitted
powerpc/iommu: Incorrect DDW Table is referenced for SR-IOV device
For an SR-IOV device, while enabling DDW, a new table is created and added at index 1 in the group. In the below 2 scenarios, the table is incorrectly referenced at index 0 (which is where the table is for default DMA window). 1. When adding DDW This issue is exposed with "slub_debug". Error thrown out from dma_iommu_dma_supported() Warning: IOMMU offset too big for device mask mask: 0xffffffff, table offset: 0x800000000000000 2. During Dynamic removal of the PCI device. Error is from iommu_tce_table_put() since a NULL table pointer is passed in. Fixes: 381ceda ("powerpc/pseries/iommu: Make use of DDW for indirect mapping") Cc: [email protected] # v5.15+ Signed-off-by: Gaurav Batra <[email protected]> Reviewed-by: Brian King <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent 096339a commit 1f7aacc

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

arch/powerpc/kernel/dma-iommu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static bool dma_iommu_bypass_supported(struct device *dev, u64 mask)
144144
/* We support DMA to/from any memory page via the iommu */
145145
int dma_iommu_dma_supported(struct device *dev, u64 mask)
146146
{
147-
struct iommu_table *tbl = get_iommu_table_base(dev);
147+
struct iommu_table *tbl;
148148

149149
if (dev_is_pci(dev) && dma_iommu_bypass_supported(dev, mask)) {
150150
/*
@@ -162,6 +162,8 @@ int dma_iommu_dma_supported(struct device *dev, u64 mask)
162162
return 1;
163163
}
164164

165+
tbl = get_iommu_table_base(dev);
166+
165167
if (!tbl) {
166168
dev_err(dev, "Warning: IOMMU dma not supported: mask 0x%08llx, table unavailable\n", mask);
167169
return 0;

arch/powerpc/platforms/pseries/iommu.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,24 @@ static struct iommu_table_group *iommu_pseries_alloc_group(int node)
9191
static void iommu_pseries_free_group(struct iommu_table_group *table_group,
9292
const char *node_name)
9393
{
94-
struct iommu_table *tbl;
95-
9694
if (!table_group)
9795
return;
9896

99-
tbl = table_group->tables[0];
10097
#ifdef CONFIG_IOMMU_API
10198
if (table_group->group) {
10299
iommu_group_put(table_group->group);
103100
BUG_ON(table_group->group);
104101
}
105102
#endif
106-
iommu_tce_table_put(tbl);
103+
104+
/* Default DMA window table is at index 0, while DDW at 1. SR-IOV
105+
* adapters only have table on index 1.
106+
*/
107+
if (table_group->tables[0])
108+
iommu_tce_table_put(table_group->tables[0]);
109+
110+
if (table_group->tables[1])
111+
iommu_tce_table_put(table_group->tables[1]);
107112

108113
kfree(table_group);
109114
}

0 commit comments

Comments
 (0)