From fef1dd5afc6e6f8107728c861f264d82c87c38ab Mon Sep 17 00:00:00 2001 From: Jordan Crouse Date: Mon, 14 Oct 2019 10:41:03 -0600 Subject: [PATCH] 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 --- drivers/gpu/msm/adreno_debugfs.c | 19 +++++++++++-------- drivers/gpu/msm/adreno_drawctxt.c | 2 ++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/msm/adreno_debugfs.c b/drivers/gpu/msm/adreno_debugfs.c index 2af76acb1200..03a59ce24408 100644 --- a/drivers/gpu/msm/adreno_debugfs.c +++ b/drivers/gpu/msm/adreno_debugfs.c @@ -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) diff --git a/drivers/gpu/msm/adreno_drawctxt.c b/drivers/gpu/msm/adreno_drawctxt.c index 2f7f98db3b8f..ab9ad91bdea4 100644 --- a/drivers/gpu/msm/adreno_drawctxt.c +++ b/drivers/gpu/msm/adreno_drawctxt.c @@ -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,