public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] intel-iommu: Obey coherent_dma_mask for alloc_coherent on passthrough
@ 2009-11-04 22:59 Alex Williamson
  2009-11-06  2:41 ` FUJITA Tomonori
  2009-11-10  0:46 ` [PATCH] intel-iommu: Obey coherent_dma_mask for alloc_coherent on passthrough David Woodhouse
  0 siblings, 2 replies; 16+ messages in thread
From: Alex Williamson @ 2009-11-04 22:59 UTC (permalink / raw)
  To: dwmw2; +Cc: iommu, linux-kernel, akpm, alex.williamson

intel_alloc_coherent() needs to follow DMA mapping convention and
make use of the coherent_dma_mask of the device for identity mappings.
Without this, devices may get buffers they can't use.  This patch
provides best effort allocations and fails the request if the mask
requirements are not met rather than returning an unusable buffer.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
---

This patch fixes a regression introduced since 2.6.31 that prevents
devices with a restricted coherent_dma_mask from working in passthrough
mode.

 drivers/pci/intel-iommu.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index b1e97e6..8283df9 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -2582,7 +2582,7 @@ static dma_addr_t __intel_map_single(struct device *hwdev, phys_addr_t paddr,
 	BUG_ON(dir == DMA_NONE);
 
 	if (iommu_no_mapping(hwdev))
-		return paddr;
+		return paddr + size > dma_mask ? 0 : paddr;
 
 	domain = get_valid_domain_for_dev(pdev);
 	if (!domain)
@@ -2767,7 +2767,15 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
 
 	size = PAGE_ALIGN(size);
 	order = get_order(size);
-	flags &= ~(GFP_DMA | GFP_DMA32);
+
+	if (!iommu_no_mapping(hwdev))
+		flags &= ~(GFP_DMA | GFP_DMA32);
+	else if (hwdev->coherent_dma_mask != DMA_BIT_MASK(64)) {
+		if (hwdev->coherent_dma_mask < DMA_BIT_MASK(32))
+			flags |= GFP_DMA;
+		else
+			flags |= GFP_DMA32;
+	}
 
 	vaddr = (void *)__get_free_pages(flags, order);
 	if (!vaddr)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-11-28  6:17 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-04 22:59 [PATCH] intel-iommu: Obey coherent_dma_mask for alloc_coherent on passthrough Alex Williamson
2009-11-06  2:41 ` FUJITA Tomonori
2009-11-06  3:19   ` Alex Williamson
2009-11-06  3:34     ` FUJITA Tomonori
2009-11-06  4:09       ` Alex Williamson
2009-11-09 23:02   ` David Woodhouse
2009-11-09 23:32     ` Alex Williamson
2009-11-10  0:19       ` David Woodhouse
2009-11-11 15:23     ` [stable][PATCH] PCIe hot-plug for Intel IOMMU Fenghua Yu
2009-11-11 21:27       ` Yinghai Lu
2009-11-28  6:17         ` David Woodhouse
2009-11-12  2:37       ` David Woodhouse
2009-11-12 23:32         ` Yu, Fenghua
2009-11-10  0:46 ` [PATCH] intel-iommu: Obey coherent_dma_mask for alloc_coherent on passthrough David Woodhouse
2009-11-10  1:01   ` David Woodhouse
2009-11-10  1:28     ` Alex Williamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox