summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Murphy <robin.murphy@arm.com>2017-09-28 12:31:23 +0200
committerJoerg Roedel <jroedel@suse.de>2017-09-28 14:57:16 +0200
commite8b198402745ed413ed8229b2eb45d34016eb5d8 (patch)
tree4b552a320579484b7f0e8e5ada98c97e2832d12f
parentiommu/iova: Make rcache limit_pfn handling more robust (diff)
downloadlinux-e8b198402745ed413ed8229b2eb45d34016eb5d8.tar.xz
linux-e8b198402745ed413ed8229b2eb45d34016eb5d8.zip
iommu/iova: Try harder to allocate from rcache magazine
When devices with different DMA masks are using the same domain, or for PCI devices where we usually try a speculative 32-bit allocation first, there is a fair possibility that the top PFN of the rcache stack at any given time may be unsuitable for the lower limit, prompting a fallback to allocating anew from the rbtree. Consequently, we may end up artifically increasing pressure on the 32-bit IOVA space as unused IOVAs accumulate lower down in the rcache stacks, while callers with 32-bit masks also impose unnecessary rbtree overhead. In such cases, let's try a bit harder to satisfy the allocation locally first - scanning the whole stack should still be relatively inexpensive. Signed-off-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
-rw-r--r--drivers/iommu/iova.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 15ff3033bbd7..b0ca23682008 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -821,12 +821,21 @@ static bool iova_magazine_empty(struct iova_magazine *mag)
static unsigned long iova_magazine_pop(struct iova_magazine *mag,
unsigned long limit_pfn)
{
+ int i;
+ unsigned long pfn;
+
BUG_ON(iova_magazine_empty(mag));
- if (mag->pfns[mag->size - 1] > limit_pfn)
- return 0;
+ /* Only fall back to the rbtree if we have no suitable pfns at all */
+ for (i = mag->size - 1; mag->pfns[i] > limit_pfn; i--)
+ if (i == 0)
+ return 0;
+
+ /* Swap it to pop it */
+ pfn = mag->pfns[i];
+ mag->pfns[i] = mag->pfns[--mag->size];
- return mag->pfns[--mag->size];
+ return pfn;
}
static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn)