]> www.infradead.org Git - users/willy/xarray.git/commitdiff
iommu: Convert intel_pasid to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 11 Feb 2019 20:42:19 +0000 (15:42 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:15 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/iommu/intel-pasid.c
drivers/iommu/intel-pasid.h

index 040a445be30091f4a7cbf6c2158ff9c69896b399..5f22155de0d7bb7639ad4feff82a1d2f331c9112 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /**
- * intel-pasid.c - PASID idr, table and entry manipulation
+ * intel-pasid.c - PASID id, table and entry manipulation
  *
  * Copyright (C) 2018 Intel Corporation
  *
 #include <linux/pci.h>
 #include <linux/pci-ats.h>
 #include <linux/spinlock.h>
+#include <linux/xarray.h>
 
 #include "intel-pasid.h"
 
 /*
  * Intel IOMMU system wide PASID name space:
  */
-static DEFINE_SPINLOCK(pasid_lock);
 u32 intel_pasid_max_id = PASID_MAX;
-static DEFINE_IDR(pasid_idr);
+static DEFINE_XARRAY_ALLOC1(pasid_ptrs);
 
 int intel_pasid_alloc_id(void *ptr, int start, int end, gfp_t gfp)
 {
-       int ret, min, max;
+       int ret, id;
 
-       min = max_t(int, start, PASID_MIN);
-       max = min_t(int, end, intel_pasid_max_id);
+       if (end > intel_pasid_max_id - 1)
+               end = intel_pasid_max_id - 1;
 
-       WARN_ON(in_interrupt());
-       idr_preload(gfp);
-       spin_lock(&pasid_lock);
-       ret = idr_alloc(&pasid_idr, ptr, min, max, GFP_ATOMIC);
-       spin_unlock(&pasid_lock);
-       idr_preload_end();
+       ret = xa_alloc(&pasid_ptrs, &id, ptr, XA_LIMIT(start, end), gfp);
+       if (ret < 0)
+               return ret;
 
-       return ret;
+       return id;
 }
 
 void intel_pasid_free_id(int pasid)
 {
-       spin_lock(&pasid_lock);
-       idr_remove(&pasid_idr, pasid);
-       spin_unlock(&pasid_lock);
+       xa_erase(&pasid_ptrs, pasid);
 }
 
 void *intel_pasid_lookup_id(int pasid)
 {
-       void *p;
-
-       spin_lock(&pasid_lock);
-       p = idr_find(&pasid_idr, pasid);
-       spin_unlock(&pasid_lock);
-
-       return p;
+       return xa_load(&pasid_ptrs, pasid);
 }
 
 /*
@@ -239,19 +228,19 @@ struct pasid_entry *intel_pasid_get_entry(struct device *dev, int pasid)
        dir_index = pasid >> PASID_PDE_SHIFT;
        index = pasid & PASID_PTE_MASK;
 
-       spin_lock(&pasid_lock);
+       xa_lock(&pasid_ptrs);
        entries = get_pasid_table_from_pde(&dir[dir_index]);
        if (!entries) {
                entries = alloc_pgtable_page(info->iommu->node);
                if (!entries) {
-                       spin_unlock(&pasid_lock);
+                       xa_unlock(&pasid_ptrs);
                        return NULL;
                }
 
                WRITE_ONCE(dir[dir_index].val,
                           (u64)virt_to_phys(entries) | PASID_PTE_PRESENT);
        }
-       spin_unlock(&pasid_lock);
+       xa_unlock(&pasid_ptrs);
 
        return &entries[index];
 }
index fc8cd8f17de166a8c96c82c3e73b3e1c3f1572d0..2bb270cb2653003e4f9eacc72701828be7f07d14 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * intel-pasid.h - PASID idr, table and entry header
+ * intel-pasid.h - PASID id, table and entry header
  *
  * Copyright (C) 2018 Intel Corporation
  *