Skip to contentSkip to conversation

drm/amdgpu: grab the id mgr lock while accessing passid_mapping

PATCH In review Christian König 2 participants 3 messages Sep 9, 2019 – Sep 10, 2019 2 messages not in the archive

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

PATCH 1/1 drm/amdgpu: grab the id mgr lock while accessing passid_mapping

Need to make sure that we actually dropping the right fence. Could be done with RCU as well, but to complicated for a fix.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -3
index b285ab25146d..e11764164cbf 100644
@@ -1036,10 +1036,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_
 		id->oa_base != job->oa_base ||
 		id->oa_size != job->oa_size);
 	bool vm_flush_needed = job->vm_needs_flush;
-	bool pasid_mapping_needed = id->pasid != job->pasid ||
-		!id->pasid_mapping ||
-		!dma_fence_is_signaled(id->pasid_mapping);
 	struct dma_fence *fence = NULL;
+	bool pasid_mapping_needed;
 	unsigned patch_offset = 0;
 	int r;
 
@@ -1049,6 +1047,12 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_
 		pasid_mapping_needed = true;
 	}
 
+	mutex_lock(&id_mgr->lock);
+	if (id->pasid != job->pasid || !id->pasid_mapping ||
+	    !dma_fence_is_signaled(id->pasid_mapping))
+		pasid_mapping_needed = true;
+	mutex_unlock(&id_mgr->lock);
+
 	gds_switch_needed &= !!ring->funcs->emit_gds_switch;
 	vm_flush_needed &= !!ring->funcs->emit_vm_flush  &&
 			job->vm_pd_addr != AMDGPU_BO_INVALID_OFFSET;
@@ -1088,9 +1092,11 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_
 	}
 
 	if (pasid_mapping_needed) {
+		mutex_lock(&id_mgr->lock);
 		id->pasid = job->pasid;
 		dma_fence_put(id->pasid_mapping);
 		id->pasid_mapping = dma_fence_get(fence);
+		mutex_unlock(&id_mgr->lock);
 	}
 	dma_fence_put(fence);
 
Signature · 6 lines
2.17.1

_______________________________________________
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): 20190909115908.43755-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Ping!

Am 09.09.19 um 13:59 schrieb Christian König:

Quoted 39 lines

Need to make sure that we actually dropping the right fence. Could be done with RCU as well, but to complicated for a fix.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -3
index b285ab25146d..e11764164cbf 100644
@@ -1036,10 +1036,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_
  		id->oa_base != job->oa_base ||
  		id->oa_size != job->oa_size);
  	bool vm_flush_needed = job->vm_needs_flush;
-	bool pasid_mapping_needed = id->pasid != job->pasid ||
-		!id->pasid_mapping ||
-		!dma_fence_is_signaled(id->pasid_mapping);
  	struct dma_fence *fence = NULL;
+	bool pasid_mapping_needed;
  	unsigned patch_offset = 0;
  	int r;
 
@@ -1049,6 +1047,12 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_
  		pasid_mapping_needed = true;
  	}
 
+	mutex_lock(&id_mgr->lock);
+	if (id->pasid != job->pasid || !id->pasid_mapping ||
+	    !dma_fence_is_signaled(id->pasid_mapping))
+		pasid_mapping_needed = true;
+	mutex_unlock(&id_mgr->lock);
+
  	gds_switch_needed &= !!ring->funcs->emit_gds_switch;
  	vm_flush_needed &= !!ring->funcs->emit_vm_flush  &&
  			job->vm_pd_addr != AMDGPU_BO_INVALID_OFFSET;
@@ -1088,9 +1092,11 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_
  	}

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_ · line 1102

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
 
  	if (pasid_mapping_needed) {
+		mutex_lock(&id_mgr->lock);
  		id->pasid = job->pasid;
  		dma_fence_put(id->pasid_mapping);
  		id->pasid_mapping = dma_fence_get(fence);
+		mutex_unlock(&id_mgr->lock);
  	}
  	dma_fence_put(fence);
 

_______________________________________________
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): 65fe177d-e9fb-3eeb-b77a-479c92dcae6d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

Reviewed-by
#4 lore raw
Quoted 49 lines · Christian König

Ping!

Am 09.09.19 um 13:59 schrieb Christian König:

Quoted 46 lines

Need to make sure that we actually dropping the right fence. Could be done with RCU as well, but to complicated for a fix.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 12 +++++++++---

  1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index b285ab25146d..e11764164cbf 100644
@@ -1036,10 +1036,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, 

struct amdgpu_job *job, bool need_
          id->oa_base != job->oa_base ||
          id->oa_size != job->oa_size);
      bool vm_flush_needed = job->vm_needs_flush;
-    bool pasid_mapping_needed = id->pasid != job->pasid || -        !id->pasid_mapping ||
-        !dma_fence_is_signaled(id->pasid_mapping); struct dma_fence *fence = NULL;
+    bool pasid_mapping_needed;
      unsigned patch_offset = 0;
      int r;
  @@ -1049,6 +1047,12 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, bool need_ pasid_mapping_needed = true;
      }
  +    mutex_lock(&id_mgr->lock);
+    if (id->pasid != job->pasid || !id->pasid_mapping || +        !dma_fence_is_signaled(id->pasid_mapping))
+        pasid_mapping_needed = true;
+    mutex_unlock(&id_mgr->lock);
+
      gds_switch_needed &= !!ring->funcs->emit_gds_switch; vm_flush_needed &= !!ring->funcs->emit_vm_flush && job->vm_pd_addr != AMDGPU_BO_INVALID_OFFSET;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -1088,9 +1092,11 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, 

struct amdgpu_job *job, bool need_
      }
        if (pasid_mapping_needed) {
+        mutex_lock(&id_mgr->lock); id->pasid = job->pasid; dma_fence_put(id->pasid_mapping); id->pasid_mapping = dma_fence_get(fence);

Quoted 8 lines
Quoted 3 lines

+        mutex_unlock(&id_mgr->lock);
      }
      dma_fence_put(fence);

_______________________________________________
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