c2341d5
From patchwork Wed Jan 25 18:31:31 2017
c2341d5
Content-Type: text/plain; charset="utf-8"
c2341d5
MIME-Version: 1.0
c2341d5
Content-Transfer-Encoding: 7bit
c2341d5
Subject: [v2] arm64: dma-mapping: Fix dma_mapping_error() when bypassing
c2341d5
 SWIOTLB
c2341d5
From: Robin Murphy <robin.murphy@arm.com>
c2341d5
X-Patchwork-Id: 9537723
c2341d5
Message-Id: <840027acb4750542003dff17b4a8902ba8972754.1485368348.git.robin.murphy@arm.com>
c2341d5
To: will.deacon@arm.com,
c2341d5
	catalin.marinas@arm.com
c2341d5
Cc: Jisheng Zhang <jszhang@marvell.com>, arnd@arndb.de,
c2341d5
 konrad.wilk@oracle.com, aaro.koskinen@iki.fi, stable@vger.kernel.org,
c2341d5
 linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org
c2341d5
Date: Wed, 25 Jan 2017 18:31:31 +0000
c2341d5
c2341d5
When bypassing SWIOTLB on small-memory systems, we need to avoid calling
c2341d5
into swiotlb_dma_mapping_error() in exactly the same way as we avoid
c2341d5
swiotlb_dma_supported(), because the former also relies on SWIOTLB state
c2341d5
being initialised.
c2341d5
c2341d5
Under the assumptions for which we skip SWIOTLB, dma_map_{single,page}()
c2341d5
will only ever return the DMA-offset-adjusted physical address of the
c2341d5
page passed in, thus we can report success unconditionally.
c2341d5
c2341d5
Fixes: b67a8b29df7e ("arm64: mm: only initialize swiotlb when necessary")
c2341d5
CC: stable@vger.kernel.org
c2341d5
CC: Jisheng Zhang <jszhang@marvell.com>
c2341d5
Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi>
c2341d5
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
c2341d5
Tested-by: Aaro Koskinen <aaro.koskinen@iki.fi>
c2341d5
---
c2341d5
c2341d5
v2: Get the return value the right way round this time... After some
c2341d5
    careful reasoning it really is that simple.
c2341d5
c2341d5
 arch/arm64/mm/dma-mapping.c | 9 ++++++++-
c2341d5
 1 file changed, 8 insertions(+), 1 deletion(-)
c2341d5
c2341d5
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
c2341d5
index e04082700bb1..1ffb7d5d299a 100644
c2341d5
--- a/arch/arm64/mm/dma-mapping.c
c2341d5
+++ b/arch/arm64/mm/dma-mapping.c
c2341d5
@@ -352,6 +352,13 @@ static int __swiotlb_dma_supported(struct device *hwdev, u64 mask)
c2341d5
 	return 1;
c2341d5
 }
c2341d5
 
c2341d5
+static int __swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t addr)
c2341d5
+{
c2341d5
+	if (swiotlb)
c2341d5
+		return swiotlb_dma_mapping_error(hwdev, addr);
c2341d5
+	return 0;
c2341d5
+}
c2341d5
+
c2341d5
 static struct dma_map_ops swiotlb_dma_ops = {
c2341d5
 	.alloc = __dma_alloc,
c2341d5
 	.free = __dma_free,
c2341d5
@@ -366,7 +373,7 @@ static struct dma_map_ops swiotlb_dma_ops = {
c2341d5
 	.sync_sg_for_cpu = __swiotlb_sync_sg_for_cpu,
c2341d5
 	.sync_sg_for_device = __swiotlb_sync_sg_for_device,
c2341d5
 	.dma_supported = __swiotlb_dma_supported,
c2341d5
-	.mapping_error = swiotlb_dma_mapping_error,
c2341d5
+	.mapping_error = __swiotlb_dma_mapping_error,
c2341d5
 };
c2341d5
 
c2341d5
 static int __init atomic_pool_init(void)