Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Cc: Matthew Auld <matthew.auld@intel.com>
Subject: Re: [PATCH 02/25] drm/i915/gem: Embed context/timeline name inside the GEM context
Date: Mon, 11 Nov 2019 13:20:16 +0200	[thread overview]
Message-ID: <8736eu64nj.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <20191110185806.17413-2-chris@chris-wilson.co.uk>

Chris Wilson <chris@chris-wilson.co.uk> writes:

> 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>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_context.c    | 12 ++----------
>  .../gpu/drm/i915/gem/i915_gem_context_types.h  | 18 +++++++++---------
>  .../gpu/drm/i915/gem/selftests/mock_context.c  |  4 +---
>  3 files changed, 12 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> index 94b51b13ef17..982770e8163d 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> @@ -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;
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
> index 861d7d92fe9f..69df5459c350 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
> @@ -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];

I consider 24 bytes as quite cheap for robustness and simplicity.
In a playground where we throw pages around like sand.

Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>

>  };
>  
>  #endif /* __I915_GEM_CONTEXT_TYPES_H__ */
> diff --git a/drivers/gpu/drm/i915/gem/selftests/mock_context.c b/drivers/gpu/drm/i915/gem/selftests/mock_context.c
> index cdcb006321a7..53e89efb09c0 100644
> --- a/drivers/gpu/drm/i915/gem/selftests/mock_context.c
> +++ b/drivers/gpu/drm/i915/gem/selftests/mock_context.c
> @@ -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)
> -- 
> 2.24.0
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Cc: Matthew Auld <matthew.auld@intel.com>
Subject: Re: [Intel-gfx] [PATCH 02/25] drm/i915/gem: Embed context/timeline name inside the GEM context
Date: Mon, 11 Nov 2019 13:20:16 +0200	[thread overview]
Message-ID: <8736eu64nj.fsf@gaia.fi.intel.com> (raw)
Message-ID: <20191111112016.4XIEeeXut5LbyvtYztBDQYRxsnZ8xbJtV-yW8saDqe4@z> (raw)
In-Reply-To: <20191110185806.17413-2-chris@chris-wilson.co.uk>

Chris Wilson <chris@chris-wilson.co.uk> writes:

> 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>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_context.c    | 12 ++----------
>  .../gpu/drm/i915/gem/i915_gem_context_types.h  | 18 +++++++++---------
>  .../gpu/drm/i915/gem/selftests/mock_context.c  |  4 +---
>  3 files changed, 12 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> index 94b51b13ef17..982770e8163d 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> @@ -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;
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
> index 861d7d92fe9f..69df5459c350 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
> @@ -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];

I consider 24 bytes as quite cheap for robustness and simplicity.
In a playground where we throw pages around like sand.

Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>

>  };
>  
>  #endif /* __I915_GEM_CONTEXT_TYPES_H__ */
> diff --git a/drivers/gpu/drm/i915/gem/selftests/mock_context.c b/drivers/gpu/drm/i915/gem/selftests/mock_context.c
> index cdcb006321a7..53e89efb09c0 100644
> --- a/drivers/gpu/drm/i915/gem/selftests/mock_context.c
> +++ b/drivers/gpu/drm/i915/gem/selftests/mock_context.c
> @@ -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)
> -- 
> 2.24.0
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-11-11 11:20 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-10 18:57 [PATCH 01/25] drm/i915: Protect context while grabbing its name for the request Chris Wilson
2019-11-10 18:57 ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 02/25] drm/i915/gem: Embed context/timeline name inside the GEM context Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 11:20   ` Mika Kuoppala [this message]
2019-11-11 11:20     ` Mika Kuoppala
2019-11-10 18:57 ` [PATCH 03/25] drm/i915/gem: Update context name on closing Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 10:47   ` Mika Kuoppala
2019-11-11 10:47     ` [Intel-gfx] " Mika Kuoppala
2019-11-11 10:58     ` Chris Wilson
2019-11-11 10:58       ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 04/25] drm/i915/execlists: Move reset_active() from schedule-out to schedule-in Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 05/25] drm/i915/pmu: "Frequency" is reported as accumulated cycles Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 06/25] drm/i915/userptr: Handle unlocked gup retries Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 07/25] drm/i915: Cancel context if it hangs after it is closed Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 10:54   ` Mika Kuoppala
2019-11-11 10:54     ` [Intel-gfx] " Mika Kuoppala
2019-11-11 11:04     ` Chris Wilson
2019-11-11 11:04       ` [Intel-gfx] " Chris Wilson
2019-11-11 11:25       ` Mika Kuoppala
2019-11-11 11:25         ` [Intel-gfx] " Mika Kuoppala
2019-11-10 18:57 ` [PATCH 08/25] drm/i915: Show guilty context name on GPU reset Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 11:26   ` Mika Kuoppala
2019-11-11 11:26     ` [Intel-gfx] " Mika Kuoppala
2019-11-10 18:57 ` [PATCH 09/25] drm/i915/icl: Refine PG_HYSTERESIS Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 10:59   ` Mika Kuoppala
2019-11-11 10:59     ` [Intel-gfx] " Mika Kuoppala
2019-11-10 18:57 ` [PATCH 10/25] drm/i915/execlists: Reduce barrier on context switch to a wmb() Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 13:19   ` Joonas Lahtinen
2019-11-11 13:19     ` [Intel-gfx] " Joonas Lahtinen
2019-11-10 18:57 ` [PATCH 11/25] drm/i915/gem: Silence sparse for RCU protection inside the constructor Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 12/25] drm/i915/userptr: Try to acquire the page lock around set_page_dirty() Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 13/25] drm/i915: Taint the kernel on dumping the GEM ftrace buffer Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 12:44   ` Joonas Lahtinen
2019-11-11 12:44     ` [Intel-gfx] " Joonas Lahtinen
2019-11-10 18:57 ` [PATCH 14/25] drm/i915/selftests: Exercise parallel blit operations on a single ctx Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 12:10   ` Matthew Auld
2019-11-11 12:10     ` [Intel-gfx] " Matthew Auld
2019-11-10 18:57 ` [PATCH 15/25] drm/i915/selftests: Perform some basic cycle counting of MI ops Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 17:10   ` Matthew Auld
2019-11-11 17:10     ` [Intel-gfx] " Matthew Auld
2019-11-11 17:16     ` Chris Wilson
2019-11-11 17:16       ` [Intel-gfx] " Chris Wilson
2019-11-11 17:20       ` Matthew Auld
2019-11-11 17:20         ` [Intel-gfx] " Matthew Auld
2019-11-10 18:57 ` [PATCH 16/25] drm/i915/selftests: Mock the engine sorting for easy validation Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 17/25] drm/i915/selftests: Fill all the drm_vma_manager holes Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-11 12:01   ` Matthew Auld
2019-11-11 12:01     ` [Intel-gfx] " Matthew Auld
2019-11-11 12:09     ` Chris Wilson
2019-11-11 12:09       ` [Intel-gfx] " Chris Wilson
2019-11-10 18:57 ` [PATCH 18/25] Revert "drm/i915: use a separate context for gpu relocs" Chris Wilson
2019-11-10 18:57   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:58 ` [PATCH 19/25] drm/i915: Use a ctor for TYPESAFE_BY_RCU i915_request Chris Wilson
2019-11-10 18:58   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:58 ` [PATCH 20/25] drm/i915: Drop GEM context as a direct link from i915_request Chris Wilson
2019-11-10 18:58   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:58 ` [PATCH 21/25] drm/i915: Push the use-semaphore marker onto the intel_context Chris Wilson
2019-11-10 18:58   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:58 ` [PATCH 22/25] drm/i915: Remove i915->kernel_context Chris Wilson
2019-11-10 18:58   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:58 ` [PATCH 23/25] drm/i915: Move i915_gem_init_contexts() earlier Chris Wilson
2019-11-10 18:58   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:58 ` [PATCH 24/25] drm/i915/uc: Use an internal buffer for firmware images Chris Wilson
2019-11-10 18:58   ` [Intel-gfx] " Chris Wilson
2019-11-10 18:58 ` [PATCH 25/25] drm/i915/gt: Pull GT initialisation under intel_gt_init() Chris Wilson
2019-11-10 18:58   ` [Intel-gfx] " Chris Wilson
2019-11-10 19:20 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/25] drm/i915: Protect context while grabbing its name for the request Patchwork
2019-11-10 19:20   ` [Intel-gfx] " Patchwork
2019-11-10 19:40 ` ✓ Fi.CI.BAT: success " Patchwork
2019-11-10 19:40   ` [Intel-gfx] " Patchwork
2019-11-11 15:34 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-11-11 15:34   ` [Intel-gfx] " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8736eu64nj.fsf@gaia.fi.intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox