diff mbox series

[v2,1/5] drm/msm: destroy msm threads after config cleanup

Message ID 1541543790-748-1-git-send-email-jsanka@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series [v2,1/5] drm/msm: destroy msm threads after config cleanup | expand

Commit Message

Jeykumar Sankaran Nov. 6, 2018, 10:36 p.m. UTC
To avoid any possible work queues to msm threads, clean up
the threads after the CRTC objects are released in
config cleanup.

changes in v2:
	- fix race condition before kthread flush and stop (Sean Paul)
	- use kthread_destroy_worker for cleaning up kthread (Sean Paul)

Signed-off-by: Jeykumar Sankaran <jsanka@codeaurora.org>
---
 drivers/gpu/drm/msm/msm_drv.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

Comments

Sean Paul Nov. 7, 2018, 3:42 p.m. UTC | #1
On Tue, Nov 06, 2018 at 02:36:26PM -0800, Jeykumar Sankaran wrote:
> To avoid any possible work queues to msm threads, clean up
> the threads after the CRTC objects are released in
> config cleanup.
> 
> changes in v2:
> 	- fix race condition before kthread flush and stop (Sean Paul)
> 	- use kthread_destroy_worker for cleaning up kthread (Sean Paul)
> 
> Signed-off-by: Jeykumar Sankaran <jsanka@codeaurora.org>
> ---
>  drivers/gpu/drm/msm/msm_drv.c | 36 +++++++++++++++++-------------------
>  1 file changed, 17 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
> index 9c9f7ff..e913059 100644
> --- a/drivers/gpu/drm/msm/msm_drv.c
> +++ b/drivers/gpu/drm/msm/msm_drv.c
> @@ -278,6 +278,21 @@ static int msm_drm_uninit(struct device *dev)
>  	 * work before drm_irq_uninstall() to avoid work re-enabling an
>  	 * irq after uninstall has disabled it.
>  	 */
> +	msm_gem_shrinker_cleanup(ddev);
> +
> +	drm_kms_helper_poll_fini(ddev);
> +
> +	drm_dev_unregister(ddev);
> +
> +	msm_perf_debugfs_cleanup(priv);
> +	msm_rd_debugfs_cleanup(priv);
> +
> +#ifdef CONFIG_DRM_FBDEV_EMULATION
> +	if (fbdev && priv->fbdev)
> +		msm_fbdev_free(ddev);
> +#endif
> +	drm_mode_config_cleanup(ddev);
> +
>  	kthread_flush_work(&vbl_ctrl->work);

What happens in the vbl_ctrl thread when it runs with drm resources cleaned up?

Sean

>  	list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
>  		list_del(&vbl_ev->node);
> @@ -287,33 +302,16 @@ static int msm_drm_uninit(struct device *dev)
>  	/* clean up display commit/event worker threads */
>  	for (i = 0; i < priv->num_crtcs; i++) {
>  		if (priv->disp_thread[i].thread) {
> -			kthread_flush_worker(&priv->disp_thread[i].worker);
> -			kthread_stop(priv->disp_thread[i].thread);
> +			kthread_destroy_worker(&priv->disp_thread[i].worker);
>  			priv->disp_thread[i].thread = NULL;
>  		}
>  
>  		if (priv->event_thread[i].thread) {
> -			kthread_flush_worker(&priv->event_thread[i].worker);
> -			kthread_stop(priv->event_thread[i].thread);
> +			kthread_destroy_worker(&priv->event_thread[i].worker);
>  			priv->event_thread[i].thread = NULL;
>  		}
>  	}
>  
> -	msm_gem_shrinker_cleanup(ddev);
> -
> -	drm_kms_helper_poll_fini(ddev);
> -
> -	drm_dev_unregister(ddev);
> -
> -	msm_perf_debugfs_cleanup(priv);
> -	msm_rd_debugfs_cleanup(priv);
> -
> -#ifdef CONFIG_DRM_FBDEV_EMULATION
> -	if (fbdev && priv->fbdev)
> -		msm_fbdev_free(ddev);
> -#endif
> -	drm_mode_config_cleanup(ddev);
> -
>  	pm_runtime_get_sync(dev);
>  	drm_irq_uninstall(ddev);
>  	pm_runtime_put_sync(dev);
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 
> _______________________________________________
> Freedreno mailing list
> Freedreno@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/freedreno
diff mbox series

Patch

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 9c9f7ff..e913059 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -278,6 +278,21 @@  static int msm_drm_uninit(struct device *dev)
 	 * work before drm_irq_uninstall() to avoid work re-enabling an
 	 * irq after uninstall has disabled it.
 	 */
+	msm_gem_shrinker_cleanup(ddev);
+
+	drm_kms_helper_poll_fini(ddev);
+
+	drm_dev_unregister(ddev);
+
+	msm_perf_debugfs_cleanup(priv);
+	msm_rd_debugfs_cleanup(priv);
+
+#ifdef CONFIG_DRM_FBDEV_EMULATION
+	if (fbdev && priv->fbdev)
+		msm_fbdev_free(ddev);
+#endif
+	drm_mode_config_cleanup(ddev);
+
 	kthread_flush_work(&vbl_ctrl->work);
 	list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
 		list_del(&vbl_ev->node);
@@ -287,33 +302,16 @@  static int msm_drm_uninit(struct device *dev)
 	/* clean up display commit/event worker threads */
 	for (i = 0; i < priv->num_crtcs; i++) {
 		if (priv->disp_thread[i].thread) {
-			kthread_flush_worker(&priv->disp_thread[i].worker);
-			kthread_stop(priv->disp_thread[i].thread);
+			kthread_destroy_worker(&priv->disp_thread[i].worker);
 			priv->disp_thread[i].thread = NULL;
 		}
 
 		if (priv->event_thread[i].thread) {
-			kthread_flush_worker(&priv->event_thread[i].worker);
-			kthread_stop(priv->event_thread[i].thread);
+			kthread_destroy_worker(&priv->event_thread[i].worker);
 			priv->event_thread[i].thread = NULL;
 		}
 	}
 
-	msm_gem_shrinker_cleanup(ddev);
-
-	drm_kms_helper_poll_fini(ddev);
-
-	drm_dev_unregister(ddev);
-
-	msm_perf_debugfs_cleanup(priv);
-	msm_rd_debugfs_cleanup(priv);
-
-#ifdef CONFIG_DRM_FBDEV_EMULATION
-	if (fbdev && priv->fbdev)
-		msm_fbdev_free(ddev);
-#endif
-	drm_mode_config_cleanup(ddev);
-
 	pm_runtime_get_sync(dev);
 	drm_irq_uninstall(ddev);
 	pm_runtime_put_sync(dev);