From: "Christian König" <christian.koenig@amd.com>
To: "Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
"David Airlie" <airlied@linux.ie>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Gurchetan Singh" <gurchetansingh@chromium.org>,
"Chia-I Wu" <olvaffe@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Gert Wollny" <gert.wollny@collabora.com>,
"Gustavo Padovan" <gustavo.padovan@collabora.com>,
"Daniel Stone" <daniel@fooishbar.org>,
"Tomeu Vizoso" <tomeu.vizoso@collabora.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Rob Clark" <robdclark@gmail.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Pan, Xinhui" <Xinhui.Pan@amd.com>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Tomasz Figa" <tfiga@chromium.org>,
"Marek Szyprowski" <m.szyprowski@samsung.com>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tvrtko.ursulin@linux.intel.com>,
"Thomas Hellström" <thomas_os@shipmail.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Dmitry Osipenko <digetx@gmail.com>,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
kernel@collabora.com, virtualization@lists.linux-foundation.org,
spice-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v1 2/6] drm/gem: Take reservation lock for vmap/vunmap operations
Date: Fri, 15 Jul 2022 09:31:12 +0200 [thread overview]
Message-ID: <138407a9-e97f-001e-6e87-e5d92a55c8e8@amd.com> (raw)
In-Reply-To: <20220715005244.42198-3-dmitry.osipenko@collabora.com>
Am 15.07.22 um 02:52 schrieb Dmitry Osipenko:
> 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 QXL and i915
> drivers to use the locked functions for the case where DRM core now holds
> the lock. This patch prepares DRM core and drivers to transition to the
> common dma-buf locking convention where vmapping of exported GEMs will
> be done under the held reservation lock.
Oh ^^ That looks like a bug fix to me!
At least drm_gem_ttm_vmap() and drm_gem_ttm_vunmap() already expected
that they are called with the reservation lock held.
Otherwise you could mess up internal structures in the TTM buffer object
while vmapping it.
I will take a deeper look at this.
Regards,
Christian.
>
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> ---
> drivers/gpu/drm/drm_client.c | 4 +--
> drivers/gpu/drm/drm_gem.c | 28 ++++++++++++++++++++
> drivers/gpu/drm/drm_gem_framebuffer_helper.c | 6 ++---
> drivers/gpu/drm/drm_prime.c | 4 +--
> drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 2 +-
> drivers/gpu/drm/qxl/qxl_object.c | 17 ++++++------
> drivers/gpu/drm/qxl/qxl_prime.c | 4 +--
> include/drm/drm_gem.h | 3 +++
> 8 files changed, 50 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
> index 2b230b4d6942..fbcb1e995384 100644
> --- a/drivers/gpu/drm/drm_client.c
> +++ b/drivers/gpu/drm/drm_client.c
> @@ -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);
>
> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> index eb0c2d041f13..9769c33cad99 100644
> --- a/drivers/gpu/drm/drm_gem.c
> +++ b/drivers/gpu/drm/drm_gem.c
> @@ -1155,6 +1155,8 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent,
>
> int drm_gem_pin(struct drm_gem_object *obj)
> {
> + dma_resv_assert_held(obj->resv);
> +
> if (obj->funcs->pin)
> return obj->funcs->pin(obj);
> else
> @@ -1163,6 +1165,8 @@ int drm_gem_pin(struct drm_gem_object *obj)
>
> void drm_gem_unpin(struct drm_gem_object *obj)
> {
> + dma_resv_assert_held(obj->resv);
> +
> if (obj->funcs->unpin)
> obj->funcs->unpin(obj);
> }
> @@ -1171,6 +1175,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 +1192,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 +1205,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.
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index 880a4975507f..e35e224e6303 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -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);
> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> index b75ef1756873..1bd234fd21a5 100644
> --- a/drivers/gpu/drm/drm_prime.c
> +++ b/drivers/gpu/drm/drm_prime.c
> @@ -678,7 +678,7 @@ int drm_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct iosys_map *map)
> {
> struct drm_gem_object *obj = dma_buf->priv;
>
> - return drm_gem_vmap(obj, map);
> + return drm_gem_vmap_unlocked(obj, map);
> }
> EXPORT_SYMBOL(drm_gem_dmabuf_vmap);
>
> @@ -694,7 +694,7 @@ void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct iosys_map *map)
> {
> struct drm_gem_object *obj = dma_buf->priv;
>
> - drm_gem_vunmap(obj, map);
> + drm_gem_vunmap_unlocked(obj, map);
> }
> EXPORT_SYMBOL(drm_gem_dmabuf_vunmap);
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> index 5ecea7df98b1..cc54a5b1d6ae 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> @@ -72,7 +72,7 @@ static int i915_gem_dmabuf_vmap(struct dma_buf *dma_buf,
> struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
> void *vaddr;
>
> - vaddr = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
> + vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
> if (IS_ERR(vaddr))
> return PTR_ERR(vaddr);
>
> diff --git a/drivers/gpu/drm/qxl/qxl_object.c b/drivers/gpu/drm/qxl/qxl_object.c
> index 695d9308d1f0..06a58dad5f5c 100644
> --- a/drivers/gpu/drm/qxl/qxl_object.c
> +++ b/drivers/gpu/drm/qxl/qxl_object.c
> @@ -168,9 +168,16 @@ int qxl_bo_vmap_locked(struct qxl_bo *bo, struct iosys_map *map)
> bo->map_count++;
> goto out;
> }
> - r = ttm_bo_vmap(&bo->tbo, &bo->map);
> +
> + r = __qxl_bo_pin(bo);
> if (r)
> return r;
> +
> + r = ttm_bo_vmap(&bo->tbo, &bo->map);
> + if (r) {
> + __qxl_bo_unpin(bo);
> + return r;
> + }
> bo->map_count = 1;
>
> /* TODO: Remove kptr in favor of map everywhere. */
> @@ -192,12 +199,6 @@ int qxl_bo_vmap(struct qxl_bo *bo, struct iosys_map *map)
> if (r)
> return r;
>
> - r = __qxl_bo_pin(bo);
> - if (r) {
> - qxl_bo_unreserve(bo);
> - return r;
> - }
> -
> r = qxl_bo_vmap_locked(bo, map);
> qxl_bo_unreserve(bo);
> return r;
> @@ -247,6 +248,7 @@ void qxl_bo_vunmap_locked(struct qxl_bo *bo)
> return;
> bo->kptr = NULL;
> ttm_bo_vunmap(&bo->tbo, &bo->map);
> + __qxl_bo_unpin(bo);
> }
>
> int qxl_bo_vunmap(struct qxl_bo *bo)
> @@ -258,7 +260,6 @@ int qxl_bo_vunmap(struct qxl_bo *bo)
> return r;
>
> qxl_bo_vunmap_locked(bo);
> - __qxl_bo_unpin(bo);
> qxl_bo_unreserve(bo);
> return 0;
> }
> diff --git a/drivers/gpu/drm/qxl/qxl_prime.c b/drivers/gpu/drm/qxl/qxl_prime.c
> index 142d01415acb..9169c26357d3 100644
> --- a/drivers/gpu/drm/qxl/qxl_prime.c
> +++ b/drivers/gpu/drm/qxl/qxl_prime.c
> @@ -59,7 +59,7 @@ int qxl_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map)
> struct qxl_bo *bo = gem_to_qxl_bo(obj);
> int ret;
>
> - ret = qxl_bo_vmap(bo, map);
> + ret = qxl_bo_vmap_locked(bo, map);
> if (ret < 0)
> return ret;
>
> @@ -71,5 +71,5 @@ void qxl_gem_prime_vunmap(struct drm_gem_object *obj,
> {
> struct qxl_bo *bo = gem_to_qxl_bo(obj);
>
> - qxl_bo_vunmap(bo);
> + qxl_bo_vunmap_locked(bo);
> }
> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
> index 87cffc9efa85..bf3700415229 100644
> --- a/include/drm/drm_gem.h
> +++ b/include/drm/drm_gem.h
> @@ -420,4 +420,7 @@ void drm_gem_unlock_reservations(struct drm_gem_object **objs, int count,
> int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
> u32 handle, u64 *offset);
>
> +int drm_gem_vmap_unlocked(struct drm_gem_object *obj, struct iosys_map *map);
> +void drm_gem_vunmap_unlocked(struct drm_gem_object *obj, struct iosys_map *map);
> +
> #endif /* __DRM_GEM_H__ */
next prev parent reply other threads:[~2022-07-15 7:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 0:52 [PATCH v1 0/6] Move all drivers to a common dma-buf locking convention Dmitry Osipenko
2022-07-15 0:52 ` [PATCH v1 1/6] dma-buf: Add _unlocked postfix to function names Dmitry Osipenko
2022-07-15 7:19 ` Christian König
2022-07-15 9:31 ` Dmitry Osipenko
2022-07-15 11:04 ` Christian König
2022-07-15 0:52 ` [PATCH v1 2/6] drm/gem: Take reservation lock for vmap/vunmap operations Dmitry Osipenko
2022-07-15 7:31 ` Christian König [this message]
2022-07-15 0:52 ` [PATCH v1 3/6] dma-buf: Move all dma-bufs to dynamic locking specification Dmitry Osipenko
2022-07-15 0:52 ` [PATCH v1 4/6] dma-buf: Acquire wait-wound context on attachment Dmitry Osipenko
2022-07-15 3:38 ` kernel test robot
2022-07-15 6:50 ` Christian König
2022-07-15 6:59 ` Dmitry Osipenko
2022-07-19 20:05 ` Dmitry Osipenko
2022-07-20 8:29 ` Christian König
2022-07-20 12:18 ` Dmitry Osipenko
2022-07-15 0:52 ` [PATCH v1 5/6] media: videobuf2: Stop using internal dma-buf lock Dmitry Osipenko
2022-07-15 0:52 ` [PATCH v1 6/6] dma-buf: Remove internal lock Dmitry Osipenko
2022-07-19 9:13 ` [PATCH v1 0/6] Move all drivers to a common dma-buf locking convention Tomasz Figa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=138407a9-e97f-001e-6e87-e5d92a55c8e8@amd.com \
--to=christian.koenig@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@linux.ie \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=daniel.almeida@collabora.com \
--cc=daniel@ffwll.ch \
--cc=daniel@fooishbar.org \
--cc=digetx@gmail.com \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gert.wollny@collabora.com \
--cc=gurchetansingh@chromium.org \
--cc=gustavo.padovan@collabora.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kernel@collabora.com \
--cc=kraxel@redhat.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mchehab@kernel.org \
--cc=mripard@kernel.org \
--cc=olvaffe@gmail.com \
--cc=robdclark@gmail.com \
--cc=rodrigo.vivi@intel.com \
--cc=spice-devel@lists.freedesktop.org \
--cc=sumit.semwal@linaro.org \
--cc=tfiga@chromium.org \
--cc=thierry.reding@gmail.com \
--cc=thomas_os@shipmail.org \
--cc=tomeu.vizoso@collabora.com \
--cc=tvrtko.ursulin@linux.intel.com \
--cc=tzimmermann@suse.de \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).