Skip to contentSkip to conversation

drm/amdgpu: fix a call trace when unload amdgpu driver

PATCH In review Asher Song 4 participants 5 messages Sep 4, 2024

Subsystems (2)
lore
Share & tools
lore

Asher Song

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: fix a call trace when unload amdgpu driver

In some APUs, the bo type of GART page table is ttm_bo_type_sg.
Those type BOs is released by bo->delayed_delete which is added in ttm_device->wq, not released immediately.

To make sure all the ttm_resource is released before ttm_resource_manager is finilized, drain the workqueue in ttm_device.

v2: move drain_workqueue to amdgpu_ttm.c

Fixes d99fbd9aab62 ("drm/ttm: Always take the bo delayed cleanup path for imported bos")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 5c938ff0bf48..cbac21df5c47 100644
@@ -2461,6 +2461,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 		drm_dev_exit(idx);
 	}
 
+	drain_workqueue(adev->mman.bdev.wq);
 	amdgpu_direct_gma_fini(adev);
 	amdgpu_vram_mgr_fini(adev);
 	amdgpu_gtt_mgr_fini(adev);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v2 1/1
#1 lore raw

Am 04.09.24 um 10:04 schrieb Asher Song:

Quoted 10 lines

In some APUs, the bo type of GART page table is ttm_bo_type_sg.
Those type BOs is released by bo->delayed_delete which is added in ttm_device->wq, not released immediately.

To make sure all the ttm_resource is released before ttm_resource_manager is finilized, drain the workqueue in ttm_device.

v2: move drain_workqueue to amdgpu_ttm.c

Fixes d99fbd9aab62 ("drm/ttm: Always take the bo delayed cleanup path for imported bos")
Quoted 16 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 5c938ff0bf48..cbac21df5c47 100644
@@ -2461,6 +2461,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
  		drm_dev_exit(idx);
  	}
 
+	drain_workqueue(adev->mman.bdev.wq);
  	amdgpu_direct_gma_fini(adev);
  	amdgpu_vram_mgr_fini(adev);
  	amdgpu_gtt_mgr_fini(adev);
Acked-by on v2 1/1
#2 lore raw
In reply to Asher Song
Quoted 10 lines · Asher Song

In some APUs, the bo type of GART page table is ttm_bo_type_sg.
Those type BOs is released by bo->delayed_delete which is added in ttm_device->wq, not released immediately.

To make sure all the ttm_resource is released before ttm_resource_manager is finilized, drain the workqueue in ttm_device.

v2: move drain_workqueue to amdgpu_ttm.c

Fixes d99fbd9aab62 ("drm/ttm: Always take the bo delayed cleanup path for imported bos")

Thanks,
Lijo

Quoted 16 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 5c938ff0bf48..cbac21df5c47 100644
@@ -2461,6 +2461,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 		drm_dev_exit(idx);
 	}
 
+	drain_workqueue(adev->mman.bdev.wq);
 	amdgpu_direct_gma_fini(adev);
 	amdgpu_vram_mgr_fini(adev);
 	amdgpu_gtt_mgr_fini(adev);
#3 lore raw
In reply to Asher Song

On 2024-09-04 04:04, Asher Song wrote:
In some APUs, the bo type of GART page table is ttm_bo_type_sg. Those type BOs is released by bo->delayed_delete which is added in ttm_device->wq, not released immediately. To make sure all the ttm_resource is released before ttm_resource_manager is finilized, drain the workqueue in ttm_device. v2: move drain_workqueue to amdgpu_ttm.c Fixes:d99fbd9aab62 ("drm/ttm: Always take the bo delayed cleanup path for imported bos") Suggested-by: Christian König <[email protected]> Signed-off-by: Asher Song <[email protected]> Acked-by: Philip Yang <[email protected]> Most likely this will fix another bug caused by race condition b/w GPU mode 1 reset and delayed bo cleanup worker. Thank you. Philip --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 5c938ff0bf48..cbac21df5c47 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -2461,6 +2461,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev) drm_dev_exit(idx); } + drain_workqueue(adev->mman.bdev.wq); amdgpu_direct_gma_fini(adev); amdgpu_vram_mgr_fini(adev); amdgpu_gtt_mgr_fini(adev);

#4 lore raw
Quoted 9 lines · Philip Yang
Quoted 7 lines · Asher Song

In some APUs, the bo type of GART page table is ttm_bo_type_sg.
Those type BOs is released by bo->delayed_delete which is added in ttm_device->wq, not released immediately.

To make sure all the ttm_resource is released before ttm_resource_manager is finilized, drain the workqueue in ttm_device.

v2: move drain_workqueue to amdgpu_ttm.c

Quoted 8 lines
Quoted 3 lines
Fixes d99fbd9aab62 ("drm/ttm: Always take the bo delayed cleanup path for imported bos")

Most likely this will fix another bug caused by race condition b/w GPU mode 1 reset and delayed bo cleanup worker.

Unfortunately this won't - sw_fini doesn't get called during a reset.

Thanks,
Lijo

Quoted 19 lines

Thank you.
Philip

Quoted 16 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 5c938ff0bf48..cbac21df5c47 100644
@@ -2461,6 +2461,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 		drm_dev_exit(idx);
 	}
 
+	drain_workqueue(adev->mman.bdev.wq);
 	amdgpu_direct_gma_fini(adev);
 	amdgpu_vram_mgr_fini(adev);
 	amdgpu_gtt_mgr_fini(adev);