linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: nwatters@codeaurora.org (Nate Watterson)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] arm64/dma-mapping: validate dma_masks against IORT defined limits
Date: Tue, 31 Jan 2017 15:16:01 -0500	[thread overview]
Message-ID: <1485893763-20671-2-git-send-email-nwatters@codeaurora.org> (raw)
In-Reply-To: <1485893763-20671-1-git-send-email-nwatters@codeaurora.org>

Some drivers set the dma_mask of client devices based solely on values
read from capability registers which may not account for platform
specific bus address width limitations. Fortunately, the ACPI IORT table
provides a way to report the effective number of address bits a device
can use to access memory. This information, when present, is used to
supplement the checks already being done in dma_supported() to avoid
setting overly generous dma_masks.

Signed-off-by: Nate Watterson <nwatters@codeaurora.org>
---
 arch/arm64/mm/dma-mapping.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index e040827..467fd23 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -19,6 +19,7 @@
 
 #include <linux/gfp.h>
 #include <linux/acpi.h>
+#include <linux/acpi_iort.h>
 #include <linux/bootmem.h>
 #include <linux/cache.h>
 #include <linux/export.h>
@@ -347,6 +348,12 @@ static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt,
 
 static int __swiotlb_dma_supported(struct device *hwdev, u64 mask)
 {
+	int dma_limit;
+
+	dma_limit = iort_get_memory_address_limit(hwdev);
+	if (dma_limit >= 0 && DMA_BIT_MASK(dma_limit) < mask)
+		return 0;
+
 	if (swiotlb)
 		return swiotlb_dma_supported(hwdev, mask);
 	return 1;
@@ -784,6 +791,17 @@ static void __iommu_unmap_sg_attrs(struct device *dev,
 	iommu_dma_unmap_sg(dev, sgl, nelems, dir, attrs);
 }
 
+static int __iommu_dma_supported(struct device *hwdev, u64 mask)
+{
+	int dma_limit;
+
+	dma_limit = iort_get_memory_address_limit(hwdev);
+	if (dma_limit >= 0 && DMA_BIT_MASK(dma_limit) < mask)
+		return 0;
+
+	return iommu_dma_supported(hwdev, mask);
+}
+
 static struct dma_map_ops iommu_dma_ops = {
 	.alloc = __iommu_alloc_attrs,
 	.free = __iommu_free_attrs,
@@ -799,7 +817,7 @@ static void __iommu_unmap_sg_attrs(struct device *dev,
 	.sync_sg_for_device = __iommu_sync_sg_for_device,
 	.map_resource = iommu_dma_map_resource,
 	.unmap_resource = iommu_dma_unmap_resource,
-	.dma_supported = iommu_dma_supported,
+	.dma_supported = __iommu_dma_supported,
 	.mapping_error = iommu_dma_mapping_error,
 };
 
-- 
Qualcomm Datacenter Technologies, Inc. on behalf of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux
Foundation Collaborative Project.

       reply	other threads:[~2017-01-31 20:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1485893763-20671-1-git-send-email-nwatters@codeaurora.org>
2017-01-31 20:16 ` Nate Watterson [this message]
2017-02-01 13:44   ` [PATCH 2/2] arm64/dma-mapping: validate dma_masks against IORT defined limits Robin Murphy
2017-02-01 14:36     ` Lorenzo Pieralisi
2017-02-01 15:27       ` Robin Murphy
2017-02-01 15:34         ` Arnd Bergmann
2017-02-01 16:38           ` Robin Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1485893763-20671-2-git-send-email-nwatters@codeaurora.org \
    --to=nwatters@codeaurora.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).