From: Zihao Mu <[email protected]>

The CPU backend repeats reservation traversal for every PTE batch. An
interrupted wait can also skip a batch whose result the walker ignores.

Wait for the shared root reservation's KERNEL dependencies in prepare,
including calls without an explicit sync. Allocation now commits and
restarts the phase, so dependencies added while the eviction lock was
dropped are covered before the resumed phase writes entries.

Preserve the existing interruptible wait policy. An interruption now
fails prepare before that phase writes any entries, while prior phases
have been committed and receive normal partial-range finalization.
Keep explicit sync handling and the CPU write/flags/commit tail intact.

The update callback now only writes entries and returns zero through
the existing interface. This does not claim that all VM preparation or
SDMA allocation operations have become non-failing.

Signed-off-by: Zihao Mu <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
index d03b9bbe20c..89e76e18d9e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
@@ -52,10 +52,19 @@ static int amdgpu_vm_cpu_prepare(struct 
amdgpu_vm_update_params *p,
                                 struct amdgpu_sync *sync,
                                 u64 k_job_id)
 {
-       if (!sync)
-               return 0;
+       struct dma_resv *resv = p->vm->root.bo->tbo.base.resv;
+       long r;
+
+       if (sync) {
+               r = amdgpu_sync_wait(sync, true);
+               if (r)
+                       return r;
+       }
 
-       return amdgpu_sync_wait(sync, true);
+       /* Allocation restarts prepare before any further page-table writes. */
+       r = dma_resv_wait_timeout(resv, DMA_RESV_USAGE_KERNEL,
+                                 true, MAX_SCHEDULE_TIMEOUT);
+       return r < 0 ? r : 0;
 }
 
 /**
@@ -78,12 +87,6 @@ static int amdgpu_vm_cpu_update(struct 
amdgpu_vm_update_params *p,
 {
        unsigned int i;
        uint64_t value;
-       long r;
-
-       r = dma_resv_wait_timeout(vmbo->bo.tbo.base.resv, DMA_RESV_USAGE_KERNEL,
-                                 true, MAX_SCHEDULE_TIMEOUT);
-       if (r < 0)
-               return r;
 
        pe += (unsigned long)amdgpu_bo_kptr(&vmbo->bo);
 
-- 
2.43.0

Reply via email to