msm: kgsl: Fix context refcounting for adreno debugfs

The code is currently using a device ID look up for the context ID. This
is presumably because there was a refcounting race when looking at the
the debugfs file while the context was being destroyed.  Instead of
trying to be clever, just take a reference count on the context when the
debugfs file is created and release it when the context is detached. This
may cause the context to stick around a bit longer, but it sure is cleaner.

Change-Id: Ic0dedbad3f30168e74d03eade59218f82b93bee4
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
This commit is contained in:
Jordan Crouse 2019-10-14 10:41:03 -06:00
commit fef1dd5afc
2 changed files with 13 additions and 8 deletions

View file

@ -312,16 +312,14 @@ static int ctx_print(struct seq_file *s, void *unused)
static int ctx_open(struct inode *inode, struct file *file)
{
int ret;
unsigned int id = (unsigned int)(unsigned long)inode->i_private;
struct kgsl_context *context;
struct adreno_context *ctx = inode->i_private;
context = kgsl_context_get(kgsl_get_device(KGSL_DEVICE_3D0), id);
if (context == NULL)
if (!_kgsl_context_get(&ctx->base))
return -ENODEV;
ret = single_open(file, ctx_print, context);
ret = single_open(file, ctx_print, &ctx->base);
if (ret)
kgsl_context_put(context);
kgsl_context_put(&ctx->base);
return ret;
}
@ -350,11 +348,16 @@ adreno_context_debugfs_init(struct adreno_device *adreno_dev,
{
unsigned char name[16];
/*
* Get the context here to make sure it still exists for the life of the
* file
*/
_kgsl_context_get(&ctx->base);
snprintf(name, sizeof(name), "%d", ctx->base.id);
ctx->debug_root = debugfs_create_file(name, 0444,
adreno_dev->ctx_d_debugfs,
(void *)(unsigned long)ctx->base.id, &ctx_fops);
adreno_dev->ctx_d_debugfs, ctx, &ctx_fops);
}
void adreno_debugfs_init(struct adreno_device *adreno_dev)

View file

@ -478,6 +478,8 @@ void adreno_drawctxt_detach(struct kgsl_context *context)
}
debugfs_remove_recursive(drawctxt->debug_root);
/* The debugfs file has a reference, release it */
kgsl_context_put(context);
/*
* internal_timestamp is set in adreno_ringbuffer_addcmds,