drm/amdgpu: only save VKMS modeset state if VKMS is initialized
Subsystems (2)
PATCH 1/1 drm/amdgpu: only save VKMS modeset state if VKMS is initialized
Commit 11a08cd5ab25 ("drm/amdgpu: save VKMS modeset state from the system PM path only") moved drm_mode_config_helper_suspend()/resume() from the VKMS IP block callbacks into amdgpu_device_suspend()/resume(), keyed on adev->enable_virtual_display.
That flag does not mean a VKMS IP block exists. amdgpu_virt_init_setting() sets it on SR-IOV VFs from the common block's early init, after the IP blocks were added. A VF without a usable display IP gets no VKMS block, so its mode config has no funcs, but enable_virtual_display is still true. The old .suspend callback was never reached on such a device. Now drm_atomic_helper_suspend() runs and drm_atomic_state_alloc() dereferences the NULL dev->mode_config.funcs.
amdgpu_pci_shutdown() calls amdgpu_device_suspend(), so the guest oopses on every shutdown and reboot, after it requested full access for FINI and before it releases it. On a Navi32 (Radeon PRO V710) VF the host times the full access out and resets the VF:
Received Event: VF1, event = 0x3(REQ_GPU_FINI)
VF1 entered full access mode.
VF1 full access timed out!
Issuing FLR on vf: 1.
After repeated timeouts the host ignores the VF's REQ_GPU_INIT_DATA and REQ_GPU_INIT, and the next boot fails to probe:
amdgpu 0000:06:00.0: Doesn't get msg:1 from pf, error=-62 amdgpu 0000:06:00.0: probe with driver amdgpu failed with error -62
Check mode_info.mode_config_initialized too, as amdgpu_device_fini_hw() does before it shuts the mode config down.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -3
@@ -4603,6 +4603,16 @@ void amdgpu_device_complete(struct drm_device *dev) } } +/* +* enable_virtual_display is also set on SR-IOV VFs that have no display IP, +* where no VKMS IP block was added and the mode config was never set up. +*/ +static bool amdgpu_device_has_vkms (struct amdgpu_device *adev) +{ +return adev->enable_virtual_display && + adev->mode_info.mode_config_initialized; +} +/** * amdgpu_device_suspend - initiate device suspend *
@@ -4644,7 +4654,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev);/* VKMS modeset state is saved here, never from the reset path */ -if (adev->enable_virtual_display) { +if (amdgpu_device_has_vkms (adev)) { r =drm_mode_config_helper_suspend (dev);if (r) goto unwind_smartshift;
@@ -4701,7 +4711,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients) } unwind_vkms: -if (adev->enable_virtual_display) +if (amdgpu_device_has_vkms (adev))drm_mode_config_helper_resume (dev); unwind_smartshift:
@@ -4803,7 +4813,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) goto exit; } -if (adev->enable_virtual_display) { +if (amdgpu_device_has_vkms (adev)) { r =drm_mode_config_helper_resume (dev);if (r) goto exit;
Signature · 1 line
2.34.1
[email protected]
AI reviewThank 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/userq: race allowing…
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/userq: race allowing resume_work after amdgpu_userq_suspend() [1]
--
commit a80bb08812a1d7a481e2390eeabf02bdbae59d10
Author: Prike Liang <[email protected]>
drm/amdgpu: only save VKMS modeset state if VKMS is initialized
This commit introduces amdgpu_device_has_vkms() to verify that both enable_virtual_display and mode_config_initialized are set before saving and restoring VKMS modeset state during device suspend and resume.
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0
[ ... ]
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients) · line 4621
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -4605,7 +4615,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev);/* VKMS modeset state is saved here, never from the reset path */ -if (adev->enable_virtual_display) { +if (amdgpu_device_has_vkms (adev)) { r =drm_mode_config_helper_suspend (dev);if (r) goto unwind_smartshift;
[Severity: High]
This problem wasn't introduced by this patch, but can amdgpu_device_suspend() leave uqm->resume_work scheduled after amdgpu_userq_suspend() returns [1]?
During system suspend, amdgpu_userq_suspend() can race with amdgpu_eviction_fence_suspend_worker():
kworker CPU0amdgpu_eviction_fence_suspend_worker()
mutex_lock(&uq_mgr->userq_mutex)
...
dma_fence_signal(ev_fence)
amdgpu_device_prepare()
amdgpu_device_suspend()
amdgpu_userq_suspend()
cancel_delayed_work_sync(
&uqm->resume_work)
schedule_delayed_work(
&uq_mgr->resume_work, 0)
mutex_unlock(&uq_mgr->userq_mutex)
guard(mutex)(&uqm->userq_mutex)
amdgpu_userq_unmap_helper()
...amdgpu_userq_restore_worker() <-- runs on suspended GPU
amdgpu_eviction_fence_suspend_worker() signals ev_fence before queuing resume_work and releasing userq_mutex, while amdgpu_userq_suspend() calls cancel_delayed_work_sync(&uqm->resume_work) before taking userq_mutex and without flushing evf_mgr->suspend_work.
In addition, amdgpu_device_suspend() calls amdgpu_userq_suspend() before amdgpu_device_evict_resources():
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:amdgpu_device_suspend() {
...
r = amdgpu_userq_suspend(adev);
if (r)
goto unwind_ip_phase1;
r = amdgpu_device_evict_resources(adev);
if (r)
goto unwind_userq;
...
}If ev_fence is still unsignaled at that point, evicting resources triggers evf_mgr->suspend_work, which schedules uqm->resume_work after amdgpu_userq_suspend() has already finished.
In either case, amdgpu_userq_restore_worker() can run after TTM buffer functions, fence drivers and GPU IP blocks are suspended, causing failed page table updates, MES command timeouts or hardware access to a suspended device.
[1] https://sashiko.dev/#/bug/linux-f4cce3e7-09c5-44f6-b753-c17f5780e3fb
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
AMD General
Since @Min, Frank has a similar fix, I will drop this patch for the moment.
Regards,
Prike
Quoted 103 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Wednesday, November 25, 2026 11:03 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Limonciello, Mario <[email protected]>; Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH] drm/amdgpu: only save VKMS modeset state if VKMS is initializedCommit
11a08cd5ab25("drm/amdgpu: save VKMS modeset state from the system PM path only") moved drm_mode_config_helper_suspend()/resume() from the VKMS IP block callbacks into amdgpu_device_suspend()/resume(), keyed onadev->enable_virtual_display.That flag does not mean a VKMS IP block exists.
amdgpu_virt_init_setting()sets it on SR-IOV VFs from the common block's early init, after the IP blocks were added. A VF without a usable display IP gets no VKMS block, so its mode config has no funcs, butenable_virtual_displayis still true.
The old .suspend callback was never reached on such a device. Nowdrm_atomic_helper_suspend()runs anddrm_atomic_state_alloc()dereferences the NULLdev->mode_config.funcs.
amdgpu_pci_shutdown()callsamdgpu_device_suspend(), so the guest oopses on every shutdown and reboot, after it requested full access for FINI and before it releases it. On a Navi32 (Radeon PRO V710) VF the host times the full access out and resets the VF:Received Event: VF1, event = 0x3(REQ_GPU_FINI)
VF1 entered full access mode.
VF1 full access timed out!
Issuing FLR on vf: 1.After repeated timeouts the host ignores the VF's
REQ_GPU_INIT_DATAandREQ_GPU_INIT, and the next boot fails to probe:amdgpu 0000:06:00.0: Doesn't get msg:1 from pf, error=-62 amdgpu 0000:06:00.0: probe with driver amdgpu failed with error -62
Check mode_info.mode_config_initialized too, as
amdgpu_device_fini_hw()does before it shuts the mode config down.Fixes 11a08cd5ab25 ("drm/amdgpu: save VKMS modeset state from the systemPM path only")
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11
-1@@ -4603,6 +4603,16 @@ void amdgpu_device_complete(struct drm_device *dev) } } +/* +* enable_virtual_display is also set on SR-IOV VFs that have no +display IP, +* where no VKMS IP block was added and the mode config was never set up. +*/ +static bool amdgpu_device_has_vkms (struct amdgpu_device *adev) { +return adev->enable_virtual_display && + adev->mode_info.mode_config_initialized; +} +/** * amdgpu_device_suspend - initiate device suspend * @@ -4644,7 +4654,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev );/* VKMS modeset state is saved here, never from the reset path */ -if (adev->enable_virtual_display) { +if (amdgpu_device_has_vkms (adev)) { r =drm_mode_config_helper_suspend (dev);if (r)goto unwind_smartshift;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -4701,7 +4711,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients) } unwind_vkms: -if (adev->enable_virtual_display) +if (amdgpu_device_has_vkms (adev))drm_mode_config_helper_resume (dev);
unwind_smartshift:drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -4803,7 +4813,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) goto exit; } -if (adev->enable_virtual_display) { +if (amdgpu_device_has_vkms (adev)) { r =drm_mode_config_helper_resume (dev);if (r)goto exit;--
2.34.1