Skip to contentSkip to conversation

drm/amdgpu/userq: reserve the VM root BO around CWSR param validation

PATCH Superseded James Zhu 3 participants 6 messages Sep 18 – Sep 21

Subsystems (2)
lore
Share & tools
lore

James Zhu

author
#0 lore raw

PATCH 1/1 drm/amdgpu/userq: reserve the VM root BO around CWSR param validation

amdgpu_userq_input_trap_params_validate() ends up in amdgpu_userq_input_va_validate(), which walks the VM mapping tree and updates bo_va->userq_va_mapped, so it requires the caller to hold the vm->root.bo reservation. The CWSR branch of mes_userq_mqd_create() called it without that reservation, tripping the dma_resv_assert_held() on every compute queue creation when trap handling is enabled:

 WARNING: drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:232 at
 amdgpu_userq_input_va_validate+0xb9/0xd0 [amdgpu]
 Call Trace:
  mes_userq_mqd_create+0x49c/0x9e0 [amdgpu]
  amdgpu_userq_ioctl+0x935/0x1070 [amdgpu]
  drm_ioctl_kernel+0xb3/0x110 [drm]

Bracket the call with amdgpu_bo_reserve()/amdgpu_bo_unreserve() like the other input VA validations in the same function.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +7 -0
index 2150973b947d..16aa22b25098 100644
@@ -508,7 +508,14 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 			trap_params.ctx_save_area_address =
 				compute_mqd->ctx_save_area_va;
 			trap_params.cwsr_sz = compute_mqd->ctx_save_area_size;
+
+			r = amdgpu_bo_reserve(queue->vm->root.bo, false);
+			if (r) {
+				kfree(compute_mqd);
+				goto free_mqd;
+			}
 			r = amdgpu_userq_input_trap_params_validate(queue, &trap_params);
+			amdgpu_bo_unreserve(queue->vm->root.bo);
 			if (r) {
 				kfree(compute_mqd);
 				goto free_mqd;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · James Zhu

amdgpu_userq_input_trap_params_validate() ends up in amdgpu_userq_input_va_validate(), which walks the VM mapping tree and updates bo_va->userq_va_mapped, so it requires the caller to hold the vm->root.bo reservation. The CWSR branch of mes_userq_mqd_create() called it without that reservation, tripping the dma_resv_assert_held() on every compute queue creation when trap handling is enabled:

  WARNING: drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:232 at
  amdgpu_userq_input_va_validate+0xb9/0xd0 [amdgpu]
  Call Trace:
   mes_userq_mqd_create+0x49c/0x9e0 [amdgpu]
   amdgpu_userq_ioctl+0x935/0x1070 [amdgpu]
   drm_ioctl_kernel+0xb3/0x110 [drm]

Bracket the call with amdgpu_bo_reserve()/amdgpu_bo_unreserve() like the other input VA validations in the same function.

---
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
index 2150973b947d..16aa22b25098 100644
@@ -508,7 +508,14 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
  			trap_params.ctx_save_area_address =
  				compute_mqd->ctx_save_area_va;
  			trap_params.cwsr_sz = compute_mqd->ctx_save_area_size;
+

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, · line 521

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +6 -0
+			r = amdgpu_bo_reserve(queue->vm->root.bo, false);
+			if (r) {
+				kfree(compute_mqd);
+				goto free_mqd;
+			}
  			r = amdgpu_userq_input_trap_params_validate(queue, &trap_params);
+			amdgpu_bo_unreserve(queue->vm->root.bo);
  			if (r) {
  				kfree(compute_mqd);
  				goto free_mqd;

The CWSR VA validation accesses shared VM mapping information, so the VM root BO needs to be reserved while doing this. This change adds the missing reservation and avoids the warning during compute queue creation.

Could we also add the corresponding |Fixes:| tag?

|Fixes: 7ca9abf4ac38 ("drm/amdgpu: Add user save area params to mqd input")|

Separately, the repeated |vm->root.bo| reserve/unreserve operations in |mes_userq_mqd_create()| could be considered for a follow-up cleanup.

#2 lore raw
Quoted 46 lines · SRINIVASAN SHANMUGAM
Quoted 31 lines · James Zhu

amdgpu_userq_input_trap_params_validate() ends up in amdgpu_userq_input_va_validate(), which walks the VM mapping tree and updates bo_va->userq_va_mapped, so it requires the caller to hold the vm->root.bo reservation. The CWSR branch of mes_userq_mqd_create() called it without that reservation, tripping the dma_resv_assert_held() on every compute queue creation when trap handling is enabled:

  WARNING: drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:232 at
  amdgpu_userq_input_va_validate+0xb9/0xd0 [amdgpu]
  Call Trace:
   mes_userq_mqd_create+0x49c/0x9e0 [amdgpu]
   amdgpu_userq_ioctl+0x935/0x1070 [amdgpu]
   drm_ioctl_kernel+0xb3/0x110 [drm]

Bracket the call with amdgpu_bo_reserve()/amdgpu_bo_unreserve() like the other input VA validations in the same function.

---
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
index 2150973b947d..16aa22b25098 100644
@@ -508,7 +508,14 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
  			trap_params.ctx_save_area_address =
  				compute_mqd->ctx_save_area_va;
  			trap_params.cwsr_sz = compute_mqd->ctx_save_area_size;
+

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, · line 521

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +6 -0
+			r = amdgpu_bo_reserve(queue->vm->root.bo, false);
+			if (r) {
+				kfree(compute_mqd);
+				goto free_mqd;
+			}
  			r = amdgpu_userq_input_trap_params_validate(queue, &trap_params);
+			amdgpu_bo_unreserve(queue->vm->root.bo);
  			if (r) {
  				kfree(compute_mqd);
  				goto free_mqd;

The CWSR VA validation accesses shared VM mapping information, so the VM root BO needs to be reserved while doing this. This change adds the missing reservation and avoids the warning during compute queue creation.

Quoted 3 lines

Could we also add the corresponding |Fixes:| tag?

|Fixes: 7ca9abf4ac38 ("drm/amdgpu: Add user save area params to mqd input")|

That change happened later
85653fe2e52e drm/amdgpu/userq: hold root bo lock in caller of
input_va_validate

But the user save area patch was not available in drm-next that time and probably that's how it missed.

Thanks,
Lijo

Quoted 5 lines

Separately, the repeated |vm->root.bo| reserve/unreserve operations in | mes_userq_mqd_create()| could be considered for a follow-up cleanup.

author
#3 lore raw

PATCH v2 1/1 drm/amdgpu/userq: reserve the VM root BO around CWSR param validation

In reply to James Zhu

amdgpu_userq_input_trap_params_validate() ends up in amdgpu_userq_input_va_validate(), which walks the VM mapping tree and updates bo_va->userq_va_mapped, so it requires the caller to hold the vm->root.bo reservation. The CWSR branch of mes_userq_mqd_create() called it without that reservation, tripping the dma_resv_assert_held() on every compute queue creation when trap handling is enabled:

 WARNING: drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:232 at
 amdgpu_userq_input_va_validate+0xb9/0xd0 [amdgpu]
 Call Trace:
  mes_userq_mqd_create+0x49c/0x9e0 [amdgpu]
  amdgpu_userq_ioctl+0x935/0x1070 [amdgpu]
  drm_ioctl_kernel+0xb3/0x110 [drm]

Bracket the call with amdgpu_bo_reserve()/amdgpu_bo_unreserve() like the other input VA validations in the same function.

Fixes 7ca9abf4ac38 ("drm/amdgpu: Add user save area params to mqd input")

-v2: add Fixes tag

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +7 -0
index 2150973b947d..16aa22b25098 100644
@@ -508,7 +508,14 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 			trap_params.ctx_save_area_address =
 				compute_mqd->ctx_save_area_va;
 			trap_params.cwsr_sz = compute_mqd->ctx_save_area_size;
+
+			r = amdgpu_bo_reserve(queue->vm->root.bo, false);
+			if (r) {
+				kfree(compute_mqd);
+				goto free_mqd;
+			}
 			r = amdgpu_userq_input_trap_params_validate(queue, &trap_params);
+			amdgpu_bo_unreserve(queue->vm->root.bo);
 			if (r) {
 				kfree(compute_mqd);
 				goto free_mqd;
Signature · 1 line
2.34.1
#4 lore raw
Quoted 14 lines · James Zhu

amdgpu_userq_input_trap_params_validate() ends up in amdgpu_userq_input_va_validate(), which walks the VM mapping tree and updates bo_va->userq_va_mapped, so it requires the caller to hold the vm->root.bo reservation. The CWSR branch of mes_userq_mqd_create() called it without that reservation, tripping the dma_resv_assert_held() on every compute queue creation when trap handling is enabled:

  WARNING: drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:232 at
  amdgpu_userq_input_va_validate+0xb9/0xd0 [amdgpu]
  Call Trace:
   mes_userq_mqd_create+0x49c/0x9e0 [amdgpu]
   amdgpu_userq_ioctl+0x935/0x1070 [amdgpu]
   drm_ioctl_kernel+0xb3/0x110 [drm]
Quoted 5 lines

Bracket the call with amdgpu_bo_reserve()/amdgpu_bo_unreserve() like the other input VA validations in the same function.

Fixes 7ca9abf4ac38 ("drm/amdgpu: Add user save area params to mqd input")

Hi Alex/Srini,

Which branch are these patches based on? I don't see any cwsr patch upstream yet, probably that makes Fixes irrelevant.

Thanks,
Lijo

Quoted 27 lines

-v2: add Fixes tag

---
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +7 -0
index 2150973b947d..16aa22b25098 100644
@@ -508,7 +508,14 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
  			trap_params.ctx_save_area_address =
  				compute_mqd->ctx_save_area_va;
  			trap_params.cwsr_sz = compute_mqd->ctx_save_area_size;
+
+			r = amdgpu_bo_reserve(queue->vm->root.bo, false);
+			if (r) {
+				kfree(compute_mqd);
+				goto free_mqd;
+			}
  			r = amdgpu_userq_input_trap_params_validate(queue, &trap_params);
+			amdgpu_bo_unreserve(queue->vm->root.bo);
  			if (r) {
  				kfree(compute_mqd);
  				goto free_mqd;
#5 lore raw
Quoted 20 lines · Lijo
Quoted 17 lines · James Zhu

amdgpu_userq_input_trap_params_validate() ends up in amdgpu_userq_input_va_validate(), which walks the VM mapping tree and updates bo_va->userq_va_mapped, so it requires the caller to hold the vm->root.bo reservation. The CWSR branch of mes_userq_mqd_create() called it without that reservation, tripping the dma_resv_assert_held() on every compute queue creation when trap handling is enabled:

  WARNING: drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:232 at
  amdgpu_userq_input_va_validate+0xb9/0xd0 [amdgpu]
  Call Trace:
   mes_userq_mqd_create+0x49c/0x9e0 [amdgpu]
   amdgpu_userq_ioctl+0x935/0x1070 [amdgpu]
   drm_ioctl_kernel+0xb3/0x110 [drm]

Bracket the call with amdgpu_bo_reserve()/amdgpu_bo_unreserve() like the other input VA validations in the same function.

Quoted 6 lines
Quoted 2 lines
Fixes 7ca9abf4ac38 ("drm/amdgpu: Add user save area params to mqd input")

Hi Alex/Srini,

Which branch are these patches based on? I don't see any cwsr patch upstream yet, probably that makes Fixes irrelevant.

These patches are based on |<exact-branch-name>| from the unified-interface tree, not upstream drm-next. The CWSR/userq changes are already present in that branch.

Thanks, Srini