From: Zihao Mu <[email protected]>

Page-table allocation drops the VM eviction lock and can introduce new
move dependencies. End the current update phase before that allocation,
then prepare a new phase after creating and clearing the table.

Preserve the original sync across each prepare. An empty SDMA phase may
be freed before allocation, so its job cannot be relied on to carry
those dependencies into the resumed phase.

Transfer the nested clear's internal completion to the outer context as
well. If a subsequent prepare fails, range finalization still orders
the TLB work after the already submitted clear, including immediate
submissions that do not expose a public output fence.

Leave a successfully cleared table installed when prepare fails, and
keep the existing fast return for already allocated tables. The earlier
cleanup patches handle failed initialization and partial range work.
No PDE iteration or output-fence policy is changed here.

Signed-off-by: Zihao Mu <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c          | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h | 5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c       | 8 +++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index f76459f8312..7d85e5e74c5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1206,6 +1206,7 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, 
struct amdgpu_vm *vm,
        params.vm = vm;
        params.immediate = immediate;
        params.pages_addr = pages_addr;
+       params.sync = sync;
        params.unlocked = unlocked;
        params.needs_flush = flush_tlb;
        params.override_pte = allow_override && adev->gmc.override_pte;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
index 71fc1fffaa6..df1aaa00603 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
@@ -82,6 +82,11 @@ struct amdgpu_vm_update_params {
         */
        struct dma_fence *last_update;
 
+       /**
+        * @sync: original dependencies to preserve across prepare calls
+        */
+       struct amdgpu_sync *sync;
+
        /**
         * @num_dw_left: number of dw left for the IB
         */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
index bdd06b7718c..e42af004dc0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
@@ -531,6 +531,11 @@ static int amdgpu_vm_pt_alloc(struct 
amdgpu_vm_update_params *p,
        if (entry->bo)
                return 0;
 
+       /* Allocation may introduce new move dependencies. End this phase. */
+       r = p->vm->update_funcs->commit(p, NULL);
+       if (r)
+               return r;
+
        amdgpu_vm_end_critical(p);
        r = amdgpu_vm_pt_create(p->adev, p->vm, cursor->level, p->immediate,
                                &pt, p->vm->root.bo->xcp_id);
@@ -556,7 +561,8 @@ static int amdgpu_vm_pt_alloc(struct 
amdgpu_vm_update_params *p,
                return r;
        }
 
-       return 0;
+       return p->vm->update_funcs->prepare(p, p->sync,
+                                        AMDGPU_KERNEL_JOB_ID_VM_UPDATE_RANGE);
 
 error_unpin:
        if (p->vm->is_npa)
-- 
2.43.0

Reply via email to