On Wed, Nov 11, 2026 at 11:55:58AM +0000, Mu, Zihao wrote:
> 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
>        */

Similarly, we might want to use the same job ID, so here is my proposal,
whcih should go before this patch (and then prepare needs to drop its job
id parameter).


>From 05a61399d6bcddb3eb75786e25e88221e70afdfd Mon Sep 17 00:00:00 2001
From: Thadeu Lima de Souza Cascardo <[email protected]>
Date: Tue, 10 Nov 2026 20:16:17 -0300
Subject: [PATCH] drm/amdgpu: pass job id as part of amdgpu_vm_update_params

Jobs may be allocated not only during prepare step, but also during the
update step. Also, in case we might want to call prepare again after a
commit when dropping the lock, we want to use the same original job ID.
So make it part of the update params instead of a parameter for prepare
only.

Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c          | 8 ++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c      | 4 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h | 7 ++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c       | 4 ++--
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 94b1cfe05e3e0..2e95f182db838 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1054,9 +1054,9 @@ int amdgpu_vm_update_pdes(struct amdgpu_device *adev,
        params.adev = adev;
        params.vm = vm;
        params.immediate = immediate;
+       params.k_job_id = AMDGPU_KERNEL_JOB_ID_VM_UPDATE_PDES;
 
-       r = vm->update_funcs->prepare(&params, NULL,
-                                     AMDGPU_KERNEL_JOB_ID_VM_UPDATE_PDES);
+       r = vm->update_funcs->prepare(&params, NULL);
        if (r)
                goto error;
 
@@ -1207,6 +1207,7 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, 
struct amdgpu_vm *vm,
        params.needs_flush = flush_tlb;
        params.override_pte = allow_override && adev->gmc.override_pte;
        INIT_LIST_HEAD(&params.tlb_flush_waitlist);
+       params.k_job_id = AMDGPU_KERNEL_JOB_ID_VM_UPDATE_RANGE;
 
        r = amdgpu_vm_begin_critical(&params);
        if (r)
@@ -1220,8 +1221,7 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, 
struct amdgpu_vm *vm,
                dma_fence_put(tmp);
        }
 
-       r = vm->update_funcs->prepare(&params, sync,
-                                     AMDGPU_KERNEL_JOB_ID_VM_UPDATE_RANGE);
+       r = vm->update_funcs->prepare(&params, sync);
        if (r)
                goto error_free;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
index d03b9bbe20c7c..dd62fef0ca164 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
@@ -43,14 +43,12 @@ static int amdgpu_vm_cpu_map_table(struct amdgpu_bo_vm 
*table)
  *
  * @p: see amdgpu_vm_update_params definition
  * @sync: sync obj with fences to wait on
- * @k_job_id: the id for tracing/debug purposes
  *
  * Returns:
  * Negativ errno, 0 for success.
  */
 static int amdgpu_vm_cpu_prepare(struct amdgpu_vm_update_params *p,
-                                struct amdgpu_sync *sync,
-                                u64 k_job_id)
+                                struct amdgpu_sync *sync)
 {
        if (!sync)
                return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
index 8ebb0b033291e..c6e4469bebef7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h
@@ -102,12 +102,17 @@ struct amdgpu_vm_update_params {
         * @tlb_flush_waitlist: temporary storage for BOs until tlb_flush
         */
        struct list_head tlb_flush_waitlist;
+
+       /**
+        * @k_job_id: job id to use for this update.
+        */
+       u64 k_job_id;
 };
 
 struct amdgpu_vm_update_funcs {
        int (*map_table)(struct amdgpu_bo_vm *bo);
        int (*prepare)(struct amdgpu_vm_update_params *p,
-                      struct amdgpu_sync *sync, u64 k_job_id);
+                      struct amdgpu_sync *sync);
        int (*update)(struct amdgpu_vm_update_params *p,
                      struct amdgpu_bo_vm *bo, uint64_t pe, uint64_t addr,
                      unsigned count, uint32_t incr, uint64_t flags);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
index c73eb416c0e26..856ea8bedb64b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
@@ -398,9 +398,9 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
        params.adev = adev;
        params.vm = vm;
        params.immediate = immediate;
+       params.k_job_id = AMDGPU_KERNEL_JOB_ID_VM_PT_CLEAR;
 
-       r = vm->update_funcs->prepare(&params, NULL,
-                                     AMDGPU_KERNEL_JOB_ID_VM_PT_CLEAR);
+       r = vm->update_funcs->prepare(&params, NULL);
        if (r)
                goto exit;
 
-- 
2.47.3


> 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