From 3ccf5c85fbc329cc5a72b86f83379d7a151a1f5a Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Tue, 16 Jan 2018 15:38:13 +0200 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/1640124 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c | 4 ++-- drivers/gpu/nvgpu/common/linux/ioctl_dbg.c | 2 +- drivers/gpu/nvgpu/common/linux/ioctl_tsg.c | 2 +- drivers/gpu/nvgpu/common/linux/module.c | 3 +++ drivers/gpu/nvgpu/common/linux/sysfs.c | 1 + drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c | 2 ++ drivers/gpu/nvgpu/gk20a/gk20a.h | 1 + 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 e2285917b..866ac39eb 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) */ priv->g = g; - if (!g->gr.sw_ready) { + if (!g->sw_ready) { err = gk20a_busy(g); if (err) goto free_ref; @@ -1556,7 +1556,7 @@ long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg return -EFAULT; } - if (!g->gr.sw_ready) { + if (!g->sw_ready) { err = gk20a_busy(g); if (err) return err; diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_dbg.c b/drivers/gpu/nvgpu/common/linux/ioctl_dbg.c index 9372fca8f..ebb869c39 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, return -EFAULT; } - if (!g->gr.sw_ready) { + if (!g->sw_ready) { err = gk20a_busy(g); if (err) return err; diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c b/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c index 931a32644..03577b974 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, return -EFAULT; } - if (!g->gr.sw_ready) { + if (!g->sw_ready) { err = gk20a_busy(g); if (err) return err; diff --git a/drivers/gpu/nvgpu/common/linux/module.c b/drivers/gpu/nvgpu/common/linux/module.c index d74d824f9..c153b56fa 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) return err; } + g->sw_ready = true; + done: if (err) g->power_on = false; @@ -1041,6 +1043,7 @@ void gk20a_driver_start_unload(struct gk20a *g) /* GR SW ready needs to be invalidated at this time with the busy lock * held to prevent a racing condition on the gr/mm code */ g->gr.sw_ready = false; + g->sw_ready = false; up_write(&l->busy_lock); if (g->is_virtual) diff --git a/drivers/gpu/nvgpu/common/linux/sysfs.c b/drivers/gpu/nvgpu/common/linux/sysfs.c index 9d2eab924..86f1877d1 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, g->gr.ctx_vars.local_golden_image = NULL; g->gr.ctx_vars.golden_image_initialized = false; g->gr.ctx_vars.golden_image_size = 0; + /* Cause next poweron to reinit just gr */ g->gr.sw_ready = false; } diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu.c index 0d04d6e4f..d0c9e66de 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) gk20a_sched_ctrl_init(g); gk20a_channel_resume(g); + g->sw_ready = true; + done: return err; } diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 0ce3b50d8..31855250b 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -1133,6 +1133,7 @@ struct gk20a { bool gpu_reset_done; bool power_on; bool suspended; + bool sw_ready; u32 log_mask; u32 log_trace;