* [PATCH] drm/amdgpu/vpe: don't let the idle work gate VPE during suspend
@ 2026-12-01 9:01 Yu-Hsiang Tseng
2026-12-02 9:41 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Yu-Hsiang Tseng @ 2026-12-01 9:01 UTC (permalink / raw)
To: amd-gfx
Cc: Alex Deucher, Christian König, David Airlie, Simona Vetter,
Caden Chien, Mario Limonciello (AMD), Lin Cao, Alan Liu,
Shahyan Soltani, Lang Yu, Peyton Lee, dri-devel, Frank Min,
stable
amdgpu_device_ip_suspend_phase1() ungates the IP blocks so that their
suspend callbacks can access them in phase 2, but the VPE idle work is
only cancelled in vpe_hw_fini(). If the idle work runs in between, it
gates VPE through the SMU, and the queue reset in vpe_ring_stop() then
times out on the gated block:
amdgpu 0000:04:00.0: Register(0) [regVPEC_QUEUE_RESET_REQ] failed to reach value 0x00000000 != 0x00000001n
amdgpu 0000:04:00.0: VPE queue reset failed
The idle work runs VPE_IDLE_TIMEOUT (1 s) after the last VPE job, and
phase 1 goes on to suspend the displays after the ungate, so this is hit
when VPE was in use about a second before the suspend, for example for
VA-API color conversion. A kprobe trace of such an s2idle suspend on a
Ryzen AI 7 H 350 (VPE 6.1.0) with 7.2.15 shows the order (time in
seconds):
907.649 amdgpu_device_ip_suspend_phase1()
vpe_set_powergating_state(UNGATE): already ungated, no SMU msg
907.783 vpe_idle_work_handler()
vpe_set_powergating_state(GATE): PowerDownVpe
908.150 amdgpu_device_ip_suspend_phase2() -> vpe_suspend()
vpe_v_6_1_ring_stop() = -ETIMEDOUT
vpe_set_powergating_state(GATE): already gated, no SMU msg
This is the failure that commit 3925683515e9 ("Revert "drm/amd: Skip
power ungate during suspend for VPE"") describes, reached through the
idle work instead.
On this machine, one suspend on 7.0.12 that logged the queue reset
failure did not reach the deepest state, and after resume the SMU no
longer responded ("SMU: No response", "Failed to power gate VPE!"), so
the system had to be power cycled.
Keep VPE powered up from phase 1 until vpe_hw_fini() has stopped the
ring:
- Cancel the idle work when VPE is ungated. In phase 1 this drops the
pending work and waits for one that is already running; if that one
gated VPE, it is powered up again right after.
- Do not gate VPE from the idle work while the device is suspending, in
case a job finishes after phase 1 and queues the work again. The work
is rescheduled rather than dropped because in_suspend is still set
during resume, where the ring tests queue it.
The idle work only ever gates VPE, and vpe_ring_begin_use() already
cancels it before ungating, so the additional cancel cannot deadlock.
The race was found and analyzed with an AI coding assistant, which also
drafted the fix and this changelog.
Fixes: 5f82a0c90cca ("drm/amdgpu/vpe: enable vpe dpm")
Cc: stable@vger.kernel.org
Signed-off-by: Yu-Hsiang Tseng <asas1asas200@gmail.com>
---
Notes (not for the changelog):
Reproducer, on a Ryzen AI 7 H 350 laptop (Krackan, VPE 6.1.0, SMU 14.0.0,
PMFW 101.17.0, mesa 26.2.6): run a short VA-API job that radeonsi
offloads to VPE (NV12 -> BGRA), then suspend up to about 0.25 s after it
finishes, so that the idle work expires while the displays are suspended:
ffmpeg -vaapi_device /dev/dri/renderD128 -re -f lavfi \
-i testsrc2=size=1920x1080:rate=30 -t 2 \
-vf 'format=nv12,hwupload,scale_vaapi=format=bgra' -f null -
sleep 0.2; rtcwake -m no -s 12; systemctl suspend
The timing below is from kprobes on the VPE, SMU and suspend functions.
Phase 1 to vpe_suspend() takes 0.5-0.6 s on this machine.
Without the fix, on linux-zen 7.2.15, the idle work powered VPE down in
that window in all three cycles that were run with the job ending just
before the suspend, 0.13 s, 0.25 s and 0.34 s after phase 1. The first is
the trace in the changelog. The other two ran with the earlier attempt
described below, which does not change that part.
With the fix, on v7.4-rc5 with CONFIG_PROVE_LOCKING and
CONFIG_DEBUG_ATOMIC_SLEEP: 27 cycles without a queue reset failure, an
SMU error or a lockdep report. 15 used /sys/power/pm_test = devices and
12 s2idle with a 12 s RTC alarm, which all reached S0i3. Each set has one
idle cycle, one with the job still running and the rest with the job
ending 0-0.45 s before the suspend. In the 11 cycles where the idle work
was still pending at phase 1, it was cancelled there, VPE stayed powered
up, the ring stop returned 0 and vpe_hw_fini() sent the only
PowerDownVpe. With a longer delay the idle work had already gated VPE
before phase 1, and phase 1 powered it up again, as it does without the
fix. The same 27 cycles on linux-zen 7.2.15 with only amdgpu rebuilt gave
the same result, and that module has since been through two suspends in
normal use, of 17 minutes and 18 hours.
Two cases needed debug code on top of the patch to be hit:
- The idle work already running when phase 1 ungates VPE. With a sleep
added to the idle work right before it gates, on v7.4-rc5 in 6 cycles
with pm_test and 4 with s2idle, the cancel waited 0.34-0.58 s for the
work, the work then sent PowerDownVpe, phase 1 sent PowerUpVpe 0.5-2.3
ms later, and the ring stop 0.54-0.59 s after that returned 0.
cancel_delayed_work_sync() tells lockdep about the wait only when it
happens, so this build also acquired the lockdep map of the idle work
on every ungate (in suspend, resume and job submission): no report.
- The in_suspend check, which needs a job that finishes after phase 1,
for example one flushed by the pending "drm/amdgpu: drain queued
scheduler jobs before suspend". With a hook that queued the idle work
100 ms after the phase 1 ungate, on 7.2.15 in 5 cycles with pm_test and
2 with s2idle, the work ran 0.10-0.14 s after phase 1, did not gate VPE
and rescheduled itself, and the ring stop returned 0.
amdgpu_vpe.c builds without warnings with W=1 on v7.4-rc5 and is the same
in drm-amdgpu-next and drm-amdgpu-fixes as of 2026-12-01.
An earlier, unposted attempt left the idle work alone and powered VPE up
again in vpe_hw_fini() before the ring stop. The error went away, but the
third suspend with it hung the machine with nothing in the log. In the
two that worked, PowerUpVpe, the queue reset and PowerDownVpe were all
sent within 0.25 ms. I did not find out whether that is what hung it.
Not tested:
- v7.4 without the fix. The one time a v7.4-rc2 build was booted on this
machine to run the reproducer (with the earlier attempt compiled in but
switched off), it hung in the first cycle before anything was saved. I
did not look into that.
- Other VPE versions, S3 and hibernation.
- GPU reset, vpe_ring_reset() and driver unload, which also ungate VPE
and so run the new cancel.
On this machine the failure never showed up in about 360 suspends on
6.19.11 and appeared with 7.0, although the VPE code and the amdgpu
suspend sequence look the same in both. I did not look into what changed.
The same message shows up in
https://gitlab.freedesktop.org/drm/amd/-/issues/5556 (s2idle on Strix
Halo). I have not checked whether that is this race.
The AI coding assistant mentioned in the changelog is Claude Code (Claude
Opus 5.5 and Claude Fable 5.2). It also wrote the test scripts and drafted
these notes. I ran the tests.
drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
index f6adbc1906..235ceb62d5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
@@ -362,6 +362,10 @@ static void vpe_idle_work_handler(struct work_struct *work)
if (fences)
goto reschedule;
+ /* Suspend needs VPE to stay ungated until vpe_hw_fini() */
+ if (adev->in_suspend)
+ goto reschedule;
+
if (vpe_need_dpm0_at_power_down(adev) && vpe_get_dpm_level(adev) != 0)
goto reschedule;
@@ -710,6 +714,7 @@ static int vpe_set_powergating_state(struct amdgpu_ip_block *ip_block,
amdgpu_dpm_enable_vpe(adev, false);
vpe->context_started = false;
} else {
+ cancel_delayed_work_sync(&adev->vpe.idle_work);
amdgpu_dpm_enable_vpe(adev, true);
}
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] drm/amdgpu/vpe: don't let the idle work gate VPE during suspend
2026-12-01 9:01 [PATCH] drm/amdgpu/vpe: don't let the idle work gate VPE during suspend Yu-Hsiang Tseng
@ 2026-12-02 9:41 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 9:41 UTC (permalink / raw)
To: Yu-Hsiang Tseng, amd-gfx; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] drm/amdgpu: missing reset-domain lock in media IP idle workers
[1]
--
commit a09c7e7c3fa4da197942c25c5f4fe4c66e24d21f
Author: Yu-Hsiang Tseng <asas1asas200@gmail.com>
drm/amdgpu/vpe: don't let the idle work gate VPE during suspend
This commit cancels pending VPE idle work when ungating VPE and reschedules
the idle work if a suspend is in progress so that VPE stays powered up until
vpe_hw_fini() stops the ring.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
> index f6adbc1906fde..235ceb62d5d69 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
> @@ -362,6 +362,10 @@ static void vpe_idle_work_handler(struct work_struct *work)
> if (fences)
> goto reschedule;
>
> + /* Suspend needs VPE to stay ungated until vpe_hw_fini() */
> + if (adev->in_suspend)
> + goto reschedule;
> +
> if (vpe_need_dpm0_at_power_down(adev) && vpe_get_dpm_level(adev) != 0)
> goto reschedule;
[Severity: High]
This problem wasn't introduced by this patch, but can vpe_idle_work_handler()
and other media IP idle workers (such as vcn_v2_5_idle_work_handler()) race
with an active GPU reset [1]?
Unlike newer IP block idle handlers that serialize against GPU resets with
down_read_trylock(&adev->reset_domain->sem), this handler calls
amdgpu_device_ip_set_powergating_state() without taking the reset domain
read lock:
CPU0 CPU1
amdgpu_device_gpu_recover()
down_write(&adev->reset_domain->sem)
vpe_idle_work_handler()
amdgpu_device_ip_set_powergating_state()
<-- unsynchronized powergating access
up_write(&adev->reset_domain->sem)
Altering powergating state while a GPU reset is mid-flight can corrupt
hardware register state and cause system lockups or crashes.
[1] https://sashiko.dev/#/bug/linux-fa3dff9c-bfd3-4822-8c68-70af026e226f
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201090146.24296-1-asas1asas200@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 9:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 9:01 [PATCH] drm/amdgpu/vpe: don't let the idle work gate VPE during suspend Yu-Hsiang Tseng
2026-12-02 9:41 ` sashiko-bot
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.