Commit 94dee3b9 authored by Thomas Zimmermann's avatar Thomas Zimmermann
Browse files

drm/gem-vram: Acquire reservation lock in GEM pin/unpin callbacks



Acquire the reservation lock directly in GEM pin callback. Same for
unpin. Prepares for further changes.

Dma-buf locking semantics require callers to hold the buffer's
reservation lock when invoking the pin and unpin callbacks. Prepare
gem-vram accordingly by pushing locking out of the implementation.
A follow-up patch will fix locking for all GEM code at once.

Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarDmitry Osipenko <dmitry.osipenko@collabora.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> # virtio-gpu
Acked-by: default avatarZack Rusin <zack.rusin@broadcom.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240227113853.8464-3-tzimmermann@suse.de
parent ec144244
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -283,6 +283,8 @@ static int drm_gem_vram_pin_locked(struct drm_gem_vram_object *gbo,
	struct ttm_operation_ctx ctx = { false, false };
	int ret;

	dma_resv_assert_held(gbo->bo.base.resv);

	if (gbo->bo.pin_count)
		goto out;

@@ -338,6 +340,8 @@ EXPORT_SYMBOL(drm_gem_vram_pin);

static void drm_gem_vram_unpin_locked(struct drm_gem_vram_object *gbo)
{
	dma_resv_assert_held(gbo->bo.base.resv);

	ttm_bo_unpin(&gbo->bo);
}

@@ -770,8 +774,14 @@ EXPORT_SYMBOL(drm_gem_vram_simple_display_pipe_cleanup_fb);
static int drm_gem_vram_object_pin(struct drm_gem_object *gem)
{
	struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
	int ret;

	/* Fbdev console emulation is the use case of these PRIME
	ret = ttm_bo_reserve(&gbo->bo, true, false, NULL);
	if (ret)
		return ret;

	/*
	 * Fbdev console emulation is the use case of these PRIME
	 * helpers. This may involve updating a hardware buffer from
	 * a shadow FB. We pin the buffer to it's current location
	 * (either video RAM or system memory) to prevent it from
@@ -779,7 +789,10 @@ static int drm_gem_vram_object_pin(struct drm_gem_object *gem)
	 * the buffer to be pinned to VRAM, implement a callback that
	 * sets the flags accordingly.
	 */
	return drm_gem_vram_pin(gbo, 0);
	ret = drm_gem_vram_pin_locked(gbo, 0);
	ttm_bo_unreserve(&gbo->bo);

	return ret;
}

/**
@@ -790,8 +803,13 @@ static int drm_gem_vram_object_pin(struct drm_gem_object *gem)
static void drm_gem_vram_object_unpin(struct drm_gem_object *gem)
{
	struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
	int ret;

	drm_gem_vram_unpin(gbo);
	ret = ttm_bo_reserve(&gbo->bo, true, false, NULL);
	if (ret)
		return;
	drm_gem_vram_unpin_locked(gbo);
	ttm_bo_unreserve(&gbo->bo);
}

/**