Skip to contentSkip to conversation

drm/amdgpu: Fix some unload driver issues

PATCH In review Emily Deng 2 participants 5 messages Mar 5, 2021

Subsystems (2)
lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix some unload driver issues

When unloading driver after killing some applications, it will hit sdma flush tlb job timeout which is called by ttm_bo_delay_delete. So
to avoid the job submit after fence driver fini, call ttm_bo_lock_delayed_workqueue before fence driver fini. And also put drm_sched_fini before waiting fence.

Set adev->gart.ptr to null to fix null pointer when calling amdgpu_gart_unbind in amdgpu_bo_fini which is after gart_fini.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c   | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
index a11760ec3924..de0597d34588 100644
@@ -3594,6 +3594,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
 {
 	dev_info(adev->dev, "amdgpu: finishing device.\n");
 	flush_delayed_work(&adev->delayed_init_work);
+	ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
 	adev->shutdown = true;
 
 	kfree(adev->pci_state);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +3 -2
index 143a14f4866f..6d16f58ac91e 100644
@@ -531,6 +531,8 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
 
 		if (!ring || !ring->fence_drv.initialized)
 			continue;
+		if (!ring->no_scheduler)
+			drm_sched_fini(&ring->sched);
 		r = amdgpu_fence_wait_empty(ring);
 		if (r) {
 			/* no need to trigger GPU reset as we are unloading */
@@ -539,8 +541,7 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
 		if (ring->fence_drv.irq_src)
 			amdgpu_irq_put(adev, ring->fence_drv.irq_src,
 				       ring->fence_drv.irq_type);
-		if (!ring->no_scheduler)
-			drm_sched_fini(&ring->sched);
+
 		del_timer_sync(&ring->fence_drv.fallback_timer);
 		for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
 			dma_fence_put(ring->fence_drv.fences[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +1 -0
index 23823a57374f..f1ede4b43d07 100644
@@ -202,6 +202,7 @@ void amdgpu_gart_table_vram_free(struct amdgpu_device *adev)
 		return;
 	}
 	amdgpu_bo_unref(&adev->gart.bo);
+	adev->gart.ptr = NULL;
 }
 
 /*
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

Am 05.03.21 um 02:20 schrieb Emily Deng:

Quoted 4 lines

When unloading driver after killing some applications, it will hit sdma flush tlb job timeout which is called by ttm_bo_delay_delete. So
to avoid the job submit after fence driver fini, call ttm_bo_lock_delayed_workqueue before fence driver fini. And also put drm_sched_fini before waiting fence.

Good catch, Reviewed-by: Christian König <[email protected]> for this part.

Quoted 2 lines

Set adev->gart.ptr to null to fix null pointer when calling amdgpu_gart_unbind in amdgpu_bo_fini which is after gart_fini.

For that one I'm wondering if we shouldn't rather rework or double check the tear down order.

On the other hand the hardware should be idle by now (this comes after the fence_driver_fini, doesn't it?) and it looks cleaner on it's own.

Regards,
Christian.

Quoted 48 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 5 +++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c   | 1 +
  3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
index a11760ec3924..de0597d34588 100644
@@ -3594,6 +3594,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
  {
  	dev_info(adev->dev, "amdgpu: finishing device.\n");
  	flush_delayed_work(&adev->delayed_init_work);
+	ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
  	adev->shutdown = true;
 
  	kfree(adev->pci_state);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +3 -2
index 143a14f4866f..6d16f58ac91e 100644
@@ -531,6 +531,8 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
 
  		if (!ring || !ring->fence_drv.initialized)
  			continue;
+		if (!ring->no_scheduler)
+			drm_sched_fini(&ring->sched);
  		r = amdgpu_fence_wait_empty(ring);
  		if (r) {
  			/* no need to trigger GPU reset as we are unloading */
@@ -539,8 +541,7 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
  		if (ring->fence_drv.irq_src)
  			amdgpu_irq_put(adev, ring->fence_drv.irq_src,
  				       ring->fence_drv.irq_type);
-		if (!ring->no_scheduler)
-			drm_sched_fini(&ring->sched);
+
  		del_timer_sync(&ring->fence_drv.fallback_timer);
  		for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
  			dma_fence_put(ring->fence_drv.fences[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +0 -0
index 23823a57374f..f1ede4b43d07 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_table_vram_free(struct amdgpu_device *adev) · line 208

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +1 -0
@@ -202,6 +202,7 @@ void amdgpu_gart_table_vram_free(struct amdgpu_device *adev)
  		return;
  	}
  	amdgpu_bo_unref(&adev->gart.bo);
+	adev->gart.ptr = NULL;
  }
 
  /*

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#2 lore raw

[AMD Official Use Only - Internal Distribution Only]

Quoted 16 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, March 5, 2021 3:55 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix some unload driver issues

Am 05.03.21 um 02:20 schrieb Emily Deng:

Quoted 4 lines

When unloading driver after killing some applications, it will hit sdma flush tlb job timeout which is called by ttm_bo_delay_delete. So to avoid the job submit after fence driver fini, call ttm_bo_lock_delayed_workqueue before fence driver fini. And also put

drm_sched_fini before waiting fence.

Good catch, Reviewed-by: Christian König <[email protected]> for this part.

Quoted 8 lines
Quoted 2 lines

Set adev->gart.ptr to null to fix null pointer when calling amdgpu_gart_unbind in amdgpu_bo_fini which is after gart_fini.

For that one I'm wondering if we shouldn't rather rework or double check the tear down order.

On the other hand the hardware should be idle by now (this comes after the fence_driver_fini, doesn't it?) and it looks cleaner on it's own.

Yes, you are right, without consider memory leak, with above patch, the bo are all cleaned, then won't have issue. But if have memory leak, maybe it will have issue in ttm_bo_force_list_clean-> ttm_mem_evict_first?

Quoted 52 lines

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini(struct amdgpu_device

Quoted 14 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 5 +++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c   | 1 +
  3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index a11760ec3924..de0597d34588 100644
@@ -3594,6 +3594,7 @@ void amdgpu_device_fini(struct amdgpu_device

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_fini(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
  {
  dev_info(adev->dev, "amdgpu: finishing device.\n");
  flush_delayed_work(&adev->delayed_init_work);
+ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
  adev->shutdown = true;
 
  kfree(adev->pci_state);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 143a14f4866f..6d16f58ac91e 100644
@@ -531,6 +531,8 @@ void amdgpu_fence_driver_fini(struct

amdgpu_device

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -0
 *adev)
 
  if (!ring || !ring->fence_drv.initialized)
  continue;
+if (!ring->no_scheduler)
+drm_sched_fini(&ring->sched);
  r = amdgpu_fence_wait_empty(ring);
  if (r) {

/* no need to trigger GPU reset as we are unloading */

@@ -539,8

Quoted 9 lines

+541,7 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
if (ring->fence_drv.irq_src)
amdgpu_irq_put(adev, ring->fence_drv.irq_src,

         ring->fence_drv.irq_type);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -2
-if (!ring->no_scheduler)
-drm_sched_fini(&ring->sched);
+
  del_timer_sync(&ring->fence_drv.fallback_timer);
  for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
Quoted 15 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_table_vram_free(struct

Quoted 7 lines
  dma_fence_put(ring->fence_drv.fences[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +0 -0
index 23823a57374f..f1ede4b43d07 100644
@@ -202,6 +202,7 @@ void amdgpu_gart_table_vram_free(struct

amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +1 -0
  return;
  }
  amdgpu_bo_unref(&adev->gart.bo);
+adev->gart.ptr = NULL;
  }
 
  /*

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw

Am 05.03.21 um 09:43 schrieb Deng, Emily:

Quoted 18 lines

[AMD Official Use Only - Internal Distribution Only]

Quoted 16 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, March 5, 2021 3:55 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix some unload driver issues

Am 05.03.21 um 02:20 schrieb Emily Deng:

Quoted 4 lines

When unloading driver after killing some applications, it will hit sdma flush tlb job timeout which is called by ttm_bo_delay_delete. So to avoid the job submit after fence driver fini, call ttm_bo_lock_delayed_workqueue before fence driver fini. And also put

drm_sched_fini before waiting fence.

Good catch, Reviewed-by: Christian König <[email protected]> for this part.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Set adev->gart.ptr to null to fix null pointer when calling amdgpu_gart_unbind in amdgpu_bo_fini which is after gart_fini.

For that one I'm wondering if we shouldn't rather rework or double check the tear down order.

On the other hand the hardware should be idle by now (this comes after the fence_driver_fini, doesn't it?) and it looks cleaner on it's own.

Yes, you are right, without consider memory leak, with above patch, the bo are all cleaned, then won't have issue. But if have memory leak, maybe it will have issue in ttm_bo_force_list_clean-> ttm_mem_evict_first?

Yeah, that is a good argument and part of what I mean with it looks cleaner on its own.

Maybe write that into the commit message like this. With that done the full patch has my rb.

Regards,
Christian.

Quoted 59 lines
Quoted 59 lines

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini(struct amdgpu_device

Quoted 13 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 5 +++--
   drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c   | 1 +
   3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index a11760ec3924..de0597d34588 100644
@@ -3594,6 +3594,7 @@ void amdgpu_device_fini(struct amdgpu_device

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_fini(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
   {
   dev_info(adev->dev, "amdgpu: finishing device.\n");
   flush_delayed_work(&adev->delayed_init_work);
+ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
   adev->shutdown = true;
 
   kfree(adev->pci_state);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 143a14f4866f..6d16f58ac91e 100644
@@ -531,6 +531,8 @@ void amdgpu_fence_driver_fini(struct

amdgpu_device

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -0
 *adev)
 
   if (!ring || !ring->fence_drv.initialized)
   continue;
+if (!ring->no_scheduler)
+drm_sched_fini(&ring->sched);
   r = amdgpu_fence_wait_empty(ring);
   if (r) {
   /* no need to trigger GPU reset as we are unloading */

@@ -539,8

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_table_vram_free(struct

Quoted 16 lines

+541,7 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
if (ring->fence_drv.irq_src)
amdgpu_irq_put(adev, ring->fence_drv.irq_src,

          ring->fence_drv.irq_type);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -2
-if (!ring->no_scheduler)
-drm_sched_fini(&ring->sched);
+
   del_timer_sync(&ring->fence_drv.fallback_timer);
   for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
   dma_fence_put(ring->fence_drv.fences[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +0 -0
index 23823a57374f..f1ede4b43d07 100644
@@ -202,6 +202,7 @@ void amdgpu_gart_table_vram_free(struct

amdgpu_device *adev)

Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_table_vram_free(struct amdgpu_device *adev) · line 208

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +1 -0
   return;
   }
   amdgpu_bo_unref(&adev->gart.bo);
+adev->gart.ptr = NULL;
   }
 
   /*

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw

[AMD Official Use Only - Internal Distribution Only]

Quoted 38 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, March 5, 2021 4:52 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix some unload driver issues

Am 05.03.21 um 09:43 schrieb Deng, Emily:

Quoted 18 lines

[AMD Official Use Only - Internal Distribution Only]

Quoted 16 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, March 5, 2021 3:55 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix some unload driver issues

Am 05.03.21 um 02:20 schrieb Emily Deng:

Quoted 4 lines

When unloading driver after killing some applications, it will hit sdma flush tlb job timeout which is called by ttm_bo_delay_delete. So to avoid the job submit after fence driver fini, call ttm_bo_lock_delayed_workqueue before fence driver fini. And also put

drm_sched_fini before waiting fence.

Good catch, Reviewed-by: Christian König <[email protected]> for this part.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Set adev->gart.ptr to null to fix null pointer when calling amdgpu_gart_unbind in amdgpu_bo_fini which is after gart_fini.

For that one I'm wondering if we shouldn't rather rework or double check the tear down order.

On the other hand the hardware should be idle by now (this comes after the fence_driver_fini, doesn't it?) and it looks cleaner on it's own.

Yes, you are right, without consider memory leak, with above patch, the bo

are all cleaned, then won't have issue. But if have memory leak, maybe it will have issue in ttm_bo_force_list_clean-> ttm_mem_evict_first?

Quoted 8 lines

Yeah, that is a good argument and part of what I mean with it looks cleaner on its own.

Maybe write that into the commit message like this. With that done the full patch has my rb.

Regards,
Christian.

Ok, thanks.

Quoted 59 lines
Quoted 59 lines
Quoted 59 lines

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini(struct amdgpu_device

Quoted 13 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 5 +++--
   drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c   | 1 +
   3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index a11760ec3924..de0597d34588 100644
@@ -3594,6 +3594,7 @@ void amdgpu_device_fini(struct amdgpu_device

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_fini(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
   {
   dev_info(adev->dev, "amdgpu: finishing device.\n");
   flush_delayed_work(&adev->delayed_init_work);
+ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
   adev->shutdown = true;
 
   kfree(adev->pci_state);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 143a14f4866f..6d16f58ac91e 100644
@@ -531,6 +531,8 @@ void amdgpu_fence_driver_fini(struct

amdgpu_device

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -0
 *adev)
 
   if (!ring || !ring->fence_drv.initialized)
   continue;
+if (!ring->no_scheduler)
+drm_sched_fini(&ring->sched);
   r = amdgpu_fence_wait_empty(ring);
   if (r) {
   /* no need to trigger GPU reset as we are unloading */

@@ -539,8

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_table_vram_free(struct

Quoted 15 lines

+541,7 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
if (ring->fence_drv.irq_src)
amdgpu_irq_put(adev, ring->fence_drv.irq_src,

          ring->fence_drv.irq_type); -if (!ring->no_scheduler)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -1
-drm_sched_fini(&ring->sched);
+
   del_timer_sync(&ring->fence_drv.fallback_timer);
   for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
   dma_fence_put(ring->fence_drv.fences[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +0 -0
index 23823a57374f..f1ede4b43d07 100644
@@ -202,6 +202,7 @@ void amdgpu_gart_table_vram_free(struct

amdgpu_device *adev)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_table_vram_free(struct amdgpu_device *adev) · line 208

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +1 -0
   return;
   }
   amdgpu_bo_unref(&adev->gart.bo);
+adev->gart.ptr = NULL;
   }
 
   /*

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx