]> www.infradead.org Git - users/willy/xarray.git/commitdiff
ocxl: Convert contexts_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 20:15:43 +0000 (15:15 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:11 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/misc/ocxl/context.c
drivers/misc/ocxl/core.c
drivers/misc/ocxl/ocxl_internal.h

index 227b63a0201088cb120bee26037cf5deb6178f77..c6ec35a0400efd0657bf04fe20e53447c6fcffe4 100644 (file)
@@ -7,7 +7,9 @@
 int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu,
                struct address_space *mapping)
 {
-       int pasid;
+       struct xa_limit limit = XA_LIMIT(afu->pasid_base,
+                       afu->pasid_base + afu->pasid_max - 1);
+       int err;
        struct ocxl_context *ctx;
 
        *context = kzalloc(sizeof(struct ocxl_context), GFP_KERNEL);
@@ -17,17 +19,15 @@ int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu,
        ctx = *context;
 
        ctx->afu = afu;
-       mutex_lock(&afu->contexts_lock);
-       pasid = idr_alloc(&afu->contexts_idr, ctx, afu->pasid_base,
-                       afu->pasid_base + afu->pasid_max, GFP_KERNEL);
-       if (pasid < 0) {
-               mutex_unlock(&afu->contexts_lock);
-               return pasid;
-       }
-       afu->pasid_count++;
-       mutex_unlock(&afu->contexts_lock);
 
-       ctx->pasid = pasid;
+       xa_lock(&afu->contexts);
+       err = __xa_alloc(&afu->contexts, &ctx->pasid, ctx, limit, GFP_KERNEL);
+       if (err == 0)
+               afu->pasid_count++;
+       xa_unlock(&afu->contexts);
+       if (err < 0)
+               return err;
+
        ctx->status = OPENED;
        mutex_init(&ctx->status_mutex);
        ctx->mapping = mapping;
@@ -258,10 +258,9 @@ EXPORT_SYMBOL_GPL(ocxl_context_detach);
 void ocxl_context_detach_all(struct ocxl_afu *afu)
 {
        struct ocxl_context *ctx;
-       int tmp;
+       unsigned long index;
 
-       mutex_lock(&afu->contexts_lock);
-       idr_for_each_entry(&afu->contexts_idr, ctx, tmp) {
+       xa_for_each(&afu->contexts, index, ctx) {
                ocxl_context_detach(ctx);
                /*
                 * We are force detaching - remove any active mmio
@@ -275,15 +274,14 @@ void ocxl_context_detach_all(struct ocxl_afu *afu)
                        unmap_mapping_range(ctx->mapping, 0, 0, 1);
                mutex_unlock(&ctx->mapping_lock);
        }
-       mutex_unlock(&afu->contexts_lock);
 }
 
 void ocxl_context_free(struct ocxl_context *ctx)
 {
-       mutex_lock(&ctx->afu->contexts_lock);
+       xa_lock(&ctx->afu->contexts);
        ctx->afu->pasid_count--;
-       idr_remove(&ctx->afu->contexts_idr, ctx->pasid);
-       mutex_unlock(&ctx->afu->contexts_lock);
+       __xa_erase(&ctx->afu->contexts, ctx->pasid);
+       xa_unlock(&ctx->afu->contexts);
 
        ocxl_afu_irq_free_all(ctx);
        /* reference to the AFU taken in ocxl_context_init */
index b7a09b21ab36f026317546c1850e283e951f88a5..80be777191fba1fe7d5b5c53a9655b7932bbbba3 100644 (file)
@@ -22,9 +22,8 @@ static struct ocxl_afu *alloc_afu(struct ocxl_fn *fn)
                return NULL;
 
        kref_init(&afu->kref);
-       mutex_init(&afu->contexts_lock);
        mutex_init(&afu->afu_control_lock);
-       idr_init(&afu->contexts_idr);
+       xa_init_flags(&afu->contexts, XA_FLAGS_ALLOC);
        afu->fn = fn;
        ocxl_fn_get(fn);
        return afu;
@@ -34,7 +33,7 @@ static void free_afu(struct kref *kref)
 {
        struct ocxl_afu *afu = container_of(kref, struct ocxl_afu, kref);
 
-       idr_destroy(&afu->contexts_idr);
+       BUG_ON(!xa_empty(&afu->contexts));
        ocxl_fn_put(afu->fn);
        kfree(afu);
 }
index a8cdb4f1947bed90b924b7a0810658af82e87916..c5bfef85c01480de4cacb4e228cfb5a11c83261f 100644 (file)
@@ -44,8 +44,7 @@ struct ocxl_afu {
        int pasid_max; /* maximum number of contexts */
        int actag_base;
        int actag_enabled;
-       struct mutex contexts_lock;
-       struct idr contexts_idr;
+       struct xarray contexts;
        struct mutex afu_control_lock;
        u64 global_mmio_start;
        u64 irq_base_offset;