* [PATCH v2] drm/mediatek: dsi: Don't let a signal cut the IRQ wait short
@ 2026-11-18 9:33 Zi-Hao Huang via B4 Relay
2026-11-18 12:32 ` AngeloGioacchino Del Regno
0 siblings, 1 reply; 5+ messages in thread
From: Zi-Hao Huang via B4 Relay @ 2026-11-18 9:33 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, shaoming chen, dri-devel,
linux-mediatek, linux-kernel, linux-arm-kernel, Zi-Hao Huang,
CK Hu
From: Zi-Hao Huang <zi-hao.huang@mediatek.com>
mtk_dsi_wait_for_irq_done() waits for the DSI IRQ with
wait_event_interruptible_timeout(). If it returns early, for example
with -ERESTARTSYS when a signal is pending, both callers still treat the
command as done, because they only handle a return value of 0 as a
failure.
On an MT8196 board this led to a hard lockup during shutdown. The wait
returned before the IRQ arrived, the panel disable sequence went on and
restarted video mode, and the late CMD_DONE interrupt was then handled
by mtk_dsi_irq(). The handler writes RACK and loops until DSI_BUSY
clears, but DSI_BUSY stays set while video mode is running, so the CPU
never leaves the handler until the watchdog fires. Forcing the wait to
return early reproduces the lockup every time, and it no longer
happens once the wait cannot return early.
The wait synchronises the driver with the hardware, and it is bounded by
its timeout. Use wait_event_timeout() so that it only ends on the IRQ or
the timeout.
wake_up_interruptible() cannot wake a task in uninterruptible sleep, so
switch mtk_dsi_irq() to wake_up(). Without it every wait would last
until its timeout.
Fixes: dd5080a54df8 ("drm/mediatek: add dsi interrupt control")
Signed-off-by: Zi-Hao Huang <zi-hao.huang@mediatek.com>
Reviewed-by: CK Hu <ck.hu@mediatek.com>
---
Changes in v2:
- Drop the remark that the wait is not made on behalf of userspace, since
a userspace backlight change can reach it (CK)
- Collect Reviewed-by
- Link to v1: https://lore.kernel.org/r/20261118-mtk-dsi-irq-wait-v1-1-205f25fac8b2@mediatek.com
---
drivers/gpu/drm/mediatek/mtk_dsi.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
index f82506e10fd5..1315dd31a834 100644
--- a/drivers/gpu/drm/mediatek/mtk_dsi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
@@ -627,9 +627,8 @@ static s32 mtk_dsi_wait_for_irq_done(struct mtk_dsi *dsi, u32 irq_flag,
unsigned long jiffies = msecs_to_jiffies(timeout);
struct drm_device *drm = dsi->bridge.dev;
- ret = wait_event_interruptible_timeout(dsi->irq_wait_queue,
- dsi->irq_data & irq_flag,
- jiffies);
+ ret = wait_event_timeout(dsi->irq_wait_queue,
+ dsi->irq_data & irq_flag, jiffies);
if (ret == 0) {
drm_warn(drm, "Wait DSI IRQ(0x%08x) Timeout\n", irq_flag);
@@ -656,7 +655,7 @@ static irqreturn_t mtk_dsi_irq(int irq, void *dev_id)
mtk_dsi_mask(dsi, DSI_INTSTA, status, 0);
mtk_dsi_irq_data_set(dsi, status);
- wake_up_interruptible(&dsi->irq_wait_queue);
+ wake_up(&dsi->irq_wait_queue);
}
return IRQ_HANDLED;
---
base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
change-id: 20261118-mtk-dsi-irq-wait-a24712ada627
Best regards,
--
Zi-Hao Huang <zi-hao.huang@mediatek.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/mediatek: dsi: Don't let a signal cut the IRQ wait short
2026-11-18 9:33 [PATCH v2] drm/mediatek: dsi: Don't let a signal cut the IRQ wait short Zi-Hao Huang via B4 Relay
@ 2026-11-18 12:32 ` AngeloGioacchino Del Regno
2026-11-19 1:28 ` CK Hu (胡俊光)
0 siblings, 1 reply; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2026-11-18 12:32 UTC (permalink / raw)
To: zi-hao.huang, Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger, shaoming chen,
dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel, CK Hu
On 11/18/26 10:33, Zi-Hao Huang via B4 Relay wrote:
> From: Zi-Hao Huang <zi-hao.huang@mediatek.com>
>
> mtk_dsi_wait_for_irq_done() waits for the DSI IRQ with
> wait_event_interruptible_timeout(). If it returns early, for example
> with -ERESTARTSYS when a signal is pending, both callers still treat the
> command as done, because they only handle a return value of 0 as a
> failure.
>
> On an MT8196 board this led to a hard lockup during shutdown. The wait
> returned before the IRQ arrived, the panel disable sequence went on and
> restarted video mode, and the late CMD_DONE interrupt was then handled
> by mtk_dsi_irq().
This happens because of the hacks that you have downstream.
With the restructured mediatek-drm adding proper support for MT8196's Display
Controller architecture, what you're describing does not happen, because the
tear down path is correct.
Regards,
Angelo
> The handler writes RACK and loops until DSI_BUSY
> clears, but DSI_BUSY stays set while video mode is running, so the CPU
> never leaves the handler until the watchdog fires. Forcing the wait to
> return early reproduces the lockup every time, and it no longer
> happens once the wait cannot return early.
>
> The wait synchronises the driver with the hardware, and it is bounded by
> its timeout. Use wait_event_timeout() so that it only ends on the IRQ or
> the timeout.
>
> wake_up_interruptible() cannot wake a task in uninterruptible sleep, so
> switch mtk_dsi_irq() to wake_up(). Without it every wait would last
> until its timeout.
>
> Fixes: dd5080a54df8 ("drm/mediatek: add dsi interrupt control")
> Signed-off-by: Zi-Hao Huang <zi-hao.huang@mediatek.com>
> Reviewed-by: CK Hu <ck.hu@mediatek.com>
> ---
> Changes in v2:
> - Drop the remark that the wait is not made on behalf of userspace, since
> a userspace backlight change can reach it (CK)
> - Collect Reviewed-by
> - Link to v1: https://lore.kernel.org/r/20261118-mtk-dsi-irq-wait-v1-1-205f25fac8b2@mediatek.com
> ---
> drivers/gpu/drm/mediatek/mtk_dsi.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> index f82506e10fd5..1315dd31a834 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> @@ -627,9 +627,8 @@ static s32 mtk_dsi_wait_for_irq_done(struct mtk_dsi *dsi, u32 irq_flag,
> unsigned long jiffies = msecs_to_jiffies(timeout);
> struct drm_device *drm = dsi->bridge.dev;
>
> - ret = wait_event_interruptible_timeout(dsi->irq_wait_queue,
> - dsi->irq_data & irq_flag,
> - jiffies);
> + ret = wait_event_timeout(dsi->irq_wait_queue,
> + dsi->irq_data & irq_flag, jiffies);
> if (ret == 0) {
> drm_warn(drm, "Wait DSI IRQ(0x%08x) Timeout\n", irq_flag);
>
> @@ -656,7 +655,7 @@ static irqreturn_t mtk_dsi_irq(int irq, void *dev_id)
>
> mtk_dsi_mask(dsi, DSI_INTSTA, status, 0);
> mtk_dsi_irq_data_set(dsi, status);
> - wake_up_interruptible(&dsi->irq_wait_queue);
> + wake_up(&dsi->irq_wait_queue);
> }
>
> return IRQ_HANDLED;
>
> ---
> base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
> change-id: 20261118-mtk-dsi-irq-wait-a24712ada627
>
> Best regards,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/mediatek: dsi: Don't let a signal cut the IRQ wait short
2026-11-18 12:32 ` AngeloGioacchino Del Regno
@ 2026-11-19 1:28 ` CK Hu (胡俊光)
2026-11-19 3:36 ` Zi-Hao Huang
0 siblings, 1 reply; 5+ messages in thread
From: CK Hu (胡俊光) @ 2026-11-19 1:28 UTC (permalink / raw)
To: p.zabel, AngeloGioacchino Del Regno,
Zi-hao Huang (黃梓豪),
chunkuang.hu
Cc: simona, Shaoming Chen (陈绍明),
dri-devel, airlied, linux-kernel, linux-arm-kernel, matthias.bgg,
linux-mediatek
On Wed, 2026-11-18 at 13:32 +0100, AngeloGioacchino Del Regno wrote:
> On 11/18/26 10:33, Zi-Hao Huang via B4 Relay wrote:
> > From: Zi-Hao Huang <zi-hao.huang@mediatek.com>
> >
> > mtk_dsi_wait_for_irq_done() waits for the DSI IRQ with
> > wait_event_interruptible_timeout(). If it returns early, for example
> > with -ERESTARTSYS when a signal is pending, both callers still treat the
> > command as done, because they only handle a return value of 0 as a
> > failure.
> >
> > On an MT8196 board this led to a hard lockup during shutdown. The wait
> > returned before the IRQ arrived, the panel disable sequence went on and
> > restarted video mode, and the late CMD_DONE interrupt was then handled
> > by mtk_dsi_irq().
>
> This happens because of the hacks that you have downstream.
>
> With the restructured mediatek-drm adding proper support for MT8196's Display
> Controller architecture, what you're describing does not happen, because the
> tear down path is correct.
So I need more information.
1. How this bug happen (include callstack, time sequence) before restructure.
2. How restructure fix this.
If this bug is trigger by some panel, the upstream SoC may have the same problem.
I would like a easy-backport patch rather than a restructure series.
Regards,
CK
>
> Regards,
> Angelo
>
> > The handler writes RACK and loops until DSI_BUSY
> > clears, but DSI_BUSY stays set while video mode is running, so the CPU
> > never leaves the handler until the watchdog fires. Forcing the wait to
> > return early reproduces the lockup every time, and it no longer
> > happens once the wait cannot return early.
> >
> > The wait synchronises the driver with the hardware, and it is bounded by
> > its timeout. Use wait_event_timeout() so that it only ends on the IRQ or
> > the timeout.
> >
> > wake_up_interruptible() cannot wake a task in uninterruptible sleep, so
> > switch mtk_dsi_irq() to wake_up(). Without it every wait would last
> > until its timeout.
> >
> > Fixes: dd5080a54df8 ("drm/mediatek: add dsi interrupt control")
> > Signed-off-by: Zi-Hao Huang <zi-hao.huang@mediatek.com>
> > Reviewed-by: CK Hu <ck.hu@mediatek.com>
> > ---
> > Changes in v2:
> > - Drop the remark that the wait is not made on behalf of userspace, since
> > a userspace backlight change can reach it (CK)
> > - Collect Reviewed-by
> > - Link to v1: https://lore.kernel.org/r/20261118-mtk-dsi-irq-wait-v1-1-205f25fac8b2@mediatek.com
> > ---
> > drivers/gpu/drm/mediatek/mtk_dsi.c | 7 +++----
> > 1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> > index f82506e10fd5..1315dd31a834 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> > @@ -627,9 +627,8 @@ static s32 mtk_dsi_wait_for_irq_done(struct mtk_dsi *dsi, u32 irq_flag,
> > unsigned long jiffies = msecs_to_jiffies(timeout);
> > struct drm_device *drm = dsi->bridge.dev;
> >
> > - ret = wait_event_interruptible_timeout(dsi->irq_wait_queue,
> > - dsi->irq_data & irq_flag,
> > - jiffies);
> > + ret = wait_event_timeout(dsi->irq_wait_queue,
> > + dsi->irq_data & irq_flag, jiffies);
> > if (ret == 0) {
> > drm_warn(drm, "Wait DSI IRQ(0x%08x) Timeout\n", irq_flag);
> >
> > @@ -656,7 +655,7 @@ static irqreturn_t mtk_dsi_irq(int irq, void *dev_id)
> >
> > mtk_dsi_mask(dsi, DSI_INTSTA, status, 0);
> > mtk_dsi_irq_data_set(dsi, status);
> > - wake_up_interruptible(&dsi->irq_wait_queue);
> > + wake_up(&dsi->irq_wait_queue);
> > }
> >
> > return IRQ_HANDLED;
> >
> > ---
> > base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
> > change-id: 20261118-mtk-dsi-irq-wait-a24712ada627
> >
> > Best regards,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/mediatek: dsi: Don't let a signal cut the IRQ wait short
2026-11-19 1:28 ` CK Hu (胡俊光)
@ 2026-11-19 3:36 ` Zi-Hao Huang
2026-11-24 0:31 ` Ryan Brue
0 siblings, 1 reply; 5+ messages in thread
From: Zi-Hao Huang @ 2026-11-19 3:36 UTC (permalink / raw)
To: ck.hu
Cc: Zi-hao.Huang, airlied, angelogioacchino.delregno, chunkuang.hu,
dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek,
matthias.bgg, p.zabel, shaoming.chen, simona
Hi CK, Angelo,
On Thu, 2026-11-19 at 01:28 +0000, CK Hu wrote:
> So I need more information.
>
> 1. How this bug happen (include callstack, time sequence) before restructure.
I'm not sure the trigger is specific to our downstream driver. On
v7.4-rc2, panel-novatek-nt36536 sends display off (0x28) and enter
sleep (0x10) from .unprepare. Because the panel sets prepare_prev_first,
this runs before mtk_dsi_bridge_atomic_post_disable(), and
mtk_dsi_bridge_atomic_disable() only clears dsi->enabled. So both
commands go through mtk_dsi_host_transfer() while video mode is running:
stop video mode, send the command, wait for CMD_DONE, restore video
mode. If that wait returns early, video mode is restarted before
CMD_DONE has been handled.
On MT8196 we hit this in a warm reboot stress test. The commands were
sent from an atomic commit by the compositor (hwcomposer) while the
system was going down. With debug prints:
- 0x28 is sent, and mtk_dsi_wait_for_irq_done() returns after about
11 us without a timeout warning, before CMD_DONE has been handled
- restore_dsi_mode sets DSI_START, so video mode runs again
- 4 to 26 us later CMD_DONE arrives, with DSI_BUSY set because video
mode is running
- mtk_dsi_irq() writes RACK and loops on DSI_BUSY; nothing stops video
mode, so it never leaves the handler until the watchdog reports a
hard lockup
Backtrace of the stuck CPU from another occurrence, without debug
prints:
readl+0x40/0x80 [mediatek_drm]
mtk_dsi_irq+0x48/0xbc [mediatek_drm]
handle_irq_event+0x88/0x2f8
handle_fasteoi_irq+0xa0/0x2e0
generic_handle_domain_irq+0x4c/0x74
gic_handle_irq+0x64/0x264
do_interrupt_handler+0x80/0x90
el1_interrupt+0x40/0x8c
el1h_64_irq_handler+0x18/0x24
el1h_64_irq+0x7c/0x80
wait_event_interruptible_timeout() can only return early like this if
the condition is already true or a signal is pending, and a task being
torn down during reboot is likely to have a signal pending. I did not
catch the signal directly. wait_event_timeout() would still return
early on a condition that is already true, but with only the wait made
uninterruptible the lockup did not show up in 2500 warm reboots, nor in
1500 more with this patch. Forcing -ERESTARTSYS for these two commands,
with CMD_DONE held off until video mode is restored, reproduces it
every time. I have not tried mainline, since it has no MT8196 display
support.
> 2. How restructure fix this.
Angelo, in the restructured driver, does the panel's .unprepare still
send its commands while DSI is in video mode? If so, I think the same
early return can happen there.
Thanks,
Zi-Hao
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/mediatek: dsi: Don't let a signal cut the IRQ wait short
2026-11-19 3:36 ` Zi-Hao Huang
@ 2026-11-24 0:31 ` Ryan Brue
0 siblings, 0 replies; 5+ messages in thread
From: Ryan Brue @ 2026-11-24 0:31 UTC (permalink / raw)
To: zi-hao.huang
Cc: airlied, angelogioacchino.delregno, chunkuang.hu, ck.hu,
dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek,
matthias.bgg, p.zabel, shaoming.chen, simona
On Thu, Nov 19, 2026 at 11:36:34AM +0800, Zi-Hao Huang wrote:
> I'm not sure the trigger is specific to our downstream driver.
I hit the same lockup on MT8173 (Amazon Fire HD 10 2017) with the
upstream driver. v7.4-rc4, whose only DSI change is "drm/mediatek: dsi:
force command mode in mtk_dsi_poweron()" from the mediatek tree, and the
mainline NT51021 panel driver, which also sets prepare_prev_first and
sends display off and enter sleep from .unprepare.
The trigger for me was suspend under Plasma. logind's PrepareForSleep
makes KWin turn the display off, and the session is frozen while KWin's
commit is still in the panel's unprepare. The freezer's fake signal ends
the interruptible wait with -ERESTARTSYS, mtk_dsi_host_send_cmd() takes
that for success, and the late CMD_DONE lands in mtk_dsi_irq()'s
DSI_BUSY loop. After the watchdog reset, MT8173's last-PC latch showed
CPU0 at mtk_dsi_irq+0x84, the DSI_INTSTA read in that loop.
With only mediatek-drm.ko changed, suspending through logind with a GPU
benchmark running: without the patch 5 of 6 suspends reset the board
(about one in three without the load); with this v2, 0 of 10, with no
DSI IRQ or vblank timeouts, and the panel's power-down still takes 270ms.
The wake_up() hunk matters. With only the wait changed, every command
waited out its 2s timeout and the panel's power-down took 10.4s.
Tested-by: Ryan Brue <ryanbrue.dev@gmail.com> # MT8173, NT51021
I actually had a similar fix ready to go, and found your patch, so thank
you :)
Best regards,
Ryan Brue
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-24 0:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 9:33 [PATCH v2] drm/mediatek: dsi: Don't let a signal cut the IRQ wait short Zi-Hao Huang via B4 Relay
2026-11-18 12:32 ` AngeloGioacchino Del Regno
2026-11-19 1:28 ` CK Hu (胡俊光)
2026-11-19 3:36 ` Zi-Hao Huang
2026-11-24 0:31 ` Ryan Brue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®