Skip to contentSkip to conversation

drm/amdgpu: implicitly sync the dependent read fences

PATCH Superseded Prike Liang 3 participants 14 messages Apr 25, 2025 – Apr 29, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/amdgpu: implicitly sync the dependent read fences

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP usage fences, so here only return and sync the dependent read fences.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2 -3
index 5576ed0b508f..4e1d30ecb6cc 100644
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
 
 	if (resv == NULL)
 		return -EINVAL;
-
-	/* TODO: Use DMA_RESV_USAGE_READ here */
-	dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_BOOKKEEP, f) {
+	/*Only return and sync the fences of usage <= DMA_RESV_USAGE_READ.*/
+	dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f) {
 		dma_fence_chain_for_each(f, f) {
 			struct dma_fence *tmp = dma_fence_chain_contained(f);
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 drm/amdgpu: fix the eviction fence dereference

The dma_resv_add_fence() already refers to the added fence. So when attaching the evciton fence to the gem bo, it needn't refer to it anymore.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2 -5
index 610f447ede9b..d2271c10498d 100644
@@ -189,7 +189,6 @@ void amdgpu_eviction_fence_destroy(struct amdgpu_eviction_fence_mgr *evf_mgr)
 int amdgpu_eviction_fence_attach(struct amdgpu_eviction_fence_mgr *evf_mgr,
 				 struct amdgpu_bo *bo)
 {
-	struct dma_fence *ef;
 	struct amdgpu_eviction_fence *ev_fence;
 	struct dma_resv *resv = bo->tbo.base.resv;
 	int ret;
@@ -205,10 +204,8 @@ int amdgpu_eviction_fence_attach(struct amdgpu_eviction_fence_mgr *evf_mgr,
 
 	spin_lock(&evf_mgr->ev_fence_lock);
 	ev_fence = evf_mgr->ev_fence;
-	if (ev_fence) {
-		ef = dma_fence_get(&ev_fence->base);
-		dma_resv_add_fence(resv, ef, DMA_RESV_USAGE_BOOKKEEP);
-	}
+	if (ev_fence)
+		dma_resv_add_fence(resv, &ev_fence->base, DMA_RESV_USAGE_BOOKKEEP);
 	spin_unlock(&evf_mgr->ev_fence_lock);
 
 	return 0;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] drm/amdgpu: fix the eviction fence dereference

Quoted 5 lines · Prike Liang

The dma_resv_add_fence() already refers to the added fence. So when attaching the evciton fence to the gem bo, it needn't refer to it anymore.

Quoted 29 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2 -5
index 610f447ede9b..d2271c10498d 100644
@@ -189,7 +189,6 @@ void amdgpu_eviction_fence_destroy(struct amdgpu_eviction_fence_mgr *evf_mgr)
 int amdgpu_eviction_fence_attach(struct amdgpu_eviction_fence_mgr *evf_mgr,
 				 struct amdgpu_bo *bo)
 {
-	struct dma_fence *ef;
 	struct amdgpu_eviction_fence *ev_fence;
 	struct dma_resv *resv = bo->tbo.base.resv;
 	int ret;
@@ -205,10 +204,8 @@ int amdgpu_eviction_fence_attach(struct amdgpu_eviction_fence_mgr *evf_mgr,
 
 	spin_lock(&evf_mgr->ev_fence_lock);
 	ev_fence = evf_mgr->ev_fence;
-	if (ev_fence) {
-		ef = dma_fence_get(&ev_fence->base);
-		dma_resv_add_fence(resv, ef, DMA_RESV_USAGE_BOOKKEEP);
-	}
+	if (ev_fence)
+		dma_resv_add_fence(resv, &ev_fence->base, DMA_RESV_USAGE_BOOKKEEP);
 	spin_unlock(&evf_mgr->ev_fence_lock);
 
 	return 0;
#3 lore raw

PATCH 3/3 drm/amdgpu: validate the eviction fence attach/detach

In reply to Prike Liang

Before the user queue BOs resume workqueue is scheduled; there's no valid eviction fence to attach the gem obj. For this case, it doesn't need to attach/detach the eviction fence. Also, it needs to unlock the bo first before returning from the eviction fence attached error.

---
 .../gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c   |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          | 16 ++++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +3 -0
index d2271c10498d..375f15b6fd58 100644
@@ -216,6 +216,9 @@ void amdgpu_eviction_fence_detach(struct amdgpu_eviction_fence_mgr *evf_mgr,
 {
 	struct dma_fence *stub = dma_fence_get_stub();
 
+	if (dma_fence_is_signaled(&evf_mgr->ev_fence->base))
+		return;
+
 	dma_resv_replace_fences(bo->tbo.base.resv, evf_mgr->ev_fence_ctx,
 				stub, DMA_RESV_USAGE_BOOKKEEP);
 	dma_fence_put(stub);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10 -6
index c1d8cee7894b..04256de4bee9 100644
@@ -292,11 +292,14 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
 	else
 		++bo_va->ref_count;
 
-	/* attach gfx eviction fence */
-	r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);
-	if (r) {
-		DRM_DEBUG_DRIVER("Failed to attach eviction fence to BO\n");
-		return r;
+	/* attach gfx the validated eviction fence */
+	if (!IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence)) {
+		r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);
+		if (r) {
+			DRM_DEBUG_DRIVER("Failed to attach eviction fence to BO\n");
+			amdgpu_bo_unreserve(abo);
+			return r;
+		}
 	}
 
 	amdgpu_bo_unreserve(abo);
@@ -362,7 +365,8 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
 			goto out_unlock;
 	}
 
-	if (!amdgpu_vm_is_bo_always_valid(vm, bo))
+	if (!amdgpu_vm_is_bo_always_valid(vm, bo) &&
+			!IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence))
 		amdgpu_eviction_fence_detach(&fpriv->evf_mgr, bo);
 
 	bo_va = amdgpu_vm_bo_find(vm, bo);
Signature · 1 line
2.34.1
maintainer
#4 lore raw

Re: [PATCH 3/3] drm/amdgpu: validate the eviction fence attach/detach

Quoted 17 lines · Prike Liang

Before the user queue BOs resume workqueue is scheduled; there's no valid eviction fence to attach the gem obj. For this case, it doesn't need to attach/detach the eviction fence. Also, it needs to unlock the bo first before returning from the eviction fence attached error.

---
 .../gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c   |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          | 16 ++++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0 -0
index d2271c10498d..375f15b6fd58 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c void amdgpu_eviction_fence_detach(struct amdgpu_eviction_fence_mgr *evf_mgr, · line 221

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +3 -0
@@ -216,6 +216,9 @@ void amdgpu_eviction_fence_detach(struct amdgpu_eviction_fence_mgr *evf_mgr,
 {
 	struct dma_fence *stub = dma_fence_get_stub();
 
+	if (dma_fence_is_signaled(&evf_mgr->ev_fence->base))
+		return;
+

Clear NAK, that is racy. You can only access evf_mgr->ev_fence while holding the spinlock to make sure that it isn't replaced.

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj, · line 296

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0 -0
 	dma_resv_replace_fences(bo->tbo.base.resv, evf_mgr->ev_fence_ctx,
 				stub, DMA_RESV_USAGE_BOOKKEEP);
 	dma_fence_put(stub);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -2
index c1d8cee7894b..04256de4bee9 100644
@@ -292,11 +292,14 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
 	else
 		++bo_va->ref_count;
 
-	/* attach gfx eviction fence */
-	r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);

That here is buggy, fpriv->evf_mgr can only be accessed while holding the spinlock.

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj, · line 296

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -3
-	if (r) {
-		DRM_DEBUG_DRIVER("Failed to attach eviction fence to BO\n");
-		return r;
+	/* attach gfx the validated eviction fence */
+	if (!IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence)) {

Please don't use ERR_PTR functions on members.

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj, · line 302

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6 -0
+		r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);
+		if (r) {
+			DRM_DEBUG_DRIVER("Failed to attach eviction fence to BO\n");
+			amdgpu_bo_unreserve(abo);
+			return r;
+		}

We should always have a stub fence in fpriv->evf_mgr.ev_fence, so those checks are unnecessary.

Regards,
Christian.

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
 	}
 
 	amdgpu_bo_unreserve(abo);
@@ -362,7 +365,8 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
 			goto out_unlock;
 	}
 
-	if (!amdgpu_vm_is_bo_always_valid(vm, bo))
+	if (!amdgpu_vm_is_bo_always_valid(vm, bo) &&
+			!IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence))
 		amdgpu_eviction_fence_detach(&fpriv->evf_mgr, bo);
 
 	bo_va = amdgpu_vm_bo_find(vm, bo);
#5 lore raw

RE: [PATCH 3/3] drm/amdgpu: validate the eviction fence attach/detach

[Public]

Quoted 65 lines

From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 29, 2025 1:52 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdgpu: validate the eviction fence attach/detach

Quoted 18 lines · Prike Liang

Before the user queue BOs resume workqueue is scheduled; there's no valid eviction fence to attach the gem obj.
For this case, it doesn't need to attach/detach the eviction fence. Also, it needs to unlock the bo first before returning from the eviction fence attached error.

---
 .../gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c   |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          | 16 ++++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0 -0
index d2271c10498d..375f15b6fd58 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c void amdgpu_eviction_fence_detach(struct · line 221

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +3 -0
@@ -216,6 +216,9 @@ void amdgpu_eviction_fence_detach(struct
 amdgpu_eviction_fence_mgr *evf_mgr,  {
    struct dma_fence *stub = dma_fence_get_stub();
 
+   if (dma_fence_is_signaled(&evf_mgr->ev_fence->base))
+           return;
+

Clear NAK, that is racy. You can only access evf_mgr->ev_fence while holding the spinlock to make sure that it isn't replaced.

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0 -0
    dma_resv_replace_fences(bo->tbo.base.resv, evf_mgr->ev_fence_ctx,
                            stub, DMA_RESV_USAGE_BOOKKEEP);
    dma_fence_put(stub);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
index c1d8cee7894b..04256de4bee9 100644
@@ -292,11 +292,14 @@ static int amdgpu_gem_object_open(struct

drm_gem_object *obj,

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj, · line 296

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -2
    else
            ++bo_va->ref_count;
 
-   /* attach gfx eviction fence */
-   r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);

That here is buggy, fpriv->evf_mgr can only be accessed while holding the spinlock.

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj, · line 296

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -3
-   if (r) {
-           DRM_DEBUG_DRIVER("Failed to attach eviction fence to BO\n");
-           return r;
+   /* attach gfx the validated eviction fence */
+   if (!IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence)) {

Please don't use ERR_PTR functions on members.

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -0
+           r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);
+           if (r) {
+                   DRM_DEBUG_DRIVER("Failed to attach eviction fence to
Quoted 7 lines

BO\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj, · line 302

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -0
+                   amdgpu_bo_unreserve(abo);
+                   return r;
+           }

We should always have a stub fence in fpriv->evf_mgr.ev_fence, so those checks are unnecessary.

I checked that when enabling the kq and uq at the same time, and before schedule any user queue task then the eviction fence is NULL. Based on the current design, the eviction fence only be created at the user queue BOs restored time.

Quoted 17 lines

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static void amdgpu_gem_object_close(struct

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
    }
 
    amdgpu_bo_unreserve(abo);
@@ -362,7 +365,8 @@ static void amdgpu_gem_object_close(struct

drm_gem_object *obj,

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
                    goto out_unlock;
    }
 
-   if (!amdgpu_vm_is_bo_always_valid(vm, bo))
+   if (!amdgpu_vm_is_bo_always_valid(vm, bo) &&
+                   !IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence))
            amdgpu_eviction_fence_detach(&fpriv->evf_mgr, bo);
 
    bo_va = amdgpu_vm_bo_find(vm, bo);
maintainer
#6 lore raw

Re: [PATCH 3/3] drm/amdgpu: validate the eviction fence attach/detach

Quoted 7 lines · Prike
Quoted 7 lines
Quoted 1 line

+ if (!IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence)) {

Please don't use ERR_PTR functions on members.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -0
+           r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);
+           if (r) {
+                   DRM_DEBUG_DRIVER("Failed to attach eviction fence to
Quoted 8 lines
Quoted 7 lines

BO\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static int amdgpu_gem_object_open(struct drm_gem_object *obj, · line 302

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -0
+                   amdgpu_bo_unreserve(abo);
+                   return r;
+           }

We should always have a stub fence in fpriv->evf_mgr.ev_fence, so those checks are unnecessary.

I checked that when enabling the kq and uq at the same time, and before schedule any user queue task then the eviction fence is NULL.

Yeah, but that case is handled by amdgpu_eviction_fence_attach() and *NOT* here.

You are completely messing up the logic with that stuff here.

Regards,
Christian.

Quoted 20 lines

Based on the current design, the eviction fence only be created at the user queue BOs restored time.

Quoted 17 lines

Regards,
Christian.

Review static void amdgpu_gem_object_close(struct

Quoted 4 lines
    }

    amdgpu_bo_unreserve(abo);
(quoted diff) +0 -0
@@ -362,7 +365,8 @@ static void amdgpu_gem_object_close(struct

drm_gem_object *obj,

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
                    goto out_unlock;
    }
 
-   if (!amdgpu_vm_is_bo_always_valid(vm, bo))
+   if (!amdgpu_vm_is_bo_always_valid(vm, bo) &&
+                   !IS_ERR_OR_NULL(fpriv->evf_mgr.ev_fence))
            amdgpu_eviction_fence_detach(&fpriv->evf_mgr, bo);
 
    bo_va = amdgpu_vm_bo_find(vm, bo);
#7 lore raw
In reply to Prike Liang

[Public]

Will send a new patch for updating the patch subject.

Regards,
Prike

Quoted 38 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Friday, April 25, 2025 3:07 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP usage fences, so here only return and sync the dependent read fences.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -3
index 5576ed0b508f..4e1d30ecb6cc 100644
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
 struct amdgpu_sync *sync,
 
      if (resv == NULL)
              return -EINVAL;
-
-     /* TODO: Use DMA_RESV_USAGE_READ here */
-     dma_resv_for_each_fence(&cursor, resv,
 DMA_RESV_USAGE_BOOKKEEP, f) {
+     /*Only return and sync the fences of usage <=

DMA_RESV_USAGE_READ.*/

+     dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f) {
              dma_fence_chain_for_each(f, f) {
                      struct dma_fence *tmp = dma_fence_chain_contained(f);

--
2.34.1

#8 lore raw
In reply to Prike Liang

This is problem for TLB flush. We should not do this changes. Here we are utilizing DMA_RESV_USAGE_BOOKKEEP due to the TLB flush fence associated with the page table (PT). We are ensuring that no page directory (PD) or page table (PT) should be free before flush and ttm bo release and delete both are also waiting for BOOKKEEP fence. Please drop this changes for eviction fence.

Regards,
~arvind

Quoted 25 lines · Prike Liang

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP usage fences, so here only return and sync the dependent read fences.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2 -3
index 5576ed0b508f..4e1d30ecb6cc 100644
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
 
  	if (resv == NULL)
  		return -EINVAL;
-
-	/* TODO: Use DMA_RESV_USAGE_READ here */
-	dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_BOOKKEEP, f) {
+	/*Only return and sync the fences of usage <= DMA_RESV_USAGE_READ.*/
+	dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f) {
  		dma_fence_chain_for_each(f, f) {
  			struct dma_fence *tmp = dma_fence_chain_contained(f);
 
#9 lore raw

[Public]

Quoted 7 lines

From: Yadav, Arvind <[email protected]>
Sent: Friday, April 25, 2025 3:21 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 5 lines

This is problem for TLB flush. We should not do this changes. Here we are utilizing DMA_RESV_USAGE_BOOKKEEP due to the TLB flush fence associated with the page table (PT). We are ensuring that no page directory (PD) or page table (PT) should be free before flush and ttm bo release and delete both are also waiting for BOOKKEEP fence. Please drop this changes for eviction fence.

Thanks for sharing the background. So, we may need to test the fence whether is an eviction fence in amdgpu_sync_test_fence () before added it to the VM sync.

Thanks,
Prike

Quoted 32 lines

Regards,
~arvind

Quoted 14 lines · Prike Liang

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP usage fences, so here only return and sync the dependent read fences.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
index 5576ed0b508f..4e1d30ecb6cc 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device *adev, · line 255

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -3
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
 struct amdgpu_sync *sync,
 
    if (resv == NULL)
            return -EINVAL;
-
-   /* TODO: Use DMA_RESV_USAGE_READ here */
-   dma_resv_for_each_fence(&cursor, resv,

DMA_RESV_USAGE_BOOKKEEP, f) {

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device *adev, · line 253

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+   /*Only return and sync the fences of usage <=

DMA_RESV_USAGE_READ.*/

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+   dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f) {
            dma_fence_chain_for_each(f, f) {
                    struct dma_fence *tmp = dma_fence_chain_contained(f);
#10 lore raw

[Public]

Quoted 15 lines

From: Liang, Prike
Sent: Friday, April 25, 2025 3:44 PM
To: Yadav, Arvind <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 8 lines

From: Yadav, Arvind <[email protected]>
Sent: Friday, April 25, 2025 3:21 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 8 lines
Quoted 5 lines

This is problem for TLB flush. We should not do this changes. Here we are utilizing DMA_RESV_USAGE_BOOKKEEP due to the TLB flush fence associated with the page table (PT). We are ensuring that no page directory (PD) or page table (PT) should be free before flush and ttm bo release and delete both are also waiting for BOOKKEEP fence. Please drop

this changes for eviction fence.
Thanks for sharing the background. So, we may need to test the fence whether is an eviction fence in amdgpu_sync_test_fence () before added it to the VM sync.

It looks the TLB flush fence only added to the VM BO reservation and requires a sync at compute VM. As to the VM reservation sync whether can return and sync to the DMA_RESV_USAGE_READ, and I will further check it separately with the eviction fence release. As to the eviction fence sync problem issue, I would like to put exclude the eviction fence sync at amdgpu_sync_test_fence().

Thanks,
Prike

Quoted 35 lines

Thanks,
Prike

Quoted 5 lines

Regards,
~arvind

Quoted 1 line · Prike Liang

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP

usage

Quoted 27 lines
Quoted 13 lines

fences, so here only return and sync the dependent read fences.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
index 5576ed0b508f..4e1d30ecb6cc 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device *adev, · line 255

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -3
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
 struct amdgpu_sync *sync,
 
          if (resv == NULL)
                  return -EINVAL;
-
- /* TODO: Use DMA_RESV_USAGE_READ here */
- dma_resv_for_each_fence(&cursor, resv,

DMA_RESV_USAGE_BOOKKEEP, f) {

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device *adev, · line 253

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ /*Only return and sync the fences of usage <=

DMA_RESV_USAGE_READ.*/

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f) {
                  dma_fence_chain_for_each(f, f) {
                          struct dma_fence *tmp = dma_fence_chain_contained(f);
maintainer
#11 lore raw
Quoted 22 lines · Prike

[Public]

Quoted 20 lines

From: Liang, Prike
Sent: Friday, April 25, 2025 3:44 PM
To: Yadav, Arvind <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 13 lines

From: Yadav, Arvind <[email protected]>
Sent: Friday, April 25, 2025 3:21 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

This is problem for TLB flush. We should not do this changes. Here we are utilizing DMA_RESV_USAGE_BOOKKEEP due to the TLB flush fence associated with the page table (PT). We are ensuring that no page directory (PD) or page table (PT) should be free before flush and ttm bo release and delete both are also waiting for BOOKKEEP fence. Please drop

Quoted 4 lines
Quoted 3 lines

this changes for eviction fence.
Thanks for sharing the background. So, we may need to test the fence whether is an eviction fence in amdgpu_sync_test_fence () before added it to the VM sync.

It looks the TLB flush fence only added to the VM BO reservation and requires a sync at compute VM.

The TLB flush fence should always be explicitly synced to by the KFD.

Where do you see that it is implicitly synced using the amdgpu_sync objected?

Regards,
Christian.

Quoted 41 lines

As to the VM reservation sync whether can return and sync to the DMA_RESV_USAGE_READ, and I will further check it separately with the eviction fence release. As to the eviction fence sync problem issue, I would like to put exclude the eviction fence sync at amdgpu_sync_test_fence().

Thanks,
Prike

Quoted 35 lines

Thanks,
Prike

Quoted 5 lines

Regards,
~arvind

Quoted 1 line · Prike Liang

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP

usage

Quoted 27 lines
Quoted 13 lines

fences, so here only return and sync the dependent read fences.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
index 5576ed0b508f..4e1d30ecb6cc 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device *adev, · line 255

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -3
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
 struct amdgpu_sync *sync,
 
          if (resv == NULL)
                  return -EINVAL;
-
- /* TODO: Use DMA_RESV_USAGE_READ here */
- dma_resv_for_each_fence(&cursor, resv,

DMA_RESV_USAGE_BOOKKEEP, f) {

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device *adev, · line 253

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ /*Only return and sync the fences of usage <=

DMA_RESV_USAGE_READ.*/

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f) {
                  dma_fence_chain_for_each(f, f) {
                          struct dma_fence *tmp = dma_fence_chain_contained(f);
#12 lore raw

[Public]

Quoted 37 lines

From: Koenig, Christian <[email protected]>
Sent: Monday, April 28, 2025 10:29 PM
To: Liang, Prike <[email protected]>; Yadav, Arvind <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 29 lines · Prike

[Public]

Quoted 27 lines

From: Liang, Prike
Sent: Friday, April 25, 2025 3:44 PM
To: Yadav, Arvind <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 9 lines

From: Yadav, Arvind <[email protected]>
Sent: Friday, April 25, 2025 3:21 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 6 lines

This is problem for TLB flush. We should not do this changes. Here we are utilizing DMA_RESV_USAGE_BOOKKEEP due to the TLB flush fence associated with the page table (PT). We are ensuring that no page directory (PD) or page table (PT) should be free before flush and ttm bo release and delete both are also waiting for BOOKKEEP fence. Please drop

this changes for eviction fence.
Thanks for sharing the background. So, we may need to test the fence whether is an eviction fence in amdgpu_sync_test_fence () before added it to

Quoted 9 lines

the VM sync.

Quoted 1 line

It looks the TLB flush fence only added to the VM BO reservation and requires a

sync at compute VM.

The TLB flush fence should always be explicitly synced to by the KFD.

Where do you see that it is implicitly synced using the amdgpu_sync objected?

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

/* Prepare a TLB flush fence to be attached to PTs */

->>>>>>>if (!params->unlocked && vm->is_compute_context) { ->>>>>>>->>>>>>>amdgpu_vm_tlb_fence_create(params->adev, vm, fence);

->>>>>>>->>>>>>>/* Makes sure no PD/PT is freed before the flush */ ->>>>>>>->>>>>>>dma_resv_add_fence(vm->root.bo->tbo.base.resv, *fence,
->>>>>>>->>>>>>>->>>>>>>->>>>>>> DMA_RESV_USAGE_BOOKKEEP);
->>>>>>>}
Yes, the TLB flush fence is explicitly sync and the flush should be performed after the dependent PD/PT fence signaled. To the Arvind's concern on the TLB flush fence should be handled properly by explicitly syncing the TLB fence, so it's ok to promote the implicit sync to the READ fence from the BOOKEEP?

Thanks,
Prike

Quoted 47 lines

Regards,
Christian.

Quoted 3 lines

As to the VM reservation sync whether can return and sync to the DMA_RESV_USAGE_READ, and I will further check it separately with the eviction fence release. As to the eviction fence sync problem issue, I would like

to put exclude the eviction fence sync at amdgpu_sync_test_fence().

Quoted 35 lines

Thanks,
Prike

Quoted 32 lines

Thanks,
Prike

Quoted 5 lines

Regards,
~arvind

Quoted 1 line · Prike Liang

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP

usage

Quoted 24 lines
Quoted 13 lines

fences, so here only return and sync the dependent read fences.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
index 5576ed0b508f..4e1d30ecb6cc 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device · line 255

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -3
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device
 *adev, struct amdgpu_sync *sync,
 
          if (resv == NULL)
                  return -EINVAL;
-
- /* TODO: Use DMA_RESV_USAGE_READ here */
- dma_resv_for_each_fence(&cursor, resv,

DMA_RESV_USAGE_BOOKKEEP, f) {

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device · line 253

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ /*Only return and sync the fences of usage <=

DMA_RESV_USAGE_READ.*/

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f)

{

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
                  dma_fence_chain_for_each(f, f) {
                          struct dma_fence *tmp =

dma_fence_chain_contained(f);

maintainer
#13 lore raw
Quoted 51 lines · Prike

[Public]

Quoted 37 lines

From: Koenig, Christian <[email protected]>
Sent: Monday, April 28, 2025 10:29 PM
To: Liang, Prike <[email protected]>; Yadav, Arvind <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 29 lines · Prike

[Public]

Quoted 27 lines

From: Liang, Prike
Sent: Friday, April 25, 2025 3:44 PM
To: Yadav, Arvind <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 9 lines

From: Yadav, Arvind <[email protected]>
Sent: Friday, April 25, 2025 3:21 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: implicitly sync the dependent read fences

Quoted 6 lines

This is problem for TLB flush. We should not do this changes. Here we are utilizing DMA_RESV_USAGE_BOOKKEEP due to the TLB flush fence associated with the page table (PT). We are ensuring that no page directory (PD) or page table (PT) should be free before flush and ttm bo release and delete both are also waiting for BOOKKEEP fence. Please drop

this changes for eviction fence.
Thanks for sharing the background. So, we may need to test the fence whether is an eviction fence in amdgpu_sync_test_fence () before added it to

Quoted 9 lines

the VM sync.

Quoted 1 line

It looks the TLB flush fence only added to the VM BO reservation and requires a

sync at compute VM.

The TLB flush fence should always be explicitly synced to by the KFD.

Where do you see that it is implicitly synced using the amdgpu_sync objected?

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

/* Prepare a TLB flush fence to be attached to PTs */

->>>>>>>if (!params->unlocked && vm->is_compute_context) { ->>>>>>>->>>>>>>amdgpu_vm_tlb_fence_create(params->adev, vm, fence);

Quoted 7 lines

->>>>>>>->>>>>>>/* Makes sure no PD/PT is freed before the flush */ ->>>>>>>->>>>>>>dma_resv_add_fence(vm->root.bo->tbo.base.resv, *fence,
->>>>>>>->>>>>>>->>>>>>>->>>>>>> DMA_RESV_USAGE_BOOKKEEP);
->>>>>>>}
Yes, the TLB flush fence is explicitly sync and the flush should be performed after the dependent PD/PT fence signaled. To the Arvind's concern on the TLB flush fence should be handled properly by explicitly syncing the TLB fence, so it's ok to promote the implicit sync to the READ fence from the BOOKEEP?

As far as I know yes. The TLB flush fence is only added as BOOKKEEP so that we only wait for it before we free the VM PDs and PTs.

Regards,
Christian.

Quoted 51 lines

Thanks,
Prike

Quoted 47 lines

Regards,
Christian.

Quoted 3 lines

As to the VM reservation sync whether can return and sync to the DMA_RESV_USAGE_READ, and I will further check it separately with the eviction fence release. As to the eviction fence sync problem issue, I would like

to put exclude the eviction fence sync at amdgpu_sync_test_fence().

Quoted 35 lines

Thanks,
Prike

Quoted 32 lines

Thanks,
Prike

Quoted 5 lines

Regards,
~arvind

Quoted 1 line · Prike Liang

The driver doesn't want to sync on the DMA_RESV_USAGE_BOOKKEEP

usage

Quoted 24 lines
Quoted 13 lines

fences, so here only return and sync the dependent read fences.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
index 5576ed0b508f..4e1d30ecb6cc 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device · line 255

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -3
@@ -249,9 +249,8 @@ int amdgpu_sync_resv(struct amdgpu_device
 *adev, struct amdgpu_sync *sync,
 
          if (resv == NULL)
                  return -EINVAL;
-
- /* TODO: Use DMA_RESV_USAGE_READ here */
- dma_resv_for_each_fence(&cursor, resv,

DMA_RESV_USAGE_BOOKKEEP, f) {

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_resv(struct amdgpu_device · line 253

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ /*Only return and sync the fences of usage <=

DMA_RESV_USAGE_READ.*/

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -0
+ dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_READ, f)

{

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
                  dma_fence_chain_for_each(f, f) {
                          struct dma_fence *tmp =

dma_fence_chain_contained(f);