diff mbox

[v2,07/11] drm/i915: Show i915_gem_context owner in debugfs

Message ID 1464003258-23669-8-git-send-email-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson May 23, 2016, 11:34 a.m. UTC
Print the context's owner (via the pid under file_priv) under debugfs.
In doing so, we must be careful that the filp is not accessed after it
is freed (notified via i915_gem_context_close).

v2: Mark the file_priv as closed.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c     | 17 +++++++++++++++--
 drivers/gpu/drm/i915/i915_gem_context.c |  3 ++-
 2 files changed, 17 insertions(+), 3 deletions(-)

Comments

Tvrtko Ursulin May 23, 2016, 12:18 p.m. UTC | #1
On 23/05/16 12:34, Chris Wilson wrote:
> Print the context's owner (via the pid under file_priv) under debugfs.
> In doing so, we must be careful that the filp is not accessed after it
> is freed (notified via i915_gem_context_close).
>
> v2: Mark the file_priv as closed.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/i915_debugfs.c     | 17 +++++++++++++++--
>   drivers/gpu/drm/i915/i915_gem_context.c |  3 ++-
>   2 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index ae28e6e9d603..945fe4710b37 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2014,9 +2014,22 @@ static int i915_context_status(struct seq_file *m, void *unused)
>   			continue;
>
>   		seq_printf(m, "HW context %u ", ctx->hw_id);
> +		if (IS_ERR(ctx->file_priv)) {
> +			seq_puts(m, "(deleted) ");
> +		} else if (ctx->file_priv) {
> +			struct pid *pid = ctx->file_priv->file->pid;
> +			struct task_struct *task;
> +
> +			task = get_pid_task(pid, PIDTYPE_PID);
> +			if (task) {
> +				seq_printf(m, "(%s [%d]) ",
> +					   task->comm, task->pid);
> +				put_task_struct(task);
> +			}
> +		} else
> +			seq_puts(m, "(kernel) ");
> +
>   		describe_ctx(m, ctx);
> -		if (ctx == dev_priv->kernel_context)
> -			seq_printf(m, "(kernel context) ");
>
>   		if (i915.enable_execlists) {
>   			seq_putc(m, '\n');
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
> index 474174c20be2..e552c936d262 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -468,6 +468,7 @@ static int context_idr_cleanup(int id, void *p, void *data)
>   {
>   	struct i915_gem_context *ctx = p;
>
> +	ctx->file_priv = ERR_PTR(-EBADF);
>   	i915_gem_context_put(ctx);
>   	return 0;
>   }
> @@ -936,7 +937,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
>   		return PTR_ERR(ctx);
>   	}
>
> -	idr_remove(&ctx->file_priv->context_idr, ctx->user_handle);
> +	idr_remove(&file_priv->context_idr, ctx->user_handle);
>   	i915_gem_context_put(ctx);
>   	mutex_unlock(&dev->struct_mutex);
>
>

Looks OK.

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko
Joonas Lahtinen May 25, 2016, 9:18 a.m. UTC | #2
On ma, 2016-05-23 at 12:34 +0100, Chris Wilson wrote:
> Print the context's owner (via the pid under file_priv) under debugfs.
> In doing so, we must be careful that the filp is not accessed after it
> is freed (notified via i915_gem_context_close).
> 
> v2: Mark the file_priv as closed.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/i915_debugfs.c     | 17 +++++++++++++++--
>  drivers/gpu/drm/i915/i915_gem_context.c |  3 ++-
>  2 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index ae28e6e9d603..945fe4710b37 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2014,9 +2014,22 @@ static int i915_context_status(struct seq_file *m, void *unused)
>  			continue;
>  
>  		seq_printf(m, "HW context %u ", ctx->hw_id);
> +		if (IS_ERR(ctx->file_priv)) {
> +			seq_puts(m, "(deleted) ");
> +		} else if (ctx->file_priv) {
> +			struct pid *pid = ctx->file_priv->file->pid;
> +			struct task_struct *task;
> +
> +			task = get_pid_task(pid, PIDTYPE_PID);
> +			if (task) {
> +				seq_printf(m, "(%s [%d]) ",
> +					   task->comm, task->pid);
> +				put_task_struct(task);
> +			}
			
What if no task, should we display something still?

> +		} else
> +			seq_puts(m, "(kernel) ");
> +
>  		describe_ctx(m, ctx);
> -		if (ctx == dev_priv->kernel_context)
> -			seq_printf(m, "(kernel context) ");
>  
>  		if (i915.enable_execlists) {
>  			seq_putc(m, '\n');
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
> index 474174c20be2..e552c936d262 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -468,6 +468,7 @@ static int context_idr_cleanup(int id, void *p, void *data)
>  {
>  	struct i915_gem_context *ctx = p;
>  
> +	ctx->file_priv = ERR_PTR(-EBADF);
>  	i915_gem_context_put(ctx);
>  	return 0;
>  }
> @@ -936,7 +937,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
>  		return PTR_ERR(ctx);
>  	}
>  
> -	idr_remove(&ctx->file_priv->context_idr, ctx->user_handle);
> +	idr_remove(&file_priv->context_idr, ctx->user_handle);
>  	i915_gem_context_put(ctx);
>  	mutex_unlock(&dev->struct_mutex);
>
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index ae28e6e9d603..945fe4710b37 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2014,9 +2014,22 @@  static int i915_context_status(struct seq_file *m, void *unused)
 			continue;
 
 		seq_printf(m, "HW context %u ", ctx->hw_id);
+		if (IS_ERR(ctx->file_priv)) {
+			seq_puts(m, "(deleted) ");
+		} else if (ctx->file_priv) {
+			struct pid *pid = ctx->file_priv->file->pid;
+			struct task_struct *task;
+
+			task = get_pid_task(pid, PIDTYPE_PID);
+			if (task) {
+				seq_printf(m, "(%s [%d]) ",
+					   task->comm, task->pid);
+				put_task_struct(task);
+			}
+		} else
+			seq_puts(m, "(kernel) ");
+
 		describe_ctx(m, ctx);
-		if (ctx == dev_priv->kernel_context)
-			seq_printf(m, "(kernel context) ");
 
 		if (i915.enable_execlists) {
 			seq_putc(m, '\n');
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 474174c20be2..e552c936d262 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -468,6 +468,7 @@  static int context_idr_cleanup(int id, void *p, void *data)
 {
 	struct i915_gem_context *ctx = p;
 
+	ctx->file_priv = ERR_PTR(-EBADF);
 	i915_gem_context_put(ctx);
 	return 0;
 }
@@ -936,7 +937,7 @@  int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
 		return PTR_ERR(ctx);
 	}
 
-	idr_remove(&ctx->file_priv->context_idr, ctx->user_handle);
+	idr_remove(&file_priv->context_idr, ctx->user_handle);
 	i915_gem_context_put(ctx);
 	mutex_unlock(&dev->struct_mutex);