Skip to contentSkip to conversation

Two bugs found while rebasing my HMM branch

PATCH In review Felix Kuehling 2 participants 7 messages Mar 13, 2021 – Mar 15, 2021

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

cover Two bugs found while rebasing my HMM branch

Felix Kuehling (2):
drm/amdkfd: Fix recursive lock warnings
drm/amdkfd: Fix resource cursor initialization

 drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c         | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 6 lines
2.30.2

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

PATCH 1/2 drm/amdkfd: Fix recursive lock warnings

memalloc_nofs_save/restore are no longer sufficient to prevent recursive lock warnings when holding locks that can be taken in MMU notifiers. Use memalloc_noreclaim_save/restore instead.

Fixes f920e413ff9c ("mm: track mmu notifiers in fs_reclaim_acquire/release")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
index 318eeea577b5..bc3951b71079 100644
@@ -93,13 +93,13 @@ struct amdgpu_prt_cb {
 static inline void amdgpu_vm_eviction_lock(struct amdgpu_vm *vm)
 {
 	mutex_lock(&vm->eviction_lock);
-	vm->saved_flags = memalloc_nofs_save();
+	vm->saved_flags = memalloc_noreclaim_save();
 }
 
 static inline int amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm)
 {
 	if (mutex_trylock(&vm->eviction_lock)) {
-		vm->saved_flags = memalloc_nofs_save();
+		vm->saved_flags = memalloc_noreclaim_save();
 		return 1;
 	}
 	return 0;
@@ -107,7 +107,7 @@ static inline int amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm)
 
 static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm)
 {
-	memalloc_nofs_restore(vm->saved_flags);
+	memalloc_noreclaim_restore(vm->saved_flags);
 	mutex_unlock(&vm->eviction_lock);
 }
 
Signature · 6 lines
2.30.2

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

Re: [PATCH 1/2] drm/amdkfd: Fix recursive lock warnings

Am 13.03.21 um 03:43 schrieb Felix Kuehling:

Quoted 6 lines

memalloc_nofs_save/restore are no longer sufficient to prevent recursive lock warnings when holding locks that can be taken in MMU notifiers. Use memalloc_noreclaim_save/restore instead.

Fixes f920e413ff9c ("mm: track mmu notifiers in fs_reclaim_acquire/release")
Quoted 25 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
index 318eeea577b5..bc3951b71079 100644
@@ -93,13 +93,13 @@ struct amdgpu_prt_cb {
  static inline void amdgpu_vm_eviction_lock(struct amdgpu_vm *vm)
  {
  	mutex_lock(&vm->eviction_lock);
-	vm->saved_flags = memalloc_nofs_save();
+	vm->saved_flags = memalloc_noreclaim_save();
  }
 
  static inline int amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm)
  {
  	if (mutex_trylock(&vm->eviction_lock)) {
-		vm->saved_flags = memalloc_nofs_save();
+		vm->saved_flags = memalloc_noreclaim_save();
  		return 1;
  	}
  	return 0;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static inline int amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm) · line 113

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -107,7 +107,7 @@ static inline int amdgpu_vm_eviction_trylock(struct amdgpu_vm *vm)
 
  static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm)
  {
-	memalloc_nofs_restore(vm->saved_flags);
+	memalloc_noreclaim_restore(vm->saved_flags);
  	mutex_unlock(&vm->eviction_lock);
  }
 

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

#3 lore raw

PATCH 2/2 drm/amdkfd: Fix resource cursor initialization

In reply to Felix Kuehling

Make sure the cur->size doesn't exceed cur->remaining. Otherwise the first call to amdgpu_res_next will trigger the BUG_ON in that function.

Fixes 3af0a018a728 ("drm/amdgpu: new resource cursor")
CC Christian König <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +1 -1
index 1335e098510f..b49a61d07d60 100644
@@ -68,7 +68,7 @@ static inline void amdgpu_res_first(struct ttm_resource *res,
 		start -= node++->size << PAGE_SHIFT;
 
 	cur->start = (node->start << PAGE_SHIFT) + start;
-	cur->size = (node->size << PAGE_SHIFT) - start;
+	cur->size = min((node->size << PAGE_SHIFT) - start, size);
 	cur->remaining = size;
 	cur->node = node;
 }
Signature · 6 lines
2.30.2

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

Re: [PATCH 2/2] drm/amdkfd: Fix resource cursor initialization

Am 13.03.21 um 03:43 schrieb Felix Kuehling:

Quoted 2 lines

Make sure the cur->size doesn't exceed cur->remaining. Otherwise the first call to amdgpu_res_next will trigger the BUG_ON in that function.

Mhm the BUG_ON is correct since the function complains that we want to move the cursor forward by more than originally expected.

The problem is rather that somebody is using cur->size which is the size of the current segment as parameter for amdgpu_res_next().

Do you have a backtrace of this?

Thanks,
Christian.

Quoted 13 lines
Fixes 3af0a018a728 ("drm/amdgpu: new resource cursor")
CC Christian König <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +0 -0
index 1335e098510f..b49a61d07d60 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h static inline void amdgpu_res_first(struct ttm_resource *res, · line 74

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +1 -1
@@ -68,7 +68,7 @@ static inline void amdgpu_res_first(struct ttm_resource *res,
  		start -= node++->size << PAGE_SHIFT;
 
  	cur->start = (node->start << PAGE_SHIFT) + start;
-	cur->size = (node->size << PAGE_SHIFT) - start;
+	cur->size = min((node->size << PAGE_SHIFT) - start, size);
  	cur->remaining = size;
  	cur->node = node;
  }

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

#5 lore raw

Re: [PATCH 2/2] drm/amdkfd: Fix resource cursor initialization

Am 2021-03-15 um 6:22 a.m. schrieb Christian König:

Quoted 11 lines

Am 13.03.21 um 03:43 schrieb Felix Kuehling:

Quoted 2 lines

Make sure the cur->size doesn't exceed cur->remaining. Otherwise the first call to amdgpu_res_next will trigger the BUG_ON in that function.

Mhm the BUG_ON is correct since the function complains that we want to move the cursor forward by more than originally expected.

The problem is rather that somebody is using cur->size which is the size of the current segment as parameter for amdgpu_res_next().

Do you have a backtrace of this?

I didn't save the backtrace. The problem was in amdgpu_vm_bo_update_mapping. num_entries is based on cursor.size and later used in the amdpu_res_next call.

But I think that should be OK. If cursor.size is the current segment size, it should not exceed cursor.remaining. Otherwise every user of the cursor would have to check both cursor.size and cursor.remaining all the time, which would be inconvenient. amdgpu_res_next ensures that with cur->size = min(node->size << PAGE_SHIFT, cur->remaining). I think amdgpu_res_first should do the same.

Regards,
  Felix

Quoted 12 lines

Thanks,
Christian.

Quoted 8 lines
Fixes 3af0a018a728 ("drm/amdgpu: new resource cursor")
CC Christian König <[email protected]>

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +0 -0
index 1335e098510f..b49a61d07d60 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h static inline void amdgpu_res_first(struct · line 74

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +1 -1
@@ -68,7 +68,7 @@ static inline void amdgpu_res_first(struct
 ttm_resource *res,
           start -= node++->size << PAGE_SHIFT;
         cur->start = (node->start << PAGE_SHIFT) + start;
-    cur->size = (node->size << PAGE_SHIFT) - start;
+    cur->size = min((node->size << PAGE_SHIFT) - start, size);
       cur->remaining = size;
       cur->node = node;
   }

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

#6 lore raw

Re: [PATCH 2/2] drm/amdkfd: Fix resource cursor initialization

Am 15.03.21 um 14:08 schrieb Felix Kuehling:

Quoted 7 lines

Am 2021-03-15 um 6:22 a.m. schrieb Christian König:

Quoted 6 lines

Am 13.03.21 um 03:43 schrieb Felix Kuehling:

Quoted 2 lines

Make sure the cur->size doesn't exceed cur->remaining. Otherwise the first call to amdgpu_res_next will trigger the BUG_ON in that function.

Mhm the BUG_ON is correct since the function complains that we want to move the cursor forward by more than originally expected.

Quoted 7 lines
Quoted 4 lines

The problem is rather that somebody is using cur->size which is the size of the current segment as parameter for amdgpu_res_next().

Do you have a backtrace of this?

I didn't save the backtrace. The problem was in amdgpu_vm_bo_update_mapping. num_entries is based on cursor.size and later used in the amdpu_res_next call.

Yeah, found that in the meantime as well.

Quoted 6 lines

But I think that should be OK. If cursor.size is the current segment size, it should not exceed cursor.remaining. Otherwise every user of the cursor would have to check both cursor.size and cursor.remaining all the time, which would be inconvenient. amdgpu_res_next ensures that with cur->size = min(node->size << PAGE_SHIFT, cur->remaining). I think amdgpu_res_first should do the same.

Ok, good point. Patch is Reviewed-by: Christian König <[email protected]> then.

Regards,
Christian.

Quoted 15 lines

Regards,
  Felix

Quoted 10 lines

Thanks,
Christian.

Quoted 7 lines
Fixes 3af0a018a728 ("drm/amdgpu: new resource cursor")
CC Christian König <[email protected]>
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +0 -0
index 1335e098510f..b49a61d07d60 100644
@@ -68,7 +68,7 @@ static inline void amdgpu_res_first(struct
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h static inline void amdgpu_res_first(struct ttm_resource *res, · line 74

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +1 -1
 ttm_resource *res,
           start -= node++->size << PAGE_SHIFT;
         cur->start = (node->start << PAGE_SHIFT) + start;
-    cur->size = (node->size << PAGE_SHIFT) - start;
+    cur->size = min((node->size << PAGE_SHIFT) - start, size);
       cur->remaining = size;
       cur->node = node;
   }

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