Skip to contentSkip to conversation

drm/amd/amdgpu: skip amdgpu_gem_va_update_vm when shadow page tables are swapped out

PATCH In review Nicolai Hähnle 2 participants 3 messages Dec 12, 2016 2 messages not in the archive

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

PATCH 1/2 drm/amd/amdgpu: skip amdgpu_gem_va_update_vm when shadow page tables are swapped out

From: Nicolai Hähnle <[email protected]>

This fixes a crash with the following stack trace:

amdgpu_gtt_mgr_alloc
amdgpu_ttm_bind
amdgpu_vm_update_page_directory
amdgpu_gem_va_update_vm

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +9 -1
index cd62f6f..fbfbe5a 100644
@@ -468,22 +468,30 @@ int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
 	drm_gem_object_unreference_unlocked(gobj);
 	return r;
 }
 
 static int amdgpu_gem_va_check(void *param, struct amdgpu_bo *bo)
 {
 	unsigned domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
 
 	/* if anything is swapped out don't swap it in here,
 	   just abort and wait for the next CS */
+	if (domain == AMDGPU_GEM_DOMAIN_CPU)
+		return -ERESTARTSYS;
 
-	return domain == AMDGPU_GEM_DOMAIN_CPU ? -ERESTARTSYS : 0;
+	if (bo->shadow) {
+		domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
+		if (domain == AMDGPU_GEM_DOMAIN_CPU)
+			return -ERESTARTSYS;
+	}
+
+	return 0;
 }
 
 /**
  * amdgpu_gem_va_update_vm -update the bo_va in its VM
  *
  * @adev: amdgpu_device pointer
  * @bo_va: bo_va to update
  *
  * Update the bo_va directly after setting it's address. Errors are not
  * vital here, so they are not reported back to userspace.
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): 1481555054-27405-1-git-send-email-nhaehnle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amd/amdgpu: skip amdgpu_gem_va_update_vm when shadow page directory is swapped out

From: Nicolai Hähnle <[email protected]>

This fixes a crash with the following stack trace:

amdgpu_gtt_mgr_alloc
amdgpu_ttm_bind
amdgpu_vm_update_page_directory
amdgpu_gem_va_update_vm

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +11 -0
index fbfbe5a..ffb3e70 100644
@@ -495,20 +495,21 @@ static int amdgpu_gem_va_check(void *param, struct amdgpu_bo *bo)
  *
  * Update the bo_va directly after setting it's address. Errors are not
  * vital here, so they are not reported back to userspace.
  */
 static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 				    struct amdgpu_bo_va *bo_va,
 				    uint32_t operation)
 {
 	struct ttm_validate_buffer tv, *entry;
 	struct amdgpu_bo_list_entry vm_pd;
+	struct amdgpu_bo *pd_shadow;
 	struct ww_acquire_ctx ticket;
 	struct list_head list, duplicates;
 	unsigned domain;
 	int r;
 
 	INIT_LIST_HEAD(&list);
 	INIT_LIST_HEAD(&duplicates);
 
 	tv.bo = &bo_va->bo->tbo;
 	tv.shared = true;
@@ -521,20 +522,30 @@ static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 	if (r)
 		goto error_print;
 
 	list_for_each_entry(entry, &list, head) {
 		domain = amdgpu_mem_type_to_domain(entry->bo->mem.mem_type);
 		/* if anything is swapped out don't swap it in here,
 		   just abort and wait for the next CS */
 		if (domain == AMDGPU_GEM_DOMAIN_CPU)
 			goto error_unreserve;
 	}
+
+	/* Also abort if the page directory shadow has been swapped out. */
+	pd_shadow = bo_va->vm->page_directory->shadow;
+	if (pd_shadow) {
+		domain = amdgpu_mem_type_to_domain(pd_shadow->tbo.mem.mem_type);
+
+		if (domain == AMDGPU_GEM_DOMAIN_CPU)
+			goto error_unreserve;
+	}
+
 	r = amdgpu_vm_validate_pt_bos(adev, bo_va->vm, amdgpu_gem_va_check,
 				      NULL);
 	if (r)
 		goto error_unreserve;
 
 	r = amdgpu_vm_update_page_directory(adev, bo_va->vm);
 	if (r)
 		goto error_unreserve;
 
 	r = amdgpu_vm_clear_freed(adev, bo_va->vm);
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): 1481555054-27405-2-git-send-email-nhaehnle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/amd/amdgpu: skip amdgpu_gem_va_update_vm when shadow page directory is swapped out

Am 12.12.2016 um 16:04 schrieb Nicolai Hähnle:

Quoted 41 lines

From: Nicolai Hähnle <[email protected]>

This fixes a crash with the following stack trace:

amdgpu_gtt_mgr_alloc
amdgpu_ttm_bind
amdgpu_vm_update_page_directory
amdgpu_gem_va_update_vm

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index fbfbe5a..ffb3e70 100644
@@ -495,20 +495,21 @@ static int amdgpu_gem_va_check(void *param, struct amdgpu_bo *bo)
   *
   * Update the bo_va directly after setting it's address. Errors are not
   * vital here, so they are not reported back to userspace.
   */
  static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
  				    struct amdgpu_bo_va *bo_va,
  				    uint32_t operation)
  {
  	struct ttm_validate_buffer tv, *entry;
  	struct amdgpu_bo_list_entry vm_pd;
+	struct amdgpu_bo *pd_shadow;
  	struct ww_acquire_ctx ticket;
  	struct list_head list, duplicates;
  	unsigned domain;
  	int r;
 
  	INIT_LIST_HEAD(&list);
  	INIT_LIST_HEAD(&duplicates);
 
  	tv.bo = &bo_va->bo->tbo;
  	tv.shared = true;

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev, · line 530

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
@@ -521,20 +522,30 @@ static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
  	if (r)
  		goto error_print;
 
  	list_for_each_entry(entry, &list, head) {
  		domain = amdgpu_mem_type_to_domain(entry->bo->mem.mem_type);
  		/* if anything is swapped out don't swap it in here,
  		   just abort and wait for the next CS */
  		if (domain == AMDGPU_GEM_DOMAIN_CPU)
  			goto error_unreserve;

I would just do the check in this loop instead of down below specialized for the page directory.

We have only two entries in the list anyway and I actually would suggest to have something like a amdgpu_bo_swapped_out() or amdgpu_bo_gpu_accessible() helper in amdgpu_object.h.

Regards,
Christian.

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10 -0
  	}
+
+	/* Also abort if the page directory shadow has been swapped out. */
+	pd_shadow = bo_va->vm->page_directory->shadow;
+	if (pd_shadow) {
+		domain = amdgpu_mem_type_to_domain(pd_shadow->tbo.mem.mem_type);
+
+		if (domain == AMDGPU_GEM_DOMAIN_CPU)
+			goto error_unreserve;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev, · line 551

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
  	r = amdgpu_vm_validate_pt_bos(adev, bo_va->vm, amdgpu_gem_va_check,
  				      NULL);
  	if (r)
  		goto error_unreserve;
 
  	r = amdgpu_vm_update_page_directory(adev, bo_va->vm);
  	if (r)
  		goto error_unreserve;
 
  	r = amdgpu_vm_clear_freed(adev, bo_va->vm);

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