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/1640136
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Konsta Holtta
2018-01-17 14:35:59 +02:00
committed by mobile promotions
parent 88bc143450
commit c386221971
7 changed files with 10 additions and 4 deletions

View File

@@ -73,7 +73,7 @@ int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp)
*/ */
priv->g = g; priv->g = g;
if (!g->gr.sw_ready) { if (!g->sw_ready) {
err = gk20a_busy(g); err = gk20a_busy(g);
if (err) if (err)
goto free_ref; goto free_ref;
@@ -1387,7 +1387,7 @@ long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg
return -EFAULT; return -EFAULT;
} }
if (!g->gr.sw_ready) { if (!g->sw_ready) {
err = gk20a_busy(g); err = gk20a_busy(g);
if (err) if (err)
return err; return err;

View File

@@ -959,7 +959,7 @@ long gk20a_dbg_gpu_dev_ioctl(struct file *filp, unsigned int cmd,
return -EFAULT; return -EFAULT;
} }
if (!g->gr.sw_ready) { if (!g->sw_ready) {
err = gk20a_busy(g); err = gk20a_busy(g);
if (err) if (err)
return err; return err;

View File

@@ -1109,6 +1109,8 @@ int gk20a_pm_finalize_poweron(struct device *dev)
} }
} }
g->sw_ready = true;
done: done:
if (err) if (err)
g->power_on = false; g->power_on = false;

View File

@@ -891,6 +891,7 @@ struct gk20a {
bool gpu_reset_done; bool gpu_reset_done;
bool power_on; bool power_on;
bool suspended; bool suspended;
bool sw_ready;
struct rw_semaphore busy_lock; struct rw_semaphore busy_lock;

View File

@@ -798,6 +798,7 @@ static ssize_t tpc_fs_mask_store(struct device *dev,
g->gr.ctx_vars.local_golden_image = NULL; g->gr.ctx_vars.local_golden_image = NULL;
g->gr.ctx_vars.golden_image_initialized = false; g->gr.ctx_vars.golden_image_initialized = false;
g->gr.ctx_vars.golden_image_size = 0; g->gr.ctx_vars.golden_image_size = 0;
/* Cause next poweron to reinit just gr */
g->gr.sw_ready = false; g->gr.sw_ready = false;
} }

View File

@@ -629,7 +629,7 @@ long gk20a_tsg_dev_ioctl(struct file *filp, unsigned int cmd,
return -EFAULT; return -EFAULT;
} }
if (!g->gr.sw_ready) { if (!g->sw_ready) {
err = gk20a_busy(g); err = gk20a_busy(g);
if (err) if (err)
return err; return err;

View File

@@ -498,6 +498,8 @@ int vgpu_pm_finalize_poweron(struct device *dev)
gk20a_sched_ctrl_init(g); gk20a_sched_ctrl_init(g);
gk20a_channel_resume(g); gk20a_channel_resume(g);
g->sw_ready = true;
done: done:
return err; return err;
} }