diff mbox series

[1/6] drm/ttm: rename and cleanup ttm_bo_init_reserved

Message ID 20220707102453.3633-2-christian.koenig@amd.com (mailing list archive)
State New, archived
Headers show
Series [1/6] drm/ttm: rename and cleanup ttm_bo_init_reserved | expand

Commit Message

Christian König July 7, 2022, 10:24 a.m. UTC
Rename ttm_bo_init_reserved to ttm_bo_init_validate since that better
matches what the function is actually doing.

Remove the unused size parameter, move the function's kerneldoc to the
implementation and cleanup the whole error handling.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |   2 +-
 drivers/gpu/drm/drm_gem_vram_helper.c      |   6 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c    |   5 +-
 drivers/gpu/drm/nouveau/nouveau_bo.c       |   6 +-
 drivers/gpu/drm/qxl/qxl_object.c           |   2 +-
 drivers/gpu/drm/radeon/radeon_object.c     |   6 +-
 drivers/gpu/drm/ttm/ttm_bo.c               | 147 +++++++++++++++------
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         |  12 +-
 include/drm/ttm/ttm_bo_api.h               |  93 ++-----------
 9 files changed, 129 insertions(+), 150 deletions(-)

Comments

Christian König July 7, 2022, 10:35 a.m. UTC | #1
Am 07.07.22 um 12:24 schrieb Christian König:
> Rename ttm_bo_init_reserved to ttm_bo_init_validate since that better

Ah, crap. Here is a typo, that should read "Rename ttm_bo_init to 
ttm_bo_init_validate"....

Please ignore during review,
Christian.

> matches what the function is actually doing.
>
> Remove the unused size parameter, move the function's kerneldoc to the
> implementation and cleanup the whole error handling.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |   2 +-
>   drivers/gpu/drm/drm_gem_vram_helper.c      |   6 +-
>   drivers/gpu/drm/i915/gem/i915_gem_ttm.c    |   5 +-
>   drivers/gpu/drm/nouveau/nouveau_bo.c       |   6 +-
>   drivers/gpu/drm/qxl/qxl_object.c           |   2 +-
>   drivers/gpu/drm/radeon/radeon_object.c     |   6 +-
>   drivers/gpu/drm/ttm/ttm_bo.c               | 147 +++++++++++++++------
>   drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         |  12 +-
>   include/drm/ttm/ttm_bo_api.h               |  93 ++-----------
>   9 files changed, 129 insertions(+), 150 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 2c82b1d5a0d7..d9cfe259f2a9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -591,7 +591,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
>   	if (!bp->destroy)
>   		bp->destroy = &amdgpu_bo_destroy;
>   
> -	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type,
> +	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, bp->type,
>   				 &bo->placement, page_align, &ctx,  NULL,
>   				 bp->resv, bp->destroy);
>   	if (unlikely(r != 0))
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index d607043716d3..125160b534be 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -226,9 +226,9 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev,
>   	 * A failing ttm_bo_init will call ttm_buffer_object_destroy
>   	 * to release gbo->bo.base and kfree gbo.
>   	 */
> -	ret = ttm_bo_init(bdev, &gbo->bo, size, ttm_bo_type_device,
> -			  &gbo->placement, pg_align, false, NULL, NULL,
> -			  ttm_buffer_object_destroy);
> +	ret = ttm_bo_init_validate(bdev, &gbo->bo, ttm_bo_type_device,
> +				   &gbo->placement, pg_align, false, NULL, NULL,
> +				   ttm_buffer_object_destroy);
>   	if (ret)
>   		return ERR_PTR(ret);
>   
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> index 4c25d9b2f138..70e2ed4e99df 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> @@ -1229,9 +1229,8 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
>   	 * Similarly, in delayed_destroy, we can't call ttm_bo_put()
>   	 * until successful initialization.
>   	 */
> -	ret = ttm_bo_init_reserved(&i915->bdev, i915_gem_to_ttm(obj), size,
> -				   bo_type, &i915_sys_placement,
> -				   page_size >> PAGE_SHIFT,
> +	ret = ttm_bo_init_reserved(&i915->bdev, i915_gem_to_ttm(obj), bo_type,
> +				   &i915_sys_placement, page_size >> PAGE_SHIFT,
>   				   &ctx, NULL, NULL, i915_ttm_bo_destroy);
>   	if (ret)
>   		return i915_ttm_err_to_gem(ret);
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 05076e530e7d..92cd19021084 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -307,9 +307,9 @@ nouveau_bo_init(struct nouveau_bo *nvbo, u64 size, int align, u32 domain,
>   	nouveau_bo_placement_set(nvbo, domain, 0);
>   	INIT_LIST_HEAD(&nvbo->io_reserve_lru);
>   
> -	ret = ttm_bo_init(nvbo->bo.bdev, &nvbo->bo, size, type,
> -			  &nvbo->placement, align >> PAGE_SHIFT, false, sg,
> -			  robj, nouveau_bo_del_ttm);
> +	ret = ttm_bo_init_validate(nvbo->bo.bdev, &nvbo->bo, type,
> +				   &nvbo->placement, align >> PAGE_SHIFT, false,
> +				   sg, robj, nouveau_bo_del_ttm);
>   	if (ret) {
>   		/* ttm will call nouveau_bo_del_ttm if it fails.. */
>   		return ret;
> diff --git a/drivers/gpu/drm/qxl/qxl_object.c b/drivers/gpu/drm/qxl/qxl_object.c
> index b42a657e4c2f..695d9308d1f0 100644
> --- a/drivers/gpu/drm/qxl/qxl_object.c
> +++ b/drivers/gpu/drm/qxl/qxl_object.c
> @@ -141,7 +141,7 @@ int qxl_bo_create(struct qxl_device *qdev, unsigned long size,
>   	qxl_ttm_placement_from_domain(bo, domain);
>   
>   	bo->tbo.priority = priority;
> -	r = ttm_bo_init_reserved(&qdev->mman.bdev, &bo->tbo, size, type,
> +	r = ttm_bo_init_reserved(&qdev->mman.bdev, &bo->tbo, type,
>   				 &bo->placement, 0, &ctx, NULL, NULL,
>   				 &qxl_ttm_bo_destroy);
>   	if (unlikely(r != 0)) {
> diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
> index 6c4a6802ca96..00c33b24d5d3 100644
> --- a/drivers/gpu/drm/radeon/radeon_object.c
> +++ b/drivers/gpu/drm/radeon/radeon_object.c
> @@ -202,9 +202,9 @@ int radeon_bo_create(struct radeon_device *rdev,
>   	radeon_ttm_placement_from_domain(bo, domain);
>   	/* Kernel allocation are uninterruptible */
>   	down_read(&rdev->pm.mclk_lock);
> -	r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
> -			&bo->placement, page_align, !kernel, sg, resv,
> -			&radeon_ttm_bo_destroy);
> +	r = ttm_bo_init_validate(&rdev->mman.bdev, &bo->tbo, type,
> +				 &bo->placement, page_align, !kernel, sg, resv,
> +				 &radeon_ttm_bo_destroy);
>   	up_read(&rdev->pm.mclk_lock);
>   	if (unlikely(r != 0)) {
>   		return r;
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 0e210df65c30..984535d6a2d0 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -921,36 +921,61 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
>   }
>   EXPORT_SYMBOL(ttm_bo_validate);
>   
> -int ttm_bo_init_reserved(struct ttm_device *bdev,
> -			 struct ttm_buffer_object *bo,
> -			 size_t size,
> -			 enum ttm_bo_type type,
> -			 struct ttm_placement *placement,
> -			 uint32_t page_alignment,
> -			 struct ttm_operation_ctx *ctx,
> -			 struct sg_table *sg,
> -			 struct dma_resv *resv,
> +/**
> + * ttm_bo_init_validate
> + *
> + * @bdev: Pointer to a ttm_device struct.
> + * @bo: Pointer to a ttm_buffer_object to be initialized.
> + * @type: Requested type of buffer object.
> + * @placement: Initial placement for buffer object.
> + * @alignment: Data alignment in pages.
> + * @ctx: TTM operation context for memory allocation.
> + * @sg: Scatter-gather table.
> + * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
> + * @destroy: Destroy function. Use NULL for kfree().
> + *
> + * This function initializes a pre-allocated struct ttm_buffer_object.
> + * As this object may be part of a larger structure, this function,
> + * together with the @destroy function, enables driver-specific objects
> + * derived from a ttm_buffer_object.
> + *
> + * On successful return, the caller owns an object kref to @bo. The kref and
> + * list_kref are usually set to 1, but note that in some situations, other
> + * tasks may already be holding references to @bo as well.
> + * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
> + * and it is the caller's responsibility to call ttm_bo_unreserve.
> + *
> + * If a failure occurs, the function will call the @destroy function. Thus,
> + * after a failure, dereferencing @bo is illegal and will likely cause memory
> + * corruption.
> + *
> + * Returns
> + * -ENOMEM: Out of memory.
> + * -EINVAL: Invalid placement flags.
> + * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
> + */
> +int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
> +			 enum ttm_bo_type type, struct ttm_placement *placement,
> +			 uint32_t alignment, struct ttm_operation_ctx *ctx,
> +			 struct sg_table *sg, struct dma_resv *resv,
>   			 void (*destroy) (struct ttm_buffer_object *))
>   {
>   	static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
> -	bool locked;
>   	int ret;
>   
> -	bo->destroy = destroy;
>   	kref_init(&bo->kref);
>   	INIT_LIST_HEAD(&bo->ddestroy);
>   	bo->bdev = bdev;
>   	bo->type = type;
> -	bo->page_alignment = page_alignment;
> +	bo->page_alignment = alignment;
> +	bo->destroy = destroy;
>   	bo->pin_count = 0;
>   	bo->sg = sg;
>   	bo->bulk_move = NULL;
> -	if (resv) {
> +	if (resv)
>   		bo->base.resv = resv;
> -		dma_resv_assert_held(bo->base.resv);
> -	} else {
> +	else
>   		bo->base.resv = &bo->base._resv;
> -	}
>   	atomic_inc(&ttm_glob.bo_count);
>   
>   	ret = ttm_resource_alloc(bo, &sys_mem, &bo->resource);
> @@ -963,50 +988,84 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
>   	 * For ttm_bo_type_device buffers, allocate
>   	 * address space from the device.
>   	 */
> -	if (bo->type == ttm_bo_type_device ||
> -	    bo->type == ttm_bo_type_sg)
> +	if (bo->type == ttm_bo_type_device || bo->type == ttm_bo_type_sg) {
>   		ret = drm_vma_offset_add(bdev->vma_manager, &bo->base.vma_node,
> -					 bo->resource->num_pages);
> +					 PFN_UP(bo->base.size));
> +		if (ret)
> +			goto err_put;
> +	}
>   
>   	/* passed reservation objects should already be locked,
>   	 * since otherwise lockdep will be angered in radeon.
>   	 */
> -	if (!resv) {
> -		locked = dma_resv_trylock(bo->base.resv);
> -		WARN_ON(!locked);
> -	}
> +	if (!resv)
> +		WARN_ON(!dma_resv_trylock(bo->base.resv));
> +	else
> +		dma_resv_assert_held(resv);
>   
> -	if (likely(!ret))
> -		ret = ttm_bo_validate(bo, placement, ctx);
> +	ret = ttm_bo_validate(bo, placement, ctx);
> +	if (unlikely(ret))
> +		goto err_unlock;
>   
> -	if (unlikely(ret)) {
> -		if (!resv)
> -			ttm_bo_unreserve(bo);
> +	return 0;
>   
> -		ttm_bo_put(bo);
> -		return ret;
> -	}
> +err_unlock:
> +	if (!resv)
> +		dma_resv_unlock(bo->base.resv);
>   
> +err_put:
> +	ttm_bo_put(bo);
>   	return ret;
>   }
>   EXPORT_SYMBOL(ttm_bo_init_reserved);
>   
> -int ttm_bo_init(struct ttm_device *bdev,
> -		struct ttm_buffer_object *bo,
> -		size_t size,
> -		enum ttm_bo_type type,
> -		struct ttm_placement *placement,
> -		uint32_t page_alignment,
> -		bool interruptible,
> -		struct sg_table *sg,
> -		struct dma_resv *resv,
> -		void (*destroy) (struct ttm_buffer_object *))
> +/**
> + * ttm_bo_init_validate
> + *
> + * @bdev: Pointer to a ttm_device struct.
> + * @bo: Pointer to a ttm_buffer_object to be initialized.
> + * @type: Requested type of buffer object.
> + * @placement: Initial placement for buffer object.
> + * @alignment: Data alignment in pages.
> + * @interruptible: If needing to sleep to wait for GPU resources,
> + * sleep interruptible.
> + * pinned in physical memory. If this behaviour is not desired, this member
> + * holds a pointer to a persistent shmem object. Typically, this would
> + * point to the shmem object backing a GEM object if TTM is used to back a
> + * GEM user interface.
> + * @sg: Scatter-gather table.
> + * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
> + * @destroy: Destroy function. Use NULL for kfree().
> + *
> + * This function initializes a pre-allocated struct ttm_buffer_object.
> + * As this object may be part of a larger structure, this function,
> + * together with the @destroy function,
> + * enables driver-specific objects derived from a ttm_buffer_object.
> + *
> + * On successful return, the caller owns an object kref to @bo. The kref and
> + * list_kref are usually set to 1, but note that in some situations, other
> + * tasks may already be holding references to @bo as well.
> + *
> + * If a failure occurs, the function will call the @destroy function, Thus,
> + * after a failure, dereferencing @bo is illegal and will likely cause memory
> + * corruption.
> + *
> + * Returns
> + * -ENOMEM: Out of memory.
> + * -EINVAL: Invalid placement flags.
> + * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
> + */
> +int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo,
> +			 enum ttm_bo_type type, struct ttm_placement *placement,
> +			 uint32_t alignment, bool interruptible,
> +			 struct sg_table *sg, struct dma_resv *resv,
> +			 void (*destroy) (struct ttm_buffer_object *))
>   {
>   	struct ttm_operation_ctx ctx = { interruptible, false };
>   	int ret;
>   
> -	ret = ttm_bo_init_reserved(bdev, bo, size, type, placement,
> -				   page_alignment, &ctx, sg, resv, destroy);
> +	ret = ttm_bo_init_reserved(bdev, bo, type, placement, alignment, &ctx,
> +				   sg, resv, destroy);
>   	if (ret)
>   		return ret;
>   
> @@ -1015,7 +1074,7 @@ int ttm_bo_init(struct ttm_device *bdev,
>   
>   	return 0;
>   }
> -EXPORT_SYMBOL(ttm_bo_init);
> +EXPORT_SYMBOL(ttm_bo_init_validate);
>   
>   /*
>    * buffer object vm functions.
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> index 85a66014c2b6..eb2fd7694cd1 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> @@ -429,9 +429,9 @@ int vmw_bo_create_kernel(struct vmw_private *dev_priv, unsigned long size,
>   
>   	drm_gem_private_object_init(vdev, &bo->base, size);
>   
> -	ret = ttm_bo_init_reserved(&dev_priv->bdev, bo, size,
> -				   ttm_bo_type_kernel, placement, 0,
> -				   &ctx, NULL, NULL, vmw_bo_default_destroy);
> +	ret = ttm_bo_init_reserved(&dev_priv->bdev, bo, ttm_bo_type_kernel,
> +				   placement, 0, &ctx, NULL, NULL,
> +				   vmw_bo_default_destroy);
>   	if (unlikely(ret))
>   		goto error_free;
>   
> @@ -512,10 +512,8 @@ int vmw_bo_init(struct vmw_private *dev_priv,
>   	size = ALIGN(size, PAGE_SIZE);
>   	drm_gem_private_object_init(vdev, &vmw_bo->base.base, size);
>   
> -	ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, size,
> -				   ttm_bo_type_device,
> -				   placement,
> -				   0, &ctx, NULL, NULL, bo_free);
> +	ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, ttm_bo_type_device,
> +				   placement, 0, &ctx, NULL, NULL, bo_free);
>   	if (unlikely(ret)) {
>   		return ret;
>   	}
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 2d524f8b0802..44a538ee5e2a 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -317,93 +317,16 @@ void ttm_bo_unlock_delayed_workqueue(struct ttm_device *bdev, int resched);
>   bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
>   			      const struct ttm_place *place);
>   
> -/**
> - * ttm_bo_init_reserved
> - *
> - * @bdev: Pointer to a ttm_device struct.
> - * @bo: Pointer to a ttm_buffer_object to be initialized.
> - * @size: Requested size of buffer object.
> - * @type: Requested type of buffer object.
> - * @placement: Initial placement for buffer object.
> - * @page_alignment: Data alignment in pages.
> - * @ctx: TTM operation context for memory allocation.
> - * @sg: Scatter-gather table.
> - * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
> - * @destroy: Destroy function. Use NULL for kfree().
> - *
> - * This function initializes a pre-allocated struct ttm_buffer_object.
> - * As this object may be part of a larger structure, this function,
> - * together with the @destroy function,
> - * enables driver-specific objects derived from a ttm_buffer_object.
> - *
> - * On successful return, the caller owns an object kref to @bo. The kref and
> - * list_kref are usually set to 1, but note that in some situations, other
> - * tasks may already be holding references to @bo as well.
> - * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
> - * and it is the caller's responsibility to call ttm_bo_unreserve.
> - *
> - * If a failure occurs, the function will call the @destroy function, or
> - * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
> - * illegal and will likely cause memory corruption.
> - *
> - * Returns
> - * -ENOMEM: Out of memory.
> - * -EINVAL: Invalid placement flags.
> - * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
> - */
> -
> -int ttm_bo_init_reserved(struct ttm_device *bdev,
> -			 struct ttm_buffer_object *bo,
> -			 size_t size, enum ttm_bo_type type,
> -			 struct ttm_placement *placement,
> -			 uint32_t page_alignment,
> -			 struct ttm_operation_ctx *ctx,
> +int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
> +			 enum ttm_bo_type type, struct ttm_placement *placement,
> +			 uint32_t alignment, struct ttm_operation_ctx *ctx,
> +			 struct sg_table *sg, struct dma_resv *resv,
> +			 void (*destroy) (struct ttm_buffer_object *));
> +int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo,
> +			 enum ttm_bo_type type, struct ttm_placement *placement,
> +			 uint32_t alignment, bool interruptible,
>   			 struct sg_table *sg, struct dma_resv *resv,
>   			 void (*destroy) (struct ttm_buffer_object *));
> -
> -/**
> - * ttm_bo_init
> - *
> - * @bdev: Pointer to a ttm_device struct.
> - * @bo: Pointer to a ttm_buffer_object to be initialized.
> - * @size: Requested size of buffer object.
> - * @type: Requested type of buffer object.
> - * @placement: Initial placement for buffer object.
> - * @page_alignment: Data alignment in pages.
> - * @interruptible: If needing to sleep to wait for GPU resources,
> - * sleep interruptible.
> - * pinned in physical memory. If this behaviour is not desired, this member
> - * holds a pointer to a persistent shmem object. Typically, this would
> - * point to the shmem object backing a GEM object if TTM is used to back a
> - * GEM user interface.
> - * @sg: Scatter-gather table.
> - * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
> - * @destroy: Destroy function. Use NULL for kfree().
> - *
> - * This function initializes a pre-allocated struct ttm_buffer_object.
> - * As this object may be part of a larger structure, this function,
> - * together with the @destroy function,
> - * enables driver-specific objects derived from a ttm_buffer_object.
> - *
> - * On successful return, the caller owns an object kref to @bo. The kref and
> - * list_kref are usually set to 1, but note that in some situations, other
> - * tasks may already be holding references to @bo as well.
> - *
> - * If a failure occurs, the function will call the @destroy function, or
> - * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
> - * illegal and will likely cause memory corruption.
> - *
> - * Returns
> - * -ENOMEM: Out of memory.
> - * -EINVAL: Invalid placement flags.
> - * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
> - */
> -int ttm_bo_init(struct ttm_device *bdev, struct ttm_buffer_object *bo,
> -		size_t size, enum ttm_bo_type type,
> -		struct ttm_placement *placement,
> -		uint32_t page_alignment, bool interrubtible,
> -		struct sg_table *sg, struct dma_resv *resv,
> -		void (*destroy) (struct ttm_buffer_object *));
>   
>   /**
>    * ttm_kmap_obj_virtual
kernel test robot July 7, 2022, 5:24 p.m. UTC | #2
Hi "Christian,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-K-nig/drm-ttm-rename-and-cleanup-ttm_bo_init_reserved/20220707-192538
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-randconfig-a011 (https://download.01.org/0day-ci/archive/20220708/202207080122.B4DLOdD2-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/607b24f78509a1fb0e55c8f9f610113bb0421706
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Christian-K-nig/drm-ttm-rename-and-cleanup-ttm_bo_init_reserved/20220707-192538
        git checkout 607b24f78509a1fb0e55c8f9f610113bb0421706
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/gpu/drm/ttm/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/gpu/drm/ttm/ttm_bo.c:99: warning: Function parameter or member 'bulk' not described in 'ttm_bo_set_bulk_move'
>> drivers/gpu/drm/ttm/ttm_bo.c:962: warning: expecting prototype for ttm_bo_init_validate(). Prototype was for ttm_bo_init_reserved() instead


vim +962 drivers/gpu/drm/ttm/ttm_bo.c

ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   923  
607b24f78509a1f Christian König   2022-07-07   924  /**
607b24f78509a1f Christian König   2022-07-07   925   * ttm_bo_init_validate
607b24f78509a1f Christian König   2022-07-07   926   *
607b24f78509a1f Christian König   2022-07-07   927   * @bdev: Pointer to a ttm_device struct.
607b24f78509a1f Christian König   2022-07-07   928   * @bo: Pointer to a ttm_buffer_object to be initialized.
607b24f78509a1f Christian König   2022-07-07   929   * @type: Requested type of buffer object.
607b24f78509a1f Christian König   2022-07-07   930   * @placement: Initial placement for buffer object.
607b24f78509a1f Christian König   2022-07-07   931   * @alignment: Data alignment in pages.
607b24f78509a1f Christian König   2022-07-07   932   * @ctx: TTM operation context for memory allocation.
607b24f78509a1f Christian König   2022-07-07   933   * @sg: Scatter-gather table.
607b24f78509a1f Christian König   2022-07-07   934   * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
607b24f78509a1f Christian König   2022-07-07   935   * @destroy: Destroy function. Use NULL for kfree().
607b24f78509a1f Christian König   2022-07-07   936   *
607b24f78509a1f Christian König   2022-07-07   937   * This function initializes a pre-allocated struct ttm_buffer_object.
607b24f78509a1f Christian König   2022-07-07   938   * As this object may be part of a larger structure, this function,
607b24f78509a1f Christian König   2022-07-07   939   * together with the @destroy function, enables driver-specific objects
607b24f78509a1f Christian König   2022-07-07   940   * derived from a ttm_buffer_object.
607b24f78509a1f Christian König   2022-07-07   941   *
607b24f78509a1f Christian König   2022-07-07   942   * On successful return, the caller owns an object kref to @bo. The kref and
607b24f78509a1f Christian König   2022-07-07   943   * list_kref are usually set to 1, but note that in some situations, other
607b24f78509a1f Christian König   2022-07-07   944   * tasks may already be holding references to @bo as well.
607b24f78509a1f Christian König   2022-07-07   945   * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
607b24f78509a1f Christian König   2022-07-07   946   * and it is the caller's responsibility to call ttm_bo_unreserve.
607b24f78509a1f Christian König   2022-07-07   947   *
607b24f78509a1f Christian König   2022-07-07   948   * If a failure occurs, the function will call the @destroy function. Thus,
607b24f78509a1f Christian König   2022-07-07   949   * after a failure, dereferencing @bo is illegal and will likely cause memory
607b24f78509a1f Christian König   2022-07-07   950   * corruption.
607b24f78509a1f Christian König   2022-07-07   951   *
607b24f78509a1f Christian König   2022-07-07   952   * Returns
607b24f78509a1f Christian König   2022-07-07   953   * -ENOMEM: Out of memory.
607b24f78509a1f Christian König   2022-07-07   954   * -EINVAL: Invalid placement flags.
607b24f78509a1f Christian König   2022-07-07   955   * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
607b24f78509a1f Christian König   2022-07-07   956   */
607b24f78509a1f Christian König   2022-07-07   957  int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
607b24f78509a1f Christian König   2022-07-07   958  			 enum ttm_bo_type type, struct ttm_placement *placement,
607b24f78509a1f Christian König   2022-07-07   959  			 uint32_t alignment, struct ttm_operation_ctx *ctx,
607b24f78509a1f Christian König   2022-07-07   960  			 struct sg_table *sg, struct dma_resv *resv,
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   961  			 void (*destroy) (struct ttm_buffer_object *))
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10  @962  {
d79025c7f5e3764 Christian König   2021-02-16   963  	static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
bfa3357ef9abc9d Christian König   2021-04-15   964  	int ret;
57de4ba959b290f Jerome Glisse     2011-11-11   965  
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   966  	kref_init(&bo->kref);
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   967  	INIT_LIST_HEAD(&bo->ddestroy);
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   968  	bo->bdev = bdev;
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   969  	bo->type = type;
607b24f78509a1f Christian König   2022-07-07   970  	bo->page_alignment = alignment;
607b24f78509a1f Christian König   2022-07-07   971  	bo->destroy = destroy;
deb0814b43f370a Christian König   2020-09-21   972  	bo->pin_count = 0;
129b78bfca591e7 Dave Airlie       2012-04-02   973  	bo->sg = sg;
fee2ede155423b0 Christian König   2022-01-24   974  	bo->bulk_move = NULL;
607b24f78509a1f Christian König   2022-07-07   975  	if (resv)
2e3c9ec4d151c04 Gerd Hoffmann     2019-08-05   976  		bo->base.resv = resv;
607b24f78509a1f Christian König   2022-07-07   977  	else
2e3c9ec4d151c04 Gerd Hoffmann     2019-08-05   978  		bo->base.resv = &bo->base._resv;
8af8a109b34fa88 Christian König   2020-10-01   979  	atomic_inc(&ttm_glob.bo_count);
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   980  
bfa3357ef9abc9d Christian König   2021-04-15   981  	ret = ttm_resource_alloc(bo, &sys_mem, &bo->resource);
bfa3357ef9abc9d Christian König   2021-04-15   982  	if (unlikely(ret)) {
bfa3357ef9abc9d Christian König   2021-04-15   983  		ttm_bo_put(bo);
bfa3357ef9abc9d Christian König   2021-04-15   984  		return ret;
bfa3357ef9abc9d Christian König   2021-04-15   985  	}
bfa3357ef9abc9d Christian König   2021-04-15   986  
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   987  	/*
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   988  	 * For ttm_bo_type_device buffers, allocate
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   989  	 * address space from the device.
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   990  	 */
607b24f78509a1f Christian König   2022-07-07   991  	if (bo->type == ttm_bo_type_device || bo->type == ttm_bo_type_sg) {
9d6f4484e81c000 Gerd Hoffmann     2019-09-05   992  		ret = drm_vma_offset_add(bdev->vma_manager, &bo->base.vma_node,
607b24f78509a1f Christian König   2022-07-07   993  					 PFN_UP(bo->base.size));
607b24f78509a1f Christian König   2022-07-07   994  		if (ret)
607b24f78509a1f Christian König   2022-07-07   995  			goto err_put;
607b24f78509a1f Christian König   2022-07-07   996  	}
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10   997  
f4f4e3e3e9f3bde Maarten Lankhorst 2014-01-09   998  	/* passed reservation objects should already be locked,
f4f4e3e3e9f3bde Maarten Lankhorst 2014-01-09   999  	 * since otherwise lockdep will be angered in radeon.
f4f4e3e3e9f3bde Maarten Lankhorst 2014-01-09  1000  	 */
607b24f78509a1f Christian König   2022-07-07  1001  	if (!resv)
607b24f78509a1f Christian König   2022-07-07  1002  		WARN_ON(!dma_resv_trylock(bo->base.resv));
607b24f78509a1f Christian König   2022-07-07  1003  	else
607b24f78509a1f Christian König   2022-07-07  1004  		dma_resv_assert_held(resv);
5e338405119a80a Maarten Lankhorst 2013-06-27  1005  
6fead44a4c5897c Christian König   2017-04-12  1006  	ret = ttm_bo_validate(bo, placement, ctx);
607b24f78509a1f Christian König   2022-07-07  1007  	if (unlikely(ret))
607b24f78509a1f Christian König   2022-07-07  1008  		goto err_unlock;
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10  1009  
607b24f78509a1f Christian König   2022-07-07  1010  	return 0;
607b24f78509a1f Christian König   2022-07-07  1011  
607b24f78509a1f Christian König   2022-07-07  1012  err_unlock:
c2c139cf435b189 Nicolai Hähnle    2017-02-14  1013  	if (!resv)
607b24f78509a1f Christian König   2022-07-07  1014  		dma_resv_unlock(bo->base.resv);
ba4e7d973dd09b6 Thomas Hellstrom  2009-06-10  1015  
607b24f78509a1f Christian König   2022-07-07  1016  err_put:
f44907593d746d4 Thomas Zimmermann 2018-06-21  1017  	ttm_bo_put(bo);
c2c139cf435b189 Nicolai Hähnle    2017-02-14  1018  	return ret;
c2c139cf435b189 Nicolai Hähnle    2017-02-14  1019  }
ca9cf68de1e7429 Nicolai Hähnle    2017-02-16  1020  EXPORT_SYMBOL(ttm_bo_init_reserved);
ca9cf68de1e7429 Nicolai Hähnle    2017-02-16  1021
Michael J. Ruhl July 8, 2022, 1:31 p.m. UTC | #3
>-----Original Message-----
>From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of
>Christian König
>Sent: Thursday, July 7, 2022 6:25 AM
>To: intel-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org;
>nouveau@lists.freedesktop.org; amd-gfx@lists.freedesktop.org
>Cc: Christian König <christian.koenig@amd.com>
>Subject: [PATCH 1/6] drm/ttm: rename and cleanup ttm_bo_init_reserved
>
>Rename ttm_bo_init_reserved to ttm_bo_init_validate since that better
>matches what the function is actually doing.
>
>Remove the unused size parameter, move the function's kerneldoc to the
>implementation and cleanup the whole error handling.
>
>Signed-off-by: Christian König <christian.koenig@amd.com>
>---
> drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |   2 +-
> drivers/gpu/drm/drm_gem_vram_helper.c      |   6 +-
> drivers/gpu/drm/i915/gem/i915_gem_ttm.c    |   5 +-
> drivers/gpu/drm/nouveau/nouveau_bo.c       |   6 +-
> drivers/gpu/drm/qxl/qxl_object.c           |   2 +-
> drivers/gpu/drm/radeon/radeon_object.c     |   6 +-
> drivers/gpu/drm/ttm/ttm_bo.c               | 147 +++++++++++++++------
> drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         |  12 +-
> include/drm/ttm/ttm_bo_api.h               |  93 ++-----------
> 9 files changed, 129 insertions(+), 150 deletions(-)
>
>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>index 2c82b1d5a0d7..d9cfe259f2a9 100644
>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>@@ -591,7 +591,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
> 	if (!bp->destroy)
> 		bp->destroy = &amdgpu_bo_destroy;
>
>-	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp-
>>type,
>+	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, bp->type,
> 				 &bo->placement, page_align, &ctx,  NULL,
> 				 bp->resv, bp->destroy);
> 	if (unlikely(r != 0))
>diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c
>b/drivers/gpu/drm/drm_gem_vram_helper.c
>index d607043716d3..125160b534be 100644
>--- a/drivers/gpu/drm/drm_gem_vram_helper.c
>+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
>@@ -226,9 +226,9 @@ struct drm_gem_vram_object
>*drm_gem_vram_create(struct drm_device *dev,
> 	 * A failing ttm_bo_init will call ttm_buffer_object_destroy
> 	 * to release gbo->bo.base and kfree gbo.
> 	 */
>-	ret = ttm_bo_init(bdev, &gbo->bo, size, ttm_bo_type_device,
>-			  &gbo->placement, pg_align, false, NULL, NULL,
>-			  ttm_buffer_object_destroy);
>+	ret = ttm_bo_init_validate(bdev, &gbo->bo, ttm_bo_type_device,
>+				   &gbo->placement, pg_align, false, NULL,
>NULL,
>+				   ttm_buffer_object_destroy);
> 	if (ret)
> 		return ERR_PTR(ret);
>
>diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
>b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
>index 4c25d9b2f138..70e2ed4e99df 100644
>--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
>+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
>@@ -1229,9 +1229,8 @@ int __i915_gem_ttm_object_init(struct
>intel_memory_region *mem,
> 	 * Similarly, in delayed_destroy, we can't call ttm_bo_put()
> 	 * until successful initialization.
> 	 */
>-	ret = ttm_bo_init_reserved(&i915->bdev, i915_gem_to_ttm(obj),
>size,
>-				   bo_type, &i915_sys_placement,
>-				   page_size >> PAGE_SHIFT,
>+	ret = ttm_bo_init_reserved(&i915->bdev, i915_gem_to_ttm(obj),
>bo_type,
>+				   &i915_sys_placement, page_size >>
>PAGE_SHIFT,
> 				   &ctx, NULL, NULL, i915_ttm_bo_destroy);
> 	if (ret)
> 		return i915_ttm_err_to_gem(ret);
>diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c
>b/drivers/gpu/drm/nouveau/nouveau_bo.c
>index 05076e530e7d..92cd19021084 100644
>--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
>+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
>@@ -307,9 +307,9 @@ nouveau_bo_init(struct nouveau_bo *nvbo, u64 size,
>int align, u32 domain,
> 	nouveau_bo_placement_set(nvbo, domain, 0);
> 	INIT_LIST_HEAD(&nvbo->io_reserve_lru);
>
>-	ret = ttm_bo_init(nvbo->bo.bdev, &nvbo->bo, size, type,
>-			  &nvbo->placement, align >> PAGE_SHIFT, false, sg,
>-			  robj, nouveau_bo_del_ttm);
>+	ret = ttm_bo_init_validate(nvbo->bo.bdev, &nvbo->bo, type,
>+				   &nvbo->placement, align >> PAGE_SHIFT,
>false,
>+				   sg, robj, nouveau_bo_del_ttm);
> 	if (ret) {
> 		/* ttm will call nouveau_bo_del_ttm if it fails.. */
> 		return ret;
>diff --git a/drivers/gpu/drm/qxl/qxl_object.c
>b/drivers/gpu/drm/qxl/qxl_object.c
>index b42a657e4c2f..695d9308d1f0 100644
>--- a/drivers/gpu/drm/qxl/qxl_object.c
>+++ b/drivers/gpu/drm/qxl/qxl_object.c
>@@ -141,7 +141,7 @@ int qxl_bo_create(struct qxl_device *qdev, unsigned
>long size,
> 	qxl_ttm_placement_from_domain(bo, domain);
>
> 	bo->tbo.priority = priority;
>-	r = ttm_bo_init_reserved(&qdev->mman.bdev, &bo->tbo, size, type,
>+	r = ttm_bo_init_reserved(&qdev->mman.bdev, &bo->tbo, type,
> 				 &bo->placement, 0, &ctx, NULL, NULL,
> 				 &qxl_ttm_bo_destroy);
> 	if (unlikely(r != 0)) {
>diff --git a/drivers/gpu/drm/radeon/radeon_object.c
>b/drivers/gpu/drm/radeon/radeon_object.c
>index 6c4a6802ca96..00c33b24d5d3 100644
>--- a/drivers/gpu/drm/radeon/radeon_object.c
>+++ b/drivers/gpu/drm/radeon/radeon_object.c
>@@ -202,9 +202,9 @@ int radeon_bo_create(struct radeon_device *rdev,
> 	radeon_ttm_placement_from_domain(bo, domain);
> 	/* Kernel allocation are uninterruptible */
> 	down_read(&rdev->pm.mclk_lock);
>-	r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
>-			&bo->placement, page_align, !kernel, sg, resv,
>-			&radeon_ttm_bo_destroy);
>+	r = ttm_bo_init_validate(&rdev->mman.bdev, &bo->tbo, type,
>+				 &bo->placement, page_align, !kernel, sg,
>resv,
>+				 &radeon_ttm_bo_destroy);
> 	up_read(&rdev->pm.mclk_lock);
> 	if (unlikely(r != 0)) {
> 		return r;
>diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>index 0e210df65c30..984535d6a2d0 100644
>--- a/drivers/gpu/drm/ttm/ttm_bo.c
>+++ b/drivers/gpu/drm/ttm/ttm_bo.c
>@@ -921,36 +921,61 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
> }
> EXPORT_SYMBOL(ttm_bo_validate);
>
>-int ttm_bo_init_reserved(struct ttm_device *bdev,
>-			 struct ttm_buffer_object *bo,
>-			 size_t size,
>-			 enum ttm_bo_type type,
>-			 struct ttm_placement *placement,
>-			 uint32_t page_alignment,
>-			 struct ttm_operation_ctx *ctx,
>-			 struct sg_table *sg,
>-			 struct dma_resv *resv,
>+/**
>+ * ttm_bo_init_validate

ttm_bo_init_reserved?

>+ *
>+ * @bdev: Pointer to a ttm_device struct.
>+ * @bo: Pointer to a ttm_buffer_object to be initialized.
>+ * @type: Requested type of buffer object.
>+ * @placement: Initial placement for buffer object.
>+ * @alignment: Data alignment in pages.
>+ * @ctx: TTM operation context for memory allocation.
>+ * @sg: Scatter-gather table.
>+ * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
>+ * @destroy: Destroy function. Use NULL for kfree().
>+ *
>+ * This function initializes a pre-allocated struct ttm_buffer_object.
>+ * As this object may be part of a larger structure, this function,
>+ * together with the @destroy function, enables driver-specific objects
>+ * derived from a ttm_buffer_object.
>+ *
>+ * On successful return, the caller owns an object kref to @bo. The kref and
>+ * list_kref are usually set to 1, but note that in some situations, other
>+ * tasks may already be holding references to @bo as well.
>+ * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
>+ * and it is the caller's responsibility to call ttm_bo_unreserve.
>+ *
>+ * If a failure occurs, the function will call the @destroy function. Thus,
>+ * after a failure, dereferencing @bo is illegal and will likely cause memory
>+ * corruption.
>+ *
>+ * Returns
>+ * -ENOMEM: Out of memory.
>+ * -EINVAL: Invalid placement flags.
>+ * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
>+ */
>+int ttm_bo_init_reserved(struct ttm_device *bdev, struct
>ttm_buffer_object *bo,
>+			 enum ttm_bo_type type, struct ttm_placement
>*placement,
>+			 uint32_t alignment, struct ttm_operation_ctx *ctx,
>+			 struct sg_table *sg, struct dma_resv *resv,
> 			 void (*destroy) (struct ttm_buffer_object *))
> {
> 	static const struct ttm_place sys_mem = { .mem_type =
>TTM_PL_SYSTEM };
>-	bool locked;
> 	int ret;
>
>-	bo->destroy = destroy;
> 	kref_init(&bo->kref);
> 	INIT_LIST_HEAD(&bo->ddestroy);
> 	bo->bdev = bdev;
> 	bo->type = type;
>-	bo->page_alignment = page_alignment;
>+	bo->page_alignment = alignment;
>+	bo->destroy = destroy;
> 	bo->pin_count = 0;
> 	bo->sg = sg;
> 	bo->bulk_move = NULL;
>-	if (resv) {
>+	if (resv)
> 		bo->base.resv = resv;

If bo->base.resv is already set, should this be overwritten?
If it is, is that an error in usage?

Nice cleanup, with the kerndoc function name fix,

Reviewed-by: Michael J. Ruhl <michael.j.ruhl@intel.com>

M
>-		dma_resv_assert_held(bo->base.resv);
>-	} else {
>+	else
> 		bo->base.resv = &bo->base._resv;
>-	}
> 	atomic_inc(&ttm_glob.bo_count);
> 	ret = ttm_resource_alloc(bo, &sys_mem, &bo->resource);
>@@ -963,50 +988,84 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
> 	 * For ttm_bo_type_device buffers, allocate
> 	 * address space from the device.
> 	 */
>-	if (bo->type == ttm_bo_type_device ||
>-	    bo->type == ttm_bo_type_sg)
>+	if (bo->type == ttm_bo_type_device || bo->type ==
>ttm_bo_type_sg) {
> 		ret = drm_vma_offset_add(bdev->vma_manager, &bo-
>>base.vma_node,
>-					 bo->resource->num_pages);
>+					 PFN_UP(bo->base.size));
>+		if (ret)
>+			goto err_put;
>+	}
>
> 	/* passed reservation objects should already be locked,
> 	 * since otherwise lockdep will be angered in radeon.
> 	 */
>-	if (!resv) {
>-		locked = dma_resv_trylock(bo->base.resv);
>-		WARN_ON(!locked);
>-	}
>+	if (!resv)
>+		WARN_ON(!dma_resv_trylock(bo->base.resv));
>+	else
>+		dma_resv_assert_held(resv);
>
>-	if (likely(!ret))
>-		ret = ttm_bo_validate(bo, placement, ctx);
>+	ret = ttm_bo_validate(bo, placement, ctx);
>+	if (unlikely(ret))
>+		goto err_unlock;
>
>-	if (unlikely(ret)) {
>-		if (!resv)
>-			ttm_bo_unreserve(bo);
>+	return 0;
>
>-		ttm_bo_put(bo);
>-		return ret;
>-	}
>+err_unlock:
>+	if (!resv)
>+		dma_resv_unlock(bo->base.resv);
>
>+err_put:
>+	ttm_bo_put(bo);
> 	return ret;
> }
> EXPORT_SYMBOL(ttm_bo_init_reserved);
>
>-int ttm_bo_init(struct ttm_device *bdev,
>-		struct ttm_buffer_object *bo,
>-		size_t size,
>-		enum ttm_bo_type type,
>-		struct ttm_placement *placement,
>-		uint32_t page_alignment,
>-		bool interruptible,
>-		struct sg_table *sg,
>-		struct dma_resv *resv,
>-		void (*destroy) (struct ttm_buffer_object *))
>+/**
>+ * ttm_bo_init_validate
>+ *
>+ * @bdev: Pointer to a ttm_device struct.
>+ * @bo: Pointer to a ttm_buffer_object to be initialized.
>+ * @type: Requested type of buffer object.
>+ * @placement: Initial placement for buffer object.
>+ * @alignment: Data alignment in pages.
>+ * @interruptible: If needing to sleep to wait for GPU resources,
>+ * sleep interruptible.
>+ * pinned in physical memory. If this behaviour is not desired, this member
>+ * holds a pointer to a persistent shmem object. Typically, this would
>+ * point to the shmem object backing a GEM object if TTM is used to back a
>+ * GEM user interface.
>+ * @sg: Scatter-gather table.
>+ * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
>+ * @destroy: Destroy function. Use NULL for kfree().
>+ *
>+ * This function initializes a pre-allocated struct ttm_buffer_object.
>+ * As this object may be part of a larger structure, this function,
>+ * together with the @destroy function,
>+ * enables driver-specific objects derived from a ttm_buffer_object.
>+ *
>+ * On successful return, the caller owns an object kref to @bo. The kref and
>+ * list_kref are usually set to 1, but note that in some situations, other
>+ * tasks may already be holding references to @bo as well.
>+ *
>+ * If a failure occurs, the function will call the @destroy function, Thus,
>+ * after a failure, dereferencing @bo is illegal and will likely cause memory
>+ * corruption.
>+ *
>+ * Returns
>+ * -ENOMEM: Out of memory.
>+ * -EINVAL: Invalid placement flags.
>+ * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
>+ */
>+int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object
>*bo,
>+			 enum ttm_bo_type type, struct ttm_placement
>*placement,
>+			 uint32_t alignment, bool interruptible,
>+			 struct sg_table *sg, struct dma_resv *resv,
>+			 void (*destroy) (struct ttm_buffer_object *))
> {
> 	struct ttm_operation_ctx ctx = { interruptible, false };
> 	int ret;
>
>-	ret = ttm_bo_init_reserved(bdev, bo, size, type, placement,
>-				   page_alignment, &ctx, sg, resv, destroy);
>+	ret = ttm_bo_init_reserved(bdev, bo, type, placement, alignment,
>&ctx,
>+				   sg, resv, destroy);
> 	if (ret)
> 		return ret;
>
>@@ -1015,7 +1074,7 @@ int ttm_bo_init(struct ttm_device *bdev,
>
> 	return 0;
> }
>-EXPORT_SYMBOL(ttm_bo_init);
>+EXPORT_SYMBOL(ttm_bo_init_validate);
>
> /*
>  * buffer object vm functions.
>diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
>b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
>index 85a66014c2b6..eb2fd7694cd1 100644
>--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
>+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
>@@ -429,9 +429,9 @@ int vmw_bo_create_kernel(struct vmw_private
>*dev_priv, unsigned long size,
>
> 	drm_gem_private_object_init(vdev, &bo->base, size);
>
>-	ret = ttm_bo_init_reserved(&dev_priv->bdev, bo, size,
>-				   ttm_bo_type_kernel, placement, 0,
>-				   &ctx, NULL, NULL,
>vmw_bo_default_destroy);
>+	ret = ttm_bo_init_reserved(&dev_priv->bdev, bo,
>ttm_bo_type_kernel,
>+				   placement, 0, &ctx, NULL, NULL,
>+				   vmw_bo_default_destroy);
> 	if (unlikely(ret))
> 		goto error_free;
>
>@@ -512,10 +512,8 @@ int vmw_bo_init(struct vmw_private *dev_priv,
> 	size = ALIGN(size, PAGE_SIZE);
> 	drm_gem_private_object_init(vdev, &vmw_bo->base.base, size);
>
>-	ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, size,
>-				   ttm_bo_type_device,
>-				   placement,
>-				   0, &ctx, NULL, NULL, bo_free);
>+	ret = ttm_bo_init_reserved(bdev, &vmw_bo->base,
>ttm_bo_type_device,
>+				   placement, 0, &ctx, NULL, NULL, bo_free);
> 	if (unlikely(ret)) {
> 		return ret;
> 	}
>diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>index 2d524f8b0802..44a538ee5e2a 100644
>--- a/include/drm/ttm/ttm_bo_api.h
>+++ b/include/drm/ttm/ttm_bo_api.h
>@@ -317,93 +317,16 @@ void ttm_bo_unlock_delayed_workqueue(struct
>ttm_device *bdev, int resched);
> bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
> 			      const struct ttm_place *place);
>
>-/**
>- * ttm_bo_init_reserved
>- *
>- * @bdev: Pointer to a ttm_device struct.
>- * @bo: Pointer to a ttm_buffer_object to be initialized.
>- * @size: Requested size of buffer object.
>- * @type: Requested type of buffer object.
>- * @placement: Initial placement for buffer object.
>- * @page_alignment: Data alignment in pages.
>- * @ctx: TTM operation context for memory allocation.
>- * @sg: Scatter-gather table.
>- * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
>- * @destroy: Destroy function. Use NULL for kfree().
>- *
>- * This function initializes a pre-allocated struct ttm_buffer_object.
>- * As this object may be part of a larger structure, this function,
>- * together with the @destroy function,
>- * enables driver-specific objects derived from a ttm_buffer_object.
>- *
>- * On successful return, the caller owns an object kref to @bo. The kref and
>- * list_kref are usually set to 1, but note that in some situations, other
>- * tasks may already be holding references to @bo as well.
>- * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
>- * and it is the caller's responsibility to call ttm_bo_unreserve.
>- *
>- * If a failure occurs, the function will call the @destroy function, or
>- * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
>- * illegal and will likely cause memory corruption.
>- *
>- * Returns
>- * -ENOMEM: Out of memory.
>- * -EINVAL: Invalid placement flags.
>- * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
>- */
>-
>-int ttm_bo_init_reserved(struct ttm_device *bdev,
>-			 struct ttm_buffer_object *bo,
>-			 size_t size, enum ttm_bo_type type,
>-			 struct ttm_placement *placement,
>-			 uint32_t page_alignment,
>-			 struct ttm_operation_ctx *ctx,
>+int ttm_bo_init_reserved(struct ttm_device *bdev, struct
>ttm_buffer_object *bo,
>+			 enum ttm_bo_type type, struct ttm_placement
>*placement,
>+			 uint32_t alignment, struct ttm_operation_ctx *ctx,
>+			 struct sg_table *sg, struct dma_resv *resv,
>+			 void (*destroy) (struct ttm_buffer_object *));
>+int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object
>*bo,
>+			 enum ttm_bo_type type, struct ttm_placement
>*placement,
>+			 uint32_t alignment, bool interruptible,
> 			 struct sg_table *sg, struct dma_resv *resv,
> 			 void (*destroy) (struct ttm_buffer_object *));
>-
>-/**
>- * ttm_bo_init
>- *
>- * @bdev: Pointer to a ttm_device struct.
>- * @bo: Pointer to a ttm_buffer_object to be initialized.
>- * @size: Requested size of buffer object.
>- * @type: Requested type of buffer object.
>- * @placement: Initial placement for buffer object.
>- * @page_alignment: Data alignment in pages.
>- * @interruptible: If needing to sleep to wait for GPU resources,
>- * sleep interruptible.
>- * pinned in physical memory. If this behaviour is not desired, this member
>- * holds a pointer to a persistent shmem object. Typically, this would
>- * point to the shmem object backing a GEM object if TTM is used to back a
>- * GEM user interface.
>- * @sg: Scatter-gather table.
>- * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
>- * @destroy: Destroy function. Use NULL for kfree().
>- *
>- * This function initializes a pre-allocated struct ttm_buffer_object.
>- * As this object may be part of a larger structure, this function,
>- * together with the @destroy function,
>- * enables driver-specific objects derived from a ttm_buffer_object.
>- *
>- * On successful return, the caller owns an object kref to @bo. The kref and
>- * list_kref are usually set to 1, but note that in some situations, other
>- * tasks may already be holding references to @bo as well.
>- *
>- * If a failure occurs, the function will call the @destroy function, or
>- * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
>- * illegal and will likely cause memory corruption.
>- *
>- * Returns
>- * -ENOMEM: Out of memory.
>- * -EINVAL: Invalid placement flags.
>- * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
>- */
>-int ttm_bo_init(struct ttm_device *bdev, struct ttm_buffer_object *bo,
>-		size_t size, enum ttm_bo_type type,
>-		struct ttm_placement *placement,
>-		uint32_t page_alignment, bool interrubtible,
>-		struct sg_table *sg, struct dma_resv *resv,
>-		void (*destroy) (struct ttm_buffer_object *));
>
> /**
>  * ttm_kmap_obj_virtual
>--
>2.25.1
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 2c82b1d5a0d7..d9cfe259f2a9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -591,7 +591,7 @@  int amdgpu_bo_create(struct amdgpu_device *adev,
 	if (!bp->destroy)
 		bp->destroy = &amdgpu_bo_destroy;
 
-	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type,
+	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, bp->type,
 				 &bo->placement, page_align, &ctx,  NULL,
 				 bp->resv, bp->destroy);
 	if (unlikely(r != 0))
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index d607043716d3..125160b534be 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -226,9 +226,9 @@  struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev,
 	 * A failing ttm_bo_init will call ttm_buffer_object_destroy
 	 * to release gbo->bo.base and kfree gbo.
 	 */
-	ret = ttm_bo_init(bdev, &gbo->bo, size, ttm_bo_type_device,
-			  &gbo->placement, pg_align, false, NULL, NULL,
-			  ttm_buffer_object_destroy);
+	ret = ttm_bo_init_validate(bdev, &gbo->bo, ttm_bo_type_device,
+				   &gbo->placement, pg_align, false, NULL, NULL,
+				   ttm_buffer_object_destroy);
 	if (ret)
 		return ERR_PTR(ret);
 
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index 4c25d9b2f138..70e2ed4e99df 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
@@ -1229,9 +1229,8 @@  int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
 	 * Similarly, in delayed_destroy, we can't call ttm_bo_put()
 	 * until successful initialization.
 	 */
-	ret = ttm_bo_init_reserved(&i915->bdev, i915_gem_to_ttm(obj), size,
-				   bo_type, &i915_sys_placement,
-				   page_size >> PAGE_SHIFT,
+	ret = ttm_bo_init_reserved(&i915->bdev, i915_gem_to_ttm(obj), bo_type,
+				   &i915_sys_placement, page_size >> PAGE_SHIFT,
 				   &ctx, NULL, NULL, i915_ttm_bo_destroy);
 	if (ret)
 		return i915_ttm_err_to_gem(ret);
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 05076e530e7d..92cd19021084 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -307,9 +307,9 @@  nouveau_bo_init(struct nouveau_bo *nvbo, u64 size, int align, u32 domain,
 	nouveau_bo_placement_set(nvbo, domain, 0);
 	INIT_LIST_HEAD(&nvbo->io_reserve_lru);
 
-	ret = ttm_bo_init(nvbo->bo.bdev, &nvbo->bo, size, type,
-			  &nvbo->placement, align >> PAGE_SHIFT, false, sg,
-			  robj, nouveau_bo_del_ttm);
+	ret = ttm_bo_init_validate(nvbo->bo.bdev, &nvbo->bo, type,
+				   &nvbo->placement, align >> PAGE_SHIFT, false,
+				   sg, robj, nouveau_bo_del_ttm);
 	if (ret) {
 		/* ttm will call nouveau_bo_del_ttm if it fails.. */
 		return ret;
diff --git a/drivers/gpu/drm/qxl/qxl_object.c b/drivers/gpu/drm/qxl/qxl_object.c
index b42a657e4c2f..695d9308d1f0 100644
--- a/drivers/gpu/drm/qxl/qxl_object.c
+++ b/drivers/gpu/drm/qxl/qxl_object.c
@@ -141,7 +141,7 @@  int qxl_bo_create(struct qxl_device *qdev, unsigned long size,
 	qxl_ttm_placement_from_domain(bo, domain);
 
 	bo->tbo.priority = priority;
-	r = ttm_bo_init_reserved(&qdev->mman.bdev, &bo->tbo, size, type,
+	r = ttm_bo_init_reserved(&qdev->mman.bdev, &bo->tbo, type,
 				 &bo->placement, 0, &ctx, NULL, NULL,
 				 &qxl_ttm_bo_destroy);
 	if (unlikely(r != 0)) {
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 6c4a6802ca96..00c33b24d5d3 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -202,9 +202,9 @@  int radeon_bo_create(struct radeon_device *rdev,
 	radeon_ttm_placement_from_domain(bo, domain);
 	/* Kernel allocation are uninterruptible */
 	down_read(&rdev->pm.mclk_lock);
-	r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
-			&bo->placement, page_align, !kernel, sg, resv,
-			&radeon_ttm_bo_destroy);
+	r = ttm_bo_init_validate(&rdev->mman.bdev, &bo->tbo, type,
+				 &bo->placement, page_align, !kernel, sg, resv,
+				 &radeon_ttm_bo_destroy);
 	up_read(&rdev->pm.mclk_lock);
 	if (unlikely(r != 0)) {
 		return r;
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 0e210df65c30..984535d6a2d0 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -921,36 +921,61 @@  int ttm_bo_validate(struct ttm_buffer_object *bo,
 }
 EXPORT_SYMBOL(ttm_bo_validate);
 
-int ttm_bo_init_reserved(struct ttm_device *bdev,
-			 struct ttm_buffer_object *bo,
-			 size_t size,
-			 enum ttm_bo_type type,
-			 struct ttm_placement *placement,
-			 uint32_t page_alignment,
-			 struct ttm_operation_ctx *ctx,
-			 struct sg_table *sg,
-			 struct dma_resv *resv,
+/**
+ * ttm_bo_init_validate
+ *
+ * @bdev: Pointer to a ttm_device struct.
+ * @bo: Pointer to a ttm_buffer_object to be initialized.
+ * @type: Requested type of buffer object.
+ * @placement: Initial placement for buffer object.
+ * @alignment: Data alignment in pages.
+ * @ctx: TTM operation context for memory allocation.
+ * @sg: Scatter-gather table.
+ * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
+ * @destroy: Destroy function. Use NULL for kfree().
+ *
+ * This function initializes a pre-allocated struct ttm_buffer_object.
+ * As this object may be part of a larger structure, this function,
+ * together with the @destroy function, enables driver-specific objects
+ * derived from a ttm_buffer_object.
+ *
+ * On successful return, the caller owns an object kref to @bo. The kref and
+ * list_kref are usually set to 1, but note that in some situations, other
+ * tasks may already be holding references to @bo as well.
+ * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
+ * and it is the caller's responsibility to call ttm_bo_unreserve.
+ *
+ * If a failure occurs, the function will call the @destroy function. Thus,
+ * after a failure, dereferencing @bo is illegal and will likely cause memory
+ * corruption.
+ *
+ * Returns
+ * -ENOMEM: Out of memory.
+ * -EINVAL: Invalid placement flags.
+ * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
+ */
+int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
+			 enum ttm_bo_type type, struct ttm_placement *placement,
+			 uint32_t alignment, struct ttm_operation_ctx *ctx,
+			 struct sg_table *sg, struct dma_resv *resv,
 			 void (*destroy) (struct ttm_buffer_object *))
 {
 	static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
-	bool locked;
 	int ret;
 
-	bo->destroy = destroy;
 	kref_init(&bo->kref);
 	INIT_LIST_HEAD(&bo->ddestroy);
 	bo->bdev = bdev;
 	bo->type = type;
-	bo->page_alignment = page_alignment;
+	bo->page_alignment = alignment;
+	bo->destroy = destroy;
 	bo->pin_count = 0;
 	bo->sg = sg;
 	bo->bulk_move = NULL;
-	if (resv) {
+	if (resv)
 		bo->base.resv = resv;
-		dma_resv_assert_held(bo->base.resv);
-	} else {
+	else
 		bo->base.resv = &bo->base._resv;
-	}
 	atomic_inc(&ttm_glob.bo_count);
 
 	ret = ttm_resource_alloc(bo, &sys_mem, &bo->resource);
@@ -963,50 +988,84 @@  int ttm_bo_init_reserved(struct ttm_device *bdev,
 	 * For ttm_bo_type_device buffers, allocate
 	 * address space from the device.
 	 */
-	if (bo->type == ttm_bo_type_device ||
-	    bo->type == ttm_bo_type_sg)
+	if (bo->type == ttm_bo_type_device || bo->type == ttm_bo_type_sg) {
 		ret = drm_vma_offset_add(bdev->vma_manager, &bo->base.vma_node,
-					 bo->resource->num_pages);
+					 PFN_UP(bo->base.size));
+		if (ret)
+			goto err_put;
+	}
 
 	/* passed reservation objects should already be locked,
 	 * since otherwise lockdep will be angered in radeon.
 	 */
-	if (!resv) {
-		locked = dma_resv_trylock(bo->base.resv);
-		WARN_ON(!locked);
-	}
+	if (!resv)
+		WARN_ON(!dma_resv_trylock(bo->base.resv));
+	else
+		dma_resv_assert_held(resv);
 
-	if (likely(!ret))
-		ret = ttm_bo_validate(bo, placement, ctx);
+	ret = ttm_bo_validate(bo, placement, ctx);
+	if (unlikely(ret))
+		goto err_unlock;
 
-	if (unlikely(ret)) {
-		if (!resv)
-			ttm_bo_unreserve(bo);
+	return 0;
 
-		ttm_bo_put(bo);
-		return ret;
-	}
+err_unlock:
+	if (!resv)
+		dma_resv_unlock(bo->base.resv);
 
+err_put:
+	ttm_bo_put(bo);
 	return ret;
 }
 EXPORT_SYMBOL(ttm_bo_init_reserved);
 
-int ttm_bo_init(struct ttm_device *bdev,
-		struct ttm_buffer_object *bo,
-		size_t size,
-		enum ttm_bo_type type,
-		struct ttm_placement *placement,
-		uint32_t page_alignment,
-		bool interruptible,
-		struct sg_table *sg,
-		struct dma_resv *resv,
-		void (*destroy) (struct ttm_buffer_object *))
+/**
+ * ttm_bo_init_validate
+ *
+ * @bdev: Pointer to a ttm_device struct.
+ * @bo: Pointer to a ttm_buffer_object to be initialized.
+ * @type: Requested type of buffer object.
+ * @placement: Initial placement for buffer object.
+ * @alignment: Data alignment in pages.
+ * @interruptible: If needing to sleep to wait for GPU resources,
+ * sleep interruptible.
+ * pinned in physical memory. If this behaviour is not desired, this member
+ * holds a pointer to a persistent shmem object. Typically, this would
+ * point to the shmem object backing a GEM object if TTM is used to back a
+ * GEM user interface.
+ * @sg: Scatter-gather table.
+ * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
+ * @destroy: Destroy function. Use NULL for kfree().
+ *
+ * This function initializes a pre-allocated struct ttm_buffer_object.
+ * As this object may be part of a larger structure, this function,
+ * together with the @destroy function,
+ * enables driver-specific objects derived from a ttm_buffer_object.
+ *
+ * On successful return, the caller owns an object kref to @bo. The kref and
+ * list_kref are usually set to 1, but note that in some situations, other
+ * tasks may already be holding references to @bo as well.
+ *
+ * If a failure occurs, the function will call the @destroy function, Thus,
+ * after a failure, dereferencing @bo is illegal and will likely cause memory
+ * corruption.
+ *
+ * Returns
+ * -ENOMEM: Out of memory.
+ * -EINVAL: Invalid placement flags.
+ * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
+ */
+int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo,
+			 enum ttm_bo_type type, struct ttm_placement *placement,
+			 uint32_t alignment, bool interruptible,
+			 struct sg_table *sg, struct dma_resv *resv,
+			 void (*destroy) (struct ttm_buffer_object *))
 {
 	struct ttm_operation_ctx ctx = { interruptible, false };
 	int ret;
 
-	ret = ttm_bo_init_reserved(bdev, bo, size, type, placement,
-				   page_alignment, &ctx, sg, resv, destroy);
+	ret = ttm_bo_init_reserved(bdev, bo, type, placement, alignment, &ctx,
+				   sg, resv, destroy);
 	if (ret)
 		return ret;
 
@@ -1015,7 +1074,7 @@  int ttm_bo_init(struct ttm_device *bdev,
 
 	return 0;
 }
-EXPORT_SYMBOL(ttm_bo_init);
+EXPORT_SYMBOL(ttm_bo_init_validate);
 
 /*
  * buffer object vm functions.
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index 85a66014c2b6..eb2fd7694cd1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -429,9 +429,9 @@  int vmw_bo_create_kernel(struct vmw_private *dev_priv, unsigned long size,
 
 	drm_gem_private_object_init(vdev, &bo->base, size);
 
-	ret = ttm_bo_init_reserved(&dev_priv->bdev, bo, size,
-				   ttm_bo_type_kernel, placement, 0,
-				   &ctx, NULL, NULL, vmw_bo_default_destroy);
+	ret = ttm_bo_init_reserved(&dev_priv->bdev, bo, ttm_bo_type_kernel,
+				   placement, 0, &ctx, NULL, NULL,
+				   vmw_bo_default_destroy);
 	if (unlikely(ret))
 		goto error_free;
 
@@ -512,10 +512,8 @@  int vmw_bo_init(struct vmw_private *dev_priv,
 	size = ALIGN(size, PAGE_SIZE);
 	drm_gem_private_object_init(vdev, &vmw_bo->base.base, size);
 
-	ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, size,
-				   ttm_bo_type_device,
-				   placement,
-				   0, &ctx, NULL, NULL, bo_free);
+	ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, ttm_bo_type_device,
+				   placement, 0, &ctx, NULL, NULL, bo_free);
 	if (unlikely(ret)) {
 		return ret;
 	}
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 2d524f8b0802..44a538ee5e2a 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -317,93 +317,16 @@  void ttm_bo_unlock_delayed_workqueue(struct ttm_device *bdev, int resched);
 bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
 			      const struct ttm_place *place);
 
-/**
- * ttm_bo_init_reserved
- *
- * @bdev: Pointer to a ttm_device struct.
- * @bo: Pointer to a ttm_buffer_object to be initialized.
- * @size: Requested size of buffer object.
- * @type: Requested type of buffer object.
- * @placement: Initial placement for buffer object.
- * @page_alignment: Data alignment in pages.
- * @ctx: TTM operation context for memory allocation.
- * @sg: Scatter-gather table.
- * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
- * @destroy: Destroy function. Use NULL for kfree().
- *
- * This function initializes a pre-allocated struct ttm_buffer_object.
- * As this object may be part of a larger structure, this function,
- * together with the @destroy function,
- * enables driver-specific objects derived from a ttm_buffer_object.
- *
- * On successful return, the caller owns an object kref to @bo. The kref and
- * list_kref are usually set to 1, but note that in some situations, other
- * tasks may already be holding references to @bo as well.
- * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
- * and it is the caller's responsibility to call ttm_bo_unreserve.
- *
- * If a failure occurs, the function will call the @destroy function, or
- * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
- * illegal and will likely cause memory corruption.
- *
- * Returns
- * -ENOMEM: Out of memory.
- * -EINVAL: Invalid placement flags.
- * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
- */
-
-int ttm_bo_init_reserved(struct ttm_device *bdev,
-			 struct ttm_buffer_object *bo,
-			 size_t size, enum ttm_bo_type type,
-			 struct ttm_placement *placement,
-			 uint32_t page_alignment,
-			 struct ttm_operation_ctx *ctx,
+int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
+			 enum ttm_bo_type type, struct ttm_placement *placement,
+			 uint32_t alignment, struct ttm_operation_ctx *ctx,
+			 struct sg_table *sg, struct dma_resv *resv,
+			 void (*destroy) (struct ttm_buffer_object *));
+int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo,
+			 enum ttm_bo_type type, struct ttm_placement *placement,
+			 uint32_t alignment, bool interruptible,
 			 struct sg_table *sg, struct dma_resv *resv,
 			 void (*destroy) (struct ttm_buffer_object *));
-
-/**
- * ttm_bo_init
- *
- * @bdev: Pointer to a ttm_device struct.
- * @bo: Pointer to a ttm_buffer_object to be initialized.
- * @size: Requested size of buffer object.
- * @type: Requested type of buffer object.
- * @placement: Initial placement for buffer object.
- * @page_alignment: Data alignment in pages.
- * @interruptible: If needing to sleep to wait for GPU resources,
- * sleep interruptible.
- * pinned in physical memory. If this behaviour is not desired, this member
- * holds a pointer to a persistent shmem object. Typically, this would
- * point to the shmem object backing a GEM object if TTM is used to back a
- * GEM user interface.
- * @sg: Scatter-gather table.
- * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
- * @destroy: Destroy function. Use NULL for kfree().
- *
- * This function initializes a pre-allocated struct ttm_buffer_object.
- * As this object may be part of a larger structure, this function,
- * together with the @destroy function,
- * enables driver-specific objects derived from a ttm_buffer_object.
- *
- * On successful return, the caller owns an object kref to @bo. The kref and
- * list_kref are usually set to 1, but note that in some situations, other
- * tasks may already be holding references to @bo as well.
- *
- * If a failure occurs, the function will call the @destroy function, or
- * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
- * illegal and will likely cause memory corruption.
- *
- * Returns
- * -ENOMEM: Out of memory.
- * -EINVAL: Invalid placement flags.
- * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
- */
-int ttm_bo_init(struct ttm_device *bdev, struct ttm_buffer_object *bo,
-		size_t size, enum ttm_bo_type type,
-		struct ttm_placement *placement,
-		uint32_t page_alignment, bool interrubtible,
-		struct sg_table *sg, struct dma_resv *resv,
-		void (*destroy) (struct ttm_buffer_object *));
 
 /**
  * ttm_kmap_obj_virtual