Commit 79e2cf2e authored by Dmitry Osipenko's avatar Dmitry Osipenko
Browse files

drm/gem: Take reservation lock for vmap/vunmap operations



The new common dma-buf locking convention will require buffer importers
to hold the reservation lock around mapping operations. Make DRM GEM core
to take the lock around the vmapping operations and update DRM drivers to
use the locked functions for the case where DRM core now holds the lock.
This patch prepares DRM core and drivers to the common dynamic dma-buf
locking convention.

Acked-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarDmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221017172229.42269-4-dmitry.osipenko@collabora.com
parent 19d6634d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ drm_client_buffer_vmap(struct drm_client_buffer *buffer,
	 * fd_install step out of the driver backend hooks, to make that
	 * final step optional for internal users.
	 */
	ret = drm_gem_vmap(buffer->gem, map);
	ret = drm_gem_vmap_unlocked(buffer->gem, map);
	if (ret)
		return ret;

@@ -345,7 +345,7 @@ void drm_client_buffer_vunmap(struct drm_client_buffer *buffer)
{
	struct iosys_map *map = &buffer->map;

	drm_gem_vunmap(buffer->gem, map);
	drm_gem_vunmap_unlocked(buffer->gem, map);
}
EXPORT_SYMBOL(drm_client_buffer_vunmap);

+24 −0
Original line number Diff line number Diff line
@@ -1171,6 +1171,8 @@ int drm_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
{
	int ret;

	dma_resv_assert_held(obj->resv);

	if (!obj->funcs->vmap)
		return -EOPNOTSUPP;

@@ -1186,6 +1188,8 @@ EXPORT_SYMBOL(drm_gem_vmap);

void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
{
	dma_resv_assert_held(obj->resv);

	if (iosys_map_is_null(map))
		return;

@@ -1197,6 +1201,26 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
}
EXPORT_SYMBOL(drm_gem_vunmap);

int drm_gem_vmap_unlocked(struct drm_gem_object *obj, struct iosys_map *map)
{
	int ret;

	dma_resv_lock(obj->resv, NULL);
	ret = drm_gem_vmap(obj, map);
	dma_resv_unlock(obj->resv);

	return ret;
}
EXPORT_SYMBOL(drm_gem_vmap_unlocked);

void drm_gem_vunmap_unlocked(struct drm_gem_object *obj, struct iosys_map *map)
{
	dma_resv_lock(obj->resv, NULL);
	drm_gem_vunmap(obj, map);
	dma_resv_unlock(obj->resv);
}
EXPORT_SYMBOL(drm_gem_vunmap_unlocked);

/**
 * drm_gem_lock_reservations - Sets up the ww context and acquires
 * the lock on an array of GEM objects.
+3 −3
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ void drm_gem_dma_free(struct drm_gem_dma_object *dma_obj)

	if (gem_obj->import_attach) {
		if (dma_obj->vaddr)
			dma_buf_vunmap(gem_obj->import_attach->dmabuf, &map);
			dma_buf_vunmap_unlocked(gem_obj->import_attach->dmabuf, &map);
		drm_prime_gem_destroy(gem_obj, dma_obj->sgt);
	} else if (dma_obj->vaddr) {
		if (dma_obj->map_noncoherent)
@@ -581,7 +581,7 @@ drm_gem_dma_prime_import_sg_table_vmap(struct drm_device *dev,
	struct iosys_map map;
	int ret;

	ret = dma_buf_vmap(attach->dmabuf, &map);
	ret = dma_buf_vmap_unlocked(attach->dmabuf, &map);
	if (ret) {
		DRM_ERROR("Failed to vmap PRIME buffer\n");
		return ERR_PTR(ret);
@@ -589,7 +589,7 @@ drm_gem_dma_prime_import_sg_table_vmap(struct drm_device *dev,

	obj = drm_gem_dma_prime_import_sg_table(dev, attach, sgt);
	if (IS_ERR(obj)) {
		dma_buf_vunmap(attach->dmabuf, &map);
		dma_buf_vunmap_unlocked(attach->dmabuf, &map);
		return obj;
	}

+3 −3
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct iosys_map *map,
			ret = -EINVAL;
			goto err_drm_gem_vunmap;
		}
		ret = drm_gem_vmap(obj, &map[i]);
		ret = drm_gem_vmap_unlocked(obj, &map[i]);
		if (ret)
			goto err_drm_gem_vunmap;
	}
@@ -376,7 +376,7 @@ int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct iosys_map *map,
		obj = drm_gem_fb_get_obj(fb, i);
		if (!obj)
			continue;
		drm_gem_vunmap(obj, &map[i]);
		drm_gem_vunmap_unlocked(obj, &map[i]);
	}
	return ret;
}
@@ -403,7 +403,7 @@ void drm_gem_fb_vunmap(struct drm_framebuffer *fb, struct iosys_map *map)
			continue;
		if (iosys_map_is_null(&map[i]))
			continue;
		drm_gem_vunmap(obj, &map[i]);
		drm_gem_vunmap_unlocked(obj, &map[i]);
	}
}
EXPORT_SYMBOL(drm_gem_fb_vunmap);
+1 −8
Original line number Diff line number Diff line
@@ -64,13 +64,8 @@ int drm_gem_ttm_vmap(struct drm_gem_object *gem,
		     struct iosys_map *map)
{
	struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);
	int ret;

	dma_resv_lock(gem->resv, NULL);
	ret = ttm_bo_vmap(bo, map);
	dma_resv_unlock(gem->resv);

	return ret;
	return ttm_bo_vmap(bo, map);
}
EXPORT_SYMBOL(drm_gem_ttm_vmap);

@@ -87,9 +82,7 @@ void drm_gem_ttm_vunmap(struct drm_gem_object *gem,
{
	struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);

	dma_resv_lock(gem->resv, NULL);
	ttm_bo_vunmap(bo, map);
	dma_resv_unlock(gem->resv);
}
EXPORT_SYMBOL(drm_gem_ttm_vunmap);

Loading