[Intel-gfx] [PATCH v3 02/12] drm/ttm: move ttm_tt_{add, clear}_mapping into amdgpu

Christian König christian.koenig at amd.com
Thu Sep 16 06:45:06 UTC 2021



Am 15.09.21 um 20:59 schrieb Matthew Auld:
> Now that setting page->index shouldn't be needed anymore, we are just
> left with setting page->mapping, and here it looks like amdgpu is the
> only user, where pointing the page->mapping at the dev_mapping is used
> to verify that the pages do indeed belong to the device, if userspace
> later tries to touch them.
>
> Signed-off-by: Matthew Auld <matthew.auld at intel.com>
> Cc: Thomas Hellström <thomas.hellstrom at linux.intel.com>
> Cc: Christian König <christian.koenig at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 27 ++++++++++++++++++++++++-
>   drivers/gpu/drm/ttm/ttm_tt.c            | 25 -----------------------
>   2 files changed, 26 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 1129e17e9f09..c5fa6e62f6ca 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1107,6 +1107,24 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_buffer_object *bo,
>   	return &gtt->ttm;
>   }
>   
> +static void amdgpu_ttm_tt_add_mapping(struct ttm_device *bdev,
> +				      struct ttm_tt *ttm)
> +{
> +	pgoff_t i;
> +
> +	for (i = 0; i < ttm->num_pages; ++i)
> +		ttm->pages[i]->mapping = bdev->dev_mapping;
> +}
> +
> +static void amdgpu_ttm_tt_clear_mapping(struct ttm_tt *ttm)
> +{
> +	struct page **page = ttm->pages;
> +	pgoff_t i;
> +
> +	for (i = 0; i < ttm->num_pages; ++i)
> +		(*page)->mapping = NULL;
> +}
> +
>   /*
>    * amdgpu_ttm_tt_populate - Map GTT pages visible to the device
>    *
> @@ -1119,6 +1137,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev,
>   {
>   	struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
>   	struct amdgpu_ttm_tt *gtt = (void *)ttm;
> +	int ret;
>   
>   	/* user pages are bound by amdgpu_ttm_tt_pin_userptr() */
>   	if (gtt->userptr) {
> @@ -1131,7 +1150,12 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev,
>   	if (ttm->page_flags & TTM_PAGE_FLAG_SG)
>   		return 0;
>   
> -	return ttm_pool_alloc(&adev->mman.bdev.pool, ttm, ctx);
> +	ret = ttm_pool_alloc(&adev->mman.bdev.pool, ttm, ctx);
> +	if (ret)
> +		return ret;
> +
> +	amdgpu_ttm_tt_add_mapping(bdev, ttm);

I don't really see why this needs to be a separate function. Just inline 
the loop here.

> +	return 0;
>   }
>   
>   /*
> @@ -1159,6 +1183,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev,
>   		return;
>   
>   	adev = amdgpu_ttm_adev(bdev);
> +	amdgpu_ttm_tt_clear_mapping(ttm);

Same here of course, apart from that looks good to me.

Christian.

>   	return ttm_pool_free(&adev->mman.bdev.pool, ttm);
>   }
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> index 1cc04c224988..980ecb079b2c 100644
> --- a/drivers/gpu/drm/ttm/ttm_tt.c
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> @@ -289,17 +289,6 @@ int ttm_tt_swapout(struct ttm_device *bdev, struct ttm_tt *ttm,
>   	return ret;
>   }
>   
> -static void ttm_tt_add_mapping(struct ttm_device *bdev, struct ttm_tt *ttm)
> -{
> -	pgoff_t i;
> -
> -	if (ttm->page_flags & TTM_PAGE_FLAG_SG)
> -		return;
> -
> -	for (i = 0; i < ttm->num_pages; ++i)
> -		ttm->pages[i]->mapping = bdev->dev_mapping;
> -}
> -
>   int ttm_tt_populate(struct ttm_device *bdev,
>   		    struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>   {
> @@ -336,7 +325,6 @@ int ttm_tt_populate(struct ttm_device *bdev,
>   	if (ret)
>   		goto error;
>   
> -	ttm_tt_add_mapping(bdev, ttm);
>   	ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
>   	if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
>   		ret = ttm_tt_swapin(ttm);
> @@ -359,24 +347,11 @@ int ttm_tt_populate(struct ttm_device *bdev,
>   }
>   EXPORT_SYMBOL(ttm_tt_populate);
>   
> -static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
> -{
> -	pgoff_t i;
> -	struct page **page = ttm->pages;
> -
> -	if (ttm->page_flags & TTM_PAGE_FLAG_SG)
> -		return;
> -
> -	for (i = 0; i < ttm->num_pages; ++i)
> -		(*page)->mapping = NULL;
> -}
> -
>   void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
>   {
>   	if (!ttm_tt_is_populated(ttm))
>   		return;
>   
> -	ttm_tt_clear_mapping(ttm);
>   	if (bdev->funcs->ttm_tt_unpopulate)
>   		bdev->funcs->ttm_tt_unpopulate(bdev, ttm);
>   	else



More information about the Intel-gfx mailing list