* [PATCH] accel/qaic: hold the dma_resv lock when mapping imported buffers
@ 2026-11-19 8:14 Wang Haoran
2026-11-19 8:24 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Wang Haoran @ 2026-11-19 8:14 UTC (permalink / raw)
To: jeff.hugo, carl.vanderlip
Cc: ogabbay, sumit.semwal, christian.koenig, phasta, linux-arm-msm,
dri-devel, linux-media, linaro-mm-sig, linux-kernel, wanghr2026
qaic_prepare_import_bo() maps an imported dma-buf with
dma_buf_map_attachment() and qaic_unprepare_import_bo() unmaps it with
dma_buf_unmap_attachment(). Those are the locked variants: the dma-buf
locking convention requires importers to hold the buffer's reservation
lock when calling them, and both assert it via dma_resv_assert_held(),
i.e. lockdep_assert_held() on attach->dmabuf->resv.
qaic calls both without holding the reservation lock, so on a
lockdep-enabled kernel every slice attach/detach against an imported
buffer trips the lockdep assertion (a WARNING with a backtrace). The
reservation lock also serializes the importer against the exporter
moving or invalidating the buffer's backing storage for a dynamic
attachment, so an unlocked map can race that move and use a stale
sg_table.
Hold the reservation lock around the map and unmap calls, which is
equivalent to the dedicated dma_buf_map_attachment_unlocked() and
dma_buf_unmap_attachment_unlocked() helpers.
Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: ff13be830333 ("accel/qaic: Add datapath")
---
diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index ee35e13091b3..0b57f8d544a2 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -895,7 +895,9 @@ static int qaic_prepare_import_bo(struct qaic_bo *bo, struct qaic_attach_slice_h
struct sg_table *sgt;
int ret;
+ dma_resv_lock(obj->resv, NULL);
sgt = dma_buf_map_attachment(obj->import_attach, hdr->dir);
+ dma_resv_unlock(obj->resv);
if (IS_ERR(sgt)) {
ret = PTR_ERR(sgt);
return ret;
@@ -936,7 +938,9 @@ static int qaic_prepare_bo(struct qaic_device *qdev, struct qaic_bo *bo,
static void qaic_unprepare_import_bo(struct qaic_bo *bo)
{
+ dma_resv_lock(bo->base.resv, NULL);
dma_buf_unmap_attachment(bo->base.import_attach, bo->sgt, bo->dir);
+ dma_resv_unlock(bo->base.resv);
bo->sgt = NULL;
}
---
The vulnerability was found by static analysis.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] accel/qaic: hold the dma_resv lock when mapping imported buffers
2026-11-19 8:14 [PATCH] accel/qaic: hold the dma_resv lock when mapping imported buffers Wang Haoran
@ 2026-11-19 8:24 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 8:24 UTC (permalink / raw)
To: Wang Haoran; +Cc: dri-devel, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] accel/qaic: open-coded dma-buf unlocked map/unmap helpers in
qaic_data.c
--
commit 393bb58da0dd7ba519229334f4b5698ecdaba857
Author: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
accel/qaic: hold the dma_resv lock when mapping imported buffers
This commit acquires the buffer reservation lock around
dma_buf_map_attachment() and dma_buf_unmap_attachment() in
qaic_prepare_import_bo() and qaic_unprepare_import_bo().
> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
> index be3ceb8c51a09..8879ffe647c52 100644
> --- a/drivers/accel/qaic/qaic_data.c
> +++ b/drivers/accel/qaic/qaic_data.c
> @@ -895,7 +895,9 @@ static int qaic_prepare_import_bo(struct qaic_bo *bo, struct qaic_attach_slice_h
> struct sg_table *sgt;
> int ret;
>
> + dma_resv_lock(obj->resv, NULL);
> sgt = dma_buf_map_attachment(obj->import_attach, hdr->dir);
> + dma_resv_unlock(obj->resv);
> if (IS_ERR(sgt)) {
> ret = PTR_ERR(sgt);
> return ret;
> @@ -936,7 +938,9 @@ static int qaic_prepare_bo(struct qaic_device *qdev, struct qaic_bo *bo,
>
> static void qaic_unprepare_import_bo(struct qaic_bo *bo)
> {
> + dma_resv_lock(bo->base.resv, NULL);
> dma_buf_unmap_attachment(bo->base.import_attach, bo->sgt, bo->dir);
> + dma_resv_unlock(bo->base.resv);
> bo->sgt = NULL;
> }
[Severity: Low]
This isn't a bug, but could qaic_prepare_import_bo() and
qaic_unprepare_import_bo() call dma_buf_map_attachment_unlocked() and
dma_buf_unmap_attachment_unlocked() directly instead of open-coding the
dma_resv_lock() and dma_resv_unlock() sequence?
--
Sashiko AI review · https://sashiko.dev/#/patchset/1795076088845-1-b103cfa7@mail.zgclab.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 8:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 8:14 [PATCH] accel/qaic: hold the dma_resv lock when mapping imported buffers Wang Haoran
2026-11-19 8:24 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.