Skip to content

Commit 65ac74f

Browse files
Marc Zyngierjoergroedel
authored andcommitted
iommu/dma: Fix MSI reservation allocation
The way cookie_init_hw_msi_region() allocates the iommu_dma_msi_page structures doesn't match the way iommu_put_dma_cookie() frees them. The former performs a single allocation of all the required structures, while the latter tries to free them one at a time. It doesn't quite work for the main use case (the GICv3 ITS where the range is 64kB) when the base granule size is 4kB. This leads to a nice slab corruption on teardown, which is easily observable by simply creating a VF on a SRIOV-capable device, and tearing it down immediately (no need to even make use of it). Fortunately, this only affects systems where the ITS isn't translated by the SMMU, which are both rare and non-standard. Fix it by allocating iommu_dma_msi_page structures one at a time. Fixes: 7c1b058 ("iommu/dma: Handle IOMMU API reserved regions") Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Eric Auger <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Reviewed-by: Robin Murphy <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 0809074 commit 65ac74f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ static int cookie_init_hw_msi_region(struct iommu_dma_cookie *cookie,
177177
start -= iova_offset(iovad, start);
178178
num_pages = iova_align(iovad, end - start) >> iova_shift(iovad);
179179

180-
msi_page = kcalloc(num_pages, sizeof(*msi_page), GFP_KERNEL);
181-
if (!msi_page)
182-
return -ENOMEM;
183-
184180
for (i = 0; i < num_pages; i++) {
185-
msi_page[i].phys = start;
186-
msi_page[i].iova = start;
187-
INIT_LIST_HEAD(&msi_page[i].list);
188-
list_add(&msi_page[i].list, &cookie->msi_page_list);
181+
msi_page = kmalloc(sizeof(*msi_page), GFP_KERNEL);
182+
if (!msi_page)
183+
return -ENOMEM;
184+
185+
msi_page->phys = start;
186+
msi_page->iova = start;
187+
INIT_LIST_HEAD(&msi_page->list);
188+
list_add(&msi_page->list, &cookie->msi_page_list);
189189
start += iovad->granule;
190190
}
191191

0 commit comments

Comments
 (0)