All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: drain queued scheduler jobs before suspend
@ 2026-11-16 20:40 Mario Limonciello
  2026-11-16 21:13 ` sashiko-bot
  2026-11-17  9:37 ` Christian König
  0 siblings, 2 replies; 8+ messages in thread
From: Mario Limonciello @ 2026-11-16 20:40 UTC (permalink / raw)
  To: Christian König
  Cc: amd-gfx, Logatharshan Thothiralingam, Mario Limonciello

At suspend, amdgpu_fence_driver_hw_fini() only waits for the last fence
emitted to each ring. Jobs still queued in a scheduler entity have not
reached run_job() yet and so have no hardware fence. Userspace is frozen
at this point, but such jobs can become runnable later, for example once
a dependency signals, and the scheduler then pushes them into the ring
after the hardware wait has finished and before the IP blocks are torn
down. On resume the ring write pointer is reset, those jobs never
signal and the GFX ring times out and hangs.

This was observed as a rare (about 2 in 400 cycles) GFX hang on S3 resume
on Picasso.

Flush the context and VM scheduler entities of every open file
before evicting resources, mirroring what amdgpu_flush() does on file
close. Like for any other dma_fence there is no timeout, the wait is
not bounded.

Reported-by: Logatharshan Thothiralingam <Logatharshan.Thothiralingam@amd.com>
Closes: https://lore.kernel.org/amd-gfx/SA1SPRMB0073292C113C6B98D9282092F87F2@SA1SPRMB0073.namprd12.prod.outlook.com/
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 19a566187dfb5..d18348116d3f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4538,6 +4538,30 @@ void amdgpu_device_complete(struct drm_device *dev)
 	}
 }
 
+/**
+ * amdgpu_device_flush_file_entities - drain scheduler entities of open files
+ * @adev: amdgpu device object
+ *
+ * Wait for the scheduler entities owned by all open files (the context
+ * entities used for command submission and the VM entities used for page
+ * table updates) to run out of queued jobs, so that nothing can slip into
+ * the rings after the hardware fences were waited on at suspend time.
+ */
+static void amdgpu_device_flush_file_entities(struct amdgpu_device *adev)
+{
+	struct drm_device *ddev = adev_to_drm(adev);
+	struct drm_file *file;
+
+	guard(mutex)(&ddev->filelist_mutex);
+	list_for_each_entry(file, &ddev->filelist, lhead) {
+		struct amdgpu_fpriv *fpriv = file->driver_priv;
+
+		amdgpu_ctx_mgr_entity_flush(&fpriv->ctx_mgr,
+					    MAX_SCHEDULE_TIMEOUT);
+		amdgpu_vm_wait_idle(&fpriv->vm, MAX_SCHEDULE_TIMEOUT);
+	}
+}
+
 /**
  * amdgpu_device_suspend - initiate device suspend
  *
@@ -4587,6 +4611,8 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)
 	if (r)
 		goto unwind_ip_phase1;
 
+	amdgpu_device_flush_file_entities(adev);
+
 	r = amdgpu_device_evict_resources(adev);
 	if (r)
 		goto unwind_userq;

---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261116-superm1-drain-submissions-17d4414ab3b9

Best regards,
--  
Mario Limonciello <mario.limonciello@amd.com>


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-17 20:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 20:40 [PATCH] drm/amdgpu: drain queued scheduler jobs before suspend Mario Limonciello
2026-11-16 21:13 ` sashiko-bot
2026-11-16 21:21   ` Mario Limonciello
2026-11-17  9:08     ` Christian König
2026-11-17  9:37 ` Christian König
2026-11-17 13:39   ` Thothiralingam, Logatharshan
2026-11-17 17:52     ` Thothiralingam, Logatharshan
2026-11-17 20:08       ` Thothiralingam, Logatharshan

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.