On Mon, Oct 07, 2019 at 01:58:57PM -0400, Arvind Sankar wrote:
> On Mon, Oct 07, 2019 at 10:56:30AM -0700, Christoph Hellwig wrote:
> > On Mon, Oct 07, 2019 at 07:55:28PM +0200, Christoph Hellwig wrote:
> > > On Mon, Oct 07, 2019 at 01:54:32PM -0400, Arvind Sankar wrote:
> > > > It doesn't boot with the patch. Won't it go
> > > >         dma_get_required_mask
> > > >         -> intel_get_required_mask
> > > >         -> iommu_need_mapping
> > > >         -> dma_get_required_mask
> > > > ?
> > > > 
> > > > Should the call to dma_get_required_mask in iommu_need_mapping be
> > > > replaced with dma_direct_get_required_mask on top of your patch?
> > > 
> > > Yes, sorry.
> > 
> > Actually my patch already calls dma_direct_get_required_mask.
> > How did you get the loop?
> 
> The function iommu_need_mapping (not changed by your patch) calls
> dma_get_required_mask internally, to check whether the device's dma_mask
> is big enough or not. That's the call I was asking whether it needs to
> be changed.

Yeah the attached patch seems to fix it.
>From 074e8cc145dde514427c40124913a90c4552dd6e Mon Sep 17 00:00:00 2001
From: Arvind Sankar <nived...@alum.mit.edu>
Date: Mon, 7 Oct 2019 14:19:12 -0400
Subject: [PATCH] iommu/vt-d: Return the correct dma mask when we are bypassing
 the IOMMU

We must return a mask covering the full physical RAM when bypassing the
IOMMU mapping. Also, in iommu_need_mapping, we need to check using
dma_direct_get_required_mask to ensure that the device's dma_mask can
cover physical RAM before deciding to bypass IOMMU mapping.

Fixes: 249baa547901 ("dma-mapping: provide a better default ->get_required_mask")
Signed-off-by: Arvind Sankar <nived...@alum.mit.edu>
---
 drivers/iommu/intel-iommu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 3f974919d3bd..79e35b3180ac 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -3471,7 +3471,7 @@ static bool iommu_need_mapping(struct device *dev)
 		if (dev->coherent_dma_mask && dev->coherent_dma_mask < dma_mask)
 			dma_mask = dev->coherent_dma_mask;
 
-		if (dma_mask >= dma_get_required_mask(dev))
+		if (dma_mask >= dma_direct_get_required_mask(dev))
 			return false;
 
 		/*
@@ -3775,6 +3775,13 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
 	return nelems;
 }
 
+static u64 intel_get_required_mask(struct device *dev)
+{
+	if (!iommu_need_mapping(dev))
+		return dma_direct_get_required_mask(dev);
+	return DMA_BIT_MASK(32);
+}
+
 static const struct dma_map_ops intel_dma_ops = {
 	.alloc = intel_alloc_coherent,
 	.free = intel_free_coherent,
@@ -3787,6 +3794,7 @@ static const struct dma_map_ops intel_dma_ops = {
 	.dma_supported = dma_direct_supported,
 	.mmap = dma_common_mmap,
 	.get_sgtable = dma_common_get_sgtable,
+	.get_required_mask = intel_get_required_mask,
 };
 
 static void
-- 
2.21.0

Reply via email to