Skip to contentSkip to conversation

drm/amd: Clean up kfd node on surprise disconnect

PATCH In review Mario Limonciello (AMD) 2 participants 2 messages Jan 7 – Jan 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd: Clean up kfd node on surprise disconnect

When an eGPU is unplugged the KFD topology should also be destroyed for that GPU. This never happens because the fini_sw callbacks never get to run. Run them manually before calling amdgpu_device_ip_fini_early() when a device has already been disconnected.

This location is intentionally chosen to make sure that the kfd locking refcount doesn't get incremented unintentionally.

---
v2:
* Move the call earlier in amdgpu_device_fini_hw() to fix locking refcount issues

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
index 021ecc988ff79..f167ba1b6ffcb 100644
@@ -5251,6 +5251,14 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
 
 	amdgpu_ttm_set_buffer_funcs_status(adev, false);
 
+	/*
+	 * device went through surprise hotplug; we need to destroy topology
+	 * before ip_fini_early to prevent kfd locking refcount issues by calling
+	 * amdgpu_amdkfd_suspend()
+	 */
+	if (drm_dev_is_unplugged(adev_to_drm(adev)))
+		amdgpu_amdkfd_device_fini_sw(adev);
+
 	amdgpu_device_ip_fini_early(adev);
 
 	amdgpu_irq_fini_hw(adev);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

[Public]

Looks good to me.

Quoted 50 lines

-----Original Message-----
From: Mario Limonciello (AMD) <[email protected]>
Sent: Wednesday, January 7, 2026 4:37 PM
To: [email protected]
Cc: Mario Limonciello (AMD) <[email protected]>; Russell, Kent <[email protected]>
Subject: [PATCH] drm/amd: Clean up kfd node on surprise disconnect

When an eGPU is unplugged the KFD topology should also be destroyed for that GPU. This never happens because the fini_sw callbacks never get to run. Run them manually before calling amdgpu_device_ip_fini_early() when a device has already been disconnected.

This location is intentionally chosen to make sure that the kfd locking refcount doesn't get incremented unintentionally.

---
v2:
* Move the call earlier in amdgpu_device_fini_hw() to fix locking refcount issues

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
index 021ecc988ff79..f167ba1b6ffcb 100644
@@ -5251,6 +5251,14 @@ void amdgpu_device_fini_hw(struct amdgpu_device
 *adev)
 
      amdgpu_ttm_set_buffer_funcs_status(adev, false);
 
+     /*
+      * device went through surprise hotplug; we need to destroy topology
+      * before ip_fini_early to prevent kfd locking refcount issues by calling
+      * amdgpu_amdkfd_suspend()
+      */
+     if (drm_dev_is_unplugged(adev_to_drm(adev)))
+             amdgpu_amdkfd_device_fini_sw(adev);
+
      amdgpu_device_ip_fini_early(adev);
 
      amdgpu_irq_fini_hw(adev);

--
2.43.0