Skip to contentSkip to conversation

drm/amdgpu: Fix the dead lock issue.

PATCH In review Emily Deng 3 participants 9 messages Sep 10, 2018 – Sep 11, 2018 8 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: Fix the dead lock issue.

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock
2. amdgpu_bo_create locked the bo's resv lock
3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock
4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -1
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)
 	long r = 1;
 	int i = 0;
 	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
 	if (amdgpu_sriov_runtime(adev))
 		tmo = msecs_to_jiffies(8000);
@@ -3013,8 +3016,15 @@ static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)
 		tmo = msecs_to_jiffies(100);
 
 	DRM_INFO("recover vram bo from shadow start\n");
+
 	mutex_lock(&adev->shadow_list_lock);
 	list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) {
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list, &local_shadow_list);
+	}
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list, copy_shadow_list) {
 		next = NULL;
 		amdgpu_device_recover_vram_from_shadow(adev, ring, bo, &next);
 		if (fence) {
@@ -3033,8 +3043,8 @@ static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)
 
 		dma_fence_put(fence);
 		fence = next;
+		amdgpu_bo_unref(&bo);
 	}
-	mutex_unlock(&adev->shadow_list_lock);
 
 	if (fence) {
 		r = dma_fence_wait_timeout(fence, false, tmo);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 907fdf4..cfee16c 100644
@@ -103,6 +103,7 @@ struct amdgpu_bo {
 		struct list_head	mn_list;
 		struct list_head	shadow_list;
 	};
+        struct list_head                copy_shadow_list;
 
 	struct kgd_mem                  *kfd_bo;
 };
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1536572057-22749-1-git-send-email-Emily.Deng-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 10.09.2018 um 11:34 schrieb Emily Deng:

Quoted 31 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock
2. amdgpu_bo_create locked the bo's resv lock
3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock
4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
  2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)
  	long r = 1;
  	int i = 0;
  	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
  	if (amdgpu_sriov_runtime(adev))
  		tmo = msecs_to_jiffies(8000);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev) · line 3024

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
@@ -3013,8 +3016,15 @@ static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)
  		tmo = msecs_to_jiffies(100);
 
  	DRM_INFO("recover vram bo from shadow start\n");
+
  	mutex_lock(&adev->shadow_list_lock);
  	list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) {
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list, &local_shadow_list);
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Christian.

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -1
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list, copy_shadow_list) {
  		next = NULL;
  		amdgpu_device_recover_vram_from_shadow(adev, ring, bo, &next);
  		if (fence) {
@@ -3033,8 +3043,8 @@ static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)
 
  		dma_fence_put(fence);
  		fence = next;
+		amdgpu_bo_unref(&bo);
  	}
-	mutex_unlock(&adev->shadow_list_lock);
 
  	if (fence) {
  		r = dma_fence_wait_timeout(fence, false, tmo);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
  		struct list_head	mn_list;
  		struct list_head	shadow_list;
  	};
+        struct list_head                copy_shadow_list;
 
  	struct kgd_mem                  *kfd_bo;
  };

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

A message that is not in the archive (sent off-list or not yet received): 953004de-38fa-df6c-7f7a-bec988b98127-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw
Quoted 43 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, September 10, 2018 5:41 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:34 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 22 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock 2. amdgpu_bo_create locked the bo's resv lock 3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock 4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
  2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
  	long r = 1;
  	int i = 0;
  	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
  	if (amdgpu_sriov_runtime(adev))
  		tmo = msecs_to_jiffies(8000);
@@ -3013,8 +3016,15 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  		tmo = msecs_to_jiffies(100);
 
Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev) · line 3024

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
  	DRM_INFO("recover vram bo from shadow start\n");
+
  	mutex_lock(&adev->shadow_list_lock);
  	list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list)
 {
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list, &local_shadow_list);
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

If don't use an extra variable, the local shadow list will change according the adev->shadow_list, both for adding or deleting, it is not we want.

Quoted 39 lines

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list,
+copy_shadow_list) {
  		next = NULL;
  		amdgpu_device_recover_vram_from_shadow(adev, ring, bo,

&next);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 2 lines
  		if (fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -3033,8 +3043,8 @@ static int

amdgpu_device_handle_vram_lost(struct

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
 amdgpu_device *adev)
 
  		dma_fence_put(fence);
  		fence = next;
+		amdgpu_bo_unref(&bo);
  	}
-	mutex_unlock(&adev->shadow_list_lock);
 
  	if (fence) {

r = dma_fence_wait_timeout(fence, false, tmo); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
  		struct list_head	mn_list;
  		struct list_head	shadow_list;
  	};
+        struct list_head                copy_shadow_list;
 
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
  	struct kgd_mem                  *kfd_bo;
  };

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

A message that is not in the archive (sent off-list or not yet received): BN7PR12MB264444C5467B65EE8AF3BE008F050-Zx/IyJUqfGKoYeSiBV3SvgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw

Am 10.09.2018 um 11:47 schrieb Deng, Emily:

Quoted 52 lines
Quoted 43 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, September 10, 2018 5:41 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:34 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 22 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock 2. amdgpu_bo_create locked the bo's resv lock 3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock 4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
   2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
   	long r = 1;
   	int i = 0;
   	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
   	if (amdgpu_sriov_runtime(adev))
   		tmo = msecs_to_jiffies(8000);
@@ -3013,8 +3016,15 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   		tmo = msecs_to_jiffies(100);
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev) · line 3024

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
   	DRM_INFO("recover vram bo from shadow start\n");
+
   	mutex_lock(&adev->shadow_list_lock);
   	list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list)
 {
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list, &local_shadow_list);
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

Quoted 2 lines

If don't use an extra variable, the local shadow list will change according the adev->shadow_list, both for adding or deleting, it is not we want.

That is not correct, see amdgpu_bo_destroy:

Quoted 5 lines

        if (!list_empty(&bo->shadow_list)) { mutex_lock(&adev->shadow_list_lock); list_del_init(&bo->shadow_list); mutex_unlock(&adev->shadow_list_lock); }

The BO is only removed from the list when it is destroyed, since we grabbed a local reference it can't be destroyed. So we are safe here.

Regards,
Christian.

Quoted 40 lines
Quoted 40 lines

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list,
+copy_shadow_list) {
   		next = NULL;
   		amdgpu_device_recover_vram_from_shadow(adev, ring, bo,

&next);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 2 lines
   		if (fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -3033,8 +3043,8 @@ static int

amdgpu_device_handle_vram_lost(struct

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
 amdgpu_device *adev)
 
   		dma_fence_put(fence);
   		fence = next;
+		amdgpu_bo_unref(&bo);
   	}
-	mutex_unlock(&adev->shadow_list_lock);
 
   	if (fence) {
   		r = dma_fence_wait_timeout(fence, false, tmo); diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
   		struct list_head	mn_list;
   		struct list_head	shadow_list;
   	};
+        struct list_head                copy_shadow_list;
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
   	struct kgd_mem                  *kfd_bo;
   };

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

A message that is not in the archive (sent off-list or not yet received): c5c4b5d0-2e7a-8dfd-4788-5aef295c6bef-5C7GfCeVMHo@public.gmane.org

#8 lore raw
Quoted 65 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Monday, September 10, 2018 5:49 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:47 schrieb Deng, Emily:

Quoted 52 lines
Quoted 43 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, September 10, 2018 5:41 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:34 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 22 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock 2. amdgpu_bo_create locked the bo's resv lock 3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock 4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
   2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
   	long r = 1;
   	int i = 0;
   	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
   	if (amdgpu_sriov_runtime(adev))
   		tmo = msecs_to_jiffies(8000);
@@ -3013,8 +3016,15 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   		tmo = msecs_to_jiffies(100);
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 3025

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
   	DRM_INFO("recover vram bo from shadow start\n");
+
   	mutex_lock(&adev->shadow_list_lock);
   	list_for_each_entry_safe(bo, tmp, &adev->shadow_list,
 shadow_list) {
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list, &local_shadow_list);
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

Quoted 2 lines

If don't use an extra variable, the local shadow list will change according the adev->shadow_list, both for adding or deleting, it is not we

want.

That is not correct, see amdgpu_bo_destroy:

Quoted 8 lines
Quoted 5 lines

        if (!list_empty(&bo->shadow_list)) { mutex_lock(&adev->shadow_list_lock); list_del_init(&bo->shadow_list); mutex_unlock(&adev->shadow_list_lock); }

The BO is only removed from the list when it is destroyed, since we grabbed a local reference it can't be destroyed. So we are safe here.

Sorry I am not meaning the delete, what about the adding.

Quoted 43 lines

Regards,
Christian.

Quoted 40 lines
Quoted 40 lines

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list,
+copy_shadow_list) {
   		next = NULL;
   		amdgpu_device_recover_vram_from_shadow(adev, ring, bo,

&next);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 2 lines
   		if (fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -3033,8 +3043,8 @@ static int

amdgpu_device_handle_vram_lost(struct

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
 amdgpu_device *adev)
 
   		dma_fence_put(fence);
   		fence = next;
+		amdgpu_bo_unref(&bo);
   	}
-	mutex_unlock(&adev->shadow_list_lock);
 
   	if (fence) {
   		r = dma_fence_wait_timeout(fence, false, tmo); diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
   		struct list_head	mn_list;
   		struct list_head	shadow_list;
   	};
+        struct list_head                copy_shadow_list;
 
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
   	struct kgd_mem                  *kfd_bo;
   };

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

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

A message that is not in the archive (sent off-list or not yet received): BN7PR12MB2644E4C7B732A9F62B95D5028F050-Zx/IyJUqfGKoYeSiBV3SvgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#10 lore raw

Am 10.09.2018 um 11:55 schrieb Deng, Emily:

Quoted 65 lines
Quoted 65 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Monday, September 10, 2018 5:49 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:47 schrieb Deng, Emily:

Quoted 52 lines
Quoted 43 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, September 10, 2018 5:41 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:34 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 22 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock 2. amdgpu_bo_create locked the bo's resv lock 3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock 4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
    drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
    2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
    	long r = 1;
    	int i = 0;
    	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
    	if (amdgpu_sriov_runtime(adev))
    		tmo = msecs_to_jiffies(8000);
@@ -3013,8 +3016,15 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
    		tmo = msecs_to_jiffies(100);
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 3025

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
    	DRM_INFO("recover vram bo from shadow start\n");
+
    	mutex_lock(&adev->shadow_list_lock);
    	list_for_each_entry_safe(bo, tmp, &adev->shadow_list,
 shadow_list) {
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list, &local_shadow_list);
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

Quoted 2 lines

If don't use an extra variable, the local shadow list will change according the adev->shadow_list, both for adding or deleting, it is not we

want.

That is not correct, see amdgpu_bo_destroy:

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

        if (!list_empty(&bo->shadow_list)) { mutex_lock(&adev->shadow_list_lock); list_del_init(&bo->shadow_list); mutex_unlock(&adev->shadow_list_lock); }

The BO is only removed from the list when it is destroyed, since we grabbed a local reference it can't be destroyed. So we are safe here.

Sorry I am not meaning the delete, what about the adding.

That will still go to adev->shadow_list and not affect our local list in any way.

We are not interested in any newly allocated shadow BOs, so that should be unproblematic.

Regards,
Christian.

Quoted 42 lines
Quoted 42 lines

Regards,
Christian.

Quoted 39 lines
Quoted 39 lines

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list,
+copy_shadow_list) {
    		next = NULL;
    		amdgpu_device_recover_vram_from_shadow(adev, ring, bo,

&next);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 2 lines
    		if (fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -3033,8 +3043,8 @@ static int

amdgpu_device_handle_vram_lost(struct

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
 amdgpu_device *adev)
 
    		dma_fence_put(fence);
    		fence = next;
+		amdgpu_bo_unref(&bo);
    	}
-	mutex_unlock(&adev->shadow_list_lock);
 
    	if (fence) {
    		r = dma_fence_wait_timeout(fence, false, tmo); diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
    		struct list_head	mn_list;
    		struct list_head	shadow_list;
    	};
+        struct list_head                copy_shadow_list;
 
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
    	struct kgd_mem                  *kfd_bo;
    };

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

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

A message that is not in the archive (sent off-list or not yet received): 4786882a-2dfb-a513-1ce2-500eaee29e57-5C7GfCeVMHo@public.gmane.org

#12 lore raw
Quoted 79 lines

-----Original Message-----
From: Koenig, Christian
Sent: Monday, September 10, 2018 6:02 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:55 schrieb Deng, Emily:

Quoted 45 lines
Quoted 45 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Monday, September 10, 2018 5:49 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:47 schrieb Deng, Emily:

Quoted 37 lines
Quoted 37 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, September 10, 2018 5:41 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:34 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 22 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock 2. amdgpu_bo_create locked the bo's resv lock 3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock 4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++-
    drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
    2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
    	long r = 1;
    	int i = 0;
    	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 3014

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
    	if (amdgpu_sriov_runtime(adev))
    		tmo = msecs_to_jiffies(8000); @@ -3013,8 +3016,15

@@ static

Quoted 24 lines
Quoted 24 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line

int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 2 lines
    		tmo = msecs_to_jiffies(100);
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 8 lines
    	DRM_INFO("recover vram bo from shadow start\n");
+
    	mutex_lock(&adev->shadow_list_lock);
    	list_for_each_entry_safe(bo, tmp, &adev->shadow_list,

shadow_list) {

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list, &local_shadow_list);
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

Quoted 3 lines

If don't use an extra variable, the local shadow list will change according the adev->shadow_list, both for adding or deleting, it is not we

want.

That is not correct, see amdgpu_bo_destroy:

Quoted 5 lines

        if (!list_empty(&bo->shadow_list)) { mutex_lock(&adev->shadow_list_lock); list_del_init(&bo->shadow_list); mutex_unlock(&adev->shadow_list_lock); }

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

The BO is only removed from the list when it is destroyed, since we grabbed a local reference it can't be destroyed. So we are safe here.

Sorry I am not meaning the delete, what about the adding.

That will still go to adev->shadow_list and not affect our local list in any way.

We are not interested in any newly allocated shadow BOs, so that should be unproblematic.

Understand, will send a patch later.

Best wishes
Emily Deng

Quoted 33 lines

Regards,
Christian.

Quoted 9 lines
Quoted 9 lines

Regards,
Christian.

Quoted 6 lines
Quoted 6 lines

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list,
+copy_shadow_list) {
    		next = NULL;
    		amdgpu_device_recover_vram_from_shadow(adev,

ring, bo,

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

&next);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 2 lines
    		if (fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -3033,8 +3043,8 @@ static int

amdgpu_device_handle_vram_lost(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
 amdgpu_device *adev)
 
    		dma_fence_put(fence);
    		fence = next;
+		amdgpu_bo_unref(&bo);
    	}
-	mutex_unlock(&adev->shadow_list_lock);
 
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
    	if (fence) {

r = dma_fence_wait_timeout(fence, false, tmo); diff --

git

Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
    		struct list_head	mn_list;
    		struct list_head	shadow_list;
    	};
+        struct list_head                copy_shadow_list;
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
    	struct kgd_mem                  *kfd_bo;
    };

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

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

A message that is not in the archive (sent off-list or not yet received): BN7PR12MB2644CD307DA43A28058692AB8F050-Zx/IyJUqfGKoYeSiBV3SvgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#14 lore raw
Quoted 69 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Deng, Emily
Sent: Monday, September 10, 2018 6:33 PM
To: Koenig, Christian <[email protected]>; amd- [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Quoted 6 lines

-----Original Message-----
From: Koenig, Christian
Sent: Monday, September 10, 2018 6:02 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Quoted 30 lines

Am 10.09.2018 um 11:55 schrieb Deng, Emily:

Quoted 29 lines
Quoted 29 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Monday, September 10, 2018 5:49 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:47 schrieb Deng, Emily:

Quoted 21 lines
Quoted 21 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, September 10, 2018 5:41 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:34 schrieb Emily Deng:

Quoted 13 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock 2. amdgpu_bo_create locked the bo's resv lock 3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock 4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12

+++++++++++-

Quoted 24 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 9 lines
    drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
    2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
    	long r = 1;
    	int i = 0;
    	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 3014

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
    	if (amdgpu_sriov_runtime(adev))
    		tmo = msecs_to_jiffies(8000); @@ -3013,8 +3016,15

@@ static

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 2 lines
    		tmo = msecs_to_jiffies(100);
Quoted 23 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 7 lines
    	DRM_INFO("recover vram bo from shadow start\n");
+
    	mutex_lock(&adev->shadow_list_lock);
    	list_for_each_entry_safe(bo, tmp, &adev->shadow_list,

shadow_list) {

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list,

&local_shadow_list);

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

If don't use an extra variable, the local shadow list will change according the adev->shadow_list, both for adding or deleting, it is not we

want.

That is not correct, see amdgpu_bo_destroy:

Quoted 5 lines

        if (!list_empty(&bo->shadow_list)) { mutex_lock(&adev->shadow_list_lock); list_del_init(&bo->shadow_list); mutex_unlock(&adev->shadow_list_lock); }

The BO is only removed from the list when it is destroyed, since we grabbed a local reference it can't be destroyed. So we are safe here.

The amdgpu_bo_ref could only avoid deleting the bo, but
when it is already in amdgpu_bo_destroy, the shadow_list seems still will be delete.

Quoted 64 lines
Quoted 6 lines
Quoted 1 line

Sorry I am not meaning the delete, what about the adding.

That will still go to adev->shadow_list and not affect our local list in any way.

We are not interested in any newly allocated shadow BOs, so that should be unproblematic.

Understand, will send a patch later.

Best wishes
Emily Deng

Quoted 33 lines

Regards,
Christian.

Quoted 9 lines
Quoted 9 lines

Regards,
Christian.

Quoted 6 lines
Quoted 6 lines

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list,
+copy_shadow_list) {
    		next = NULL;
    		amdgpu_device_recover_vram_from_shadow(adev,

ring, bo,

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

&next);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 2 lines
    		if (fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -3033,8 +3043,8 @@ static int

amdgpu_device_handle_vram_lost(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
 amdgpu_device *adev)
 
    		dma_fence_put(fence);
    		fence = next;
+		amdgpu_bo_unref(&bo);
    	}
-	mutex_unlock(&adev->shadow_list_lock);
 
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
    	if (fence) {

r = dma_fence_wait_timeout(fence, false, tmo); diff --

git

Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
    		struct list_head	mn_list;
    		struct list_head	shadow_list;
    	};
+        struct list_head                copy_shadow_list;
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
    	struct kgd_mem                  *kfd_bo;
    };

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

Quoted 4 lines

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

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

A message that is not in the archive (sent off-list or not yet received): BN7PR12MB264497480CBAA632E86BCAA68F040-Zx/IyJUqfGKoYeSiBV3SvgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#16 lore raw

Am 11.09.2018 um 04:16 schrieb Deng, Emily:

Quoted 90 lines
Quoted 90 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Deng, Emily
Sent: Monday, September 10, 2018 6:33 PM
To: Koenig, Christian <[email protected]>; amd- [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Quoted 6 lines

-----Original Message-----
From: Koenig, Christian
Sent: Monday, September 10, 2018 6:02 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Quoted 30 lines

Am 10.09.2018 um 11:55 schrieb Deng, Emily:

Quoted 29 lines
Quoted 29 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Monday, September 10, 2018 5:49 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:47 schrieb Deng, Emily:

Quoted 21 lines
Quoted 21 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, September 10, 2018 5:41 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Fix the dead lock issue.

Am 10.09.2018 um 11:34 schrieb Emily Deng:

Quoted 13 lines

It will ramdomly have the dead lock issue when test TDR:
1. amdgpu_device_handle_vram_lost gets the lock shadow_list_lock 2. amdgpu_bo_create locked the bo's resv lock 3. amdgpu_bo_create_shadow is waiting for the shadow_list_lock 4. amdgpu_device_recover_vram_from_shadow is waiting for the bo's resv lock.

v2:
Make a local copy of the list

---
     drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12

+++++++++++-

Quoted 24 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 9 lines
     drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
     2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index acfc63e..2b9f597 100644
@@ -3006,6 +3006,9 @@ static int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
     	long r = 1;
     	int i = 0;
     	long tmo;
+	struct list_head local_shadow_list;
+
+	INIT_LIST_HEAD(&local_shadow_list);
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 3014

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
     	if (amdgpu_sriov_runtime(adev))
     		tmo = msecs_to_jiffies(8000); @@ -3013,8 +3016,15

@@ static

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

int

amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)

Quoted 2 lines
     		tmo = msecs_to_jiffies(100);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 7 lines
     	DRM_INFO("recover vram bo from shadow start\n");
+
     	mutex_lock(&adev->shadow_list_lock);
     	list_for_each_entry_safe(bo, tmp, &adev->shadow_list,

shadow_list) {

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
+		amdgpu_bo_ref(bo);
+		list_add_tail(&bo->copy_shadow_list,

&local_shadow_list);

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+	}

Please don't add an extra copy_shadow_list field to amdgpu_bo.

If don't use an extra variable, the local shadow list will change according the adev->shadow_list, both for adding or deleting, it is not we

want.

That is not correct, see amdgpu_bo_destroy:

Quoted 5 lines
          if (!list_empty(&bo->shadow_list)) {
                  mutex_lock(&adev->shadow_list_lock);
                  list_del_init(&bo->shadow_list);
                  mutex_unlock(&adev->shadow_list_lock);
          }
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The BO is only removed from the list when it is destroyed, since we grabbed a local reference it can't be destroyed. So we are safe here.

The amdgpu_bo_ref could only avoid deleting the bo, but
when it is already in amdgpu_bo_destroy, the shadow_list seems still will be delete.

Yeah, had the same thought this night. To make it even worse the reservation object will already be destroyed and so we actually can't reserve the BOs here.

Christian.

Quoted 61 lines
Quoted 61 lines
Quoted 4 lines
Quoted 1 line

Sorry I am not meaning the delete, what about the adding.

That will still go to adev->shadow_list and not affect our local list in any way. We are not interested in any newly allocated shadow BOs, so that should be unproblematic.

Understand, will send a patch later.

Best wishes
Emily Deng

Quoted 53 lines

Regards,
Christian.

Quoted 9 lines
Quoted 9 lines

Regards,
Christian.

Quoted 6 lines
Quoted 6 lines

Instead just use bo->shadow list for this. When you hold a reference to the BO it should not be removed from the shadow list.

Additional to that you can just use list_splice_init() to move the whole shadow list to your local list.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+	mutex_unlock(&adev->shadow_list_lock);
+
+	list_for_each_entry_safe(bo, tmp, &local_shadow_list,
+copy_shadow_list) {
     		next = NULL;
     		amdgpu_device_recover_vram_from_shadow(adev,

ring, bo,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

&next);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 2 lines
     		if (fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -3033,8 +3043,8 @@ static int

amdgpu_device_handle_vram_lost(struct

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
 amdgpu_device *adev)
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
     		dma_fence_put(fence);
     		fence = next;
+		amdgpu_bo_unref(&bo);
     	}
-	mutex_unlock(&adev->shadow_list_lock);
 
     	if (fence) {

r = dma_fence_wait_timeout(fence, false, tmo); diff --

git

Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 907fdf4..cfee16c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -103,6 +103,7 @@ struct amdgpu_bo {
     		struct list_head	mn_list;
     		struct list_head	shadow_list;
     	};
+        struct list_head                copy_shadow_list;
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 109

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
     	struct kgd_mem                  *kfd_bo;
     };

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

Quoted 4 lines
Quoted 4 lines

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

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