From: Matthew Wilcox (Oracle) Date: Wed, 15 May 2019 17:35:38 +0000 (-0400) Subject: drm/i915: Convert vm_idr to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9c8a6be4f84ec8931312359ddf57c500b35e621b;p=users%2Fwilly%2Fxarray.git drm/i915: Convert vm_idr to XArray Rename vm_idr to vms and remove the mutex protecting it. Signed-off-by: Matthew Wilcox (Oracle) --- diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index d93e319f88c0a..902bdb34c2bab 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -704,12 +704,6 @@ void i915_gem_contexts_fini(struct drm_i915_private *i915) ida_destroy(&i915->contexts.hw_ida); } -static int vm_idr_cleanup(int id, void *p, void *data) -{ - i915_vm_put(p); - return 0; -} - static int gem_context_register(struct i915_gem_context *ctx, struct drm_i915_file_private *fpriv) { @@ -745,10 +739,8 @@ int i915_gem_context_open(struct drm_i915_private *i915, struct i915_gem_context *ctx; int err; - mutex_init(&file_priv->vm_idr_lock); - xa_init_flags(&file_priv->contexts, XA_FLAGS_ALLOC); - idr_init_base(&file_priv->vm_idr, 1); + xa_init_flags(&file_priv->vms, XA_FLAGS_ALLOC1); mutex_lock(&i915->drm.struct_mutex); ctx = i915_gem_create_context(i915, 0); @@ -770,9 +762,8 @@ int i915_gem_context_open(struct drm_i915_private *i915, err_ctx: context_close(ctx); err: - idr_destroy(&file_priv->vm_idr); + xa_destroy(&file_priv->vms); xa_destroy(&file_priv->contexts); - mutex_destroy(&file_priv->vm_idr_lock); return err; } @@ -780,15 +771,16 @@ void i915_gem_context_close(struct drm_file *file) { struct drm_i915_file_private *file_priv = file->driver_priv; struct i915_gem_context *ctx; + struct i915_address_space *vm; unsigned long index; xa_for_each(&file_priv->contexts, index, ctx) context_close(ctx); xa_destroy(&file_priv->contexts); - idr_for_each(&file_priv->vm_idr, vm_idr_cleanup, NULL); - idr_destroy(&file_priv->vm_idr); - mutex_destroy(&file_priv->vm_idr_lock); + xa_for_each(&file_priv->vms, index, vm) + i915_vm_put(vm); + xa_destroy(&file_priv->vms); } int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data, @@ -820,23 +812,15 @@ int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data, goto err_put; } - err = mutex_lock_interruptible(&file_priv->vm_idr_lock); - if (err) - goto err_put; - - err = idr_alloc(&file_priv->vm_idr, &ppgtt->vm, 0, 0, GFP_KERNEL); + err = xa_alloc(&file_priv->vms, &args->vm_id, &ppgtt->vm, + xa_limit_32b, GFP_KERNEL); if (err < 0) - goto err_unlock; - - GEM_BUG_ON(err == 0); /* reserved for invalid/unassigned ppgtt */ + goto err_put; - mutex_unlock(&file_priv->vm_idr_lock); + GEM_BUG_ON(args->vm_id == 0); /* reserved for invalid/unassigned */ - args->vm_id = err; return 0; -err_unlock: - mutex_unlock(&file_priv->vm_idr_lock); err_put: i915_vm_put(&ppgtt->vm); return err; @@ -848,7 +832,6 @@ int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data, struct drm_i915_file_private *file_priv = file->driver_priv; struct drm_i915_gem_vm_control *args = data; struct i915_address_space *vm; - int err; u32 id; if (args->flags) @@ -861,13 +844,7 @@ int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data, if (!id) return -ENOENT; - err = mutex_lock_interruptible(&file_priv->vm_idr_lock); - if (err) - return err; - - vm = idr_remove(&file_priv->vm_idr, id); - - mutex_unlock(&file_priv->vm_idr_lock); + vm = xa_erase(&file_priv->vms, id); if (!vm) return -ENOENT; @@ -963,6 +940,7 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv, { struct i915_address_space *vm; int ret; + u32 id; if (!ctx->vm) return -ENODEV; @@ -975,23 +953,15 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv, vm = i915_vm_get(ctx->vm); mutex_unlock(&ctx->i915->drm.struct_mutex); - ret = mutex_lock_interruptible(&file_priv->vm_idr_lock); - if (ret) - goto err_put; - - ret = idr_alloc(&file_priv->vm_idr, vm, 0, 0, GFP_KERNEL); - GEM_BUG_ON(!ret); + ret = xa_alloc(&file_priv->vms, &id, vm, xa_limit_32b, GFP_KERNEL); if (ret < 0) - goto err_unlock; - - i915_vm_get(vm); + goto err_put; + GEM_BUG_ON(!id); args->size = 0; - args->value = ret; + args->value = id; - ret = 0; -err_unlock: - mutex_unlock(&file_priv->vm_idr_lock); + return 0; err_put: i915_vm_put(vm); return ret; @@ -1082,14 +1052,11 @@ static int set_ppgtt(struct drm_i915_file_private *file_priv, if (upper_32_bits(args->value)) return -ENOENT; - err = mutex_lock_interruptible(&file_priv->vm_idr_lock); - if (err) - return err; - - vm = idr_find(&file_priv->vm_idr, args->value); + xa_lock(&file_priv->vms); + vm = xa_load(&file_priv->vms, args->value); if (vm) i915_vm_get(vm); - mutex_unlock(&file_priv->vm_idr_lock); + xa_unlock(&file_priv->vms); if (!vm) return -ENOENT; diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index d84239cfd2bbf..41e37f72d67db 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -219,9 +219,7 @@ struct drm_i915_file_private { } mm; struct xarray contexts; - - struct idr vm_idr; - struct mutex vm_idr_lock; /* guards vm_idr */ + struct xarray vms; unsigned int bsd_engine;