]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915/gem: Embed context/timeline name inside the GEM context
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 11 Nov 2019 11:43:20 +0000 (11:43 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 11 Nov 2019 11:46:40 +0000 (11:46 +0000)
Use a small char buffer inside the i915_gem_context to store the user
friendly name so that ctx->name has the same lifetime as the RCU
protected GEM context. That is, e.g. when using print_request() that
prints the timeline name (ctx->name), the name will not be prematurely
freed upon the context being closed and the last reference dropped.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191111114323.5833-2-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/gem/i915_gem_context.c
drivers/gpu/drm/i915/gem/i915_gem_context_types.h
drivers/gpu/drm/i915/gem/selftests/mock_context.c

index 94b51b13ef177be596018d8e1ec22ed43789a6c6..982770e8163d623cbadc27ad06f978dbd410ec7a 100644 (file)
@@ -277,9 +277,7 @@ static void i915_gem_context_free(struct i915_gem_context *ctx)
        if (ctx->timeline)
                intel_timeline_put(ctx->timeline);
 
-       kfree(ctx->name);
        put_pid(ctx->pid);
-
        mutex_destroy(&ctx->mutex);
 
        kfree_rcu(ctx, rcu);
@@ -789,12 +787,8 @@ static int gem_context_register(struct i915_gem_context *ctx,
        mutex_unlock(&ctx->mutex);
 
        ctx->pid = get_task_pid(current, PIDTYPE_PID);
-       ctx->name = kasprintf(GFP_KERNEL, "%s[%d]",
-                             current->comm, pid_nr(ctx->pid));
-       if (!ctx->name) {
-               ret = -ENOMEM;
-               goto err_pid;
-       }
+       snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
+                current->comm, pid_nr(ctx->pid));
 
        /* And finally expose ourselves to userspace via the idr */
        mutex_lock(&fpriv->context_idr_lock);
@@ -803,8 +797,6 @@ static int gem_context_register(struct i915_gem_context *ctx,
        if (ret >= 0)
                goto out;
 
-       kfree(fetch_and_zero(&ctx->name));
-err_pid:
        put_pid(fetch_and_zero(&ctx->pid));
 out:
        return ret;
index 861d7d92fe9f6fced21ba89cdc73d42b6053c5a6..69df5459c350ab50aeac482e529aa9e989aec859 100644 (file)
@@ -100,15 +100,6 @@ struct i915_gem_context {
         */
        struct pid *pid;
 
-       /**
-        * @name: arbitrary name
-        *
-        * A name is constructed for the context from the creator's process
-        * name, pid and user handle in order to uniquely identify the
-        * context in messages.
-        */
-       const char *name;
-
        /** link: place with &drm_i915_private.context_list */
        struct list_head link;
        struct llist_node free_link;
@@ -176,6 +167,15 @@ struct i915_gem_context {
         * per vm, which may be one per context or shared with the global GTT)
         */
        struct radix_tree_root handles_vma;
+
+       /**
+        * @name: arbitrary name, used for user debug
+        *
+        * A name is constructed for the context from the creator's process
+        * name, pid and user handle in order to uniquely identify the
+        * context in messages.
+        */
+       char name[TASK_COMM_LEN + 8];
 };
 
 #endif /* __I915_GEM_CONTEXT_TYPES_H__ */
index cdcb006321a7d52fca8e32917f2a1c7dfbfa51f4..53e89efb09c0b6cbd864037f63b6d92e30448dbb 100644 (file)
@@ -37,9 +37,7 @@ mock_context(struct drm_i915_private *i915,
        if (name) {
                struct i915_ppgtt *ppgtt;
 
-               ctx->name = kstrdup(name, GFP_KERNEL);
-               if (!ctx->name)
-                       goto err_put;
+               strncpy(ctx->name, name, sizeof(ctx->name));
 
                ppgtt = mock_ppgtt(i915, name);
                if (!ppgtt)