iommu/dma: Fix arch_sync_dma for map
authorDavid Stevens <stevensd@chromium.org>
Wed, 29 Sep 2021 02:32:55 +0000 (11:32 +0900)
committerJoerg Roedel <jroedel@suse.de>
Wed, 29 Sep 2021 10:49:44 +0000 (12:49 +0200)
commit06e620345d544e559b2961cb5a676ec9c80c8950
treed0a96d2c97a8329fa981498556b5bfeaa2bcfb2b
parent08ae5d4a1ae96b72222e7b02d072bb997ff29dac
iommu/dma: Fix arch_sync_dma for map

When calling arch_sync_dma, we need to pass it the memory that's
actually being used for dma. When using swiotlb bounce buffers, this is
the bounce buffer. Move arch_sync_dma into the __iommu_dma_map_swiotlb
helper, so it can use the bounce buffer address if necessary.

Now that iommu_dma_map_sg delegates to a function which takes care of
architectural syncing in the untrusted device case, the call to
iommu_dma_sync_sg_for_device can be moved so it only occurs for trusted
devices. Doing the sync for untrusted devices before mapping never
really worked, since it needs to be able to target swiotlb buffers.

This also moves the architectural sync to before the call to
__iommu_dma_map, to guarantee that untrusted devices can't see stale
data they shouldn't see.

Fixes: 82612d66d51d ("iommu: Allow the iommu/dma api to use bounce buffers")
Signed-off-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/20210929023300.335969-3-stevensd@google.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/dma-iommu.c