drm/ttm: prevent moving of pinned BOs

We have checks for this in the individual drivers move callback, but
it's probably better to generally forbid that on a higher level.

Also stops exporting ttm_resource_compat() since that's not necessary
any more after removing the extra checks in vmwgfx.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230124125726.13323-4-christian.koenig@amd.com
This commit is contained in:
Christian König 2022-12-13 10:07:36 +01:00
parent 4110872b81
commit b49323aa35
6 changed files with 14 additions and 37 deletions

View File

@ -466,11 +466,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
return r; return r;
} }
/* Can't move a pinned BO */
abo = ttm_to_amdgpu_bo(bo); abo = ttm_to_amdgpu_bo(bo);
if (WARN_ON_ONCE(abo->tbo.pin_count > 0))
return -EINVAL;
adev = amdgpu_ttm_adev(bo->bdev); adev = amdgpu_ttm_adev(bo->bdev);
if (!old_mem || (old_mem->mem_type == TTM_PL_SYSTEM && if (!old_mem || (old_mem->mem_type == TTM_PL_SYSTEM &&

View File

@ -1015,9 +1015,6 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
if (ret) if (ret)
goto out_ntfy; goto out_ntfy;
if (nvbo->bo.pin_count)
NV_WARN(drm, "Moving pinned object %p!\n", nvbo);
if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) { if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
ret = nouveau_bo_vm_bind(bo, new_reg, &new_tile); ret = nouveau_bo_vm_bind(bo, new_reg, &new_tile);
if (ret) if (ret)

View File

@ -211,11 +211,7 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
if (r) if (r)
return r; return r;
/* Can't move a pinned BO */
rbo = container_of(bo, struct radeon_bo, tbo); rbo = container_of(bo, struct radeon_bo, tbo);
if (WARN_ON_ONCE(rbo->tbo.pin_count > 0))
return -EINVAL;
rdev = radeon_get_rdev(bo->bdev); rdev = radeon_get_rdev(bo->bdev);
if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) { if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
ttm_bo_move_null(bo, new_mem); ttm_bo_move_null(bo, new_mem);

View File

@ -894,14 +894,18 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
if (!placement->num_placement && !placement->num_busy_placement) if (!placement->num_placement && !placement->num_busy_placement)
return ttm_bo_pipeline_gutting(bo); return ttm_bo_pipeline_gutting(bo);
/* /* Check whether we need to move buffer. */
* Check whether we need to move buffer. if (bo->resource && ttm_resource_compat(bo->resource, placement))
*/ return 0;
if (!bo->resource || !ttm_resource_compat(bo->resource, placement)) {
/* Moving of pinned BOs is forbidden */
if (bo->pin_count)
return -EINVAL;
ret = ttm_bo_move_buffer(bo, placement, ctx); ret = ttm_bo_move_buffer(bo, placement, ctx);
if (ret) if (ret)
return ret; return ret;
}
/* /*
* We might need to add a TTM. * We might need to add a TTM.
*/ */

View File

@ -361,7 +361,6 @@ bool ttm_resource_compat(struct ttm_resource *res,
return false; return false;
} }
EXPORT_SYMBOL(ttm_resource_compat);
void ttm_resource_set_bo(struct ttm_resource *res, void ttm_resource_set_bo(struct ttm_resource *res,
struct ttm_buffer_object *bo) struct ttm_buffer_object *bo)

View File

@ -87,12 +87,7 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto err; goto err;
if (buf->base.pin_count > 0)
ret = ttm_resource_compat(bo->resource, placement)
? 0 : -EINVAL;
else
ret = ttm_bo_validate(bo, placement, &ctx); ret = ttm_bo_validate(bo, placement, &ctx);
if (!ret) if (!ret)
vmw_bo_pin_reserved(buf, true); vmw_bo_pin_reserved(buf, true);
@ -128,12 +123,6 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto err; goto err;
if (buf->base.pin_count > 0) {
ret = ttm_resource_compat(bo->resource, &vmw_vram_gmr_placement)
? 0 : -EINVAL;
goto out_unreserve;
}
ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, &ctx); ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, &ctx);
if (likely(ret == 0) || ret == -ERESTARTSYS) if (likely(ret == 0) || ret == -ERESTARTSYS)
goto out_unreserve; goto out_unreserve;
@ -218,10 +207,6 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
(void) ttm_bo_validate(bo, &vmw_sys_placement, &ctx); (void) ttm_bo_validate(bo, &vmw_sys_placement, &ctx);
} }
if (buf->base.pin_count > 0)
ret = ttm_resource_compat(bo->resource, &placement)
? 0 : -EINVAL;
else
ret = ttm_bo_validate(bo, &placement, &ctx); ret = ttm_bo_validate(bo, &placement, &ctx);
/* For some reason we didn't end up at the start of vram */ /* For some reason we didn't end up at the start of vram */