From 9e02111a768ab631a6719c1eae8d7c03e6e89c23 Mon Sep 17 00:00:00 2001 From: Seshendra Gadagottu Date: Thu, 28 Jan 2016 10:54:32 -0800 Subject: gpu: nvgpu: fix race condition with poweroff When gpu rail-gating is enabled, it is possible that both rail gating code and system shudown can start executing gk20a_pm_prepare_poweroff() in parallel. To synchronize this execution, protect gk20a_pm_prepare_poweroff() with a mutex lock. Bug 200168805 Change-Id: I19536a43ed20c3e82b32c316922dc3e19e3f59bb Signed-off-by: Seshendra Gadagottu Reviewed-on: http://git-master/r/999548 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/gk20a.c | 12 +++++++++--- drivers/gpu/nvgpu/gk20a/gk20a.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a') diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c index 0982ecdf..1000eba2 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a.c @@ -669,6 +669,7 @@ static int gk20a_init_support(struct platform_device *dev) mutex_init(&g->dbg_sessions_lock); mutex_init(&g->client_lock); mutex_init(&g->ch_wdt_lock); + mutex_init(&g->poweroff_lock); mutex_init(&g->interleave_lock); g->num_interleaved_channels = 0; @@ -689,17 +690,19 @@ static int gk20a_pm_prepare_poweroff(struct device *dev) gk20a_dbg_fn(""); - gk20a_scale_suspend(pdev); + mutex_lock(&g->poweroff_lock); if (!g->power_on) - return 0; + goto done; + + gk20a_scale_suspend(pdev); /* cancel any pending cde work */ gk20a_cde_suspend(g); ret = gk20a_channel_suspend(g); if (ret) - return ret; + goto done; /* disable elpg before gr or fifo suspend */ ret |= gk20a_pmu_destroy(g); @@ -723,6 +726,9 @@ static int gk20a_pm_prepare_poweroff(struct device *dev) /* Stop CPU from accessing the GPU registers. */ gk20a_lockout_registers(g); +done: + mutex_unlock(&g->poweroff_lock); + return ret; } diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index b02d6111..0207588f 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -521,6 +521,8 @@ struct gk20a { struct mutex ch_wdt_lock; + struct mutex poweroff_lock; + /* Channel priorities */ u32 timeslice_low_priority_us; u32 timeslice_medium_priority_us; -- cgit v1.2.2