diff options
author | Dave Airlie <airlied@redhat.com> | 2020-09-17 05:54:24 +0300 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2020-09-17 23:14:00 +0300 |
commit | 0b988ca1c7c4c73983b4ea96ef7c2af2263c87eb (patch) | |
tree | 729ee7adfc399e41f03a768f1a1df8f036d7af88 /drivers/gpu/drm/ttm | |
parent | 67d6a8b358eac488112a4775f77dc3dbf63bea88 (diff) | |
download | linux-0b988ca1c7c4c73983b4ea96ef7c2af2263c87eb.tar.xz |
drm/ttm: protect against reentrant bind in the drivers
This moves the generic tracking into the drivers and protects
against reentrancy in the drivers. It fixes up radeon and agp
to be able to query the bound status as that is required.
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200917043040.146575-2-airlied@gmail.com
Diffstat (limited to 'drivers/gpu/drm/ttm')
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_agp_backend.c | 14 | ||||
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo.c | 20 | ||||
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo_util.c | 5 |
3 files changed, 16 insertions, 23 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c index 7b36fdaab766..a98fd795b752 100644 --- a/drivers/gpu/drm/ttm/ttm_agp_backend.c +++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c @@ -57,6 +57,9 @@ int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem) int ret, cached = (bo_mem->placement & TTM_PL_FLAG_CACHED); unsigned i; + if (agp_be->mem) + return 0; + mem = agp_allocate_memory(agp_be->bridge, ttm->num_pages, AGP_USER_MEMORY); if (unlikely(mem == NULL)) return -ENOMEM; @@ -98,6 +101,17 @@ void ttm_agp_unbind(struct ttm_tt *ttm) } EXPORT_SYMBOL(ttm_agp_unbind); +bool ttm_agp_is_bound(struct ttm_tt *ttm) +{ + struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm); + + if (!ttm) + return false; + + return (agp_be->mem != NULL); +} +EXPORT_SYMBOL(ttm_agp_is_bound); + void ttm_agp_destroy(struct ttm_tt *ttm) { struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm); diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 92d60585deb1..4741c73f6ea4 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1626,27 +1626,11 @@ void ttm_bo_tt_destroy(struct ttm_buffer_object *bo) int ttm_bo_tt_bind(struct ttm_buffer_object *bo, struct ttm_resource *mem) { - int ret; - - if (!bo->ttm) - return -EINVAL; - - if (ttm_bo_tt_is_bound(bo)) - return 0; - - ret = bo->bdev->driver->ttm_tt_bind(bo->bdev, bo->ttm, mem); - if (unlikely(ret != 0)) - return ret; - - ttm_bo_tt_set_bound(bo); - return 0; + return bo->bdev->driver->ttm_tt_bind(bo->bdev, bo->ttm, mem); } EXPORT_SYMBOL(ttm_bo_tt_bind); void ttm_bo_tt_unbind(struct ttm_buffer_object *bo) { - if (ttm_bo_tt_is_bound(bo)) { - bo->bdev->driver->ttm_tt_unbind(bo->bdev, bo->ttm); - ttm_bo_tt_set_unbound(bo); - } + bo->bdev->driver->ttm_tt_unbind(bo->bdev, bo->ttm); } diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 980368049d68..919489f6a5a3 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -574,10 +574,8 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, if (man->use_tt) { ghost_obj->ttm = NULL; - ttm_bo_tt_set_unbound(ghost_obj); } else { bo->ttm = NULL; - ttm_bo_tt_set_unbound(bo); } dma_resv_unlock(&ghost_obj->base._resv); @@ -633,10 +631,8 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo, if (to->use_tt) { ghost_obj->ttm = NULL; - ttm_bo_tt_set_unbound(ghost_obj); } else { bo->ttm = NULL; - ttm_bo_tt_set_unbound(bo); } dma_resv_unlock(&ghost_obj->base._resv); @@ -701,7 +697,6 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo) memset(&bo->mem, 0, sizeof(bo->mem)); bo->mem.mem_type = TTM_PL_SYSTEM; bo->ttm = NULL; - ttm_bo_tt_set_unbound(bo); dma_resv_unlock(&ghost->base._resv); ttm_bo_put(ghost); |