• Catalin Marinas's avatar
    iommu/dma: force bouncing if the size is not cacheline-aligned · 861370f4
    Catalin Marinas authored
    Similarly to the direct DMA, bounce small allocations as they may have
    originated from a kmalloc() cache not safe for DMA. Unlike the direct
    DMA, iommu_dma_map_sg() cannot call iommu_dma_map_sg_swiotlb() for all
    non-coherent devices as this would break some cases where the iova is
    expected to be contiguous (dmabuf). Instead, scan the scatterlist for
    any small sizes and only go the swiotlb path if any element of the list
    needs bouncing (note that iommu_dma_map_page() would still only bounce
    those buffers which are not DMA-aligned).
    
    To avoid scanning the scatterlist on the 'sync' operations, introduce an
    SG_DMA_SWIOTLB flag set by iommu_dma_map_sg_swiotlb(). The
    dev_use_swiotlb() function together with the newly added
    dev_use_sg_swiotlb() now check for both untrusted devices and unaligned
    kmalloc() buffers (suggested by Robin Murphy).
    
    Link: https://lkml.kernel.org/r/20230612153201.554742-16-catalin.marinas@arm.comSigned-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
    Reviewed-by: default avatarRobin Murphy <robin.murphy@arm.com>
    Tested-by: default avatarIsaac J. Manjarres <isaacmanjarres@google.com>
    Cc: Joerg Roedel <joro@8bytes.org>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Alasdair Kergon <agk@redhat.com>
    Cc: Ard Biesheuvel <ardb@kernel.org>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Daniel Vetter <daniel@ffwll.ch>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Herbert Xu <herbert@gondor.apana.org.au>
    Cc: Jerry Snitselaar <jsnitsel@redhat.com>
    Cc: Jonathan Cameron <jic23@kernel.org>
    Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Cc: Lars-Peter Clausen <lars@metafoo.de>
    Cc: Logan Gunthorpe <logang@deltatee.com>
    Cc: Marc Zyngier <maz@kernel.org>
    Cc: Mark Brown <broonie@kernel.org>
    Cc: Mike Snitzer <snitzer@kernel.org>
    Cc: "Rafael J. Wysocki" <rafael@kernel.org>
    Cc: Saravana Kannan <saravanak@google.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Will Deacon <will@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    861370f4
dma-iommu.c 46.7 KB