Any page table update may currently add up to three fences to the root
PD's resv (last_unlocked, SDMA commit, and TLB flush). In addition if
any PD/PT BOs need to be allocated, it can add up to TTM_NUM_MOVE_FENCES
on top.

Introduce AMDGPU_VM_UPDATE_FENCES for this count and reserve it in
amdgpu_vm_lock_pd().

Fixes: d8a3f0a0348d ("drm/amdgpu: implement TLB flush fence")
Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
Fixes: ddc3c87584e2 ("drm/amdgpu: clear vm pts upon a vm->generation mismatch")
Signed-off-by: Benjamin Cheng <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     | 8 ++++++++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index 2d4a17e11a1f..2403cd911058 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -3073,9 +3073,9 @@ static void 
amdgpu_ualink_invalidate_import_mappings(struct amdgpu_bo *bo)
                struct amdgpu_vm *vm = bo_base->vm;
 
                /*
-                * Fences for the two SDMA page table updates were already
-                * reserved by amdgpu_vm_lock_pd() above (it reserves 2 +
-                * num_fences on the same VM root PD dma_resv).
+                * Fences for the two page table updates were already
+                * reserved by amdgpu_vm_lock_pd() above on the same VM
+                * root PD dma_resv.
                 */
                r = amdgpu_vm_clear_freed(adev, vm, NULL);
                if (!r)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 8cc5964f29c0..6d8d639e5986 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -462,9 +462,8 @@ void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
 int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
                      unsigned int num_fences)
 {
-       /* We need at least two fences for the VM PD/PT updates */
        return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base,
-                                   2 + num_fences);
+                                   AMDGPU_VM_UPDATE_FENCES + num_fences);
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index f6285a9d9e98..8117bec01e4e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -187,6 +187,14 @@ struct amdgpu_bo_vm;
 #define AMDGPU_VM_USE_CPU_FOR_GFX (1 << 0)
 #define AMDGPU_VM_USE_CPU_FOR_COMPUTE (1 << 1)
 
+/*
+ * The number of fence slots needed on the root PD resv for a page table
+ * update: last_unlocked, the SDMA commit fence, the TLB flush fence, plus
+ * the TTM eviction/move fences of any PD/PT BO that is validated or allocated.
+ * This needs to be bumped whenever a new fence is added.
+ */
+#define AMDGPU_VM_UPDATE_FENCES (3 + TTM_NUM_MOVE_FENCES)
+
 /* VMPT level enumerate, and the hiberachy is:
  * PDB3->PDB2->PDB1->PDB0->PTB
  */
-- 
2.56.1

Reply via email to