diff mbox series

[1/2] drm: Fix vblank refcount during modeset

Message ID 20220722215234.129793-1-Yunxiang.Li@amd.com (mailing list archive)
State New, archived
Headers show
Series [1/2] drm: Fix vblank refcount during modeset | expand

Commit Message

Yunxiang Li July 22, 2022, 9:52 p.m. UTC
drm_crtc_vblank_off increments the refcount to prevent vblank from
getting enabled during modeset, but this causes the refcount elsewhere
to be off if they call drm_vblank_get without checking the return and
do a drm_vblank_put later. This can be reproduced by toggling vrr mode
on amdgpu.

Since drm_crtc_vblank_on later re-enables vblank if the refcount is not
zero, letting drm_vblank_get succeed during modeset should fix the behavior.

Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/1380
Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
---
 drivers/gpu/drm/drm_vblank.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yunxiang Li Aug. 2, 2022, 2:51 p.m. UTC | #1
[AMD Official Use Only - General]

I found out that elsewhere in the drm code (e.g. in drm_atomic_helper.c) expects drm_vblank_get() to fail as part of normal operation. So this patch doesn't seem appropriate anymore and it seems more appropriate to hunt down all the unchecked calls for drm_vblank_get and fix them instead. I don't know how to best make sure this doesn't reoccur in the future though.

Regards,
Yunxiang
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 2ff31717a3de..159d13b5d97b 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -1174,7 +1174,7 @@  int drm_vblank_get(struct drm_device *dev, unsigned int pipe)
 	if (atomic_add_return(1, &vblank->refcount) == 1) {
 		ret = drm_vblank_enable(dev, pipe);
 	} else {
-		if (!vblank->enabled) {
+		if (!vblank->enabled && !vblank->inmodeset) {
 			atomic_dec(&vblank->refcount);
 			ret = -EINVAL;
 		}