Skip to contentSkip to conversation

drm/amdgpu:put CSA unmap after sched_entity_fini

PATCH In review Monk Liu 2 participants 4 messages Jan 13, 2017 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Monk Liu

author
#0 lore raw

PATCH 1/1 drm/amdgpu:put CSA unmap after sched_entity_fini

otherwise CSA may unmapped before gpu_scheduler scheduling jobs and trigger VM fault on CSA address

Change-Id Ib2e25ededf89bca44c764477dd2f9127024ca78c
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 8 --------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 8 ++++++++
 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -8
index 45484c0..e13cdde 100644
@@ -694,14 +694,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 	amdgpu_uvd_free_handles(adev, file_priv);
 	amdgpu_vce_free_handles(adev, file_priv);
 
-	if (amdgpu_sriov_vf(adev)) {
-		/* TODO: how to handle reserve failure */
-		BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
-		amdgpu_vm_bo_rmv(adev, fpriv->vm.csa_bo_va);
-		fpriv->vm.csa_bo_va = NULL;
-		amdgpu_bo_unreserve(adev->virt.csa_obj);
-	}
-
 	amdgpu_vm_fini(adev, &fpriv->vm);
 
 	idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -0
index d05546e..94098bc 100644
@@ -1608,6 +1608,14 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 
 	amd_sched_entity_fini(vm->entity.sched, &vm->entity);
 
+	if (amdgpu_sriov_vf(adev)) {
+		/* TODO: how to handle reserve failure */
+		BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
+		amdgpu_vm_bo_rmv(adev, vm->csa_bo_va);
+		vm->csa_bo_va = NULL;
+		amdgpu_bo_unreserve(adev->virt.csa_obj);
+	}
+
 	if (!RB_EMPTY_ROOT(&vm->va)) {
 		dev_err(adev->dev, "still active bo inside vm\n");
 	}
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): 1484280664-22845-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 13.01.2017 um 05:11 schrieb Monk Liu:

Quoted 5 lines

otherwise CSA may unmapped before gpu_scheduler scheduling jobs and trigger VM fault on CSA address

Change-Id Ib2e25ededf89bca44c764477dd2f9127024ca78c

Did you really run into an issue because of that?

Calling amdgpu_vm_bo_rmv() shouldn't affect the page tables nor already submitted command submissions in any way.

Regards,
Christian.

Quoted 33 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 8 --------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 8 ++++++++
  2 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -8
index 45484c0..e13cdde 100644
@@ -694,14 +694,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
  	amdgpu_uvd_free_handles(adev, file_priv);
  	amdgpu_vce_free_handles(adev, file_priv);
 
-	if (amdgpu_sriov_vf(adev)) {
-		/* TODO: how to handle reserve failure */
-		BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
-		amdgpu_vm_bo_rmv(adev, fpriv->vm.csa_bo_va);
-		fpriv->vm.csa_bo_va = NULL;
-		amdgpu_bo_unreserve(adev->virt.csa_obj);
-	}
-
  	amdgpu_vm_fini(adev, &fpriv->vm);
 
  	idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
index d05546e..94098bc 100644
@@ -1608,6 +1608,14 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 
  	amd_sched_entity_fini(vm->entity.sched, &vm->entity);
 
+	if (amdgpu_sriov_vf(adev)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 1621

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -0
+		/* TODO: how to handle reserve failure */
+		BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
+		amdgpu_vm_bo_rmv(adev, vm->csa_bo_va);
+		vm->csa_bo_va = NULL;
+		amdgpu_bo_unreserve(adev->virt.csa_obj);
+	}
+
  	if (!RB_EMPTY_ROOT(&vm->va)) {
  		dev_err(adev->dev, "still active bo inside vm\n");
  	}

_______________________________________________
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): dadee34c-ca4c-6a2a-8053-4bfdeb1466c3-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

author
#4 lore raw

only with amdgpu_vm_bo_rmv() won't has such bug, but in another branch for sriov, we not only call vm_bo_rmv(), and we also set csa_addr to NULL after it, so the NULL address is inserted in RB, and when preemption occured, CP backup snapshot to NULL address.

although in staging-4.9 we didn't set csa_addr to NULL (because as you suggested we always use HARDCODE/MACRO for CSA address), but logically we'd better put CSA unmapping stuffs behind "sched_entity_fini", which is more reasonable ...

BR Monk

________________________________
发件人: amd-gfx <[email protected]> 代表 Christian König <[email protected]> 发送时间: 2017年1月13日 17:25:09
收件人: Liu, Monk; [email protected]
主题: Re: [PATCH] drm/amdgpu:put CSA unmap after sched_entity_fini

Am 13.01.2017 um 05:11 schrieb Monk Liu:

Quoted 5 lines

otherwise CSA may unmapped before gpu_scheduler scheduling jobs and trigger VM fault on CSA address

Change-Id Ib2e25ededf89bca44c764477dd2f9127024ca78c

Did you really run into an issue because of that?

Calling amdgpu_vm_bo_rmv() shouldn't affect the page tables nor already submitted command submissions in any way.

Regards,
Christian.

Quoted 33 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 8 --------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 8 ++++++++
  2 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -8
index 45484c0..e13cdde 100644
@@ -694,14 +694,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
       amdgpu_uvd_free_handles(adev, file_priv);
       amdgpu_vce_free_handles(adev, file_priv);
 
-     if (amdgpu_sriov_vf(adev)) {
-             /* TODO: how to handle reserve failure */
-             BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
-             amdgpu_vm_bo_rmv(adev, fpriv->vm.csa_bo_va);
-             fpriv->vm.csa_bo_va = NULL;
-             amdgpu_bo_unreserve(adev->virt.csa_obj);
-     }
-
       amdgpu_vm_fini(adev, &fpriv->vm);
 
       idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
index d05546e..94098bc 100644
@@ -1608,6 +1608,14 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 
       amd_sched_entity_fini(vm->entity.sched, &vm->entity);
 
+     if (amdgpu_sriov_vf(adev)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 1621

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -0
+             /* TODO: how to handle reserve failure */
+             BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
+             amdgpu_vm_bo_rmv(adev, vm->csa_bo_va);
+             vm->csa_bo_va = NULL;
+             amdgpu_bo_unreserve(adev->virt.csa_obj);
+     }
+
       if (!RB_EMPTY_ROOT(&vm->va)) {
               dev_err(adev->dev, "still active bo inside vm\n");
       }

_______________________________________________
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): BY2PR1201MB11102468908DDFD083C45B5384780-O28G1zQ8oGliQkyLPkmea2rFom/aUZj6nBOFsp37pqbUKgpGm//BTAC/[email protected]

#6 lore raw

Ah, in this case please separate the amdgpu_vm_bo_rmv() from setting csa_addr to NULL.

Cause amdgpu_vm_bo_rmv() should come before amdgpu_vm_fini() and that in turn should become before waiting for the scheduler so that the MM knows that the memory is about to be freed.

Regards,
Christian.

Am 13.01.2017 um 10:56 schrieb Liu, Monk:

Quoted 84 lines

only with amdgpu_vm_bo_rmv() won't has such bug, but in another branch for sriov, we not only call vm_bo_rmv(), and we also set csa_addr to NULL after it, so the NULL address is inserted in RB, and when preemption occured, CP backup snapshot to NULL address.

although in staging-4.9 we didn't set csa_addr to NULL (because as you suggested we always use HARDCODE/MACRO for CSA address), but logically we'd better put CSA unmapping stuffs behind "sched_entity_fini", which is more reasonable ...

BR Monk

------------------------------------------------------------------------
*发件人:* amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> 代表 Christian König <[email protected]> *发送时间:* 2017年1月13日 17:25:09
*收件人:* Liu, Monk; [email protected]
*主题:* Re: [PATCH] drm/amdgpu:put CSA unmap after sched_entity_fini
Am 13.01.2017 um 05:11 schrieb Monk Liu:

Quoted 5 lines

otherwise CSA may unmapped before gpu_scheduler scheduling jobs and trigger VM fault on CSA address

Change-Id Ib2e25ededf89bca44c764477dd2f9127024ca78c

Did you really run into an issue because of that?

Calling amdgpu_vm_bo_rmv() shouldn't affect the page tables nor already submitted command submissions in any way.

Regards,
Christian.

Review

Quoted 6 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 8 --------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 8 ++++++++
  2 files changed, 8 insertions(+), 8 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c void amdgpu_driver_postclose_kms(struct

Quoted 4 lines

index 45484c0..e13cdde 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -694,14 +694,6 @@ void amdgpu_driver_postclose_kms(struct 

drm_device *dev,

Review

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -8
       amdgpu_uvd_free_handles(adev, file_priv);
       amdgpu_vce_free_handles(adev, file_priv);
 
-     if (amdgpu_sriov_vf(adev)) {
-             /* TODO: how to handle reserve failure */
- BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
-             amdgpu_vm_bo_rmv(adev, fpriv->vm.csa_bo_va);
-             fpriv->vm.csa_bo_va = NULL;
- amdgpu_bo_unreserve(adev->virt.csa_obj);
-     }
-
       amdgpu_vm_fini(adev, &fpriv->vm);
 
 idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

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

Quoted 4 lines

index d05546e..94098bc 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -1608,6 +1608,14 @@ void amdgpu_vm_fini(struct amdgpu_device 

*adev, struct amdgpu_vm *vm)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
       amd_sched_entity_fini(vm->entity.sched, &vm->entity);
 
+     if (amdgpu_sriov_vf(adev)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 1621

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -0
+             /* TODO: how to handle reserve failure */
+ BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, false));
+             amdgpu_vm_bo_rmv(adev, vm->csa_bo_va);
+             vm->csa_bo_va = NULL;
+ amdgpu_bo_unreserve(adev->virt.csa_obj);
+     }
+
       if (!RB_EMPTY_ROOT(&vm->va)) {
               dev_err(adev->dev, "still active bo inside vm\n");
       }

_______________________________________________
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