diff mbox series

drm/ttm: move bo->resource check in vm_access

Message ID 20220930153957.416938-1-matthew.auld@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/ttm: move bo->resource check in vm_access | expand

Commit Message

Matthew Auld Sept. 30, 2022, 3:39 p.m. UTC
Touching bo->resource looks like it should require first locking the
object, since this state is dynamic and could potentially change from
under us.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Christian König Sept. 30, 2022, 6:15 p.m. UTC | #1
Am 30.09.22 um 17:39 schrieb Matthew Auld:
> Touching bo->resource looks like it should require first locking the
> object, since this state is dynamic and could potentially change from
> under us.
>
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Christian König <christian.koenig@amd.com>


> ---
>   drivers/gpu/drm/ttm/ttm_bo_vm.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index 38119311284d..8a0de14d8c85 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -412,13 +412,15 @@ int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
>   		 << PAGE_SHIFT);
>   	int ret;
>   
> -	if (len < 1 || (offset + len) >> PAGE_SHIFT > bo->resource->num_pages)
> -		return -EIO;
> -

Alternatively I think checking bo->base.size instead would probably be 
better.

Either way the patch is  Reviewed-by: Christian König 
<christian.koenig@amd.com>

Christian.

>   	ret = ttm_bo_reserve(bo, true, false, NULL);
>   	if (ret)
>   		return ret;
>   
> +	if (len < 1 || (offset + len) >> PAGE_SHIFT > bo->resource->num_pages) {
> +		ret = -EIO;
> +		goto out_reserve;
> +	}
> +
>   	switch (bo->resource->mem_type) {
>   	case TTM_PL_SYSTEM:
>   		fallthrough;
> @@ -433,6 +435,7 @@ int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
>   			ret = -EIO;
>   	}
>   
> +out_reserve:
>   	ttm_bo_unreserve(bo);
>   
>   	return ret;
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 38119311284d..8a0de14d8c85 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -412,13 +412,15 @@  int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
 		 << PAGE_SHIFT);
 	int ret;
 
-	if (len < 1 || (offset + len) >> PAGE_SHIFT > bo->resource->num_pages)
-		return -EIO;
-
 	ret = ttm_bo_reserve(bo, true, false, NULL);
 	if (ret)
 		return ret;
 
+	if (len < 1 || (offset + len) >> PAGE_SHIFT > bo->resource->num_pages) {
+		ret = -EIO;
+		goto out_reserve;
+	}
+
 	switch (bo->resource->mem_type) {
 	case TTM_PL_SYSTEM:
 		fallthrough;
@@ -433,6 +435,7 @@  int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
 			ret = -EIO;
 	}
 
+out_reserve:
 	ttm_bo_unreserve(bo);
 
 	return ret;