Skip to contentSkip to conversation

drm/amdkfd: handle duplicate BOs in reserve_bo_and_cond_vms

PATCH In review Alex Deucher 3 participants 8 messages May 31, 2024 – Jun 13, 2024

Subsystems (4)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdkfd: handle duplicate BOs in reserve_bo_and_cond_vms

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used. Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]  amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -1
index e4d4e55c08ad..0535b07987d9 100644
@@ -1188,7 +1188,8 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 	int ret;
 
 	ctx->sync = &mem->sync;
-	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
+	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT |
+		      DRM_EXEC_IGNORE_DUPLICATES, 0);
 	drm_exec_until_all_locked(&ctx->exec) {
 		ctx->n_vms = 0;
 		list_for_each_entry(entry, &mem->attachments, list) {
Signature · 1 line
2.45.1
maintainer
#1 lore raw
Quoted 29 lines · Alex Deucher

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used. Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]  amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30
Quoted 3 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

What kernel release(s) is this backport for?

thanks,

greg k-h

author maintainer
#2 lore raw

[Public]

Quoted 41 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Saturday, June 1, 2024 1:24 AM
To: Deucher, Alexander <[email protected]>
Cc: [email protected]; [email protected]; Yu, Lang <[email protected]>; Tomáš Trnka <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: handle duplicate BOs in reserve_bo_and_cond_vms

Quoted 3 lines · Alex Deucher

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where

KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used.

Quoted 5 lines

Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]
amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
> [   57.793923]  ? idr_get_next_ul+0xbe/0x100
> [   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
> [   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
> [   57.794141]  ? process_scheduled_works+0x29c/0x580
> [   57.794147]  process_scheduled_works+0x303/0x580
> [   57.794157]  ? __pfx_worker_thread+0x10/0x10
> [   57.794160]  worker_thread+0x1a2/0x370
> [   57.794165]  ? __pfx_worker_thread+0x10/0x10
> [   57.794167]  kthread+0x11b/0x150
> [   57.794172]  ? __pfx_kthread+0x10/0x10
> [   57.794177]  ret_from_fork+0x3d/0x60
> [   57.794181]  ? __pfx_kthread+0x10/0x10
> [   57.794184]  ret_from_fork_asm+0x1b/0x30
Quoted 8 lines
Quoted 6 lines

2a705f3e49d20b59cd9e5cc3061b2d92ebe1e5f0)

Quoted 3 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

What kernel release(s) is this backport for?

6.6.x and newer.

Thanks!

Alex

maintainer
#3 lore raw
Quoted 43 lines · Alexander

[Public]

Quoted 41 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Saturday, June 1, 2024 1:24 AM
To: Deucher, Alexander <[email protected]>
Cc: [email protected]; [email protected]; Yu, Lang <[email protected]>; Tomáš Trnka <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: handle duplicate BOs in reserve_bo_and_cond_vms

Quoted 3 lines · Alex Deucher

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where

KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used.

Quoted 5 lines

Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]
amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
> [   57.793923]  ? idr_get_next_ul+0xbe/0x100
> [   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
> [   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
> [   57.794141]  ? process_scheduled_works+0x29c/0x580
> [   57.794147]  process_scheduled_works+0x303/0x580
> [   57.794157]  ? __pfx_worker_thread+0x10/0x10
> [   57.794160]  worker_thread+0x1a2/0x370
> [   57.794165]  ? __pfx_worker_thread+0x10/0x10
> [   57.794167]  kthread+0x11b/0x150
> [   57.794172]  ? __pfx_kthread+0x10/0x10
> [   57.794177]  ret_from_fork+0x3d/0x60
> [   57.794181]  ? __pfx_kthread+0x10/0x10
> [   57.794184]  ret_from_fork_asm+0x1b/0x30
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

2a705f3e49d20b59cd9e5cc3061b2d92ebe1e5f0)

Quoted 3 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

What kernel release(s) is this backport for?

6.6.x and newer.

Does not apply to 6.6.y, sorry, how was this tested? Can you submit a patch that does work?

thanks,

greg k-h

Tested-by Reviewed-by Felix Kuehling
#4 lore raw
Quoted 59 lines · Greg KH
Quoted 58 lines · Alexander

[Public]

Quoted 55 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Saturday, June 1, 2024 1:24 AM
To: Deucher, Alexander <[email protected]>
Cc: [email protected]; [email protected]; Yu, Lang <[email protected]>;
Tomáš Trnka <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: handle duplicate BOs in reserve_bo_and_cond_vms

Quoted 3 lines · Alex Deucher

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where

KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used.

Quoted 5 lines

Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]

amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]

Quoted 14 lines
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30
Quoted 7 lines

2a705f3e49d20b59cd9e5cc3061b2d92ebe1e5f0)

Quoted 4 lines

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

What kernel release(s) is this backport for?

Quoted 8 lines
Quoted 1 line

6.6.x and newer.

Does not apply to 6.6.y, sorry, how was this tested? Can you submit a patch that does work?

thanks,

greg k-h

Sorry about that. 6.6 does not have commit 05d249352f1ae909230c230767ca8f4e9fdf8e7b "drm/exec: Pass in initial # of objects" which adds the trailing 0 argument. Just removing that zero makes the patch apply and work. Such a modified version is attached below.

Tested on 6.6.32 (version below), 6.8.12 and 6.9.3 (version sent by Alex above).

2T

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used. Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]  amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -0

drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 15c5a2533ba6..9115fc8c96ba 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -1
@@ -1135,7 +1135,8 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 	int ret;
 
 	ctx->sync = &mem->sync;
-	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
+	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT |
+		      DRM_EXEC_IGNORE_DUPLICATES);
 	drm_exec_until_all_locked(&ctx->exec) {
 		ctx->n_vms = 0;
 		list_for_each_entry(entry, &mem->attachments, list) {
Signature · 1 line
2.45.1
maintainer
#5 lore raw
Quoted 101 lines · Tomáš Trnka
Quoted 59 lines · Greg KH
Quoted 58 lines · Alexander

[Public]

Quoted 55 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Saturday, June 1, 2024 1:24 AM
To: Deucher, Alexander <[email protected]>
Cc: [email protected]; [email protected]; Yu, Lang <[email protected]>;
Tomáš Trnka <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: handle duplicate BOs in reserve_bo_and_cond_vms

Quoted 3 lines · Alex Deucher

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where

KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used.

Quoted 5 lines

Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]

amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]

Quoted 14 lines
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30
Quoted 7 lines

2a705f3e49d20b59cd9e5cc3061b2d92ebe1e5f0)

Quoted 4 lines

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

What kernel release(s) is this backport for?

Quoted 8 lines
Quoted 1 line

6.6.x and newer.

Does not apply to 6.6.y, sorry, how was this tested? Can you submit a patch that does work?

thanks,

greg k-h

Sorry about that. 6.6 does not have commit 05d249352f1ae909230c230767ca8f4e9fdf8e7b "drm/exec: Pass in initial # of objects" which adds the trailing 0 argument. Just removing that zero makes the patch apply and work. Such a modified version is attached below.

Tested on 6.6.32 (version below), 6.8.12 and 6.9.3 (version sent by Alex above).

2T

From: Lang Yu <[email protected]>

Observed on gfx8 ASIC where KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used. Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]  amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30
Quoted 7 lines

As you are modifying, and passing on, a patch, you need to also sign off on this.

Please submit this in a format that I can apply it in, not as something I need to hand-edit out of an email.

thanks,

greg k-h

#6 lore raw

PATCH 1/1 drm/amdkfd: handle duplicate BOs in reserve_bo_and_cond_vms

From: Lang Yu <[email protected]>

[ Upstream commit 2a705f3e49d20b59cd9e5cc3061b2d92ebe1e5f0 ]

Observed on gfx8 ASIC where KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used. Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]  amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30

[TT: trivially adjusted for 6.6 which does not have commit 05d249352f
(third argument to drm_exec_init removed)]

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -0

drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 15c5a2533ba6..9115fc8c96ba 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -1
@@ -1135,7 +1135,8 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 	int ret;
 
 	ctx->sync = &mem->sync;
-	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
+	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT |
+		      DRM_EXEC_IGNORE_DUPLICATES);
 	drm_exec_until_all_locked(&ctx->exec) {
 		ctx->n_vms = 0;
 		list_for_each_entry(entry, &mem->attachments, list) {
Signature · 1 line
2.45.1
maintainer
#7 lore raw
Quoted 31 lines · Tomáš Trnka

From: Lang Yu <[email protected]>

[ Upstream commit 2a705f3e49d20b59cd9e5cc3061b2d92ebe1e5f0 ]

Observed on gfx8 ASIC where KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM is used. Two attachments use the same VM, root PD would be locked twice.

[   57.910418] Call Trace:
[   57.793726]  ? reserve_bo_and_cond_vms+0x111/0x1c0 [amdgpu]
[   57.793820]  amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu+0x6c/0x1c0 [amdgpu]
[   57.793923]  ? idr_get_next_ul+0xbe/0x100
[   57.793933]  kfd_process_device_free_bos+0x7e/0xf0 [amdgpu]
[   57.794041]  kfd_process_wq_release+0x2ae/0x3c0 [amdgpu]
[   57.794141]  ? process_scheduled_works+0x29c/0x580
[   57.794147]  process_scheduled_works+0x303/0x580
[   57.794157]  ? __pfx_worker_thread+0x10/0x10
[   57.794160]  worker_thread+0x1a2/0x370
[   57.794165]  ? __pfx_worker_thread+0x10/0x10
[   57.794167]  kthread+0x11b/0x150
[   57.794172]  ? __pfx_kthread+0x10/0x10
[   57.794177]  ret_from_fork+0x3d/0x60
[   57.794181]  ? __pfx_kthread+0x10/0x10
[   57.794184]  ret_from_fork_asm+0x1b/0x30
Quoted 5 lines

[TT: trivially adjusted for 6.6 which does not have commit 05d249352f
(third argument to drm_exec_init removed)]

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Now queued up, thanks.

greg k-h