mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 16:24:13 +08:00
566fb90e05
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: Rahul Singh <Rahul.Singh@arm.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Rahul Singh <rahul.singh@arm.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Tested-by: Rahul Singh <rahul.singh@arm.com>
16 lines
483 B
C
16 lines
483 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __LINUX_SWIOTLB_XEN_H
|
|
#define __LINUX_SWIOTLB_XEN_H
|
|
|
|
#include <linux/swiotlb.h>
|
|
#include <asm/xen/swiotlb-xen.h>
|
|
|
|
void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
|
|
size_t size, enum dma_data_direction dir);
|
|
void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
|
|
size_t size, enum dma_data_direction dir);
|
|
|
|
extern const struct dma_map_ops xen_swiotlb_dma_ops;
|
|
|
|
#endif /* __LINUX_SWIOTLB_XEN_H */
|