From: Prike Liang <Prike.Liang@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>
Cc: <Alexander.Deucher@amd.com>, <Christian.Koenig@amd.com>,
<Harry.Wentland@amd.com>, <Sunpeng.Li@amd.com>,
<tzimmermann@suse.de>, <ville.syrjala@linux.intel.com>,
Prike Liang <Prike.Liang@amd.com>,
"Harry Wentland" <harry.wentland@amd.com>,
Leo Li <sunpeng.li@amd.com>
Subject: [PATCH v2 4/5] drm/amd/display: send the flip event right away if vblank is off
Date: Thu, 19 Nov 2026 16:24:23 +0800 [thread overview]
Message-ID: <20261119082424.554841-4-Prike.Liang@amd.com> (raw)
In-Reply-To: <20261119082424.554841-1-Prike.Liang@amd.com>
dm_arm_vblank_event_pre_programming() takes a vblank reference for a
page flip or cursor update that carries an event, and the handler that
later sends the event drops that reference again. The return value of
drm_crtc_vblank_get() is ignored, though. If vblank is off, the event
is armed anyway, and the handler that eventually sends it drops a
reference that was never taken, which unbalances the vblank refcount.
That can't happen today: DM only turns vblank off for a CRTC that it
disables, and a disabled CRTC has no active planes. The next patch also
turns vblank off while a GPU reset has the streams stopped, though.
Page flips that don't modify the DC state skip
amdgpu_dm_commit_streams() and only take dc_lock after this point, so
they still get here while the reset holds it.
Send the event right away when no vblank reference can be taken, like
drm_crtc_vblank_off() does for queued vblank events. No vblank interrupt
could deliver it in that case anyway.
Add a KUnit test for it.
Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Leo Li <sunpeng.li@amd.com>
Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Prike Liang <Prike.Liang@amd.com>
---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 15 ++++++++--
.../display/amdgpu_dm/tests/amdgpu_dm_test.c | 29 +++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 3d2201285888..3bf6b407bfdf 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3824,6 +3824,11 @@ EXPORT_IF_KUNIT(dm_arm_vblank_event);
* Grab a reference on the vblank counter if a page flip or cursor update is to
* be programmed. Do this before programming so the HW is not in any
* idle-optimized state (such as PSR).
+ *
+ * If vblank is off, no vblank interrupt can deliver the event, and the
+ * handlers that send it would drop a reference that was never taken. Send
+ * the event right away instead, like drm_crtc_vblank_off() does for queued
+ * vblank events.
*/
STATIC_IFN_KUNIT void dm_arm_vblank_event_pre_programming(struct amdgpu_crtc *acrtc,
struct dm_crtc_state *acrtc_state,
@@ -3835,8 +3840,14 @@ STATIC_IFN_KUNIT void dm_arm_vblank_event_pre_programming(struct amdgpu_crtc *ac
if (!acrtc->base.state->event || acrtc_state->active_planes == 0)
return;
- if (pflip_update || cursor_update)
- drm_crtc_vblank_get(&acrtc->base);
+ if (!pflip_update && !cursor_update)
+ return;
+
+ if (drm_crtc_vblank_get(&acrtc->base)) {
+ drm_crtc_send_vblank_event(&acrtc->base,
+ acrtc->base.state->event);
+ acrtc->base.state->event = NULL;
+ }
}
EXPORT_IF_KUNIT(dm_arm_vblank_event_pre_programming);
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
index d400a223f1ad..99f2a6a41970 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
@@ -1813,6 +1813,34 @@ static void dm_test_arm_vblank_pre_programming_update(struct kunit *test)
drm_crtc_vblank_put(&ctx->acrtc->base);
}
+/**
+ * dm_test_arm_vblank_pre_programming_vblank_off - Test the event is sent with vblank off
+ * @test: The KUnit test context
+ *
+ * No vblank interrupt can deliver the event, and the handlers that send it
+ * must not drop a vblank reference that was never taken.
+ */
+static void dm_test_arm_vblank_pre_programming_vblank_off(struct kunit *test)
+{
+ struct dm_test_vblank_ctx *ctx = dm_test_vblank_ctx_alloc(test);
+ struct drm_vblank_crtc *vblank;
+
+ KUNIT_ASSERT_EQ(test, drm_vblank_init(&ctx->adev->ddev, 1), 0);
+ vblank = drm_crtc_vblank_crtc(&ctx->acrtc->base);
+ drm_crtc_vblank_off(&ctx->acrtc->base);
+
+ /* Sending an event that has no file frees it. */
+ ctx->acrtc_state->base.event = kzalloc_obj(*ctx->event, GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, ctx->acrtc_state->base.event);
+
+ dm_test_arm_vblank_pre_programming(ctx, true, false);
+
+ KUNIT_EXPECT_NULL(test, ctx->acrtc_state->base.event);
+ /* Only drm_crtc_vblank_off() holds a reference. */
+ KUNIT_EXPECT_EQ(test, atomic_read(&vblank->refcount), 1);
+ kfree(ctx->acrtc_state->base.event);
+}
+
/**
* dm_test_arm_vblank_event_no_event - Test a commit without an event is a no-op
* @test: The KUnit test context
@@ -5481,6 +5509,7 @@ static struct kunit_case amdgpu_dm_tests[] = {
KUNIT_CASE(dm_test_arm_vblank_pre_programming_no_event),
KUNIT_CASE(dm_test_arm_vblank_pre_programming_no_planes),
KUNIT_CASE(dm_test_arm_vblank_pre_programming_update),
+ KUNIT_CASE(dm_test_arm_vblank_pre_programming_vblank_off),
/* dm_update_pflip_irq_state */
KUNIT_CASE(dm_test_update_pflip_irq_state_dcn),
KUNIT_CASE(dm_test_update_pflip_irq_state_dce),
--
2.34.1
next prev parent reply other threads:[~2026-11-19 8:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:24 [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Prike Liang
2026-11-19 8:24 ` [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible() Prike Liang
2026-11-19 14:33 ` Ville Syrjälä
2026-11-19 8:24 ` [PATCH v2 3/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible Prike Liang
2026-11-19 14:40 ` Ville Syrjälä
2026-11-19 8:24 ` Prike Liang [this message]
2026-11-19 8:24 ` [PATCH v2 5/5] drm/amd/display: turn vblank off in DRM across GPU reset Prike Liang
2026-11-19 8:56 ` sashiko-bot
2026-11-19 14:31 ` [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Ville Syrjälä
2026-11-20 2:23 ` Liang, Prike
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=20261119082424.554841-4-Prike.Liang@amd.com \
--to=prike.liang@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Christian.Koenig@amd.com \
--cc=Harry.Wentland@amd.com \
--cc=Sunpeng.Li@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=tzimmermann@suse.de \
--cc=ville.syrjala@linux.intel.com \
/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.