Skip to contentSkip to conversation

drm/amdgpu: always emit the job vm fence

PATCH In review Alex Deucher 4 participants 5 messages Jun 3 – Jun 5

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: always emit the job vm fence

We need the fence to reemit the gds switch or spm update after a queue reset.

Fixes a17ef941212b ("drm/amdgpu: rework ring reset backup and reemit v9")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -6
index 2f3470208829e..7e0e2281719b1 100644
@@ -853,12 +853,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
 					    job->oa_size);
 	}
 
-	if (vm_flush_needed || pasid_mapping_needed || cleaner_shader_needed) {
-		amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
-		fence = &job->hw_vm_fence->base;
-		/* get a ref for the job */
-		dma_fence_get(fence);
-	}
+	amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
+	fence = &job->hw_vm_fence->base;
+	/* get a ref for the job */
+	dma_fence_get(fence);
 
 	if (vm_flush_needed) {
 		mutex_lock(&id_mgr->lock);
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Alex,

Quoted 7 lines · On 2026. június 3., szerda 21:45:35 közép-európai nyári idő Alex Deucher wrote:

We need the fence to reemit the gds switch or spm update after a queue reset.

Fixes a17ef941212b ("drm/amdgpu: rework ring reset backup and reemit v9")

The patch makes good sense to me. Thanks!

Quoted 10 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 2f3470208829e..7e0e2281719b1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_flush(struct amdgpu_ring *ring, struct · line 856

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -1
@@ -853,12 +853,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct
 amdgpu_job *job, job->oa_size);
 	}
 
-	if (vm_flush_needed || pasid_mapping_needed || 

cleaner_shader_needed) {

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -5
-		amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
-		fence = &job->hw_vm_fence->base;
-		/* get a ref for the job */
-		dma_fence_get(fence);
-	}
+	amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
+	fence = &job->hw_vm_fence->base;
+	/* get a ref for the job */
+	dma_fence_get(fence);
 
 	if (vm_flush_needed) {
 		mutex_lock(&id_mgr->lock);
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Alex Deucher
Quoted 7 lines · Alex Deucher

We need the fence to reemit the gds switch or spm update after a queue reset.

Fixes a17ef941212b ("drm/amdgpu: rework ring reset backup and reemit v9")

That was avoided because it means another entry in the EOP ring buffer which can be bad for performance.

But correctness is obviously more important, just to keep in mind when we suddenly see 1% fps decrease and don't know where it's coming from.

Quoted 25 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -6
index 2f3470208829e..7e0e2281719b1 100644
@@ -853,12 +853,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
 					    job->oa_size);
 	}
 
-	if (vm_flush_needed || pasid_mapping_needed || cleaner_shader_needed) {
-		amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
-		fence = &job->hw_vm_fence->base;
-		/* get a ref for the job */
-		dma_fence_get(fence);
-	}
+	amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
+	fence = &job->hw_vm_fence->base;
+	/* get a ref for the job */
+	dma_fence_get(fence);
 
 	if (vm_flush_needed) {
 		mutex_lock(&id_mgr->lock);
#3 lore raw
Quoted 9 lines · On 2026. június 5., péntek 11:24:45 közép-európai nyári idő Christian König…
Quoted 7 lines · Alex Deucher

We need the fence to reemit the gds switch or spm update after a queue reset.

Fixes a17ef941212b ("drm/amdgpu: rework ring reset backup and reemit v9")
Quoted 7 lines

That was avoided because it means another entry in the EOP ring buffer which can be bad for performance.

But correctness is obviously more important, just to keep in mind when we suddenly see 1% fps decrease and don't know where it's coming from.

Thanks Christian, that's a valid point.
Do you think we should worry about an actual perf impact here?

If we want to avoid adding an extra fence, then an alternative solution could be to include the emitted commands in the ib_wptr of the job's own fence when a VM fence was not emitted.

What do you guys think?

Thanks,
Timur

Quoted 15 lines
Quoted 15 lines

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index
2f3470208829e..7e0e2281719b1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -853,12 +853,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring,

struct amdgpu_job *job,>
job->oa_size);

Quoted 3 lines

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

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -1
 	}
 
-	if (vm_flush_needed || pasid_mapping_needed || 

cleaner_shader_needed) {

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -5
-		amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
-		fence = &job->hw_vm_fence->base;
-		/* get a ref for the job */
-		dma_fence_get(fence);
-	}
+	amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
+	fence = &job->hw_vm_fence->base;
+	/* get a ref for the job */
+	dma_fence_get(fence);
 
 	if (vm_flush_needed) {
 
 		mutex_lock(&id_mgr->lock);
#4 lore raw
Quoted 20 lines · Timur Kristóf
Quoted 9 lines · On 2026. június 5., péntek 11:24:45 közép-európai nyári idő Christian König…
Quoted 7 lines · Alex Deucher

We need the fence to reemit the gds switch or spm update after a queue reset.

Fixes a17ef941212b ("drm/amdgpu: rework ring reset backup and reemit v9")
Quoted 7 lines

That was avoided because it means another entry in the EOP ring buffer which can be bad for performance.

But correctness is obviously more important, just to keep in mind when we suddenly see 1% fps decrease and don't know where it's coming from.

Quoted 8 lines

Thanks Christian, that's a valid point.
Do you think we should worry about an actual perf impact here?

If we want to avoid adding an extra fence, then an alternative solution could be to include the emitted commands in the ib_wptr of the job's own fence when a VM fence was not emitted.

What do you guys think?

@Christian Koenig Is there a reason we need to emit gds and spm before the vm fence if the vm fence is required? I've sent out a series to retain that behavior, but if it doesn't matter, we could simplify things more and move gds and spm into the ib fence.

Alex

Quoted 40 lines

Thanks,
Timur

Quoted 15 lines
Quoted 15 lines

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index
2f3470208829e..7e0e2281719b1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -853,12 +853,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring,

struct amdgpu_job *job,>

                                        job->oa_size);
Quoted 3 lines
Quoted 3 lines
    }

- if (vm_flush_needed || pasid_mapping_needed ||

cleaner_shader_needed) {

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -5
-           amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
-           fence = &job->hw_vm_fence->base;
-           /* get a ref for the job */
-           dma_fence_get(fence);
-   }
+   amdgpu_fence_emit(ring, job->hw_vm_fence, 0);
+   fence = &job->hw_vm_fence->base;
+   /* get a ref for the job */
+   dma_fence_get(fence);
 
    if (vm_flush_needed) {
 
            mutex_lock(&id_mgr->lock);