Skip to contentSkip to conversation

drm/amdgpu: Remove kfd eviction fence before release bo

RFC PATCH Superseded xinhui pan 4 participants 5 messages Feb 18, 2020 – Feb 19, 2020

Subsystems (3)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

xinhui pan

author
#0 lore raw

RFC PATCH v5 1/1 drm/amdgpu: Remove kfd eviction fence before release bo

No need to trigger eviction as the memory mapping will not be used anymore.

All pt/pd bos share same resv, hence the same shared eviction fence. Everytime page table is freed, the fence will be signled and that cuases kfd unexcepted evictions.

CC Christian König <[email protected]>
CC Felix Kuehling <[email protected]>
CC Alex Deucher <[email protected]>

---
change from v4:
based on new ttm code.

change from v3:
fix a coding error

change from v2:
based on Chris' drm/ttm: rework BO delayed delete patchset.

---

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 37 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  4 ++
 3 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 9e8db702d878..0ee8aae6c519 100644
@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u64 context,
 						       struct mm_struct *mm);
 bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm);
 struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f);
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo);
 
 struct amdkfd_process_info {
 	/* List head of all VMs that belong to a KFD process */
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +37 -0
index ef721cb65868..6aa20aa82bd3 100644
@@ -276,6 +276,41 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
 	return 0;
 }
 
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo)
+{
+	struct amdgpu_bo *root = bo;
+	struct amdgpu_vm_bo_base *vm_bo;
+	struct amdgpu_vm *vm;
+	struct amdkfd_process_info *info;
+	struct amdgpu_amdkfd_fence *ef;
+	int ret;
+
+	while (root->parent)
+		root = root->parent;
+
+	vm_bo = root->vm_bo;
+	if (!vm_bo)
+		return 0;
+
+	vm = vm_bo->vm;
+	if (!vm)
+		return 0;
+
+	info = vm->process_info;
+	if (!info || !info->eviction_fence)
+		return 0;
+
+	ef = container_of(dma_fence_get(&info->eviction_fence->base),
+			struct amdgpu_amdkfd_fence, base);
+
+	dma_resv_lock(bo->tbo.base.resv, NULL);
+	ret = amdgpu_amdkfd_remove_eviction_fence(bo, ef);
+	dma_resv_unlock(bo->tbo.base.resv);
+
+	dma_fence_put(&ef->base);
+	return ret;
+}
+
 static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain,
 				     bool wait)
 {
@@ -1045,6 +1080,8 @@ void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
 	list_del(&vm->vm_list_node);
 	mutex_unlock(&process_info->lock);
 
+	vm->process_info = NULL;
+
 	/* Release per-process resources when last compute VM is destroyed */
 	if (!process_info->n_vms) {
 		WARN_ON(!list_empty(&process_info->kfd_bo_list));
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
index 6f60a581e3ba..16586651020f 100644
@@ -1307,6 +1307,10 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)
 	if (abo->kfd_bo)
 		amdgpu_amdkfd_unreserve_memory_limit(abo);
 
+	/* We only remove the fence if the resv has individualized. */
+	if (bo->base.resv == &bo->base._resv)
+		amdgpu_amdkfd_remove_fence_on_pt_pd_bos(abo);
+
 	if (bo->mem.mem_type != TTM_PL_VRAM || !bo->mem.mm_node ||
 	    !(abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE))
 		return;
Signature · 6 lines
2.17.1

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

Am 18.02.20 um 04:36 schrieb xinhui pan:

Quoted 11 lines

No need to trigger eviction as the memory mapping will not be used anymore.

All pt/pd bos share same resv, hence the same shared eviction fence. Everytime page table is freed, the fence will be signled and that cuases kfd unexcepted evictions.

CC Christian König <[email protected]>
CC Felix Kuehling <[email protected]>
CC Alex Deucher <[email protected]>
Quoted 89 lines

---
change from v4:
based on new ttm code.

change from v3:
fix a coding error

change from v2:
based on Chris' drm/ttm: rework BO delayed delete patchset.

---

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 37 +++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  4 ++
  3 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 9e8db702d878..0ee8aae6c519 100644
@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u64 context,
  						       struct mm_struct *mm);
  bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm);
  struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f);
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo);
 
  struct amdkfd_process_info {
  	/* List head of all VMs that belong to a KFD process */
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +37 -0
index ef721cb65868..6aa20aa82bd3 100644
@@ -276,6 +276,41 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
  	return 0;
  }
 
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo)
+{
+	struct amdgpu_bo *root = bo;
+	struct amdgpu_vm_bo_base *vm_bo;
+	struct amdgpu_vm *vm;
+	struct amdkfd_process_info *info;
+	struct amdgpu_amdkfd_fence *ef;
+	int ret;
+
+	while (root->parent)
+		root = root->parent;
+
+	vm_bo = root->vm_bo;
+	if (!vm_bo)
+		return 0;
+
+	vm = vm_bo->vm;
+	if (!vm)
+		return 0;
+
+	info = vm->process_info;
+	if (!info || !info->eviction_fence)
+		return 0;
+
+	ef = container_of(dma_fence_get(&info->eviction_fence->base),
+			struct amdgpu_amdkfd_fence, base);
+
+	dma_resv_lock(bo->tbo.base.resv, NULL);
+	ret = amdgpu_amdkfd_remove_eviction_fence(bo, ef);
+	dma_resv_unlock(bo->tbo.base.resv);
+
+	dma_fence_put(&ef->base);
+	return ret;
+}
+
  static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain,
  				     bool wait)
  {
@@ -1045,6 +1080,8 @@ void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
  	list_del(&vm->vm_list_node);
  	mutex_unlock(&process_info->lock);
 
+	vm->process_info = NULL;
+
  	/* Release per-process resources when last compute VM is destroyed */
  	if (!process_info->n_vms) {
  		WARN_ON(!list_empty(&process_info->kfd_bo_list));
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 6f60a581e3ba..16586651020f 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) · line 1316

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
@@ -1307,6 +1307,10 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)
  	if (abo->kfd_bo)
  		amdgpu_amdkfd_unreserve_memory_limit(abo);
 
+	/* We only remove the fence if the resv has individualized. */
+	if (bo->base.resv == &bo->base._resv)
+		amdgpu_amdkfd_remove_fence_on_pt_pd_bos(abo);
+
  	if (bo->mem.mem_type != TTM_PL_VRAM || !bo->mem.mm_node ||
  	    !(abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE))
  		return;

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

maintainer
#2 lore raw
In reply to xinhui pan

Hi Xinhui,

Two suggestions inline. Looks good to me otherwise.

Quoted 49 lines · xinhui pan

No need to trigger eviction as the memory mapping will not be used anymore.

All pt/pd bos share same resv, hence the same shared eviction fence. Everytime page table is freed, the fence will be signled and that cuases kfd unexcepted evictions.

CC Christian König <[email protected]>
CC Felix Kuehling <[email protected]>
CC Alex Deucher <[email protected]>

---
change from v4:
based on new ttm code.

change from v3:
fix a coding error

change from v2:
based on Chris' drm/ttm: rework BO delayed delete patchset.

---

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 37 +++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  4 ++
  3 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 9e8db702d878..0ee8aae6c519 100644
@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u64 context,
  						       struct mm_struct *mm);
  bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm);
  struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f);
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo);
 
  struct amdkfd_process_info {
  	/* List head of all VMs that belong to a KFD process */
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -0
index ef721cb65868..6aa20aa82bd3 100644
@@ -276,6 +276,41 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
  	return 0;
  }
 
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo)

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, · line 289

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +10 -0
+{
+	struct amdgpu_bo *root = bo;
+	struct amdgpu_vm_bo_base *vm_bo;
+	struct amdgpu_vm *vm;
+	struct amdkfd_process_info *info;
+	struct amdgpu_amdkfd_fence *ef;
+	int ret;
+
+	while (root->parent)
+		root = root->parent;

This should not be necessary. Every page table BO has a pointer to a vm_bo that has a pointer to the vm. So you don't need to find the root.

This should do the trick:

	if (!bo->vm_bo || !bo->vm_bo->vm)
		return 0;
	vm = bo->vm_bo->vm;
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +26 -0
+
+	vm_bo = root->vm_bo;
+	if (!vm_bo)
+		return 0;
+
+	vm = vm_bo->vm;
+	if (!vm)
+		return 0;
+
+	info = vm->process_info;
+	if (!info || !info->eviction_fence)
+		return 0;
+
+	ef = container_of(dma_fence_get(&info->eviction_fence->base),
+			struct amdgpu_amdkfd_fence, base);
+
+	dma_resv_lock(bo->tbo.base.resv, NULL);
+	ret = amdgpu_amdkfd_remove_eviction_fence(bo, ef);
+	dma_resv_unlock(bo->tbo.base.resv);
+
+	dma_fence_put(&ef->base);
+	return ret;
+}
+
  static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain,
  				     bool wait)
  {
@@ -1045,6 +1080,8 @@ void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
  	list_del(&vm->vm_list_node);
  	mutex_unlock(&process_info->lock);
 
+	vm->process_info = NULL;
+
  	/* Release per-process resources when last compute VM is destroyed */
  	if (!process_info->n_vms) {
  		WARN_ON(!list_empty(&process_info->kfd_bo_list));
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 6f60a581e3ba..16586651020f 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) · line 1311

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
@@ -1307,6 +1307,10 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)
  	if (abo->kfd_bo)
  		amdgpu_amdkfd_unreserve_memory_limit(abo);
 
+	/* We only remove the fence if the resv has individualized. */
+	if (bo->base.resv == &bo->base._resv)

Should this be a WARN_ON? We expect this condition to be always true. If it's not, there should be a noisy warning that something is wrong.

Regards,
  Felix

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) · line 1316

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
+		amdgpu_amdkfd_remove_fence_on_pt_pd_bos(abo);
+
  	if (bo->mem.mem_type != TTM_PL_VRAM || !bo->mem.mm_node ||
  	    !(abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE))
  		return;

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

#3 lore raw
Quoted 69 lines

2020年2月19日 07:10,Kuehling, Felix <[email protected]> 写道:

Hi Xinhui,

Two suggestions inline. Looks good to me otherwise.

Quoted 47 lines · xinhui pan

No need to trigger eviction as the memory mapping will not be used anymore.

All pt/pd bos share same resv, hence the same shared eviction fence. Everytime page table is freed, the fence will be signled and that cuases kfd unexcepted evictions.

CC Christian König <[email protected]>
CC Felix Kuehling <[email protected]>
CC Alex Deucher <[email protected]>

---
change from v4:
based on new ttm code.

change from v3:
fix a coding error

change from v2:
based on Chris' drm/ttm: rework BO delayed delete patchset.

---

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 37 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  4 ++
 3 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 9e8db702d878..0ee8aae6c519 100644
@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u64 context,
 						       struct mm_struct *mm);
 bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm);
 struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f);
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo);
   struct amdkfd_process_info {
 	/* List head of all VMs that belong to a KFD process */
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -0
index ef721cb65868..6aa20aa82bd3 100644
@@ -276,6 +276,41 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
 	return 0;
 }
 +int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo)

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, · line 288

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +10 -0
+{
+	struct amdgpu_bo *root = bo;
+	struct amdgpu_vm_bo_base *vm_bo;
+	struct amdgpu_vm *vm;
+	struct amdkfd_process_info *info;
+	struct amdgpu_amdkfd_fence *ef;
+	int ret;
+
+	while (root->parent)
+		root = root->parent;

This should not be necessary. Every page table BO has a pointer to a vm_bo that has a pointer to the vm. So you don't need to find the root.

Quoted 7 lines

This should do the trick:

	if (!bo->vm_bo || !bo->vm_bo->vm)
		return 0;
	vm = bo->vm_bo->vm;

well,when free page tables, it clears bo->vm_bo first then release pt/pd bo. Also we can change the sequence like I do in V2, looks like hit some weird issues.

Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +25 -0
+
+	vm_bo = root->vm_bo;
+	if (!vm_bo)
+		return 0;
+
+	vm = vm_bo->vm;
+	if (!vm)
+		return 0;
+
+	info = vm->process_info;
+	if (!info || !info->eviction_fence)
+		return 0;
+
+	ef = container_of(dma_fence_get(&info->eviction_fence->base),
+			struct amdgpu_amdkfd_fence, base);
+
+	dma_resv_lock(bo->tbo.base.resv, NULL);
+	ret = amdgpu_amdkfd_remove_eviction_fence(bo, ef);
+	dma_resv_unlock(bo->tbo.base.resv);
+
+	dma_fence_put(&ef->base);
+	return ret;
+}
+
 static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain,
 				     bool wait)
 {
@@ -1045,6 +1080,8 @@ void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
 	list_del(&vm->vm_list_node);
 	mutex_unlock(&process_info->lock);
 +	vm->process_info = NULL;
+
 	/* Release per-process resources when last compute VM is destroyed */
 	if (!process_info->n_vms) {
 		WARN_ON(!list_empty(&process_info->kfd_bo_list));
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -1
index 6f60a581e3ba..16586651020f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) · line 1310

Quoted 6 lines

+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -0
@@ -1307,6 +1307,10 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)
 	if (abo->kfd_bo)
 		amdgpu_amdkfd_unreserve_memory_limit(abo);
 +	/* We only remove the fence if the resv has individualized. */
+	if (bo->base.resv == &bo->base._resv)

Should this be a WARN_ON? We expect this condition to be always true. If it's not, there should be a noisy warning that something is wrong.

good point.

thanks
xinhui

Quoted 10 lines

Regards,
Felix

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) · line 1316

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
+		amdgpu_amdkfd_remove_fence_on_pt_pd_bos(abo);
+
 	if (bo->mem.mem_type != TTM_PL_VRAM || !bo->mem.mm_node ||
 	    !(abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE))
 		return;

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

maintainer
#4 lore raw

Am 19.02.20 um 02:54 schrieb Pan, Xinhui:

Quoted 86 lines
Quoted 67 lines

2020年2月19日 07:10,Kuehling, Felix <[email protected]> 写道:

Hi Xinhui,

Two suggestions inline. Looks good to me otherwise.

Quoted 47 lines · xinhui pan

No need to trigger eviction as the memory mapping will not be used anymore.

All pt/pd bos share same resv, hence the same shared eviction fence. Everytime page table is freed, the fence will be signled and that cuases kfd unexcepted evictions.

CC Christian König <[email protected]>
CC Felix Kuehling <[email protected]>
CC Alex Deucher <[email protected]>

---
change from v4:
based on new ttm code.

change from v3:
fix a coding error

change from v2:
based on Chris' drm/ttm: rework BO delayed delete patchset.

---

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 37 +++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  4 ++
  3 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 9e8db702d878..0ee8aae6c519 100644
@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u64 context,
  						       struct mm_struct *mm);
  bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm);
  struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f);
+int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo);
    struct amdkfd_process_info {
  	/* List head of all VMs that belong to a KFD process */
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -0
index ef721cb65868..6aa20aa82bd3 100644
@@ -276,6 +276,41 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
  	return 0;
  }
  +int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo)

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, · line 288

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +10 -0
+{
+	struct amdgpu_bo *root = bo;
+	struct amdgpu_vm_bo_base *vm_bo;
+	struct amdgpu_vm *vm;
+	struct amdkfd_process_info *info;
+	struct amdgpu_amdkfd_fence *ef;
+	int ret;
+
+	while (root->parent)
+		root = root->parent;

This should not be necessary. Every page table BO has a pointer to a vm_bo that has a pointer to the vm. So you don't need to find the root.

Quoted 7 lines

This should do the trick:

	if (!bo->vm_bo || !bo->vm_bo->vm)
		return 0;
	vm = bo->vm_bo->vm;

well,when free page tables, it clears bo->vm_bo first then release pt/pd bo. Also we can change the sequence like I do in V2, looks like hit some weird issues.

Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9 -0
+
+	vm_bo = root->vm_bo;
+	if (!vm_bo)
+		return 0;
+
+	vm = vm_bo->vm;
+	if (!vm)
+		return 0;
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, · line 306

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8 -0
+	info = vm->process_info;
+	if (!info || !info->eviction_fence)
+		return 0;
+
+	ef = container_of(dma_fence_get(&info->eviction_fence->base),
+			struct amdgpu_amdkfd_fence, base);
+
+	dma_resv_lock(bo->tbo.base.resv, NULL);

Now that Felix mentioned it this should be a dma_resv_trylock().

dma_resv_lock() can intentionally fail randomly for testing purposes, but trylock() will always succeed because we are the only one referencing the BO at the moment.

Regards,
Christian.

Quoted 37 lines
Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8 -0
+	ret = amdgpu_amdkfd_remove_eviction_fence(bo, ef);
+	dma_resv_unlock(bo->tbo.base.resv);
+
+	dma_fence_put(&ef->base);
+	return ret;
+}
+
  static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain,
  				     bool wait)
  {
@@ -1045,6 +1080,8 @@ void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
  	list_del(&vm->vm_list_node);
  	mutex_unlock(&process_info->lock);
  +	vm->process_info = NULL;
+
  	/* Release per-process resources when last compute VM is destroyed */
  	if (!process_info->n_vms) {
  		WARN_ON(!list_empty(&process_info->kfd_bo_list));
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 6f60a581e3ba..16586651020f 100644
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) · line 1310

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -0
@@ -1307,6 +1307,10 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)
  	if (abo->kfd_bo)
  		amdgpu_amdkfd_unreserve_memory_limit(abo);
  +	/* We only remove the fence if the resv has individualized. */
+	if (bo->base.resv == &bo->base._resv)

Should this be a WARN_ON? We expect this condition to be always true. If it's not, there should be a noisy warning that something is wrong.

good point.

thanks
xinhui

Quoted 4 lines

Regards,
Felix

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) · line 1316

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
+		amdgpu_amdkfd_remove_fence_on_pt_pd_bos(abo);
+
  	if (bo->mem.mem_type != TTM_PL_VRAM || !bo->mem.mm_node ||
  	    !(abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE))
  		return;

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