Skip to content

Commit f316ba0

Browse files
superm1joergroedel
authored andcommitted
dma-iommu: Check that swiotlb is active before trying to use it
If the IOMMU is in use and an untrusted device is connected to an external facing port but the address requested isn't page aligned will cause the kernel to attempt to use bounce buffers. If for some reason the bounce buffers have not been allocated this is a problem that should be made apparent to the user. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20220404204723.9767-3-mario.limonciello@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 121660b commit f316ba0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/iommu/dma-iommu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,11 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
971971
void *padding_start;
972972
size_t padding_size, aligned_size;
973973

974+
if (!is_swiotlb_active(dev)) {
975+
dev_warn_once(dev, "DMA bounce buffers are inactive, unable to map unaligned transaction.\n");
976+
return DMA_MAPPING_ERROR;
977+
}
978+
974979
aligned_size = iova_align(iovad, size);
975980
phys = swiotlb_tbl_map_single(dev, phys, size, aligned_size,
976981
iova_mask(iovad), dir, attrs);

0 commit comments

Comments
 (0)