Commit 0dbd555a authored by Christian König's avatar Christian König
Browse files

dma-buf: add more reservation object locking wrappers



Complete the abstraction of the ww_mutex inside the reservation object.

This allows us to add more handling and debugging to the reservation
object in the future.

Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/320761/
parent 05103ea9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1729,7 +1729,7 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
	*map = mapping;

	/* Double check that the BO is reserved by this CS */
	if (READ_ONCE((*bo)->tbo.resv->lock.ctx) != &parser->ticket)
	if (reservation_object_locking_ctx((*bo)->tbo.resv) != &parser->ticket)
		return -EINVAL;

	if (!((*bo)->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)) {
+3 −3
Original line number Diff line number Diff line
@@ -380,7 +380,7 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
	bp.flags = 0;
	bp.type = ttm_bo_type_sg;
	bp.resv = resv;
	ww_mutex_lock(&resv->lock, NULL);
	reservation_object_lock(resv, NULL);
	ret = amdgpu_bo_create(adev, &bp, &bo);
	if (ret)
		goto error;
@@ -392,11 +392,11 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
	if (attach->dmabuf->ops != &amdgpu_dmabuf_ops)
		bo->prime_shared_count = 1;

	ww_mutex_unlock(&resv->lock);
	reservation_object_unlock(resv);
	return &bo->gem_base;

error:
	ww_mutex_unlock(&resv->lock);
	reservation_object_unlock(resv);
	return ERR_PTR(ret);
}

+3 −3
Original line number Diff line number Diff line
@@ -546,7 +546,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,

fail_unreserve:
	if (!bp->resv)
		ww_mutex_unlock(&bo->tbo.resv->lock);
		reservation_object_unlock(bo->tbo.resv);
	amdgpu_bo_unref(&bo);
	return r;
}
@@ -1089,7 +1089,7 @@ int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
 */
void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
{
	lockdep_assert_held(&bo->tbo.resv->lock.base);
	reservation_object_assert_held(bo->tbo.resv);

	if (tiling_flags)
		*tiling_flags = bo->tiling_flags;
@@ -1330,7 +1330,7 @@ int amdgpu_bo_sync_wait(struct amdgpu_bo *bo, void *owner, bool intr)
u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
{
	WARN_ON_ONCE(bo->tbo.mem.mem_type == TTM_PL_SYSTEM);
	WARN_ON_ONCE(!ww_mutex_is_locked(&bo->tbo.resv->lock) &&
	WARN_ON_ONCE(!reservation_object_is_locked(bo->tbo.resv) &&
		     !bo->pin_count && bo->tbo.type != ttm_bo_type_kernel);
	WARN_ON_ONCE(bo->tbo.mem.start == AMDGPU_BO_INVALID_OFFSET);
	WARN_ON_ONCE(bo->tbo.mem.mem_type == TTM_PL_VRAM &&
+2 −1
Original line number Diff line number Diff line
@@ -2416,7 +2416,8 @@ void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket)
			struct amdgpu_bo *bo;

			bo = mapping->bo_va->base.bo;
			if (READ_ONCE(bo->tbo.resv->lock.ctx) != ticket)
			if (reservation_object_locking_ctx(bo->tbo.resv) !=
			    ticket)
				continue;
		}

+7 −7
Original line number Diff line number Diff line
@@ -1288,7 +1288,7 @@ retry:
	if (contended != -1) {
		struct drm_gem_object *obj = objs[contended];

		ret = ww_mutex_lock_slow_interruptible(&obj->resv->lock,
		ret = reservation_object_lock_slow_interruptible(obj->resv,
								 acquire_ctx);
		if (ret) {
			ww_acquire_done(acquire_ctx);
@@ -1300,16 +1300,16 @@ retry:
		if (i == contended)
			continue;

		ret = ww_mutex_lock_interruptible(&objs[i]->resv->lock,
		ret = reservation_object_lock_interruptible(objs[i]->resv,
							    acquire_ctx);
		if (ret) {
			int j;

			for (j = 0; j < i; j++)
				ww_mutex_unlock(&objs[j]->resv->lock);
				reservation_object_unlock(objs[j]->resv);

			if (contended != -1 && contended >= i)
				ww_mutex_unlock(&objs[contended]->resv->lock);
				reservation_object_unlock(objs[contended]->resv);

			if (ret == -EDEADLK) {
				contended = i;
@@ -1334,7 +1334,7 @@ drm_gem_unlock_reservations(struct drm_gem_object **objs, int count,
	int i;

	for (i = 0; i < count; i++)
		ww_mutex_unlock(&objs[i]->resv->lock);
		reservation_object_unlock(objs[i]->resv);

	ww_acquire_fini(acquire_ctx);
}
Loading