public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/dma: limit the IOVA allocated to dma-ranges region
@ 2017-08-31 22:08 Krishna Reddy
  2017-09-01  9:26 ` Joerg Roedel
  0 siblings, 1 reply; 6+ messages in thread
From: Krishna Reddy @ 2017-08-31 22:08 UTC (permalink / raw)
  To: joro, iommu, linux-kernel, vdumpa

Limit the IOVA allocated to dma-ranges specified for the device.
This is necessary to ensure that IOVA allocated is addressable
by device.

Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
---
 drivers/iommu/dma-iommu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 9d1cebe7f6cb..e8a8320b571b 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -364,6 +364,7 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain,
 	struct iommu_dma_cookie *cookie = domain->iova_cookie;
 	struct iova_domain *iovad = &cookie->iovad;
 	unsigned long shift, iova_len, iova = 0;
+	dma_addr_t dma_end_addr;
 
 	if (cookie->type == IOMMU_DMA_MSI_COOKIE) {
 		cookie->msi_iova += size;
@@ -381,6 +382,10 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain,
 	if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
 		iova_len = roundup_pow_of_two(iova_len);
 
+	/* Limit IOVA allocated to device addressable dma-ranges region. */
+	dma_end_addr = (dma_addr_t)iovad->dma_32bit_pfn << shift;
+	dma_limit = dma_limit > dma_end_addr ? dma_end_addr : dma_limit;
+
 	if (domain->geometry.force_aperture)
 		dma_limit = min(dma_limit, domain->geometry.aperture_end);
 
-- 
2.1.4

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

end of thread, other threads:[~2017-09-08 18:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-31 22:08 [PATCH] iommu/dma: limit the IOVA allocated to dma-ranges region Krishna Reddy
2017-09-01  9:26 ` Joerg Roedel
2017-09-01  9:43   ` Robin Murphy
2017-09-05 17:35     ` Krishna Reddy
2017-09-08 14:12       ` Robin Murphy
2017-09-08 18:12         ` Krishna Reddy

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