drm/amdgpu/userq: fix S3 suspend hang with user queues
Subsystems (2)
PATCH 1/1 drm/amdgpu/userq: don't restore user queues during system sleep
In reply to Arisa SnowbellBefore system sleep, amdgpu_device_prepare() moves all BOs out of VRAM. When it evicts a BO of a process with user queues, the eviction fence of that process signals, and amdgpu_eviction_fence_suspend_worker() queues the restore worker right away. So the restore worker runs while the eviction is still going on and does the opposite: it locks the VM and its BOs, moves them back into VRAM and waits for the page table updates while still holding the locks. amdgpu_userq_suspend() cancels the restore worker, but only later, in amdgpu_device_suspend().
On an RX 9070 XT (gfx12) this hung S3 suspend for good after a few hours of uptime. A restore worker waited forever on a page table update fence while holding the reservations, and systemd-sleep waited in ttm_bo_evict_first() for one of them. Why the fence never signaled is not known, but the eviction should not depend on the restore at all.
Keep the restore out of system sleep:
- Prepare sets a flag that stops the eviction worker from queuing the restore, then cancels any restore already queued. The worker checks the flag under the userq_mutex, so prepare also takes and releases each userq_mutex to wait for a worker that checked it just before.
- amdgpu_userq_resume() does not map the queues of a process whose BOs were evicted, as its page tables are out of date. It queues the restore worker instead, which validates the BOs, rearms the eviction fence and maps the queues. It decides this under the userq_mutex, which the eviction worker holds while it signals.
- Complete clears the flag and queues the restore for evicted processes, unless the device is still suspended, as it is after the hibernation snapshot. A failed prepare does the same.
- The restore worker runs on system_freezable_wq, like the amdkfd restore workers, so a restore queued during resume waits until the system is thawed.
The flag is needed besides the freezable workqueue because for hibernation dpm_prepare() runs before freeze_kernel_threads(). amdgpu_userq_ensure_ev_fence() still queues the restore directly, since only ioctls reach it and user space is frozen by then.
A restore worker that was already stuck before suspend started still blocks it: hibernation waits for it in amdgpu_userq_block_restore(), and for S3 and s2idle the freezer gives up after 20 seconds and aborts the suspend instead of hanging.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 13 +++- .../drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 64 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 + 5 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -975,6 +975,7 @@ struct amdgpu_device {bool apu_prefer_gtt;bool userq_halt_for_enforce_isolation; +bool userq_restore_blocked;struct amdgpu_uid *uid_info;struct amdgpu_uma_carveout_info uma_info;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +11 -2
@@ -2647,6 +2647,7 @@ static int amdgpu_pmops_prepare(struct device *dev) {struct drm_device *drm_dev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (drm_dev); +int r;/* device maybe not resumed here, return immediately in this case */ if (adev->in_s4 && adev->in_suspend)
@@ -2665,12 +2666,20 @@ static int amdgpu_pmops_prepare(struct device *dev) !amdgpu_acpi_is_s3_active(adev))return 1 ; -return amdgpu_device_prepare (drm_dev); +amdgpu_userq_block_restore (adev); + r =amdgpu_device_prepare (drm_dev); +if (r) +amdgpu_userq_unblock_restore (adev); + +return r; }static void amdgpu_pmops_complete (struct device *dev) { -amdgpu_device_complete (dev_get_drvdata (dev)); +struct drm_device *drm_dev =dev_get_drvdata (dev); + +amdgpu_device_complete (drm_dev); +amdgpu_userq_unblock_restore (drm_to_adev (drm_dev)); }static int amdgpu_pmops_suspend (struct device *dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1 -1
@@ -91,7 +91,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_put (ev_fence);if (!evf_mgr->shutdown) -schedule_delayed_work (&uq_mgr->resume_work,0 ); +amdgpu_userq_schedule_resume (uq_mgr);mutex_unlock (&uq_mgr->userq_mutex); }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +63 -1
88 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -0
@@ -160,6 +160,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *fvoid amdgpu_userq_mgr_cancel_reset_work (struct amdgpu_device *adev);void amdgpu_userq_mgr_cancel_resume (struct amdgpu_userq_mgr *userq_mgr); +void amdgpu_userq_schedule_resume (struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_mgr_fini (struct amdgpu_userq_mgr *userq_mgr);void amdgpu_userq_wait_for_signal (struct amdgpu_userq_mgr *uq_mgr);
@@ -173,6 +174,8 @@ bool amdgpu_userq_enabled(struct drm_device *dev);int amdgpu_userq_suspend (struct amdgpu_device *adev);int amdgpu_userq_resume (struct amdgpu_device *adev); +void amdgpu_userq_block_restore (struct amdgpu_device *adev); +void amdgpu_userq_unblock_restore (struct amdgpu_device *adev);int amdgpu_userq_stop_sched_for_enforce_isolation (struct amdgpu_device *adev,u32 idx);
Signature · 1 line
2.56.1
cover drm/amdgpu/userq: fix S3 suspend hang with user queues
Hi,
I've been testing user queues on my RX 9070 XT (amdgpu.user_queue=1, with AMD_USERQ=1 for everything I run through Steam) and came across a suspend hang. After a few hours of uptime, S3 suspend sometimes never finishes, and I have to reboot the machine by hand. What I see depends on how the suspend started:
- When the screen locks in parallel with the suspend, the machine freezes on the lock screen.
- When it locks first, the screens turn off and the suspend starts after that, the screens stay off; the machine looks asleep but never wakes up.
Either way it never actually sleeps. Short sessions suspend and resume fine.
In short: while amdgpu_device_prepare() evicts VRAM for suspend, the user queue restore worker starts and moves the same BOs back. One restore worker got stuck waiting on a page table update fence while holding the BO locks, and the suspend waited for those locks forever.
The patch keeps the restore worker out of system sleep; the details are in its commit message. It builds cleanly with W=1 against v7.4-rc4 and passes checkpatch. I'm running it now: S3 suspend and resume work, also with a game on user queues running, which keeps running after resume, so the restore worker maps the queues again. It hasn't seen enough long sessions with suspends yet to show that the hang is gone, so I'm sending it for review first and will report back once I have more runtime on it.
System:
GPU: RX 9070 XT, Navi 48 [1002:7550] rev c0, gfx12, MES fw 0x97
Kernel: 7.4.0-rc4 (linux-mainline)
Firmware: linux-firmware-amdgpu 20261019
Mesa: mesa-git 27.0.0_devel.234528.a54c80d04d3 (RADV)
Options: amdgpu ppfeaturemask=0xfff7ffff user_queue=1 runpm=0
What I saw:
The suspend started about 11 hours after boot and never finished. About 4 hours later I pressed SysRq w, s and c, and efi-pstore kept the dump. 22 tasks were blocked:
- systemd-sleep, in ttm_bo_evict_first() waiting for a BO lock
- 3 amdgpu_userq_restore_worker: one waiting on a page table update fence, two waiting for its locks
- 12 amdgpu_tlb_fence_work, waiting on their page table update fences
- 5 ttm_bo_delayed_delete, waiting on BO fences
All the workers except one TLB fence worker have higher PIDs than systemd-sleep, so they started after the suspend did.
The earlier suspends of that boot worked. The only amdgpu error before the hang was one "MES(1) failed to respond to msg=INVALIDATE_TLBS" about 1.5 hours before it; the desktop kept working after it, and I don't know if it's related.
systemd-sleep:
[31192.858314] task:systemd-sleep state:D stack:0 pid:466006 tgid:466006 ppid:1 task_flags:0x80400100 flags:0x00080800 [31192.858315] Call Trace: [31192.858315] <TASK> [31192.858315] __schedule+0x400/0x1770 [31192.858317] schedule+0x28/0xa0 [31192.858317] schedule_preempt_disabled+0x16/0x30 [31192.858318] __ww_mutex_lock.constprop.0+0x7cb/0xd40 [31192.858320] ttm_bo_evict_first+0x14e/0x240 [ttm] [31192.858323] ? __pfx_pci_pm_prepare+0x10/0x10 [31192.858325] ttm_resource_manager_evict_all+0x55/0x220 [ttm] [31192.858329] amdgpu_device_evict_resources+0x32/0x80 [amdgpu] [31192.858430] amdgpu_device_prepare+0x2f/0xe0 [amdgpu] [31192.858532] ? amdgpu_pmops_prepare+0x5b/0xb0 [amdgpu] [31192.858632] pci_pm_prepare+0x33/0x80 [31192.858633] dpm_prepare+0x187/0x4e0 [31192.858635] dpm_suspend_start+0x1e/0x60 [31192.858636] suspend_devices_and_enter+0x131/0x8b0 [31192.858638] pm_suspend.cold+0x2bc/0x336 [31192.858639] state_store+0x7f/0xf0 [31192.858640] kernfs_fop_write_iter+0x16b/0x210 [31192.858642] vfs_write+0x258/0x540 [31192.858644] ksys_write+0x7b/0x110 [31192.858645] do_syscall_64+0xce/0x580 [31192.858647] ? do_user_addr_fault+0x235/0x760 [31192.858648] ? do_syscall_64+0x35/0x580 [31192.858649] entry_SYSCALL_64_after_hwframe+0x76/0x7e [31192.858662] </TASK>
The stuck restore worker:
[31192.862190] task:kworker/0:12 state:D stack:0 pid:466979 tgid:466979 ppid:2 task_flags:0x4208060 flags:0x00080000 [31192.862191] Workqueue: events amdgpu_userq_restore_worker [amdgpu] [31192.862307] Call Trace: [31192.862307] <TASK> [31192.862307] __schedule+0x400/0x1770 [31192.862309] schedule+0x28/0xa0 [31192.862310] schedule_timeout+0xce/0x120 [31192.862311] dma_fence_default_wait+0x19b/0x2f0 [31192.862312] ? __pfx_dma_fence_default_wait_cb+0x10/0x10 [31192.862313] dma_fence_wait_timeout+0xee/0x1b0 [31192.862314] amdgpu_userq_vm_validate_and_restore_queue+0x702/0x990 [amdgpu] [31192.862432] amdgpu_userq_restore_worker+0xb3/0x1a0 [amdgpu] [31192.862547] process_one_work+0x1d6/0x3b0 [31192.862548] worker_thread+0x1aa/0x310 [31192.862549] ? __pfx_worker_thread+0x10/0x10 [31192.862550] kthread+0xe9/0x120 [31192.862551] ? __pfx_kthread+0x10/0x10 [31192.862551] ret_from_fork+0x2a9/0x340 [31192.862552] ? __pfx_kthread+0x10/0x10 [31192.862552] ret_from_fork_asm+0x1a/0x30 [31192.862554] </TASK>
I can send the full pstore dump if it helps; the journal of that boot has nothing beyond the MES timeout above. I'm also happy to test other patches or collect more data.
Thanks,
Arisa
Arisa Snowbell (1):
drm/amdgpu/userq: don't restore user queues during system sleep
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 13 +++- .../drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 64 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 + 5 files changed, 79 insertions(+), 4 deletions(-)
--
2.56.1
[email protected]
AI reviewRe: [PATCH 1/1] drm/amdgpu/userq: don't restore user queues during system sleep
In reply to Arisa SnowbellThank 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: infinite retry loop in…
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: infinite retry loop in amdgpu_userq_ensure_ev_fence() [1]
--
commit 1073e972cefe081a3547954bcb099da6f1184516
Author: Arisa Snowbell <[email protected]>
drm/amdgpu/userq: don't restore user queues during system sleep
This commit blocks user queue restore work from being scheduled during system sleep preparation and moves the restore worker to system_freezable_wq so restores do not race with VRAM eviction.
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0
[ ... ]
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr, · line 468
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -453,7 +464,7 @@ amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr,* Looks like there was no pending resume work, * add one now to create a valid eviction fence */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +amdgpu_userq_queue_restore (uq_mgr); goto retry;
[Severity: High]
This problem wasn't introduced by this patch, but can amdgpu_userq_ensure_ev_fence() loop forever [1] if amdgpu_userq_restore_worker() fails to install a new eviction fence?
When amdgpu_userq_vm_validate_and_restore_queue() fails (for example with -ENOMEM), amdgpu_userq_restore_worker() exits without replacing the signaled eviction fence:
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:amdgpu_userq_restore_worker() {
...
ret = amdgpu_userq_vm_validate_and_restore_queue(uq_mgr);
if (ret) {
drm_file_err(uq_mgr->file, "Failed to validate BOs to restore ret=%d\n", ret);
goto put_fence;
}
...
}amdgpu_userq_ensure_ev_fence() then sees the same signaled fence on the next iteration and re-queues resume_work in an unkillable loop.
[1] https://sashiko.dev/#/bug/linux-d9fc724f-ccb0-417c-8973-b83fdfc48280
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/1] drm/amdgpu/userq: don't restore user queues during system sleep
It needs ensure_ev_fence() to return an error to its ioctl callers. I can look at it as a separate patch.
Quoted 58 lines · On Tue, Nov 24, 2026 at 9:56 AM <[email protected]> wrote:
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: infinite retry loop inamdgpu_userq_ensure_ev_fence()[1]
--commit
1073e972cefe081a3547954bcb099da6f1184516
Author: Arisa Snowbell <[email protected]>drm/amdgpu/userq: don't restore user queues during system sleep
This commit blocks user queue restore work from being scheduled during system sleep preparation and moves the restore worker to
system_freezable_wqso restores do not race with VRAM eviction.Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0[ ... ]
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr, · line 468
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -453,7 +464,7 @@ amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr,* Looks like there was no pending resume work, * add one now to create a valid eviction fence */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +amdgpu_userq_queue_restore (uq_mgr); goto retry;[Severity: High]
This problem wasn't introduced by this patch, but canamdgpu_userq_ensure_ev_fence()loop forever [1] ifamdgpu_userq_restore_worker()fails to install a new eviction fence?When
amdgpu_userq_vm_validate_and_restore_queue()fails (for example with-ENOMEM),amdgpu_userq_restore_worker()exits without replacing the signaled eviction fence:drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:amdgpu_userq_restore_worker() { ... ret = amdgpu_userq_vm_validate_and_restore_queue(uq_mgr); if (ret) { drm_file_err(uq_mgr->file, "Failed to validate BOs to restore ret=%d\n", ret); goto put_fence; } ... }
amdgpu_userq_ensure_ev_fence()then sees the same signaled fence on the next iteration and re-queuesresume_workin an unkillable loop.[1] https://sashiko.dev/#/bug/linux-d9fc724f-ccb0-417c-8973-b83fdfc48280
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Christian König
maintainerHi Arisa,
Quoted 8 lines · Arisa Snowbell
Hi,
I've been testing user queues on my RX 9070 XT (amdgpu.user_queue=1, with AMD_USERQ=1 for everything I run through Steam) and came across a suspend hang. After a few hours of uptime, S3 suspend sometimes never finishes, and I have to reboot the machine by hand. What I see depends on how the suspend started:
Quoted 8 lines
- When the screen locks in parallel with the suspend, the machine freezes on the lock screen.
- When it locks first, the screens turn off and the suspend starts after that, the screens stay off; the machine looks asleep but never wakes up.Either way it never actually sleeps. Short sessions suspend and resume fine.
well first of all thanks a lot for testing user queues we haven't got much feedback so far.
So I also have the question if you have encountered any other problems except suspend/resume?
Quoted 4 lines
In short: while
amdgpu_device_prepare()evicts VRAM for suspend, the user queue restore worker starts and moves the same BOs back. One restore worker got stuck waiting on a page table update fence while holding the BO locks, and the suspend waited for those locks forever.
Yeah we haven't tested suspend/resume with userqueues yet and I don't think we have a test case for that.
@Vitaly is that right? If yes we should probably create a test case.
Quoted 8 lines
The patch keeps the restore worker out of system sleep; the details are in its commit message. It builds cleanly with W=1 against v7.4-rc4 and passes checkpatch. I'm running it now: S3 suspend and resume work, also with a game on user queues running, which keeps running after resume, so the restore worker maps the queues again. It hasn't seen enough long sessions with suspends yet to show that the hang is gone, so I'm sending it for review first and will report back once I have more runtime on it.
That approach looks a bit to complicated, in theory it should work out of the box.
In general the workqueue who executes the restore should been frozen during suspend, so evicting VRAM can then do it's work without userspace interfering.
What could be is that Mario's work to evict VRAM before swapping is disabled somehow broke that.
Or it could be that we are submitting the restore work to a non-freezeable workqeueu.
Either way Sunil should probably take a look after he's back from vacation.
Regards,
Christian.
Quoted 103 lines
System:
GPU: RX 9070 XT, Navi 48 [1002:7550] rev c0, gfx12, MES fw
0x97
Kernel: 7.4.0-rc4 (linux-mainline)
Firmware: linux-firmware-amdgpu 20261019
Mesa: mesa-git 27.0.0_devel.234528.a54c80d04d3 (RADV)
Options: amdgpu ppfeaturemask=0xfff7ffff user_queue=1 runpm=0What I saw:
The suspend started about 11 hours after boot and never finished. About 4 hours later I pressed SysRq w, s and c, and efi-pstore kept the dump. 22 tasks were blocked:
- systemd-sleep, in
ttm_bo_evict_first()waiting for a BO lock
- 3amdgpu_userq_restore_worker: one waiting on a page table update fence, two waiting for its locks
- 12amdgpu_tlb_fence_work, waiting on their page table update fences
- 5ttm_bo_delayed_delete, waiting on BO fencesAll the workers except one TLB fence worker have higher PIDs than systemd-sleep, so they started after the suspend did.
The earlier suspends of that boot worked. The only amdgpu error before the hang was one "MES(1) failed to respond to msg=INVALIDATE_TLBS" about 1.5 hours before it; the desktop kept working after it, and I don't know if it's related.
systemd-sleep:
[31192.858314] task:systemd-sleep state:D stack:0 pid:466006 tgid:466006 ppid:1 task_flags:0x80400100 flags:0x00080800 [31192.858315] Call Trace: [31192.858315] <TASK> [31192.858315] __schedule+0x400/0x1770 [31192.858317] schedule+0x28/0xa0 [31192.858317] schedule_preempt_disabled+0x16/0x30 [31192.858318] __ww_mutex_lock.constprop.0+0x7cb/0xd40 [31192.858320] ttm_bo_evict_first+0x14e/0x240 [ttm] [31192.858323] ? __pfx_pci_pm_prepare+0x10/0x10 [31192.858325] ttm_resource_manager_evict_all+0x55/0x220 [ttm] [31192.858329] amdgpu_device_evict_resources+0x32/0x80 [amdgpu] [31192.858430] amdgpu_device_prepare+0x2f/0xe0 [amdgpu] [31192.858532] ? amdgpu_pmops_prepare+0x5b/0xb0 [amdgpu] [31192.858632] pci_pm_prepare+0x33/0x80 [31192.858633] dpm_prepare+0x187/0x4e0 [31192.858635] dpm_suspend_start+0x1e/0x60 [31192.858636] suspend_devices_and_enter+0x131/0x8b0 [31192.858638] pm_suspend.cold+0x2bc/0x336 [31192.858639] state_store+0x7f/0xf0 [31192.858640] kernfs_fop_write_iter+0x16b/0x210 [31192.858642] vfs_write+0x258/0x540 [31192.858644] ksys_write+0x7b/0x110 [31192.858645] do_syscall_64+0xce/0x580 [31192.858647] ? do_user_addr_fault+0x235/0x760 [31192.858648] ? do_syscall_64+0x35/0x580 [31192.858649] entry_SYSCALL_64_after_hwframe+0x76/0x7e [31192.858662] </TASK>The stuck restore worker:
[31192.862190] task:kworker/0:12 state:D stack:0 pid:466979 tgid:466979 ppid:2 task_flags:0x4208060 flags:0x00080000 [31192.862191] Workqueue: events amdgpu_userq_restore_worker [amdgpu] [31192.862307] Call Trace: [31192.862307] <TASK> [31192.862307] __schedule+0x400/0x1770 [31192.862309] schedule+0x28/0xa0 [31192.862310] schedule_timeout+0xce/0x120 [31192.862311] dma_fence_default_wait+0x19b/0x2f0 [31192.862312] ? __pfx_dma_fence_default_wait_cb+0x10/0x10 [31192.862313] dma_fence_wait_timeout+0xee/0x1b0 [31192.862314] amdgpu_userq_vm_validate_and_restore_queue+0x702/0x990 [amdgpu] [31192.862432] amdgpu_userq_restore_worker+0xb3/0x1a0 [amdgpu] [31192.862547] process_one_work+0x1d6/0x3b0 [31192.862548] worker_thread+0x1aa/0x310 [31192.862549] ? __pfx_worker_thread+0x10/0x10 [31192.862550] kthread+0xe9/0x120 [31192.862551] ? __pfx_kthread+0x10/0x10 [31192.862551] ret_from_fork+0x2a9/0x340 [31192.862552] ? __pfx_kthread+0x10/0x10 [31192.862552] ret_from_fork_asm+0x1a/0x30 [31192.862554] </TASK>I can send the full pstore dump if it helps; the journal of that boot has nothing beyond the MES timeout above. I'm also happy to test other patches or collect more data.
Thanks,
ArisaArisa Snowbell (1):
drm/amdgpu/userq: don't restore user queues during system sleepdrivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 13 +++- .../drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 64 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 + 5 files changed, 79 insertions(+), 4 deletions(-)--
2.56.1
Re: [PATCH v2] drm/amdgpu/userq: queue the restore worker on a freezable workqueue
In reply to Arisa SnowbellHi,
Turns out I found the answer to my own question while testing, sorry for the extra mail. v2 on its own isn't enough: with Hyprland on user queues, the first S3 resume failed when amdgpu_userq_resume() mapped the queues again:
MES(0) failed to respond to msg=ADD_QUEUE fence_wait_ret=0 status=0x0_0 [drm:mes_userq_map [amdgpu]] *ERROR* Failed to map queue in HW, err (-110) amdgpu 0000:03:00.0: PM: dpm_run_callback(): pci_pm_resume returns -110
With the restore worker frozen, the BOs are still evicted at that point. Queuing the restore worker for evicted processes, instead of mapping their queues in resume, fixes it for me: the desktop and a game, both on user queues, came back fine after resume. I'll send that as v3 after a few more suspends.
Thanks,
Arisa
Quoted 60 lines · Arisa Snowbell
Before system sleep,
amdgpu_device_prepare()moves all BOs out of VRAM. When it evicts a BO of a process with user queues, the eviction fence of that process signals, andamdgpu_eviction_fence_suspend_worker()queues the restore worker onsystem_wq. That workqueue is not frozen, so the restore worker runs while the eviction is still going on and moves the BOs back into VRAM, waiting for the page table updates while it holds their reservations.On an RX 9070 XT (gfx12) this hung S3 suspend for good after a few hours of uptime. A restore worker waited forever on a page table update fence while holding the reservations, and systemd-sleep waited in
ttm_bo_evict_first()for one of them.Queue the restore worker on
system_freezable_wq, like the amdkfd restore workers. Its work is frozen beforedpm_prepare(), so a restore queued during the eviction stays pending untilamdgpu_userq_suspend()cancels it.Fixes 44cfdf368fb7 ("drm/amdgpu: resume gfx userqueues")Signed-off-by Arisa Snowbell <[email protected]>---
v2: drop the restore block flag and the resume changes, only move the
restore worker tosystem_freezable_wq(Christian). v1 claimed that for hibernationdpm_prepare()runs beforefreeze_kernel_threads(), which is wrong.drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1
-1@@ -91,7 +91,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_put (ev_fence);if (!evf_mgr->shutdown) -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); }drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-2@@ -456,7 +456,7 @@ amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr,* Looks like there was no pending resume work, * add one now to create a valid eviction fence */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 ); goto retry; }dma_fence_put (ev_fence); --2.56.1
PATCH v2 1/1 drm/amdgpu/userq: queue the restore worker on a freezable workqueue
In reply to Arisa SnowbellBefore system sleep, amdgpu_device_prepare() moves all BOs out of VRAM. When it evicts a BO of a process with user queues, the eviction fence of that process signals, and amdgpu_eviction_fence_suspend_worker() queues the restore worker on system_wq. That workqueue is not frozen, so the restore worker runs while the eviction is still going on and moves the BOs back into VRAM, waiting for the page table updates while it holds their reservations.
On an RX 9070 XT (gfx12) this hung S3 suspend for good after a few hours of uptime. A restore worker waited forever on a page table update fence while holding the reservations, and systemd-sleep waited in ttm_bo_evict_first() for one of them.
Queue the restore worker on system_freezable_wq, like the amdkfd restore workers. Its work is frozen before dpm_prepare(), so a restore queued during the eviction stays pending until amdgpu_userq_suspend() cancels it.
---
v2: drop the restore block flag and the resume changes, only move the
restore worker to system_freezable_wq (Christian). v1 claimed that for hibernation dpm_prepare() runs before freeze_kernel_threads(), which is wrong.
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1 -1
@@ -91,7 +91,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_put (ev_fence);if (!evf_mgr->shutdown) -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -1
@@ -456,7 +456,7 @@ amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr,* Looks like there was no pending resume work, * add one now to create a valid eviction fence */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 ); goto retry; }dma_fence_put (ev_fence);
Signature · 1 line
2.56.1
PATCH v3 1/1 drm/amdgpu/userq: keep the restore worker out of system sleep
Before system sleep, amdgpu_device_prepare() moves all BOs out of VRAM. When it evicts a BO of a process with user queues, the eviction fence of that process signals, and amdgpu_eviction_fence_suspend_worker() queues the restore worker on system_wq. That workqueue is not frozen, so the restore worker runs while the eviction is still going on and moves the BOs back into VRAM, waiting for the page table updates while it holds their reservations.
On an RX 9070 XT (gfx12) this hung S3 suspend for good after a few hours of uptime. A restore worker waited forever on a page table update fence while holding the reservations, and systemd-sleep waited in ttm_bo_evict_first() for one of them.
Queue the restore worker on system_freezable_wq, like the amdkfd restore workers. Its work is frozen before dpm_prepare(), so a restore queued during the eviction stays pending until amdgpu_userq_suspend() cancels it.
The processes are then still evicted at resume, so amdgpu_userq_resume() must not map their queues: their BOs are not validated and their page tables are out of date. Mapping them made MES time out on ADD_QUEUE and the resume fail with -110. Queue the restore worker for them instead, which validates the BOs, rearms the eviction fence and maps the queues once the system is thawed.
---
v3: bring back the resume change from v1: amdgpu_userq_resume() does not
map the queues of processes whose BOs are evicted, and queues the restore worker for them instead. With v2 alone, resume mapped them with the BOs still evicted, MES timed out on ADD_QUEUE and the resume failed with -110.
v2: drop the restore block flag and the resume changes, only move the
restore worker to system_freezable_wq (Christian). v1 claimed that for hibernation dpm_prepare() runs before freeze_kernel_threads(), which is wrong.
Tested with S3 on an RX 9070 XT, with the desktop (Hyprland) and a game on user queues: suspend and resume complete and the queues keep running. Rendering after resume is still corrupted (the game, and small artifacts on the desktop), but that also happens with kernel queues; I'll report it separately.
.../drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1 -1
@@ -91,7 +91,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_put (ev_fence);if (!evf_mgr->shutdown) -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +18 -1
@@ -456,7 +456,7 @@ amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr,* Looks like there was no pending resume work, * add one now to create a valid eviction fence */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 ); goto retry; }dma_fence_put (ev_fence);
@@ -1428,6 +1428,16 @@ int amdgpu_userq_suspend(struct amdgpu_device *adev)return 0 ; } +static bool amdgpu_userq_evicted (struct amdgpu_userq_mgr *uq_mgr) +{ +struct amdgpu_fpriv *fpriv =uq_mgr_to_fpriv (uq_mgr); +struct dma_fence *ev_fence =amdgpu_evf_mgr_get_fence (&fpriv->evf_mgr); +bool evicted =dma_fence_is_signaled (ev_fence); + +dma_fence_put (ev_fence); +return evicted; +} +int amdgpu_userq_resume (struct amdgpu_device *adev) {struct amdgpu_usermode_queue *queue;
@@ -1438,6 +1448,13 @@ int amdgpu_userq_resume(struct amdgpu_device *adev)xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { uqm = queue->userq_mgr;guard (mutex)(&uqm->userq_mutex); + +/* The BOs moved, let the restore worker validate them first */ +if (amdgpu_userq_evicted (uqm)) { +queue_delayed_work (system_freezable_wq, &uqm->resume_work,0 ); +continue ; + } +if (adev->in_s0ix) r =amdgpu_userq_restore_helper (queue);else
Signature · 1 line
2.56.1
Re: [PATCH v3] drm/amdgpu/userq: keep the restore worker out of system sleep
Hi,
Now that suspend works with user queues, I ran into another userq bug. About ten minutes after a clean resume, while I was moving a window, the eviction of Firefox's video decoder process failed because MES stopped answering REMOVE_QUEUE:
MES(0) failed to respond to msg=REMOVE_QUEUE fence_wait_ret=453176
status=0x81000301_0
[drm:mes_userq_unmap [amdgpu]] *ERROR* Failed to unmap queue in HW, err (-110)
comm: RDD Process pid: 6022 client-id:44 client: Unset ... Couldn't
unmap all the queues, eviction failed ret=-110
After the GPU reset that followed, the desktop locked up: the eviction fence suspend worker sat in amdgpu_userq_wait_for_signal() holding the userq_mutex, and Hyprland blocked on that mutex in amdgpu_userq_ensure_ev_fence().
This patch doesn't touch that path, and I've seen MES time out under heavy load without any suspend before, so I don't think the suspend caused it. It's a separate bug, but suspend with user queues should be working now. I'll try to reproduce it without suspending and grab the devcoredump, then report it separately.
Sorry again for all the extra mails.
Thanks,
Arisa
Quoted 110 lines · Arisa Snowbell
Before system sleep,
amdgpu_device_prepare()moves all BOs out of VRAM. When it evicts a BO of a process with user queues, the eviction fence of that process signals, andamdgpu_eviction_fence_suspend_worker()queues the restore worker onsystem_wq. That workqueue is not frozen, so the restore worker runs while the eviction is still going on and moves the BOs back into VRAM, waiting for the page table updates while it holds their reservations.On an RX 9070 XT (gfx12) this hung S3 suspend for good after a few hours of uptime. A restore worker waited forever on a page table update fence while holding the reservations, and systemd-sleep waited in
ttm_bo_evict_first()for one of them.Queue the restore worker on
system_freezable_wq, like the amdkfd restore workers. Its work is frozen beforedpm_prepare(), so a restore queued during the eviction stays pending untilamdgpu_userq_suspend()cancels it.The processes are then still evicted at resume, so
amdgpu_userq_resume()must not map their queues: their BOs are not validated and their page tables are out of date. Mapping them made MES time out onADD_QUEUEand the resume fail with -110. Queue the restore worker for them instead, which validates the BOs, rearms the eviction fence and maps the queues once the system is thawed.Fixes 44cfdf368fb7 ("drm/amdgpu: resume gfx userqueues")Signed-off-by Arisa Snowbell <[email protected]>---
v3: bring back the resume change from v1:amdgpu_userq_resume()does not
map the queues of processes whose BOs are evicted, and queues the restore worker for them instead. With v2 alone, resume mapped them with the BOs still evicted, MES timed out onADD_QUEUEand the resume failed with -110.v2: drop the restore block flag and the resume changes, only move the
restore worker tosystem_freezable_wq(Christian). v1 claimed that for hibernationdpm_prepare()runs beforefreeze_kernel_threads(), which is wrong.Tested with S3 on an RX 9070 XT, with the desktop (Hyprland) and a game on user queues: suspend and resume complete and the queues keep running. Rendering after resume is still corrupted (the game, and small artifacts on the desktop), but that also happens with kernel queues; I'll report it separately.
.../drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1
-1@@ -91,7 +91,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_put (ev_fence);if (!evf_mgr->shutdown) -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); }drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +18
-2@@ -456,7 +456,7 @@ amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *uq_mgr,* Looks like there was no pending resume work, * add one now to create a valid eviction fence */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 ); goto retry; }dma_fence_put (ev_fence);@@ -1428,6 +1428,16 @@ int amdgpu_userq_suspend(struct amdgpu_device *adev)return 0 ; } +static bool amdgpu_userq_evicted (struct amdgpu_userq_mgr *uq_mgr) +{ +struct amdgpu_fpriv *fpriv =uq_mgr_to_fpriv (uq_mgr); +struct dma_fence *ev_fence =amdgpu_evf_mgr_get_fence (&fpriv->evf_mgr); +bool evicted =dma_fence_is_signaled (ev_fence); + +dma_fence_put (ev_fence); +return evicted; +} +int amdgpu_userq_resume (struct amdgpu_device *adev) {struct amdgpu_usermode_queue *queue;@@ -1438,6 +1448,13 @@ int amdgpu_userq_resume(struct amdgpu_device *adev)xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { uqm = queue->userq_mgr;guard (mutex)(&uqm->userq_mutex); + +/* The BOs moved, let the restore worker validate them first */ +if (amdgpu_userq_evicted (uqm)) { +queue_delayed_work (system_freezable_wq, &uqm->resume_work,0 ); +continue ; + } +if (adev->in_s0ix) r =amdgpu_userq_restore_helper (queue);else --2.56.1
Hi Christian,
Quoted 2 lines · Christian König
So I also have the question if you have encountered any other problems except suspend/resume?
Apart from the suspend hang, two things:
- "MES(1) failed to respond to msg=INVALIDATE_TLBS", like the one before the hang in the report. It has shown up a few times under different kinds of heavy load, also when nothing was using user queues, but I never saw it before I enabled amdgpu.user_queue=1. The desktop kept working each time.
- After S3 resume, a D3D12 game (Hunt: Showdown 1896 through vkd3d-proton) keeps running but renders wrong until it is restarted. It happens with kernel queues too, so it doesn't look like a user queue problem, though the artifacts look different with user queues.
Otherwise games and the desktop have run fine on user queues so far. Maybe that's why there's so little feedback: it just works pretty well.
Quoted 3 lines
In general the workqueue who executes the restore should been frozen during suspend, so evicting VRAM can then do it's work without userspace interfering.
[...]
Quoted 2 lines
Or it could be that we are submitting the restore work to a non-freezeable workqeueu.
Oh I see, amdgpu_eviction_fence_suspend_worker() and amdgpu_userq_ensure_ev_fence() queue resume_work with schedule_delayed_work(), so it runs on system_wq. The stuck worker in the dump shows "Workqueue: events amdgpu_userq_restore_worker", and the eviction there comes from amdgpu_device_prepare(), which runs after freeze_kernel_threads(), so a freezable workqueue would have held the restore back.
I took a quick look and I think the patch can be simplified a lot. In v1 I also claimed that hibernation calls dpm_prepare() before freezing kernel threads, and that was the only reason for the extra flag. I'll send a v2 that only moves the restore worker to system_freezable_wq.
One thing v1 also changed and v2 will leave alone: amdgpu_userq_resume() maps the queues again even when the BOs of the process were evicted before suspend, while only the restore worker validates them and updates the page tables. With v2 nothing queues that restore at resume; it runs with the next signal ioctl. Is it fine for the queues to run before that, or should resume queue the restore instead of mapping?
Thanks,
Arisa
Quoted 160 lines · Christian König
Hi Arisa,
Quoted 8 lines · Arisa Snowbell
Hi,
I've been testing user queues on my RX 9070 XT (amdgpu.user_queue=1, with AMD_USERQ=1 for everything I run through Steam) and came across a suspend hang. After a few hours of uptime, S3 suspend sometimes never finishes, and I have to reboot the machine by hand. What I see depends on how the suspend started:
Quoted 8 lines
- When the screen locks in parallel with the suspend, the machine freezes on the lock screen.
- When it locks first, the screens turn off and the suspend starts after that, the screens stay off; the machine looks asleep but never wakes up.Either way it never actually sleeps. Short sessions suspend and resume fine.
well first of all thanks a lot for testing user queues we haven't got much feedback so far.
So I also have the question if you have encountered any other problems except suspend/resume?
Quoted 4 lines
In short: while
amdgpu_device_prepare()evicts VRAM for suspend, the user queue restore worker starts and moves the same BOs back. One restore worker got stuck waiting on a page table update fence while holding the BO locks, and the suspend waited for those locks forever.Yeah we haven't tested suspend/resume with userqueues yet and I don't think we have a test case for that.
@Vitaly is that right? If yes we should probably create a test case.
Quoted 8 lines
The patch keeps the restore worker out of system sleep; the details are in its commit message. It builds cleanly with W=1 against v7.4-rc4 and passes checkpatch. I'm running it now: S3 suspend and resume work, also with a game on user queues running, which keeps running after resume, so the restore worker maps the queues again. It hasn't seen enough long sessions with suspends yet to show that the hang is gone, so I'm sending it for review first and will report back once I have more runtime on it.
That approach looks a bit to complicated, in theory it should work out of the box.
In general the workqueue who executes the restore should been frozen during suspend, so evicting VRAM can then do it's work without userspace interfering.
What could be is that Mario's work to evict VRAM before swapping is disabled somehow broke that.
Or it could be that we are submitting the restore work to a non-freezeable workqeueu.
Either way Sunil should probably take a look after he's back from vacation.
Regards,
Christian.Quoted 103 lines
System:
GPU: RX 9070 XT, Navi 48 [1002:7550] rev c0, gfx12, MES fw
0x97
Kernel: 7.4.0-rc4 (linux-mainline)
Firmware: linux-firmware-amdgpu 20261019
Mesa: mesa-git 27.0.0_devel.234528.a54c80d04d3 (RADV)
Options: amdgpu ppfeaturemask=0xfff7ffff user_queue=1 runpm=0What I saw:
The suspend started about 11 hours after boot and never finished. About 4 hours later I pressed SysRq w, s and c, and efi-pstore kept the dump. 22 tasks were blocked:
- systemd-sleep, in
ttm_bo_evict_first()waiting for a BO lock
- 3amdgpu_userq_restore_worker: one waiting on a page table update fence, two waiting for its locks
- 12amdgpu_tlb_fence_work, waiting on their page table update fences
- 5ttm_bo_delayed_delete, waiting on BO fencesAll the workers except one TLB fence worker have higher PIDs than systemd-sleep, so they started after the suspend did.
The earlier suspends of that boot worked. The only amdgpu error before the hang was one "MES(1) failed to respond to msg=INVALIDATE_TLBS" about 1.5 hours before it; the desktop kept working after it, and I don't know if it's related.
systemd-sleep:
[31192.858314] task:systemd-sleep state:D stack:0 pid:466006 tgid:466006 ppid:1 task_flags:0x80400100 flags:0x00080800 [31192.858315] Call Trace: [31192.858315] <TASK> [31192.858315] __schedule+0x400/0x1770 [31192.858317] schedule+0x28/0xa0 [31192.858317] schedule_preempt_disabled+0x16/0x30 [31192.858318] __ww_mutex_lock.constprop.0+0x7cb/0xd40 [31192.858320] ttm_bo_evict_first+0x14e/0x240 [ttm] [31192.858323] ? __pfx_pci_pm_prepare+0x10/0x10 [31192.858325] ttm_resource_manager_evict_all+0x55/0x220 [ttm] [31192.858329] amdgpu_device_evict_resources+0x32/0x80 [amdgpu] [31192.858430] amdgpu_device_prepare+0x2f/0xe0 [amdgpu] [31192.858532] ? amdgpu_pmops_prepare+0x5b/0xb0 [amdgpu] [31192.858632] pci_pm_prepare+0x33/0x80 [31192.858633] dpm_prepare+0x187/0x4e0 [31192.858635] dpm_suspend_start+0x1e/0x60 [31192.858636] suspend_devices_and_enter+0x131/0x8b0 [31192.858638] pm_suspend.cold+0x2bc/0x336 [31192.858639] state_store+0x7f/0xf0 [31192.858640] kernfs_fop_write_iter+0x16b/0x210 [31192.858642] vfs_write+0x258/0x540 [31192.858644] ksys_write+0x7b/0x110 [31192.858645] do_syscall_64+0xce/0x580 [31192.858647] ? do_user_addr_fault+0x235/0x760 [31192.858648] ? do_syscall_64+0x35/0x580 [31192.858649] entry_SYSCALL_64_after_hwframe+0x76/0x7e [31192.858662] </TASK>The stuck restore worker:
[31192.862190] task:kworker/0:12 state:D stack:0 pid:466979 tgid:466979 ppid:2 task_flags:0x4208060 flags:0x00080000 [31192.862191] Workqueue: events amdgpu_userq_restore_worker [amdgpu] [31192.862307] Call Trace: [31192.862307] <TASK> [31192.862307] __schedule+0x400/0x1770 [31192.862309] schedule+0x28/0xa0 [31192.862310] schedule_timeout+0xce/0x120 [31192.862311] dma_fence_default_wait+0x19b/0x2f0 [31192.862312] ? __pfx_dma_fence_default_wait_cb+0x10/0x10 [31192.862313] dma_fence_wait_timeout+0xee/0x1b0 [31192.862314] amdgpu_userq_vm_validate_and_restore_queue+0x702/0x990 [amdgpu] [31192.862432] amdgpu_userq_restore_worker+0xb3/0x1a0 [amdgpu] [31192.862547] process_one_work+0x1d6/0x3b0 [31192.862548] worker_thread+0x1aa/0x310 [31192.862549] ? __pfx_worker_thread+0x10/0x10 [31192.862550] kthread+0xe9/0x120 [31192.862551] ? __pfx_kthread+0x10/0x10 [31192.862551] ret_from_fork+0x2a9/0x340 [31192.862552] ? __pfx_kthread+0x10/0x10 [31192.862552] ret_from_fork_asm+0x1a/0x30 [31192.862554] </TASK>I can send the full pstore dump if it helps; the journal of that boot has nothing beyond the MES timeout above. I'm also happy to test other patches or collect more data.
Thanks,
ArisaArisa Snowbell (1):
drm/amdgpu/userq: don't restore user queues during system sleepdrivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 13 +++- .../drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 64 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 + 5 files changed, 79 insertions(+), 4 deletions(-)--
2.56.1
[email protected]
AI reviewRe: [PATCH v2] drm/amdgpu/userq: queue the restore worker on a freezable workqueue
In reply to Arisa SnowbellThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu/userq: canceled resume_work leaves VM unvalidated in amdgpu_userq_resume() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/amdgpu/userq: canceled resume_work leaves VM unvalidated in amdgpu_userq_resume()
--
commit 5bc8d4302fb0871c6ac59bea95139558edabb658
Author: Arisa Snowbell <[email protected]>
drm/amdgpu/userq: queue the restore worker on a freezable workqueue
This commit moves the userqueue restore worker from system_wq to system_freezable_wq so it does not run concurrently with VRAM BO eviction during amdgpu_device_prepare().
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct *work) · line 97
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1
-1@@ -91,7 +91,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_put (ev_fence);if (!evf_mgr->shutdown) -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); }
[Severity: High]
Does canceling uq_mgr->resume_work in amdgpu_userq_suspend() leave the process's VM unvalidated and its eviction fence signaled on resume?
When amdgpu_device_prepare() evicts VRAM BOs, amdgpu_eviction_fence_suspend_worker() unmaps the user queues, signals ev_fence, and queues uq_mgr->resume_work on system_freezable_wq. Because system_freezable_wq is already frozen, uq_mgr->resume_work stays pending while the remaining BOs (including vm->root.bo and page tables) are evicted, and amdgpu_userq_suspend() then cancels it:
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:amdgpu_userq_suspend() {
...
xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
uqm = queue->userq_mgr;
cancel_delayed_work_sync(&uqm->resume_work);
...
}On resume, amdgpu_userq_resume() never re-queues uqm->resume_work or calls amdgpu_userq_vm_validate_and_restore_queue():
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:amdgpu_userq_resume() {
...
xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
uqm = queue->userq_mgr;
guard(mutex)(&uqm->userq_mutex);
if (adev->in_s0ix)
r = amdgpu_userq_restore_helper(queue);
else
r = amdgpu_userq_map_helper(queue);
...
}For S3 and S4, amdgpu_userq_map_helper() maps the queue in MES while the VM BOs and page tables are still evicted and ev_fence remains signaled, causing GPU page faults or MES mapping failures. In addition, because amdgpu_userq_map_helper() sets queue->state to AMDGPU_USERQ_STATE_MAPPED, a later resume_work run that moves vm->root.bo back to VRAM will see queue->state != AMDGPU_USERQ_STATE_UNMAPPED and skip updating MES with the new page table base address. For dGPU S0ix, queue->state was already set to AMDGPU_USERQ_STATE_UNMAPPED during amdgpu_device_prepare(), so amdgpu_userq_restore_helper() (which only restores AMDGPU_USERQ_STATE_PREEMPTED queues) is a no-op and the queue stays unmapped.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v3] drm/amdgpu/userq: keep the restore worker out of system sleep
In reply to Arisa SnowbellThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu/userq: system_freezable_wq is not frozen during hibernation dpm_prepare() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/amdgpu/userq: system_freezable_wq is not frozen during hibernation dpm_prepare()
--
commit f10cd6c65f3801c912d63876fd1a81a692e96c5a
Author: Arisa Snowbell <[email protected]>
drm/amdgpu/userq: keep the restore worker out of system sleep
This commit moves the user queue restore worker (resume_work) to system_freezable_wq and skips mapping evicted queues in amdgpu_userq_resume(), queuing the restore worker for them instead.
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct *work) · line 97
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1
-1@@ -91,7 +91,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_put (ev_fence);if (!evf_mgr->shutdown) -schedule_delayed_work (&uq_mgr->resume_work,0 ); +queue_delayed_work (system_freezable_wq, &uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); }
[Severity: High]
Can uq_mgr->resume_work still run during amdgpu_device_prepare() on the hibernation (S4) path?
In hibernate(), freeze_processes() passes user_only = true to try_to_freeze_tasks(), which skips freeze_workqueues_begin(). hibernation_snapshot() then calls dpm_prepare(PMSG_FREEZE) before freeze_kernel_threads() freezes freezable workqueues:
kernel/power/hibernate.c:hibernation_snapshot() {
...
error = dpm_prepare(PMSG_FREEZE);
if (error)
goto Complete;
/* Preallocate image memory before freezing kernel threads and shutting down devices. */
error = hibernate_preallocate_memory();
if (error)
goto Complete;
error = freeze_kernel_threads();
...
}When amdgpu_pmops_prepare() -> amdgpu_device_prepare() -> amdgpu_device_evict_resources() evicts a user queue BO during hibernation prepare, system_freezable_wq is not frozen yet, so uq_mgr->resume_work runs immediately and can still deadlock with ttm_bo_evict_first() on the BO reservations or move evicted BOs back into VRAM before freeze_kernel_threads() runs.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1