[5/5] drm/amd/amdgpu: add check that shadow page tables are GPU-accessible

Submitted by Nicolai Hähnle on Dec. 15, 2016, 5:10 p.m.

Details

Message ID 1481821815-9971-6-git-send-email-nhaehnle@gmail.com
State New
Headers show
Series "drm/ttm, amdgpu: fix crashes due to shadow page table evictions" ( rev: 1 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Nicolai Hähnle Dec. 15, 2016, 5:10 p.m.
From: Nicolai Hähnle <nicolai.haehnle@amd.com>

Skip amdgpu_gem_va_update_vm otherwise. Also clean up the check for the
non-shadow page tables using the new helper function.

This fixes a crash with the stack trace:

amdgpu_gem_va_update_vm
-> amdgpu_vm_update_page_directory
 -> amdgpu_ttm_bind
  -> amdgpu_gtt_mgr_alloc

Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 4e1eb05..d91c80b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -464,26 +464,29 @@  int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
 
 unreserve:
 	amdgpu_bo_unreserve(robj);
 out:
 	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 (!amdgpu_bo_gpu_accessible(bo))
+		return -ERESTARTSYS;
+
+	if (bo->shadow && !amdgpu_bo_gpu_accessible(bo))
+		return -ERESTARTSYS;
 
-	return domain == AMDGPU_GEM_DOMAIN_CPU ? -ERESTARTSYS : 0;
+	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.

Comments

On 2016年12月16日 01:10, Nicolai Hähnle wrote:
> From: Nicolai Hähnle <nicolai.haehnle@amd.com>
>
> Skip amdgpu_gem_va_update_vm otherwise. Also clean up the check for the
> non-shadow page tables using the new helper function.
>
> This fixes a crash with the stack trace:
>
> amdgpu_gem_va_update_vm
> -> amdgpu_vm_update_page_directory
>   -> amdgpu_ttm_bind
>    -> amdgpu_gtt_mgr_alloc
>
> Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 4e1eb05..d91c80b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -464,26 +464,29 @@ int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
>   
>   unreserve:
>   	amdgpu_bo_unreserve(robj);
>   out:
>   	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 (!amdgpu_bo_gpu_accessible(bo))
> +		return -ERESTARTSYS;
> +
> +	if (bo->shadow && !amdgpu_bo_gpu_accessible(bo))

this should be 'if (bo->shadow && !amdgpu_bo_gpu_accessible(bo->shadow))'.

Regards,
David Zhou

> +		return -ERESTARTSYS;
>   
> -	return domain == AMDGPU_GEM_DOMAIN_CPU ? -ERESTARTSYS : 0;
> +	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.