drm/msm/atomic: Drop per-CRTC locks in reverse order
diff mbox series

Message ID 20201020222600.264876-1-robdclark@gmail.com
State In Next
Commit cb21f3f882ad12811331c1067b9acfc4dd359d3f
Headers show
Series
  • drm/msm/atomic: Drop per-CRTC locks in reverse order
Related show

Commit Message

Rob Clark Oct. 20, 2020, 10:26 p.m. UTC
From: Rob Clark <robdclark@chromium.org>

lockdep dislikes seeing locks unwound in a non-nested fashion.

Fixes: 37c2016e3608 ("drm/msm: Fix race condition in msm driver with async layer updates")
Signed-off-by: Rob Clark <robdclark@chromium.org>
---
 drivers/gpu/drm/msm/msm_atomic.c |  2 +-
 drivers/gpu/drm/msm/msm_kms.h    |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

Comments

Abhinav Kumar Oct. 21, 2020, 12:48 a.m. UTC | #1
On 2020-10-20 15:26, Rob Clark wrote:
> From: Rob Clark <robdclark@chromium.org>
> 
> lockdep dislikes seeing locks unwound in a non-nested fashion.
> 
> Fixes: 37c2016e3608 ("drm/msm: Fix race condition in msm driver with
> async layer updates")
> Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Abhinav Kumar <abhinavk@codeaurora.org>
> ---
>  drivers/gpu/drm/msm/msm_atomic.c |  2 +-
>  drivers/gpu/drm/msm/msm_kms.h    |  4 ++++
>  include/drm/drm_crtc.h           | 10 ++++++++++
>  3 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/msm/msm_atomic.c 
> b/drivers/gpu/drm/msm/msm_atomic.c
> index b03d6ab6b19b..6a326761dc4a 100644
> --- a/drivers/gpu/drm/msm/msm_atomic.c
> +++ b/drivers/gpu/drm/msm/msm_atomic.c
> @@ -67,7 +67,7 @@ static void unlock_crtcs(struct msm_kms *kms,
> unsigned int crtc_mask)
>  {
>  	struct drm_crtc *crtc;
> 
> -	for_each_crtc_mask(kms->dev, crtc, crtc_mask)
> +	for_each_crtc_mask_reverse(kms->dev, crtc, crtc_mask)
>  		mutex_unlock(&kms->commit_lock[drm_crtc_index(crtc)]);
>  }
> 
> diff --git a/drivers/gpu/drm/msm/msm_kms.h 
> b/drivers/gpu/drm/msm/msm_kms.h
> index 8d3e626c9fee..d8151a89e163 100644
> --- a/drivers/gpu/drm/msm/msm_kms.h
> +++ b/drivers/gpu/drm/msm/msm_kms.h
> @@ -211,4 +211,8 @@ int dpu_mdss_init(struct drm_device *dev);
>  	drm_for_each_crtc(crtc, dev) \
>  		for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
> 
> +#define for_each_crtc_mask_reverse(dev, crtc, crtc_mask) \
> +	drm_for_each_crtc_reverse(crtc, dev) \
> +		for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
> +
>  #endif /* __MSM_KMS_H__ */
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index dfdb04619b0d..25f5958f2882 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -1274,4 +1274,14 @@ static inline struct drm_crtc
> *drm_crtc_find(struct drm_device *dev,
>  #define drm_for_each_crtc(crtc, dev) \
>  	list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
> 
> +/**
> + * drm_for_each_crtc_reverse - iterate over all CRTCs in reverse order
> + * @crtc: a &struct drm_crtc as the loop cursor
> + * @dev: the &struct drm_device
> + *
> + * Iterate over all CRTCs of @dev.
> + */
> +#define drm_for_each_crtc_reverse(crtc, dev) \
> +	list_for_each_entry_reverse(crtc, &(dev)->mode_config.crtc_list, 
> head)
> +
>  #endif /* __DRM_CRTC_H__ */

Patch
diff mbox series

diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c
index b03d6ab6b19b..6a326761dc4a 100644
--- a/drivers/gpu/drm/msm/msm_atomic.c
+++ b/drivers/gpu/drm/msm/msm_atomic.c
@@ -67,7 +67,7 @@  static void unlock_crtcs(struct msm_kms *kms, unsigned int crtc_mask)
 {
 	struct drm_crtc *crtc;
 
-	for_each_crtc_mask(kms->dev, crtc, crtc_mask)
+	for_each_crtc_mask_reverse(kms->dev, crtc, crtc_mask)
 		mutex_unlock(&kms->commit_lock[drm_crtc_index(crtc)]);
 }
 
diff --git a/drivers/gpu/drm/msm/msm_kms.h b/drivers/gpu/drm/msm/msm_kms.h
index 8d3e626c9fee..d8151a89e163 100644
--- a/drivers/gpu/drm/msm/msm_kms.h
+++ b/drivers/gpu/drm/msm/msm_kms.h
@@ -211,4 +211,8 @@  int dpu_mdss_init(struct drm_device *dev);
 	drm_for_each_crtc(crtc, dev) \
 		for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
 
+#define for_each_crtc_mask_reverse(dev, crtc, crtc_mask) \
+	drm_for_each_crtc_reverse(crtc, dev) \
+		for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
+
 #endif /* __MSM_KMS_H__ */
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index dfdb04619b0d..25f5958f2882 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -1274,4 +1274,14 @@  static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
 #define drm_for_each_crtc(crtc, dev) \
 	list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
 
+/**
+ * drm_for_each_crtc_reverse - iterate over all CRTCs in reverse order
+ * @crtc: a &struct drm_crtc as the loop cursor
+ * @dev: the &struct drm_device
+ *
+ * Iterate over all CRTCs of @dev.
+ */
+#define drm_for_each_crtc_reverse(crtc, dev) \
+	list_for_each_entry_reverse(crtc, &(dev)->mode_config.crtc_list, head)
+
 #endif /* __DRM_CRTC_H__ */