From e0f2afe5eb43fb32490ccabd504879c3e3e54623 Mon Sep 17 00:00:00 2001 From: David Nieto Date: Mon, 13 Mar 2017 20:23:03 -0700 Subject: gpu: nvgpu: refactor teardown to support unbind This change refactors the teardown in remove to ensure that it is possible to unload the driver while leaving fds open. This is achieved by making sure that the SW state is kept alive till all fds are closed and by checking that subsequent calls to ioctls after the teardown fail. Normally, this would be achieved ny calls into gk20a_busy(), but in kickoff we dont call into that to reduce latency, so we need to check the driver status directly, and also in some of the functions as we need to make sure the ioctl does not dereference the device or platform struct bug 200277762 JIRA: EVLR-1023 Change-Id: I163e47a08c29d4d5b3ab79f0eb531ef234f40bde Signed-off-by: David Nieto Reviewed-on: http://git-master/r/1320219 Reviewed-by: Terje Bergstrom Reviewed-by: svccoveritychecker Reviewed-by: Shreshtha Sahu Reviewed-by: Vijayakumar Subbu --- drivers/gpu/nvgpu/gk20a/channel_gk20a.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a/channel_gk20a.c') diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c index 0249a1c6..d0d38f83 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c @@ -122,7 +122,8 @@ static struct channel_gk20a *allocate_channel(struct fifo_gk20a *f) static void free_channel(struct fifo_gk20a *f, struct channel_gk20a *ch) { - struct gk20a_platform *platform = gk20a_get_platform(f->g->dev); + struct gk20a_platform *platform; + struct gk20a *g = f->g; trace_gk20a_release_used_channel(ch->hw_chid); /* refcount is zero here and channel is in a freed/dead state */ @@ -132,10 +133,18 @@ static void free_channel(struct fifo_gk20a *f, f->used_channels--; nvgpu_mutex_release(&f->free_chs_mutex); - if (platform->aggressive_sync_destroy_thresh && + /* + * On teardown it is not possible to dereference platform, but ignoring + * this is fine then because no new channels would be created. + */ + if (!g->driver_is_dying) { + platform = gk20a_get_platform(g->dev); + + if (platform->aggressive_sync_destroy_thresh && (f->used_channels < platform->aggressive_sync_destroy_thresh)) - platform->aggressive_sync_destroy = false; + platform->aggressive_sync_destroy = false; + } } int channel_gk20a_commit_va(struct channel_gk20a *c) @@ -3016,7 +3025,12 @@ int gk20a_submit_channel_gpfifo(struct channel_gk20a *c, bool need_deferred_cleanup = false; struct nvgpu_gpfifo __user *user_gpfifo = args ? (struct nvgpu_gpfifo __user *)(uintptr_t)args->gpfifo : NULL; - struct gk20a_platform *platform = gk20a_get_platform(d); + struct gk20a_platform *platform; + + if (g->driver_is_dying) + return -ENODEV; + + platform = gk20a_get_platform(d); if (c->has_timedout) return -ETIMEDOUT; -- cgit v1.2.2