From: Thadeu Lima de Souza Cascardo <[email protected]>

A failed PTE walk can leave an allocated SDMA job with no commands, or
no current job after submitting a full IB and failing to allocate its
replacement. A final commit of partial work must handle both states.

Return without submitting when there is no job, and free an empty job
instead of emitting an empty IB. Clear the job pointer after freeing
or submitting it so that a later final commit cannot consume it twice.

Based on Cascardo's earlier NULL/empty-job patch. Retain the current
int-returning commit callback and scheduler layout.

[zmu: Clear the job pointer after submission and retain the current API.]
Link: 
https://lore.kernel.org/amd-gfx/[email protected]/
Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]>
Signed-off-by: Zihao Mu <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
index d3a5e848741..ade6c7aa15c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
@@ -91,6 +91,7 @@ static int amdgpu_vm_sdma_prepare(struct 
amdgpu_vm_update_params *p,
        if (r) {
                p->num_dw_left = 0;
                amdgpu_job_free(p->job);
+               p->job = NULL;
        }
        return r;
 }
@@ -107,14 +108,23 @@ static int amdgpu_vm_sdma_prepare(struct 
amdgpu_vm_update_params *p,
 static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p,
                                 struct dma_fence **fence)
 {
-       struct amdgpu_ib *ib = p->job->ibs;
+       struct amdgpu_ib *ib;
        struct amdgpu_ring *ring;
        struct dma_fence *f;
 
+       if (!p->job)
+               return 0;
+
+       ib = p->job->ibs;
+       if (!ib->length_dw) {
+               amdgpu_job_free(p->job);
+               p->job = NULL;
+               return 0;
+       }
+
        ring = container_of(p->vm->delayed.rq->sched, struct amdgpu_ring,
                            sched);
 
-       WARN_ON(ib->length_dw == 0);
        amdgpu_ring_pad_ib(ring, ib);
 
        if (p->needs_flush)
@@ -122,6 +132,7 @@ static int amdgpu_vm_sdma_commit(struct 
amdgpu_vm_update_params *p,
 
        WARN_ON(ib->length_dw > p->num_dw_left);
        f = amdgpu_job_submit(p->job);
+       p->job = NULL;
 
        if (p->unlocked) {
                struct dma_fence *tmp = dma_fence_get(f);
-- 
2.43.0

Reply via email to