+++ /dev/null
-From fa46024e864ac17a8ac8ec7dcfb126d10419ffcb Mon Sep 17 00:00:00 2001
-From: Sasha Levin <sashal@kernel.org>
-Date: Tue, 19 Nov 2019 17:38:58 +0100
-Subject: dma-direct: exclude dma_direct_map_resource from the min_low_pfn
- check
-
-From: Christoph Hellwig <hch@lst.de>
-
-[ Upstream commit 68a33b1794665ba8a1d1ef1d3bfcc7c587d380a6 ]
-
-The valid memory address check in dma_capable only makes sense when mapping
-normal memory, not when using dma_map_resource to map a device resource.
-Add a new boolean argument to dma_capable to exclude that check for the
-dma_map_resource case.
-
-Fixes: b12d66278dd6 ("dma-direct: check for overflows on 32 bit DMA addresses")
-Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
-Signed-off-by: Christoph Hellwig <hch@lst.de>
-Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
-Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- arch/x86/kernel/amd_gart_64.c | 4 ++--
- drivers/xen/swiotlb-xen.c | 4 ++--
- include/linux/dma-direct.h | 5 +++--
- kernel/dma/direct.c | 4 ++--
- kernel/dma/swiotlb.c | 2 +-
- 5 files changed, 10 insertions(+), 9 deletions(-)
-
-diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
-index a6ac3712db8bc..5cfab41e8509c 100644
---- a/arch/x86/kernel/amd_gart_64.c
-+++ b/arch/x86/kernel/amd_gart_64.c
-@@ -185,13 +185,13 @@ static void iommu_full(struct device *dev, size_t size, int dir)
- static inline int
- need_iommu(struct device *dev, unsigned long addr, size_t size)
- {
-- return force_iommu || !dma_capable(dev, addr, size);
-+ return force_iommu || !dma_capable(dev, addr, size, true);
- }
-
- static inline int
- nonforced_iommu(struct device *dev, unsigned long addr, size_t size)
- {
-- return !dma_capable(dev, addr, size);
-+ return !dma_capable(dev, addr, size, true);
- }
-
- /* Map a single continuous physical area into the IOMMU.
-diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
-index bd3a10dfac157..8123cccec40dd 100644
---- a/drivers/xen/swiotlb-xen.c
-+++ b/drivers/xen/swiotlb-xen.c
-@@ -375,7 +375,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
- * we can safely return the device addr and not worry about bounce
- * buffering it.
- */
-- if (dma_capable(dev, dev_addr, size) &&
-+ if (dma_capable(dev, dev_addr, size, true) &&
- !range_straddles_page_boundary(phys, size) &&
- !xen_arch_need_swiotlb(dev, phys, dev_addr) &&
- swiotlb_force != SWIOTLB_FORCE)
-@@ -397,7 +397,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
- /*
- * Ensure that the address returned is DMA'ble
- */
-- if (unlikely(!dma_capable(dev, dev_addr, size))) {
-+ if (unlikely(!dma_capable(dev, dev_addr, size, true))) {
- swiotlb_tbl_unmap_single(dev, map, size, size, dir,
- attrs | DMA_ATTR_SKIP_CPU_SYNC);
- return DMA_MAPPING_ERROR;
-diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
-index 6a18a97b76a87..076c2ecb7fa06 100644
---- a/include/linux/dma-direct.h
-+++ b/include/linux/dma-direct.h
-@@ -25,14 +25,15 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
- return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
- }
-
--static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
-+static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
-+ bool is_ram)
- {
- dma_addr_t end = addr + size - 1;
-
- if (!dev->dma_mask)
- return false;
-
-- if (!IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
-+ if (is_ram && !IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
- min(addr, end) < phys_to_dma(dev, PFN_PHYS(min_low_pfn)))
- return false;
-
-diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
-index 867fd72cb2605..c4bf29361f75e 100644
---- a/kernel/dma/direct.c
-+++ b/kernel/dma/direct.c
-@@ -326,7 +326,7 @@ static inline bool dma_direct_possible(struct device *dev, dma_addr_t dma_addr,
- size_t size)
- {
- return swiotlb_force != SWIOTLB_FORCE &&
-- dma_capable(dev, dma_addr, size);
-+ dma_capable(dev, dma_addr, size, true);
- }
-
- dma_addr_t dma_direct_map_page(struct device *dev, struct page *page,
-@@ -375,7 +375,7 @@ dma_addr_t dma_direct_map_resource(struct device *dev, phys_addr_t paddr,
- {
- dma_addr_t dma_addr = paddr;
-
-- if (unlikely(!dma_capable(dev, dma_addr, size))) {
-+ if (unlikely(!dma_capable(dev, dma_addr, size, false))) {
- report_addr(dev, dma_addr, size);
- return DMA_MAPPING_ERROR;
- }
-diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
-index 673a2cdb2656b..9280d6f8271ed 100644
---- a/kernel/dma/swiotlb.c
-+++ b/kernel/dma/swiotlb.c
-@@ -678,7 +678,7 @@ bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr,
-
- /* Ensure that the address returned is DMA'ble */
- *dma_addr = __phys_to_dma(dev, *phys);
-- if (unlikely(!dma_capable(dev, *dma_addr, size))) {
-+ if (unlikely(!dma_capable(dev, *dma_addr, size, true))) {
- swiotlb_tbl_unmap_single(dev, *phys, size, size, dir,
- attrs | DMA_ATTR_SKIP_CPU_SYNC);
- return false;
---
-2.20.1
-
+++ /dev/null
-From 182e83b42c1adbbde6c22f0cf1a0a00c79c49e26 Mon Sep 17 00:00:00 2001
-From: Sasha Levin <sashal@kernel.org>
-Date: Tue, 12 Nov 2019 17:06:04 +0100
-Subject: dma-direct: unify the dma_capable definitions
-
-From: Christoph Hellwig <hch@lst.de>
-
-[ Upstream commit 130c1ccbf55330b55e82612a6e54eebb82c9d746 ]
-
-Currently each architectures that wants to override dma_to_phys and
-phys_to_dma also has to provide dma_capable. But there isn't really
-any good reason for that. powerpc and mips just have copies of the
-generic one minus the latests fix, and the arm one was the inspiration
-for said fix, but misses the bus_dma_mask handling.
-Make all architectures use the generic version instead.
-
-Signed-off-by: Christoph Hellwig <hch@lst.de>
-Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
-Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- arch/arm/include/asm/dma-direct.h | 19 -------------------
- arch/mips/include/asm/dma-direct.h | 8 --------
- arch/powerpc/include/asm/dma-direct.h | 9 ---------
- include/linux/dma-direct.h | 2 +-
- 4 files changed, 1 insertion(+), 37 deletions(-)
-
-diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h
-index b67e5fc1fe436..7c3001a6a775b 100644
---- a/arch/arm/include/asm/dma-direct.h
-+++ b/arch/arm/include/asm/dma-direct.h
-@@ -14,23 +14,4 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
- return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
- }
-
--static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
--{
-- u64 limit, mask;
--
-- if (!dev->dma_mask)
-- return 0;
--
-- mask = *dev->dma_mask;
--
-- limit = (mask + 1) & ~mask;
-- if (limit && size > limit)
-- return 0;
--
-- if ((addr | (addr + size - 1)) & ~mask)
-- return 0;
--
-- return 1;
--}
--
- #endif /* ASM_ARM_DMA_DIRECT_H */
-diff --git a/arch/mips/include/asm/dma-direct.h b/arch/mips/include/asm/dma-direct.h
-index b5c240806e1bb..14e352651ce94 100644
---- a/arch/mips/include/asm/dma-direct.h
-+++ b/arch/mips/include/asm/dma-direct.h
-@@ -2,14 +2,6 @@
- #ifndef _MIPS_DMA_DIRECT_H
- #define _MIPS_DMA_DIRECT_H 1
-
--static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
--{
-- if (!dev->dma_mask)
-- return false;
--
-- return addr + size - 1 <= *dev->dma_mask;
--}
--
- dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
- phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
-
-diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h
-index a2912b47102cf..e29e8a236b8df 100644
---- a/arch/powerpc/include/asm/dma-direct.h
-+++ b/arch/powerpc/include/asm/dma-direct.h
-@@ -2,15 +2,6 @@
- #ifndef ASM_POWERPC_DMA_DIRECT_H
- #define ASM_POWERPC_DMA_DIRECT_H 1
-
--static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
--{
-- if (!dev->dma_mask)
-- return false;
--
-- return addr + size - 1 <=
-- min_not_zero(*dev->dma_mask, dev->bus_dma_mask);
--}
--
- static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
- {
- if (!dev)
-diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
-index 076c2ecb7fa06..9e764a798c819 100644
---- a/include/linux/dma-direct.h
-+++ b/include/linux/dma-direct.h
-@@ -24,6 +24,7 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
-
- return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
- }
-+#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
-
- static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
- bool is_ram)
-@@ -39,7 +40,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
-
- return end <= min_not_zero(*dev->dma_mask, dev->bus_dma_mask);
- }
--#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
-
- #ifdef CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED
- bool force_dma_unencrypted(struct device *dev);
---
-2.20.1
-