Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Maíra Canal" <mcanal@igalia.com>,
	"Iago Toral Quiroga" <itoral@igalia.com>,
	"Sasha Levin" <sashal@kernel.org>
Subject: [PATCH 6.18.y] drm/vc4: Look up the async page flip fence before committing the flip
Date: Thu,  3 Dec 2026 20:30:13 -0500	[thread overview]
Message-ID: <20261204013004.1636142-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120252-corner-overreact-fdda@gregkh>

From: Maíra Canal <mcanal@igalia.com>

[ Upstream commit f9fc6da01a290609428d308033143f1d96ab658f ]

vc4_async_page_flip_common() ignores dma_resv_get_singleton() failures.
By then the plane state already points at the new framebuffer, so the
flip is never completed. So, its state leaks, the vblank reference is
never dropped and the event is never sent.

Look up the fence before changing any state, so the error can be properly
returned to userspace.

Cc: stable@vger.kernel.org
Fixes: d19e00ee06a9 ("drm/vc4: crtc: Fix out of order frames during asynchronous page flips")
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Link: https://patch.msgid.link/20261114-vc4-async-flip-fixes-v2-3-d33cbe99ed5d@igalia.com
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/vc4/vc4_crtc.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c
index dc7c14ae642d5..d315ff38f9c7a 100644
--- a/drivers/gpu/drm/vc4/vc4_crtc.c
+++ b/drivers/gpu/drm/vc4/vc4_crtc.c
@@ -948,33 +948,22 @@ static void vc4_async_page_flip_fence_cb(struct dma_fence *fence,
 	queue_work(vc4_crtc->async_flip_wq, &flip_state->work);
 }
 
-static int vc4_async_set_fence_cb(struct drm_device *dev,
-				  struct vc4_async_flip_state *flip_state)
+static void vc4_async_set_fence_cb(struct vc4_async_flip_state *flip_state)
 {
-	struct drm_framebuffer *fb = flip_state->fb;
-	struct drm_gem_dma_object *dma_bo = drm_fb_dma_get_gem_obj(fb, 0);
 	struct vc4_crtc *vc4_crtc = to_vc4_crtc(flip_state->crtc);
-	int ret;
 
 	INIT_WORK(&flip_state->work, vc4_async_page_flip_work);
 
-	ret = dma_resv_get_singleton(dma_bo->base.resv, DMA_RESV_USAGE_READ,
-				     &flip_state->fence);
-	if (ret)
-		return ret;
-
 	if (flip_state->fence &&
 	    !dma_fence_add_callback(flip_state->fence, &flip_state->cb,
 				    vc4_async_page_flip_fence_cb))
-		return 0;
+		return;
 
 	/* No fence or the fence has already signaled. Complete the flip
 	 * immediately, after earlier queued flips.
 	 */
 	flush_workqueue(vc4_crtc->async_flip_wq);
 	vc4_async_page_flip_work(&flip_state->work);
-
-	return 0;
 }
 
 static int
@@ -983,14 +972,22 @@ vc4_async_page_flip_common(struct drm_crtc *crtc,
 			   struct drm_pending_vblank_event *event,
 			   uint32_t flags)
 {
-	struct drm_device *dev = crtc->dev;
+	struct drm_gem_dma_object *dma_bo = drm_fb_dma_get_gem_obj(fb, 0);
 	struct drm_plane *plane = crtc->primary;
 	struct vc4_async_flip_state *flip_state;
+	int ret;
 
 	flip_state = kzalloc(sizeof(*flip_state), GFP_KERNEL);
 	if (!flip_state)
 		return -ENOMEM;
 
+	ret = dma_resv_get_singleton(dma_bo->base.resv, DMA_RESV_USAGE_READ,
+				     &flip_state->fence);
+	if (ret) {
+		kfree(flip_state);
+		return ret;
+	}
+
 	drm_framebuffer_get(fb);
 	flip_state->fb = fb;
 	flip_state->crtc = crtc;
@@ -1016,7 +1013,7 @@ vc4_async_page_flip_common(struct drm_crtc *crtc,
 	 */
 	drm_atomic_set_fb_for_plane(plane->state, fb);
 
-	vc4_async_set_fence_cb(dev, flip_state);
+	vc4_async_set_fence_cb(flip_state);
 
 	/* Driver takes ownership of state on successful async commit. */
 	return 0;
-- 
2.53.0


      reply	other threads:[~2026-12-04  1:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:45 FAILED: patch "[PATCH] drm/vc4: Look up the async page flip fence before committing" failed to apply to 6.18-stable tree gregkh
2026-12-04  1:30 ` Sasha Levin [this message]

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=20261204013004.1636142-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=itoral@igalia.com \
    --cc=mcanal@igalia.com \
    --cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox