drm/i915: Stop storing ctx->user_handle
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 21 Mar 2019 14:07:10 +0000 (14:07 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 21 Mar 2019 15:59:29 +0000 (15:59 +0000)
The user_handle need only be known by userspace for it to lookup the
context via the idr; internally we have no use for it.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190321140711.11190-3-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_debugfs.c
drivers/gpu/drm/i915/i915_gem_context.c
drivers/gpu/drm/i915/i915_gem_context.h
drivers/gpu/drm/i915/i915_gem_context_types.h
drivers/gpu/drm/i915/i915_gpu_error.c
drivers/gpu/drm/i915/i915_gpu_error.h
drivers/gpu/drm/i915/selftests/mock_context.c

index 0dd8b3fa7fb9881b7963590b14f20747326d4db4..47bf07a59b5e1bd39e395b1817d09bcb652595cf 100644 (file)
@@ -409,9 +409,8 @@ static void print_context_stats(struct seq_file *m,
 
                        rcu_read_lock();
                        task = pid_task(ctx->pid ?: file->pid, PIDTYPE_PID);
-                       snprintf(name, sizeof(name), "%s/%d",
-                                task ? task->comm : "<unknown>",
-                                ctx->user_handle);
+                       snprintf(name, sizeof(name), "%s",
+                                task ? task->comm : "<unknown>");
                        rcu_read_unlock();
 
                        print_file_stats(m, name, stats);
index 9c6987ee27e5d7d218ca2789b9e261a93a9809ba..9187910391d8f7ecdecf433abac684693af9a481 100644 (file)
@@ -602,20 +602,15 @@ static int gem_context_register(struct i915_gem_context *ctx,
 
        /* And finally expose ourselves to userspace via the idr */
        mutex_lock(&fpriv->context_idr_lock);
-       ret = idr_alloc(&fpriv->context_idr, ctx,
-                       DEFAULT_CONTEXT_HANDLE, 0, GFP_KERNEL);
-       if (ret >= 0)
-               ctx->user_handle = ret;
+       ret = idr_alloc(&fpriv->context_idr, ctx, 0, 0, GFP_KERNEL);
        mutex_unlock(&fpriv->context_idr_lock);
-       if (ret < 0)
-               goto err_name;
-
-       return 0;
+       if (ret >= 0)
+               goto out;
 
-err_name:
        kfree(fetch_and_zero(&ctx->name));
 err_pid:
        put_pid(fetch_and_zero(&ctx->pid));
+out:
        return ret;
 }
 
@@ -638,11 +633,11 @@ int i915_gem_context_open(struct drm_i915_private *i915,
        }
 
        err = gem_context_register(ctx, file_priv);
-       if (err)
+       if (err < 0)
                goto err_ctx;
 
-       GEM_BUG_ON(ctx->user_handle != DEFAULT_CONTEXT_HANDLE);
        GEM_BUG_ON(i915_gem_context_is_kernel(ctx));
+       GEM_BUG_ON(err > 0);
 
        return 0;
 
@@ -852,10 +847,10 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
                return PTR_ERR(ctx);
 
        ret = gem_context_register(ctx, file_priv);
-       if (ret)
+       if (ret < 0)
                goto err_ctx;
 
-       args->ctx_id = ctx->user_handle;
+       args->ctx_id = ret;
        DRM_DEBUG("HW context %d created\n", args->ctx_id);
 
        return 0;
@@ -877,7 +872,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
        if (args->pad != 0)
                return -EINVAL;
 
-       if (args->ctx_id == DEFAULT_CONTEXT_HANDLE)
+       if (!args->ctx_id)
                return -ENOENT;
 
        if (mutex_lock_interruptible(&file_priv->context_idr_lock))
index 5a32c4b4816f87e144300beb14b06458c0445a35..7e79d1ffbaef1ecf5f5a98aabfa586409c42cf98 100644 (file)
@@ -126,11 +126,6 @@ static inline void i915_gem_context_unpin_hw_id(struct i915_gem_context *ctx)
        atomic_dec(&ctx->hw_id_pin_count);
 }
 
-static inline bool i915_gem_context_is_default(const struct i915_gem_context *c)
-{
-       return c->user_handle == DEFAULT_CONTEXT_HANDLE;
-}
-
 static inline bool i915_gem_context_is_kernel(struct i915_gem_context *ctx)
 {
        return !ctx->file_priv;
index 2bf19730eaa97086fe718d6bcdbf6fa38e15b572..63ae8eb219393d6217bd488393eae0dc61dd1f75 100644 (file)
@@ -129,15 +129,6 @@ struct i915_gem_context {
        struct list_head active_engines;
        struct mutex mutex;
 
-       /**
-        * @user_handle: userspace identifier
-        *
-        * A unique per-file identifier is generated from
-        * &drm_i915_file_private.contexts.
-        */
-       u32 user_handle;
-#define DEFAULT_CONTEXT_HANDLE 0
-
        struct i915_sched_attr sched;
 
        /** hw_contexts: per-engine logical HW state */
index 26bac517e38360ea9f1e4113690b4c41d07045b8..a9557f92756f62e7ecfa7659df6ee34838ada844 100644 (file)
@@ -454,8 +454,8 @@ static void error_print_context(struct drm_i915_error_state_buf *m,
                                const char *header,
                                const struct drm_i915_error_context *ctx)
 {
-       err_printf(m, "%s%s[%d] user_handle %d hw_id %d, prio %d, guilty %d active %d\n",
-                  header, ctx->comm, ctx->pid, ctx->handle, ctx->hw_id,
+       err_printf(m, "%s%s[%d] hw_id %d, prio %d, guilty %d active %d\n",
+                  header, ctx->comm, ctx->pid, ctx->hw_id,
                   ctx->sched_attr.priority, ctx->guilty, ctx->active);
 }
 
@@ -758,11 +758,9 @@ static void __err_print_to_sgl(struct drm_i915_error_state_buf *m,
                if (obj) {
                        err_puts(m, m->i915->engine[i]->name);
                        if (ee->context.pid)
-                               err_printf(m, " (submitted by %s [%d], ctx %d [%d])",
+                               err_printf(m, " (submitted by %s [%d])",
                                           ee->context.comm,
-                                          ee->context.pid,
-                                          ee->context.handle,
-                                          ee->context.hw_id);
+                                          ee->context.pid);
                        err_printf(m, " --- gtt_offset = 0x%08x %08x\n",
                                   upper_32_bits(obj->gtt_offset),
                                   lower_32_bits(obj->gtt_offset));
@@ -1330,7 +1328,6 @@ static void record_context(struct drm_i915_error_context *e,
                rcu_read_unlock();
        }
 
-       e->handle = ctx->user_handle;
        e->hw_id = ctx->hw_id;
        e->sched_attr = ctx->sched;
        e->guilty = atomic_read(&ctx->guilty_count);
index 99d6b7b270c2033bc2d8fa6771c51615482a90bb..302a14240b456fd42363dcc6beb80c97b591f455 100644 (file)
@@ -116,7 +116,6 @@ struct i915_gpu_state {
                struct drm_i915_error_context {
                        char comm[TASK_COMM_LEN];
                        pid_t pid;
-                       u32 handle;
                        u32 hw_id;
                        int active;
                        int guilty;
index ad3875b01722dc3387fdfbee6663b20cc6b5bd98..bc14e9aec2748bd61b35520575ffc99cef6c5a60 100644 (file)
@@ -98,7 +98,7 @@ live_context(struct drm_i915_private *i915, struct drm_file *file)
                return ctx;
 
        err = gem_context_register(ctx, file->driver_priv);
-       if (err)
+       if (err < 0)
                goto err_ctx;
 
        return ctx;