summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonsta Holtta <kholtta@nvidia.com>2018-01-16 08:38:13 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2018-01-20 05:19:02 -0500
commit3ccf5c85fbc329cc5a72b86f83379d7a151a1f5a (patch)
treedcf5471132826f285b5ad0c38b789ff177a8fec9
parent4021d42cbb37c6d7cd30bd132d1d08d004422917 (diff)
gpu: nvgpu: add g->sw_ready flag
Fix a race condition where we'd still be booting up the gpu and/or initializing the driver but elsewhere assume that all is done already. Some userspace APIs to make sure that we're ready by testing g->gr.sw_ready, but this flag is set in the middle of bootup; there are other things after gr initialization. Add a new flag that is enabled after bootup is fully complete at the end of finalize_poweron, and change the checks in user API paths to test the new flag only. These checks are only in the ioctl paths for ctrl, dbg and tsg, and in the ctrl device's opening path. The gr.sw_ready flag is still left there to signify whether just gr has had its bookkeeping initialized. Bug 200370011 Change-Id: I2995500e06de46430d9b835de1e9d60b3f01744e Signed-off-by: Konsta Holtta <kholtta@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1640124 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c4
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_dbg.c2
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_tsg.c2
-rw-r--r--drivers/gpu/nvgpu/common/linux/module.c3
-rw-r--r--drivers/gpu/nvgpu/common/linux/sysfs.c1
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c2
-rw-r--r--drivers/gpu/nvgpu/gk20a/gk20a.h1
7 files changed, 11 insertions, 4 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
index e2285917..866ac39e 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
@@ -86,7 +86,7 @@ int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp)
86 */ 86 */
87 priv->g = g; 87 priv->g = g;
88 88
89 if (!g->gr.sw_ready) { 89 if (!g->sw_ready) {
90 err = gk20a_busy(g); 90 err = gk20a_busy(g);
91 if (err) 91 if (err)
92 goto free_ref; 92 goto free_ref;
@@ -1556,7 +1556,7 @@ long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg
1556 return -EFAULT; 1556 return -EFAULT;
1557 } 1557 }
1558 1558
1559 if (!g->gr.sw_ready) { 1559 if (!g->sw_ready) {
1560 err = gk20a_busy(g); 1560 err = gk20a_busy(g);
1561 if (err) 1561 if (err)
1562 return err; 1562 return err;
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_dbg.c b/drivers/gpu/nvgpu/common/linux/ioctl_dbg.c
index 9372fca8..ebb869c3 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_dbg.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_dbg.c
@@ -1835,7 +1835,7 @@ long gk20a_dbg_gpu_dev_ioctl(struct file *filp, unsigned int cmd,
1835 return -EFAULT; 1835 return -EFAULT;
1836 } 1836 }
1837 1837
1838 if (!g->gr.sw_ready) { 1838 if (!g->sw_ready) {
1839 err = gk20a_busy(g); 1839 err = gk20a_busy(g);
1840 if (err) 1840 if (err)
1841 return err; 1841 return err;
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c b/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c
index 931a3264..03577b97 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c
@@ -458,7 +458,7 @@ long nvgpu_ioctl_tsg_dev_ioctl(struct file *filp, unsigned int cmd,
458 return -EFAULT; 458 return -EFAULT;
459 } 459 }
460 460
461 if (!g->gr.sw_ready) { 461 if (!g->sw_ready) {
462 err = gk20a_busy(g); 462 err = gk20a_busy(g);
463 if (err) 463 if (err)
464 return err; 464 return err;
diff --git a/drivers/gpu/nvgpu/common/linux/module.c b/drivers/gpu/nvgpu/common/linux/module.c
index d74d824f..c153b56f 100644
--- a/drivers/gpu/nvgpu/common/linux/module.c
+++ b/drivers/gpu/nvgpu/common/linux/module.c
@@ -290,6 +290,8 @@ int gk20a_pm_finalize_poweron(struct device *dev)
290 return err; 290 return err;
291 } 291 }
292 292
293 g->sw_ready = true;
294
293done: 295done:
294 if (err) 296 if (err)
295 g->power_on = false; 297 g->power_on = false;
@@ -1041,6 +1043,7 @@ void gk20a_driver_start_unload(struct gk20a *g)
1041 /* GR SW ready needs to be invalidated at this time with the busy lock 1043 /* GR SW ready needs to be invalidated at this time with the busy lock
1042 * held to prevent a racing condition on the gr/mm code */ 1044 * held to prevent a racing condition on the gr/mm code */
1043 g->gr.sw_ready = false; 1045 g->gr.sw_ready = false;
1046 g->sw_ready = false;
1044 up_write(&l->busy_lock); 1047 up_write(&l->busy_lock);
1045 1048
1046 if (g->is_virtual) 1049 if (g->is_virtual)
diff --git a/drivers/gpu/nvgpu/common/linux/sysfs.c b/drivers/gpu/nvgpu/common/linux/sysfs.c
index 9d2eab92..86f1877d 100644
--- a/drivers/gpu/nvgpu/common/linux/sysfs.c
+++ b/drivers/gpu/nvgpu/common/linux/sysfs.c
@@ -815,6 +815,7 @@ static ssize_t tpc_fs_mask_store(struct device *dev,
815 g->gr.ctx_vars.local_golden_image = NULL; 815 g->gr.ctx_vars.local_golden_image = NULL;
816 g->gr.ctx_vars.golden_image_initialized = false; 816 g->gr.ctx_vars.golden_image_initialized = false;
817 g->gr.ctx_vars.golden_image_size = 0; 817 g->gr.ctx_vars.golden_image_size = 0;
818 /* Cause next poweron to reinit just gr */
818 g->gr.sw_ready = false; 819 g->gr.sw_ready = false;
819 } 820 }
820 821
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c
index 0d04d6e4..d0c9e66d 100644
--- a/drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c
@@ -505,6 +505,8 @@ int vgpu_pm_finalize_poweron(struct device *dev)
505 gk20a_sched_ctrl_init(g); 505 gk20a_sched_ctrl_init(g);
506 gk20a_channel_resume(g); 506 gk20a_channel_resume(g);
507 507
508 g->sw_ready = true;
509
508done: 510done:
509 return err; 511 return err;
510} 512}
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h
index 0ce3b50d..31855250 100644
--- a/drivers/gpu/nvgpu/gk20a/gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/gk20a.h
@@ -1133,6 +1133,7 @@ struct gk20a {
1133 bool gpu_reset_done; 1133 bool gpu_reset_done;
1134 bool power_on; 1134 bool power_on;
1135 bool suspended; 1135 bool suspended;
1136 bool sw_ready;
1136 1137
1137 u32 log_mask; 1138 u32 log_mask;
1138 u32 log_trace; 1139 u32 log_trace;