linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] gpu: drm: Fix spinlock vblank_time_lock use error.
@ 2020-07-22  1:05 Xu Qiang
  2020-07-22 11:40 ` Ville Syrjälä
  0 siblings, 1 reply; 2+ messages in thread
From: Xu Qiang @ 2020-07-22  1:05 UTC (permalink / raw)
  To: maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: dri-devel, linux-kernel, rui.xiang

The drm_handle_vblank function is in the interrupt context.
Therefore, the spin lock vblank_time_lock is obtained
from the interrupt context.

Cc: <stable@vger.kernel.org>
Signed-off-by: Xu Qiang <xuqiang36@huawei.com>
---
 drivers/gpu/drm/drm_vblank.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index f402c75b9d34..4ca63ff33a43 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -229,10 +229,11 @@ static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe
 {
 	u32 cur_vblank;
 	bool rc;
+	unsigned long irqflags;
 	ktime_t t_vblank;
 	int count = DRM_TIMESTAMP_MAXRETRIES;
 
-	spin_lock(&dev->vblank_time_lock);
+	spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
 
 	/*
 	 * sample the current counter to avoid random jumps
@@ -257,7 +258,7 @@ static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe
 	 */
 	store_vblank(dev, pipe, 1, t_vblank, cur_vblank);
 
-	spin_unlock(&dev->vblank_time_lock);
+	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
 }
 
 /*
@@ -1106,11 +1107,12 @@ static int __enable_vblank(struct drm_device *dev, unsigned int pipe)
 static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
 {
 	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
+	unsigned long irqflags;
 	int ret = 0;
 
 	assert_spin_locked(&dev->vbl_lock);
 
-	spin_lock(&dev->vblank_time_lock);
+	spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
 
 	if (!vblank->enabled) {
 		/*
@@ -1136,7 +1138,7 @@ static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
 		}
 	}
 
-	spin_unlock(&dev->vblank_time_lock);
+	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
 
 	return ret;
 }
@@ -1917,6 +1919,7 @@ bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe)
 {
 	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 	unsigned long irqflags;
+	unsigned long irqflags_vblank;
 	bool disable_irq;
 
 	if (drm_WARN_ON_ONCE(dev, !drm_dev_has_vblank(dev)))
@@ -1931,18 +1934,18 @@ bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe)
 	 * vblank enable/disable, as this would cause inconsistent
 	 * or corrupted timestamps and vblank counts.
 	 */
-	spin_lock(&dev->vblank_time_lock);
+	spin_lock_irqsave(&dev->vblank_time_lock, irqflags_vblank);
 
 	/* Vblank irq handling disabled. Nothing to do. */
 	if (!vblank->enabled) {
-		spin_unlock(&dev->vblank_time_lock);
+		spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags_vblank);
 		spin_unlock_irqrestore(&dev->event_lock, irqflags);
 		return false;
 	}
 
 	drm_update_vblank_count(dev, pipe, true);
 
-	spin_unlock(&dev->vblank_time_lock);
+	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags_vblank);
 
 	wake_up(&vblank->queue);
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -next] gpu: drm: Fix spinlock vblank_time_lock use error.
  2020-07-22  1:05 [PATCH -next] gpu: drm: Fix spinlock vblank_time_lock use error Xu Qiang
@ 2020-07-22 11:40 ` Ville Syrjälä
  0 siblings, 0 replies; 2+ messages in thread
From: Ville Syrjälä @ 2020-07-22 11:40 UTC (permalink / raw)
  To: Xu Qiang
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, daniel,
	rui.xiang, linux-kernel, dri-devel

On Wed, Jul 22, 2020 at 01:05:27AM +0000, Xu Qiang wrote:
> The drm_handle_vblank function is in the interrupt context.
> Therefore, the spin lock vblank_time_lock is obtained
> from the interrupt context.
> 
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Xu Qiang <xuqiang36@huawei.com>
> ---
>  drivers/gpu/drm/drm_vblank.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index f402c75b9d34..4ca63ff33a43 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -229,10 +229,11 @@ static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe
>  {
>  	u32 cur_vblank;
>  	bool rc;
> +	unsigned long irqflags;
>  	ktime_t t_vblank;
>  	int count = DRM_TIMESTAMP_MAXRETRIES;
>  
> -	spin_lock(&dev->vblank_time_lock);
> +	spin_lock_irqsave(&dev->vblank_time_lock, irqflags);

Nak. This is always called with interrupts off, so no point on wasting
time saving/restoring the flags. And it's the same situation for all the
other cases you have below.

>  
>  	/*
>  	 * sample the current counter to avoid random jumps
> @@ -257,7 +258,7 @@ static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe
>  	 */
>  	store_vblank(dev, pipe, 1, t_vblank, cur_vblank);
>  
> -	spin_unlock(&dev->vblank_time_lock);
> +	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
>  }
>  
>  /*
> @@ -1106,11 +1107,12 @@ static int __enable_vblank(struct drm_device *dev, unsigned int pipe)
>  static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
>  {
>  	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
> +	unsigned long irqflags;
>  	int ret = 0;
>  
>  	assert_spin_locked(&dev->vbl_lock);
>  
> -	spin_lock(&dev->vblank_time_lock);
> +	spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
>  
>  	if (!vblank->enabled) {
>  		/*
> @@ -1136,7 +1138,7 @@ static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
>  		}
>  	}
>  
> -	spin_unlock(&dev->vblank_time_lock);
> +	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
>  
>  	return ret;
>  }
> @@ -1917,6 +1919,7 @@ bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe)
>  {
>  	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
>  	unsigned long irqflags;
> +	unsigned long irqflags_vblank;
>  	bool disable_irq;
>  
>  	if (drm_WARN_ON_ONCE(dev, !drm_dev_has_vblank(dev)))
> @@ -1931,18 +1934,18 @@ bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe)
>  	 * vblank enable/disable, as this would cause inconsistent
>  	 * or corrupted timestamps and vblank counts.
>  	 */
> -	spin_lock(&dev->vblank_time_lock);
> +	spin_lock_irqsave(&dev->vblank_time_lock, irqflags_vblank);
>  
>  	/* Vblank irq handling disabled. Nothing to do. */
>  	if (!vblank->enabled) {
> -		spin_unlock(&dev->vblank_time_lock);
> +		spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags_vblank);
>  		spin_unlock_irqrestore(&dev->event_lock, irqflags);
>  		return false;
>  	}
>  
>  	drm_update_vblank_count(dev, pipe, true);
>  
> -	spin_unlock(&dev->vblank_time_lock);
> +	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags_vblank);
>  
>  	wake_up(&vblank->queue);
>  
> -- 
> 2.25.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-22 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22  1:05 [PATCH -next] gpu: drm: Fix spinlock vblank_time_lock use error Xu Qiang
2020-07-22 11:40 ` Ville Syrjälä

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).