@@ -795,18 +795,19 @@ static void iova_magazine_free(struct iova_magazine *mag)
kfree(mag);
}
-static void
-iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad)
+static void iova_magazine_compact_pfns(struct iova_magazine *mag,
+ struct iova_domain *iovad,
+ unsigned long newsize)
{
unsigned long flags;
int i;
- if (!mag)
+ if (!mag || mag->size <= newsize)
return;
spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
- for (i = 0 ; i < mag->size; ++i) {
+ for (i = newsize; i < mag->size; ++i) {
struct iova *iova = private_find_iova(iovad, mag->pfns[i]);
BUG_ON(!iova);
@@ -815,7 +816,13 @@ static void iova_magazine_free(struct iova_magazine *mag)
spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
- mag->size = 0;
+ mag->size = newsize;
+}
+
+static void
+iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad)
+{
+ iova_magazine_compact_pfns(mag, iovad, 0);
}
static bool iova_magazine_full(struct iova_magazine *mag)
iova_magazine_free_pfns() can only free the whole magazine buffer, add iova_magazine_compact_pfns() to support free part of it. Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> --- drivers/iommu/iova.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) -- 1.8.3