iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/dma: Fix IOVA reserve dma ranges
@ 2020-09-09  5:32 Srinath Mannam via iommu
  2020-09-09 12:05 ` Robin Murphy
  0 siblings, 1 reply; 3+ messages in thread
From: Srinath Mannam via iommu @ 2020-09-09  5:32 UTC (permalink / raw)
  To: Robin Murphy, Joerg Roedel, Lorenzo Pieralisi, Bjorn Helgaas, poza
  Cc: Srinath Mannam, iommu, bcm-kernel-feedback-list, linux-kernel

Fix IOVA reserve failure for memory regions listed in dma-ranges in the
following cases.

- start address of memory region is 0x0.
- end address of a memory region is equal to start address of next memory
  region.

Fixes: aadad097cd46f ("iommu/dma: Reserve IOVA for PCIe inaccessible DMA address")
Signed-off-by: Srinath Mannam <srinath.mannam@broadcom.com>
---
 drivers/iommu/dma-iommu.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 5141d49a046b..0a3f67a4f9ae 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -213,14 +213,21 @@ static int iova_reserve_pci_windows(struct pci_dev *dev,
 	resource_list_for_each_entry(window, &bridge->dma_ranges) {
 		end = window->res->start - window->offset;
 resv_iova:
+		if (end < start) {
+			/* dma_ranges list should be sorted */
+			dev_err(&dev->dev, "Failed to reserve IOVA\n");
+			return -EINVAL;
+		}
+		/*
+		 * Skip the cases when start address of first memory region is
+		 * 0x0 and end address of one memory region and start address
+		 * of next memory region are equal. Reserve IOVA for rest of
+		 * addresses fall in between given memory ranges.
+		 */
 		if (end > start) {
 			lo = iova_pfn(iovad, start);
 			hi = iova_pfn(iovad, end);
 			reserve_iova(iovad, lo, hi);
-		} else {
-			/* dma_ranges list should be sorted */
-			dev_err(&dev->dev, "Failed to reserve IOVA\n");
-			return -EINVAL;
 		}
 
 		start = window->res->end - window->offset + 1;
-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, other threads:[~2020-09-10  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09  5:32 [PATCH] iommu/dma: Fix IOVA reserve dma ranges Srinath Mannam via iommu
2020-09-09 12:05 ` Robin Murphy
2020-09-10  8:26   ` Srinath Mannam via iommu

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).