Skip to contentSkip to conversation

drm: kirin: Add a mutex to avoid fb initialization race

RFC PATCH In review John Stultz 3 participants 7 messages Feb 25, 2017 – Feb 27, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 drm: kirin: Add a mutex to avoid fb initialization race

In some cases I've been seeing a race where two framebuffers would be initialized, as kirin_fbdev_output_poll_changed() might get called quickly in succession, resulting in the initialization happening twice. This could cause the system to boot up with a blank screen.

This patch adds a simple mutex to serialize it and seems to avoid the race.

Suggestions or feedback would be greatly appreciated!

Cc Xinliang Liu <[email protected]>
Cc Rongrong Zou <[email protected]>
Cc Xinwei Kong <[email protected]>
Cc Chen Feng <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 4 ++++
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h | 1 +
 2 files changed, 5 insertions(+)
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +4 -0
index 7ec93ae..b83556a 100644
@@ -55,6 +55,7 @@ static void kirin_fbdev_output_poll_changed(struct drm_device *dev)
 {
 	struct kirin_drm_private *priv = dev->dev_private;
 
+	mutex_lock(&priv->fb_lock);
 	if (priv->fbdev) {
 		drm_fbdev_cma_hotplug_event(priv->fbdev);
 	} else {
@@ -63,6 +64,7 @@ static void kirin_fbdev_output_poll_changed(struct drm_device *dev)
 		if (IS_ERR(priv->fbdev))
 			priv->fbdev = NULL;
 	}
+	mutex_unlock(&priv->fb_lock);
 }
 #endif
 
@@ -95,6 +97,8 @@ static int kirin_drm_kms_init(struct drm_device *dev)
 	if (!priv)
 		return -ENOMEM;
 
+	mutex_init(&priv->fb_lock);
+
 	dev->dev_private = priv;
 	dev_set_drvdata(dev->dev, dev);
 
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h +1 -0
index 7f60c649..9b6d2b1 100644
@@ -23,6 +23,7 @@ struct kirin_drm_private {
 #ifdef CONFIG_DRM_FBDEV_EMULATION
 	struct drm_fbdev_cma *fbdev;
 #endif
+	struct mutex fb_lock;
 };
 
 extern const struct kirin_dc_ops ade_dc_ops;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Hi John,

The patch seems good to me, except one minus comment. Maybe change fb_lock to fbdev_lock would be better.

Thanks,
-xinliang

Quoted 66 lines · John Stultz

In some cases I've been seeing a race where two framebuffers would be initialized, as kirin_fbdev_output_poll_changed() might get called quickly in succession, resulting in the initialization happening twice. This could cause the system to boot up with a blank screen.

This patch adds a simple mutex to serialize it and seems to avoid the race.

Suggestions or feedback would be greatly appreciated!

Cc Xinliang Liu <[email protected]>
Cc Rongrong Zou <[email protected]>
Cc Xinwei Kong <[email protected]>
Cc Chen Feng <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
---
  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 4 ++++
  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h | 1 +
  2 files changed, 5 insertions(+)
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +4 -0
index 7ec93ae..b83556a 100644
@@ -55,6 +55,7 @@ static void kirin_fbdev_output_poll_changed(struct drm_device *dev)
  {
  	struct kirin_drm_private *priv = dev->dev_private;
 
+	mutex_lock(&priv->fb_lock);
  	if (priv->fbdev) {
  		drm_fbdev_cma_hotplug_event(priv->fbdev);
  	} else {
@@ -63,6 +64,7 @@ static void kirin_fbdev_output_poll_changed(struct drm_device *dev)
  		if (IS_ERR(priv->fbdev))
  			priv->fbdev = NULL;
  	}
+	mutex_unlock(&priv->fb_lock);
  }
  #endif
 
@@ -95,6 +97,8 @@ static int kirin_drm_kms_init(struct drm_device *dev)
  	if (!priv)
  		return -ENOMEM;
 
+	mutex_init(&priv->fb_lock);
+
  	dev->dev_private = priv;
  	dev_set_drvdata(dev->dev, dev);
 
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h +1 -0
index 7f60c649..9b6d2b1 100644
@@ -23,6 +23,7 @@ struct kirin_drm_private {
  #ifdef CONFIG_DRM_FBDEV_EMULATION
  	struct drm_fbdev_cma *fbdev;
  #endif
+	struct mutex fb_lock;
  };
 
  extern const struct kirin_dc_ops ade_dc_ops;
#3 lore raw
In reply to liuxinliang
Quoted 51 lines · liuxinliang

Hi John,

The patch seems good to me, except one minus comment. Maybe change fb_lock to fbdev_lock would be better.

Thanks,
-xinliang

Quoted 42 lines · John Stultz

In some cases I've been seeing a race where two framebuffers would be initialized, as kirin_fbdev_output_poll_changed() might get called quickly in succession, resulting in the initialization happening twice. This could cause the system to boot up with a blank screen.

This patch adds a simple mutex to serialize it and seems to avoid the race.

Suggestions or feedback would be greatly appreciated!

Cc Xinliang Liu <[email protected]>
Cc Rongrong Zou <[email protected]>
Cc Xinwei Kong <[email protected]>
Cc Chen Feng <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
---
  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 4 ++++
  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h | 1 +
  2 files changed, 5 insertions(+)
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +0 -0
index 7ec93ae..b83556a 100644
@@ -55,6 +55,7 @@ static void kirin_fbdev_output_poll_changed(struct 
 drm_device *dev)
  {
      struct kirin_drm_private *priv = dev->dev_private;
  +    mutex_lock(&priv->fb_lock);
      if (priv->fbdev) {
          drm_fbdev_cma_hotplug_event(priv->fbdev);
      } else {
@@ -63,6 +64,7 @@ static void kirin_fbdev_output_poll_changed(struct 
 drm_device *dev)
          if (IS_ERR(priv->fbdev))
              priv->fbdev = NULL;
      }
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +1 -0
+    mutex_unlock(&priv->fb_lock);
  }
  #endif

@@ -95,6 +97,8 @@ static int kirin_drm_kms_init(struct drm_device
*dev)

      if (!priv)
          return -ENOMEM;

+ mutex_init(&priv->fb_lock);

And put this line in CONFIG_DRM_FBDEV_EMULATION

Quoted 5 lines
Quoted 5 lines

+

      dev->dev_private = priv;
      dev_set_drvdata(dev->dev, dev);

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h

Quoted 8 lines

drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h struct kirin_drm_private { · line 26

Quoted 8 lines

index 7f60c649..9b6d2b1 100644

drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h +1 -0
@@ -23,6 +23,7 @@ struct kirin_drm_private {
  #ifdef CONFIG_DRM_FBDEV_EMULATION
      struct drm_fbdev_cma *fbdev;
  #endif
+    struct mutex fb_lock;

And here.

-xinliang

Quoted 3 lines
Quoted 2 lines
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h +0 -0
  };
    extern const struct kirin_dc_ops ade_dc_ops;
#4 lore raw
Quoted 58 lines · liuxinliang
Quoted 55 lines · liuxinliang

Hi John,

The patch seems good to me, except one minus comment. Maybe change fb_lock to fbdev_lock would be better.

Thanks,
-xinliang

Quoted 45 lines · John Stultz

In some cases I've been seeing a race where two framebuffers would be initialized, as kirin_fbdev_output_poll_changed() might get called quickly in succession, resulting in the initialization happening twice. This could cause the system to boot up with a blank screen.

This patch adds a simple mutex to serialize it and seems to avoid the race.

Suggestions or feedback would be greatly appreciated!

Cc Xinliang Liu <[email protected]>
Cc Rongrong Zou <[email protected]>
Cc Xinwei Kong <[email protected]>
Cc Chen Feng <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
---
  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 4 ++++
  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h | 1 +
  2 files changed, 5 insertions(+)
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +1 -0
index 7ec93ae..b83556a 100644
@@ -55,6 +55,7 @@ static void kirin_fbdev_output_poll_changed(struct
 drm_device *dev)
  {
      struct kirin_drm_private *priv = dev->dev_private;
  +    mutex_lock(&priv->fb_lock);
      if (priv->fbdev) {
          drm_fbdev_cma_hotplug_event(priv->fbdev);
      } else {
@@ -63,6 +64,7 @@ static void kirin_fbdev_output_poll_changed(struct
 drm_device *dev)
          if (IS_ERR(priv->fbdev))
              priv->fbdev = NULL;
      }
+    mutex_unlock(&priv->fb_lock);
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +0 -0
  }
  #endif

@@ -95,6 +97,8 @@ static int kirin_drm_kms_init(struct drm_device *dev)

      if (!priv)
          return -ENOMEM;

+ mutex_init(&priv->fb_lock);

And put this line in CONFIG_DRM_FBDEV_EMULATION

Ok. Done! Thanks again for the review and feedback! -john
_______________________________________________
dri-devel mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
In reply to John Stultz
Quoted 10 lines · John Stultz

In some cases I've been seeing a race where two framebuffers would be initialized, as kirin_fbdev_output_poll_changed() might get called quickly in succession, resulting in the initialization happening twice. This could cause the system to boot up with a blank screen.

This patch adds a simple mutex to serialize it and seems to avoid the race.

Suggestions or feedback would be greatly appreciated!

I feel a bit like a broken record, but:

Instead of reinventing broken delayed fbdev setup everywhere, can we polish Thierry's patches to move that into the fbdev helpers in the core? hisilicon isn't the only driver the (re)invents this weel, it'd be really awesome if we could fix this bug just once ...

For reference, the patches:

http://markmail.org/message/d3jc4vebkndtvlkf#query:+page:1+mid:d3jc4vebkndtvlkf+state:results

I guess Thierry got sidetracked on these, but except for a bit of locking scheme polish I think they've been mostly ready. Shouldn't be much work to refresh them, hunt for other new drivers reinventing this wheel, do the locking polish maybe and then get them landed.

Thanks, Daniel

Quoted 59 lines
Cc Xinliang Liu <[email protected]>
Cc Rongrong Zou <[email protected]>
Cc Xinwei Kong <[email protected]>
Cc Chen Feng <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 4 ++++
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h | 1 +
 2 files changed, 5 insertions(+)
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +4 -0
index 7ec93ae..b83556a 100644
@@ -55,6 +55,7 @@ static void kirin_fbdev_output_poll_changed(struct drm_device *dev)
 {
 	struct kirin_drm_private *priv = dev->dev_private;
 
+	mutex_lock(&priv->fb_lock);
 	if (priv->fbdev) {
 		drm_fbdev_cma_hotplug_event(priv->fbdev);
 	} else {
@@ -63,6 +64,7 @@ static void kirin_fbdev_output_poll_changed(struct drm_device *dev)
 		if (IS_ERR(priv->fbdev))
 			priv->fbdev = NULL;
 	}
+	mutex_unlock(&priv->fb_lock);
 }
 #endif
 
@@ -95,6 +97,8 @@ static int kirin_drm_kms_init(struct drm_device *dev)
 	if (!priv)
 		return -ENOMEM;
 
+	mutex_init(&priv->fb_lock);
+
 	dev->dev_private = priv;
 	dev_set_drvdata(dev->dev, dev);
 
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h +1 -0
index 7f60c649..9b6d2b1 100644
@@ -23,6 +23,7 @@ struct kirin_drm_private {
 #ifdef CONFIG_DRM_FBDEV_EMULATION
 	struct drm_fbdev_cma *fbdev;
 #endif
+	struct mutex fb_lock;
 };
 
 extern const struct kirin_dc_ops ade_dc_ops;
Signature · 1 line
2.7.4
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
Quoted 14 lines · Daniel Vetter
Quoted 10 lines · John Stultz

In some cases I've been seeing a race where two framebuffers would be initialized, as kirin_fbdev_output_poll_changed() might get called quickly in succession, resulting in the initialization happening twice. This could cause the system to boot up with a blank screen.

This patch adds a simple mutex to serialize it and seems to avoid the race.

Suggestions or feedback would be greatly appreciated!

I feel a bit like a broken record, but:

Quoted 8 lines

Instead of reinventing broken delayed fbdev setup everywhere, can we polish Thierry's patches to move that into the fbdev helpers in the core? hisilicon isn't the only driver the (re)invents this weel, it'd be really awesome if we could fix this bug just once ...

For reference, the patches:

http://markmail.org/message/d3jc4vebkndtvlkf#query:+page:1+mid:d3jc4vebkndtvlkf+state:results

Thanks for the pointer here, and apologies, I really am not very deep into or do that much following DRM development. I just am chasing bugs on my board and trying to fix them up, so I wasn't aware this was something brought up before.

Quoted 4 lines

I guess Thierry got sidetracked on these, but except for a bit of locking scheme polish I think they've been mostly ready. Shouldn't be much work to refresh them, hunt for other new drivers reinventing this wheel, do the locking polish maybe and then get them landed.

I'll take a look at it and see what I can sort out.

thanks
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel