All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yunxiang Li <Yunxiang.Li@amd.com>
To: <dri-devel@lists.freedesktop.org>
Cc: Yunxiang Li <Yunxiang.Li@amd.com>
Subject: [PATCH 2/2] drm: get lock before accessing vblank refcount
Date: Fri, 22 Jul 2022 17:52:34 -0400	[thread overview]
Message-ID: <20220722215234.129793-2-Yunxiang.Li@amd.com> (raw)
In-Reply-To: <20220722215234.129793-1-Yunxiang.Li@amd.com>

Acquire vbl_lock before accessing vblank refcount in drm_vblank_put,
just like everywhere else that access the refcount.

Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
---
 drivers/gpu/drm/drm_vblank.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 159d13b5d97b..77b8c40fc7ba 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -1203,15 +1203,22 @@ EXPORT_SYMBOL(drm_crtc_vblank_get);
 void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
 {
 	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
+	unsigned long irqflags;
+	int ret;
 
 	if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
 		return;
 
-	if (drm_WARN_ON(dev, atomic_read(&vblank->refcount) == 0))
+	spin_lock_irqsave(&dev->vbl_lock, irqflags);
+	if (drm_WARN_ON(dev, atomic_read(&vblank->refcount) == 0)) {
+		spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
 		return;
+	}
 
 	/* Last user schedules interrupt disable */
-	if (atomic_dec_and_test(&vblank->refcount)) {
+	ret = atomic_dec_and_test(&vblank->refcount);
+	spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+	if (ret) {
 		if (drm_vblank_offdelay == 0)
 			return;
 		else if (drm_vblank_offdelay < 0)
-- 
2.37.1


  reply	other threads:[~2022-07-22 21:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 21:52 [PATCH 1/2] drm: Fix vblank refcount during modeset Yunxiang Li
2022-07-22 21:52 ` Yunxiang Li [this message]
2022-09-06 19:20   ` [PATCH 2/2] drm: get lock before accessing vblank refcount Daniel Vetter
2022-09-06 20:18     ` Li, Yunxiang (Teddy)
2022-09-06 21:58       ` Daniel Vetter
2022-08-02 14:51 ` [PATCH 1/2] drm: Fix vblank refcount during modeset Li, Yunxiang (Teddy)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220722215234.129793-2-Yunxiang.Li@amd.com \
    --to=yunxiang.li@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.