• Christoph Hellwig's avatar
    swiotlb-xen: fix DMA_ATTR_NO_KERNEL_MAPPING on arm · 566fb90e
    Christoph Hellwig authored
    swiotlb-xen uses very different ways to allocate coherent memory on x86
    vs arm.  On the former it allocates memory from the page allocator, while
    on the later it reuses the dma-direct allocator the handles the
    complexities of non-coherent DMA on arm platforms.
    
    Unfortunately the complexities of trying to deal with the two cases in
    the swiotlb-xen.c code lead to a bug in the handling of
    DMA_ATTR_NO_KERNEL_MAPPING on arm.  With the DMA_ATTR_NO_KERNEL_MAPPING
    flag the coherent memory allocator does not actually allocate coherent
    memory, but just a DMA handle for some memory that is DMA addressable
    by the device, but which does not have to have a kernel mapping.  Thus
    dereferencing the return value will lead to kernel crashed and memory
    corruption.
    
    Fix this by using the dma-direct allocator directly for arm, which works
    perfectly fine because on arm swiotlb-xen is only used when the domain is
    1:1 mapped, and then simplifying the remaining code to only cater for the
    x86 case with DMA coherent device.
    Reported-by: default avatarRahul Singh <Rahul.Singh@arm.com>
    Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
    Reviewed-by: default avatarRahul Singh <rahul.singh@arm.com>
    Reviewed-by: default avatarStefano Stabellini <sstabellini@kernel.org>
    Tested-by: default avatarRahul Singh <rahul.singh@arm.com>
    566fb90e
swiotlb-xen.h 483 Bytes