So we can later update all changed BOs without needing to do tracking
separately.

Signed-off-by: Natalie Vock <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 16 ++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     |  5 +++++
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index e0090dc10682f..068c57ed537fd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -80,6 +80,8 @@ struct amdgpu_bo_va {
        /* protected by bo being reserved */
        unsigned                        ref_count;
 
+       struct list_head                update_link;
+
        /* all other members protected by the VM PD being reserved */
        struct dma_fence                *last_pt_update;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 1e2d45979efdb..330c288053352 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1718,6 +1718,8 @@ amdgpu_vm_update_ctx_add_new_mapping(struct 
amdgpu_vm_update_ctx *ctx,
        mapping->bo_va = bo_va;
        WARN_ON(!list_empty(&mapping->pending_list));
        list_add(&mapping->pending_list, &ctx->new);
+       if (list_empty(&mapping->bo_va->update_link))
+               list_add(&mapping->bo_va->update_link, &ctx->dirty_bo_vas);
        return 0;
 }
 
@@ -1733,8 +1735,10 @@ static void
 amdgpu_vm_update_ctx_add_freed_mapping(struct amdgpu_vm_update_ctx *ctx,
                                       struct amdgpu_bo_va_mapping *mapping)
 {
-       WARN_ON(!list_empty(&mapping->pending_list));
-       list_add(&mapping->pending_list, &ctx->deleted);
+       if (list_empty(&mapping->bo_va->update_link))
+               list_add(&mapping->bo_va->update_link, &ctx->dirty_bo_vas);
+       if (list_empty(&mapping->pending_list))
+               list_add(&mapping->pending_list, &ctx->deleted);
 }
 
 int amdgpu_vm_update_ctx_execute_replace(struct amdgpu_vm_update_ctx *ctx)
@@ -1861,6 +1865,7 @@ void amdgpu_vm_update_ctx_init(struct 
amdgpu_vm_update_ctx *ctx,
 
        ctx->pending_maps = RB_ROOT_CACHED;
        ctx->cleared_ranges = RB_ROOT_CACHED;
+       INIT_LIST_HEAD(&ctx->dirty_bo_vas);
        INIT_LIST_HEAD(&ctx->new);
        INIT_LIST_HEAD(&ctx->deleted);
        INIT_LIST_HEAD(&ctx->freed);
@@ -1878,10 +1883,16 @@ void amdgpu_vm_update_ctx_init(struct 
amdgpu_vm_update_ctx *ctx,
 void amdgpu_vm_update_ctx_fini(struct amdgpu_vm_update_ctx *ctx)
 {
        struct interval_tree_node *node, *next_node;
+       struct amdgpu_bo_va *bo_va, *next_bo_va;
 
        list_splice(&ctx->freed, &ctx->vm->delayed_freed);
        amdgpu_sync_free(&ctx->sync);
 
+       list_for_each_entry_safe(bo_va, next_bo_va, &ctx->dirty_bo_vas,
+                                update_link) {
+               list_del_init(&bo_va->update_link);
+       }
+
        rbtree_postorder_for_each_entry_safe(node, next_node, 
&ctx->pending_maps.rb_root, rb) {
                kfree(node);
        }
@@ -2135,6 +2146,7 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct 
amdgpu_device *adev,
 
        bo_va->ref_count = 1;
        bo_va->last_pt_update = dma_fence_get_stub();
+       INIT_LIST_HEAD(&bo_va->update_link);
        INIT_LIST_HEAD(&bo_va->valids);
        INIT_LIST_HEAD(&bo_va->invalids);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 5657aa63e9491..7a5f558970b5c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -305,6 +305,11 @@ struct amdgpu_vm_update_ctx {
         */
        struct list_head cleared;
 
+       /**
+        * @dirty_bo_vas: amdgpu_bo_va structures touched by current pending 
mapping changes.
+        */
+       struct list_head dirty_bo_vas;
+
        /**
         * @freed: A list of mappings that are freed and pending PT/PD updates 
during
         * this update operation.

-- 
2.56.1

Reply via email to