Skip to contentSkip to conversation

drm/amdgpu: fix VM sync with always valid BOs

PATCH In review Christian König 5 participants 6 messages Sep 8, 2017 – Sep 11, 2017 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: fix VM sync with always valid BOs

From: Christian König <[email protected]>

All users of a VM must always wait for updates with always valid BOs to be completed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
 3 files changed, 21 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -4
index 8aa37e0..d6e66b7 100644
@@ -752,10 +752,6 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	if (r)
 		return r;
 
-	r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_dir_update);
-	if (r)
-		return r;
-
 	r = amdgpu_vm_clear_freed(adev, vm, NULL);
 	if (r)
 		return r;
@@ -797,6 +793,10 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 			if (bo_va == NULL)
 				continue;
 
+			if (bo_va->base.bo->flags &
+			    AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
+				continue;
+
 			r = amdgpu_vm_bo_update(adev, bo_va, false);
 			if (r)
 				return r;
@@ -810,6 +810,12 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	}
 
 	r = amdgpu_vm_handle_moved(adev, vm, &p->job->sync);
+	if (r)
+		return r;
+
+	r = amdgpu_sync_fence(adev, &p->job->sync, vm->mandatory_update);
+	if (r)
+		return r;
 
 	if (amdgpu_vm_debug && p->bo_list) {
 		/* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -5
index 55f1ecb..12c8a4c 100644
@@ -1140,9 +1140,8 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
 				goto error_free;
 
 			amdgpu_bo_fence(parent->base.bo, fence, true);
-			dma_fence_put(vm->last_dir_update);
-			vm->last_dir_update = dma_fence_get(fence);
-			dma_fence_put(fence);
+			dma_fence_put(vm->mandatory_update);
+			vm->mandatory_update = fence;
 		}
 	}
 
@@ -1803,6 +1802,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
 			trace_amdgpu_vm_bo_mapping(mapping);
 	}
 
+	if (bo_va->base.bo &&
+	    bo_va->base.bo->tbo.resv == vm->root.base.bo->tbo.resv) {
+		dma_fence_put(vm->mandatory_update);
+		vm->mandatory_update = dma_fence_get(bo_va->last_pt_update);
+	}
+
 	return 0;
 }
 
@@ -2586,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			 vm->use_cpu_for_update ? "CPU" : "SDMA");
 	WARN_ONCE((vm->use_cpu_for_update & !amdgpu_vm_is_large_bar(adev)),
 		  "CPU update of VM recommended only for large BAR system\n");
-	vm->last_dir_update = NULL;
+	vm->mandatory_update = NULL;
 
 	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
 			AMDGPU_GEM_CREATE_VRAM_CLEARED;
@@ -2692,7 +2697,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 	}
 
 	amdgpu_vm_free_levels(&vm->root);
-	dma_fence_put(vm->last_dir_update);
+	dma_fence_put(vm->mandatory_update);
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
 		amdgpu_vm_free_reserved_vmid(adev, vm, i);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
index c1accd1..63fa2e5 100644
@@ -140,7 +140,7 @@ struct amdgpu_vm {
 
 	/* contains the page directory */
 	struct amdgpu_vm_pt     root;
-	struct dma_fence	*last_dir_update;
+	struct dma_fence	*mandatory_update;
 
 	/* protecting freed */
 	spinlock_t		freed_lock;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1504873115-7651-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#2 lore raw

Marek this one will most likely fix your issues with always valid BOs on Raven.

Please give it a try when you have time.

Thanks,
Christian.

Am 08.09.2017 um 14:18 schrieb Christian König:

Quoted 103 lines

From: Christian König <[email protected]>

All users of a VM must always wait for updates with always valid BOs to be completed.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
  3 files changed, 21 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -4
index 8aa37e0..d6e66b7 100644
@@ -752,10 +752,6 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
  	if (r)
  		return r;
 
-	r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_dir_update);
-	if (r)
-		return r;
-
  	r = amdgpu_vm_clear_freed(adev, vm, NULL);
  	if (r)
  		return r;
@@ -797,6 +793,10 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
  			if (bo_va == NULL)
  				continue;
 
+			if (bo_va->base.bo->flags &
+			    AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
+				continue;
+
  			r = amdgpu_vm_bo_update(adev, bo_va, false);
  			if (r)
  				return r;
@@ -810,6 +810,12 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
  	}
 
  	r = amdgpu_vm_handle_moved(adev, vm, &p->job->sync);
+	if (r)
+		return r;
+
+	r = amdgpu_sync_fence(adev, &p->job->sync, vm->mandatory_update);
+	if (r)
+		return r;
 
  	if (amdgpu_vm_debug && p->bo_list) {
  		/* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -5
index 55f1ecb..12c8a4c 100644
@@ -1140,9 +1140,8 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
  				goto error_free;
 
  			amdgpu_bo_fence(parent->base.bo, fence, true);
-			dma_fence_put(vm->last_dir_update);
-			vm->last_dir_update = dma_fence_get(fence);
-			dma_fence_put(fence);
+			dma_fence_put(vm->mandatory_update);
+			vm->mandatory_update = fence;
  		}
  	}
 
@@ -1803,6 +1802,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
  			trace_amdgpu_vm_bo_mapping(mapping);
  	}
 
+	if (bo_va->base.bo &&
+	    bo_va->base.bo->tbo.resv == vm->root.base.bo->tbo.resv) {
+		dma_fence_put(vm->mandatory_update);
+		vm->mandatory_update = dma_fence_get(bo_va->last_pt_update);
+	}
+
  	return 0;
  }
 
@@ -2586,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  			 vm->use_cpu_for_update ? "CPU" : "SDMA");
  	WARN_ONCE((vm->use_cpu_for_update & !amdgpu_vm_is_large_bar(adev)),
  		  "CPU update of VM recommended only for large BAR system\n");
-	vm->last_dir_update = NULL;
+	vm->mandatory_update = NULL;
 
  	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
  			AMDGPU_GEM_CREATE_VRAM_CLEARED;
@@ -2692,7 +2697,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
  	}
 
  	amdgpu_vm_free_levels(&vm->root);
-	dma_fence_put(vm->last_dir_update);
+	dma_fence_put(vm->mandatory_update);
  	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
  		amdgpu_vm_free_reserved_vmid(adev, vm, i);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index c1accd1..63fa2e5 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 146

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
@@ -140,7 +140,7 @@ struct amdgpu_vm {
 
  	/* contains the page directory */
  	struct amdgpu_vm_pt     root;
-	struct dma_fence	*last_dir_update;
+	struct dma_fence	*mandatory_update;
 
  	/* protecting freed */
  	spinlock_t		freed_lock;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 3bbd85c1-6e3d-0dec-73d5-8ccb575d430d-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#4 lore raw

The hang seems to be gone with this patch.

Marek

Quoted 115 lines · Christian König

Marek this one will most likely fix your issues with always valid BOs on Raven.

Please give it a try when you have time.

Thanks,
Christian.

Am 08.09.2017 um 14:18 schrieb Christian König:

Quoted 105 lines

From: Christian König <[email protected]>

All users of a VM must always wait for updates with always valid BOs to be completed.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
  3 files changed, 21 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +9 -3
index 8aa37e0..d6e66b7 100644
@@ -752,10 +752,6 @@ static int amdgpu_bo_vm_update_pte(struct
 amdgpu_cs_parser *p)
        if (r)
                return r;
  -     r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_dir_update);
-       if (r)
-               return r;
-
        r = amdgpu_vm_clear_freed(adev, vm, NULL);
        if (r)
                return r;
@@ -797,6 +793,10 @@ static int amdgpu_bo_vm_update_pte(struct
 amdgpu_cs_parser *p)
                        if (bo_va == NULL)
                                continue;
  +                     if (bo_va->base.bo->flags &
+                           AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
+                               continue;
+
                        r = amdgpu_vm_bo_update(adev, bo_va, false);
                        if (r)
                                return r;
@@ -810,6 +810,12 @@ static int amdgpu_bo_vm_update_pte(struct
 amdgpu_cs_parser *p)
        }
        r = amdgpu_vm_handle_moved(adev, vm, &p->job->sync);
+       if (r)
+               return r;
+
+       r = amdgpu_sync_fence(adev, &p->job->sync, vm->mandatory_update);
+       if (r)
+               return r;
        if (amdgpu_vm_debug && p->bo_list) {
                /* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -3
index 55f1ecb..12c8a4c 100644
@@ -1140,9 +1140,8 @@ static int amdgpu_vm_update_level(struct
 amdgpu_device *adev,
                                goto error_free;
                        amdgpu_bo_fence(parent->base.bo, fence, true);
-                       dma_fence_put(vm->last_dir_update);
-                       vm->last_dir_update = dma_fence_get(fence);
-                       dma_fence_put(fence);
+                       dma_fence_put(vm->mandatory_update);
+                       vm->mandatory_update = fence;
                }
        }
  @@ -1803,6 +1802,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device

*adev,

                        trace_amdgpu_vm_bo_mapping(mapping);
        }

+ if (bo_va->base.bo &&

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -0
+           bo_va->base.bo->tbo.resv == vm->root.base.bo->tbo.resv) {
+               dma_fence_put(vm->mandatory_update);
+               vm->mandatory_update =

dma_fence_get(bo_va->last_pt_update);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
+       }
+
        return 0;
  }
  @@ -2586,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev,

struct amdgpu_vm *vm,

                         vm->use_cpu_for_update ? "CPU" : "SDMA");
        WARN_ONCE((vm->use_cpu_for_update &

!amdgpu_vm_is_large_bar(adev)),
"CPU update of VM recommended only for large BAR
system\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
-       vm->last_dir_update = NULL;
+       vm->mandatory_update = NULL;
        flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
                        AMDGPU_GEM_CREATE_VRAM_CLEARED;
@@ -2692,7 +2697,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev,
 struct amdgpu_vm *vm)
        }
        amdgpu_vm_free_levels(&vm->root);
-       dma_fence_put(vm->last_dir_update);
+       dma_fence_put(vm->mandatory_update);
        for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
                amdgpu_vm_free_reserved_vmid(adev, vm, i);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -1
index c1accd1..63fa2e5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 144

Quoted 8 lines

+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
@@ -140,7 +140,7 @@ struct amdgpu_vm {
        /* contains the page directory */
        struct amdgpu_vm_pt     root;
-       struct dma_fence        *last_dir_update;
+       struct dma_fence        *mandatory_update;
        /* protecting freed */
        spinlock_t              freed_lock;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw
In reply to a message not in the archive

+Roger,

Roger, this change could also help GuoKai's issue(he needs to pass bo in first CS when enabling Per-VM-BOs).

Regards,

David Zhou

Quoted 113 lines · Christian König

Marek this one will most likely fix your issues with always valid BOs on Raven.

Please give it a try when you have time.

Thanks,
Christian.

Am 08.09.2017 um 14:18 schrieb Christian König:

Quoted 105 lines

From: Christian König <[email protected]>

All users of a VM must always wait for updates with always valid BOs to be completed.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
  3 files changed, 21 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +9 -3
index 8aa37e0..d6e66b7 100644
@@ -752,10 +752,6 @@ static int amdgpu_bo_vm_update_pte(struct 
 amdgpu_cs_parser *p)
      if (r)
          return r;
  -    r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_dir_update);
-    if (r)
-        return r;
-
      r = amdgpu_vm_clear_freed(adev, vm, NULL);
      if (r)
          return r;
@@ -797,6 +793,10 @@ static int amdgpu_bo_vm_update_pte(struct 
 amdgpu_cs_parser *p)
              if (bo_va == NULL)
                  continue;
  +            if (bo_va->base.bo->flags &
+                AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
+                continue;
+
              r = amdgpu_vm_bo_update(adev, bo_va, false);
              if (r)
                  return r;
@@ -810,6 +810,12 @@ static int amdgpu_bo_vm_update_pte(struct 
 amdgpu_cs_parser *p)
      }
        r = amdgpu_vm_handle_moved(adev, vm, &p->job->sync);
+    if (r)
+        return r;
+
+    r = amdgpu_sync_fence(adev, &p->job->sync, vm->mandatory_update);
+    if (r)
+        return r;
        if (amdgpu_vm_debug && p->bo_list) {
          /* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -3
index 55f1ecb..12c8a4c 100644
@@ -1140,9 +1140,8 @@ static int amdgpu_vm_update_level(struct 
 amdgpu_device *adev,
                  goto error_free;
                amdgpu_bo_fence(parent->base.bo, fence, true);
-            dma_fence_put(vm->last_dir_update);
-            vm->last_dir_update = dma_fence_get(fence);
-            dma_fence_put(fence);
+            dma_fence_put(vm->mandatory_update);
+            vm->mandatory_update = fence;
          }
      }
  @@ -1803,6 +1802,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device 

*adev,

              trace_amdgpu_vm_bo_mapping(mapping);
      }

+ if (bo_va->base.bo &&

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -0
+        bo_va->base.bo->tbo.resv == vm->root.base.bo->tbo.resv) {
+        dma_fence_put(vm->mandatory_update);
+        vm->mandatory_update = dma_fence_get(bo_va->last_pt_update);
+    }
+
      return 0;
  }
  @@ -2586,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device 

*adev, struct amdgpu_vm *vm,

               vm->use_cpu_for_update ? "CPU" : "SDMA");
      WARN_ONCE((vm->use_cpu_for_update & 
!amdgpu_vm_is_large_bar(adev)),
            "CPU update of VM recommended only for large BAR system\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
-    vm->last_dir_update = NULL;
+    vm->mandatory_update = NULL;
        flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
              AMDGPU_GEM_CREATE_VRAM_CLEARED;
@@ -2692,7 +2697,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, 
 struct amdgpu_vm *vm)
      }
        amdgpu_vm_free_levels(&vm->root);
-    dma_fence_put(vm->last_dir_update);
+    dma_fence_put(vm->mandatory_update);
      for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
          amdgpu_vm_free_reserved_vmid(adev, vm, i);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
index c1accd1..63fa2e5 100644
@@ -140,7 +140,7 @@ struct amdgpu_vm {
        /* contains the page directory */
      struct amdgpu_vm_pt     root;
-    struct dma_fence    *last_dir_update;
+    struct dma_fence    *mandatory_update;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 146

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
        /* protecting freed */
      spinlock_t        freed_lock;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#6 lore raw
In reply to a message not in the archive

I think this change could use a little more explanation. I also have some ideas for simplifying the code and making it easier to understand. See comments inline.

But it looks good to me otherwise. Reviewed-by: Felix Kuehling <[email protected]>

Regards,
Felix

Quoted 28 lines · Christian König

From: Christian König <[email protected]>

All users of a VM must always wait for updates with always valid BOs to be completed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
 3 files changed, 21 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -4
index 8aa37e0..d6e66b7 100644
@@ -752,10 +752,6 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	if (r)
 		return r;
 
-	r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_dir_update);
-	if (r)
-		return r;
-
 	r = amdgpu_vm_clear_freed(adev, vm, NULL);
 	if (r)
 		return r;

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) · line 798

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -0
@@ -797,6 +793,10 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 			if (bo_va == NULL)
 				continue;
 
+			if (bo_va->base.bo->flags &
+			    AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
+				continue;

This looks like somewhat unrelated. If you don't make it a separate patch, at least mention it in the change description. Something like:
Always-valid BOs' page table entries are updated by amdgpu_vm_handle_moved. Skip them in amdgpu_bo_vm_update_pte.

Quoted 34 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7 -0
+
 			r = amdgpu_vm_bo_update(adev, bo_va, false);
 			if (r)
 				return r;
@@ -810,6 +810,12 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	}
 
 	r = amdgpu_vm_handle_moved(adev, vm, &p->job->sync);
+	if (r)
+		return r;
+
+	r = amdgpu_sync_fence(adev, &p->job->sync, vm->mandatory_update);
+	if (r)
+		return r;
 
 	if (amdgpu_vm_debug && p->bo_list) {
 		/* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -3
index 55f1ecb..12c8a4c 100644
@@ -1140,9 +1140,8 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
 				goto error_free;
 
 			amdgpu_bo_fence(parent->base.bo, fence, true);
-			dma_fence_put(vm->last_dir_update);
-			vm->last_dir_update = dma_fence_get(fence);
-			dma_fence_put(fence);
+			dma_fence_put(vm->mandatory_update);
+			vm->mandatory_update = fence;
 		}
 	}
 

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6 -0
@@ -1803,6 +1802,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
 			trace_amdgpu_vm_bo_mapping(mapping);
 	}
 
+	if (bo_va->base.bo &&
+	    bo_va->base.bo->tbo.resv == vm->root.base.bo->tbo.resv) {
+		dma_fence_put(vm->mandatory_update);
+		vm->mandatory_update = dma_fence_get(bo_va->last_pt_update);
+	}
+

A suggestion: This could be handled with fewer cryptic conditions littered throughout the code by passing a struct dma_fence **fence parameter to amdgpu_vm_bo_update. When this is called for updating VM BOs (page tables or always valid) in handle_moved, pass vm->mandatory_update as the fence pointer.

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
 	return 0;
 }
 
@@ -2586,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			 vm->use_cpu_for_update ? "CPU" : "SDMA");
 	WARN_ONCE((vm->use_cpu_for_update & !amdgpu_vm_is_large_bar(adev)),
 		  "CPU update of VM recommended only for large BAR system\n");
-	vm->last_dir_update = NULL;
+	vm->mandatory_update = NULL;
 
 	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
 			AMDGPU_GEM_CREATE_VRAM_CLEARED;
@@ -2692,7 +2697,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 	}
 
 	amdgpu_vm_free_levels(&vm->root);
-	dma_fence_put(vm->last_dir_update);
+	dma_fence_put(vm->mandatory_update);
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
 		amdgpu_vm_free_reserved_vmid(adev, vm, i);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index c1accd1..63fa2e5 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 143

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
@@ -140,7 +140,7 @@ struct amdgpu_vm {
 
 	/* contains the page directory */
 	struct amdgpu_vm_pt     root;
-	struct dma_fence	*last_dir_update;
+	struct dma_fence	*mandatory_update;

I'm not sure about this renaming. I don't find the new name clearer than the old one. What's mandatory? The update, or syncing with the fence? I think the name should reflect whatever completes when the fence signals. I can see that last_dir_update is no longer accurate because it also includes other VM-local (always valid) BOs. Maybe last_vm_update?

I'm thinking with the fence pointer idea above, maybe you could get rid of this completely. Just return a fence from each amdgpu_vm_bo_update call and also return that fence from amdgpu_vm_handle_moved. Then amdgpu_bo_vm_update_pte can treat the fences from regular BOs, always valid BOs and page tables all in the same way.

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 146

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
 	/* protecting freed */
 	spinlock_t		freed_lock;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 10b0467a-bb1e-adb4-c999-ad81b5a5e730-5C7GfCeVMHo@public.gmane.org

#8 lore raw

Thanks for the review, please see some comments inline.

Am 08.09.2017 um 23:12 schrieb Felix Kuehling:

Quoted 43 lines

I think this change could use a little more explanation. I also have some ideas for simplifying the code and making it easier to understand. See comments inline.

But it looks good to me otherwise. Reviewed-by: Felix Kuehling <[email protected]>

Regards,
Felix

Quoted 31 lines · Christian König

From: Christian König <[email protected]>

All users of a VM must always wait for updates with always valid BOs to be completed.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
  3 files changed, 21 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -4
index 8aa37e0..d6e66b7 100644
@@ -752,10 +752,6 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
  	if (r)
  		return r;
 
-	r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_dir_update);
-	if (r)
-		return r;
-
  	r = amdgpu_vm_clear_freed(adev, vm, NULL);
  	if (r)
  		return r;
@@ -797,6 +793,10 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
  			if (bo_va == NULL)
  				continue;
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) · line 798

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -0
+			if (bo_va->base.bo->flags &
+			    AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
+				continue;

This looks like somewhat unrelated. If you don't make it a separate patch, at least mention it in the change description. Something like:
Always-valid BOs' page table entries are updated by amdgpu_vm_handle_moved. Skip them in amdgpu_bo_vm_update_pte.

Sorry that was just a leftover from debugging and not intended to be comitted. Chunk is removed in V2.

Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7 -0
+
  			r = amdgpu_vm_bo_update(adev, bo_va, false);
  			if (r)
  				return r;
@@ -810,6 +810,12 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
  	}
 
  	r = amdgpu_vm_handle_moved(adev, vm, &p->job->sync);
+	if (r)
+		return r;
+
+	r = amdgpu_sync_fence(adev, &p->job->sync, vm->mandatory_update);
+	if (r)
+		return r;
 
  	if (amdgpu_vm_debug && p->bo_list) {
  		/* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -3
index 55f1ecb..12c8a4c 100644
@@ -1140,9 +1140,8 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
  				goto error_free;
 
  			amdgpu_bo_fence(parent->base.bo, fence, true);
-			dma_fence_put(vm->last_dir_update);
-			vm->last_dir_update = dma_fence_get(fence);
-			dma_fence_put(fence);
+			dma_fence_put(vm->mandatory_update);
+			vm->mandatory_update = fence;
  		}
  	}
 
@@ -1803,6 +1802,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
  			trace_amdgpu_vm_bo_mapping(mapping);
  	}
 
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6 -0
+	if (bo_va->base.bo &&
+	    bo_va->base.bo->tbo.resv == vm->root.base.bo->tbo.resv) {
+		dma_fence_put(vm->mandatory_update);
+		vm->mandatory_update = dma_fence_get(bo_va->last_pt_update);
+	}
+

A suggestion: This could be handled with fewer cryptic conditions littered throughout the code by passing a struct dma_fence **fence parameter to amdgpu_vm_bo_update. When this is called for updating VM BOs (page tables or always valid) in handle_moved, pass vm->mandatory_update as the fence pointer.

That won't work. We need the fence both in vm->mandatory_update (or whatever we are calling it now) and bo_va->last_pt_update.

Quoted 28 lines
Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
  	return 0;
  }
 
@@ -2586,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  			 vm->use_cpu_for_update ? "CPU" : "SDMA");
  	WARN_ONCE((vm->use_cpu_for_update & !amdgpu_vm_is_large_bar(adev)),
  		  "CPU update of VM recommended only for large BAR system\n");
-	vm->last_dir_update = NULL;
+	vm->mandatory_update = NULL;
 
  	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
  			AMDGPU_GEM_CREATE_VRAM_CLEARED;
@@ -2692,7 +2697,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
  	}
 
  	amdgpu_vm_free_levels(&vm->root);
-	dma_fence_put(vm->last_dir_update);
+	dma_fence_put(vm->mandatory_update);
  	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
  		amdgpu_vm_free_reserved_vmid(adev, vm, i);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index c1accd1..63fa2e5 100644
@@ -140,7 +140,7 @@ struct amdgpu_vm {
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 143

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
  	/* contains the page directory */
  	struct amdgpu_vm_pt     root;
-	struct dma_fence	*last_dir_update;
+	struct dma_fence	*mandatory_update;

I'm not sure about this renaming. I don't find the new name clearer than the old one. What's mandatory? The update, or syncing with the fence? I think the name should reflect whatever completes when the fence signals. I can see that last_dir_update is no longer accurate because it also includes other VM-local (always valid) BOs. Maybe last_vm_update?

I've just named it last_update, cause that it is an VM update should be obvious.

Quoted 5 lines

I'm thinking with the fence pointer idea above, maybe you could get rid of this completely. Just return a fence from each amdgpu_vm_bo_update call and also return that fence from amdgpu_vm_handle_moved. Then amdgpu_bo_vm_update_pte can treat the fences from regular BOs, always valid BOs and page tables all in the same way.

That won't work at all.

See the problem is that we not only need to sync to those updates in the current submission, but also all future submissions.

That's why we should probably getting rid of passing the fences as parameters instead.

Please review V2 as well.

Thanks,
Christian.

Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 146

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
  	/* protecting freed */
  	spinlock_t		freed_lock;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx