All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bilal Hashim" <AeeSec@126.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] accel/qaic: Synchronize access to dbc->bo_lists
Date: Sun, 29 Nov 2026 07:10:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-239357@kernel.org> (raw)
In-Reply-To: <20261129065740.864-1-AeeSec@126.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] accel/qaic: missing Fixes trailer for dbc->bo_lists concurrency
  fix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] accel/qaic: missing dma_resv lock in qaic_prepare_import_bo()
  and qaic_unprepare_import_bo() [1]
--

commit 119c19ad9fdb0134dda384da400bc1108d8356d8
Author: Bilal Hashim <AeeSec@126.com>

> accel/qaic: Synchronize access to dbc->bo_lists
>
> Each `struct dma_bridge_chan` maintains a `bo_lists` linked list of all
> sliced BOs attached to that DBC, which is modified in
> `qaic_attach_slice_bo_ioctl()` via `list_add_tail()` and in
> `detach_slice_bo()` (called from `qaic_detach_slice_bo_ioctl()` and
> `release_dbc()`) via `list_del()`.
>
> However, `dbc->bo_lists` is not protected by any lock. Both
> `qaic_attach_slice_bo_ioctl()` and `qaic_detach_slice_bo_ioctl()` only
> hold the per-BO `bo->lock` mutex and shared SRCU read locks
> (`usr->qddev_lock`, `qdev->dev_lock`, and `dbc->ch_lock`). Two threads
> from the same user concurrently attaching or detaching different BOs on
> the same DBC can race on `dbc->bo_lists`, causing linked-list corruption
> and potential use-after-free when `release_dbc()` later iterates
> `dbc->bo_lists`.
>
> Add a dedicated `spinlock_t bo_lists_lock` to `struct dma_bridge_chan`,
> initialize it in `create_qdev()`, and hold it around `list_add_tail()`
> in `qaic_attach_slice_bo_ioctl()` and `list_del()` in
> `detach_slice_bo()`.
>
> Found by manual code inspection.
>
> Signed-off-by: Bilal Hashim <AeeSec@126.com>

[Severity: Low]
Should this bug fix include Fixes tags for the commits that introduced the
unlocked list insertion and removal on dbc->bo_lists?

  Fixes: ff13be830333 ("accel/qaic: Add datapath")
  Fixes: 217b812364d3 ("accel/qaic: Add QAIC_DETACH_SLICE_BO IOCTL")

> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
> index 1f0b31fefc447..f65782f3333e2 100644
> --- a/drivers/accel/qaic/qaic_data.c
> +++ b/drivers/accel/qaic/qaic_data.c

[ ... ]

> @@ -1903,10 +1905,16 @@ int qaic_perf_stats_bo_ioctl(struct drm_device *dev, void *data, struct drm_file
>  
>  static void detach_slice_bo(struct qaic_device *qdev, struct qaic_bo *bo)
>  {
> +	struct dma_bridge_chan *dbc = bo->dbc;
> +
>  	qaic_free_slices_bo(bo);
>  	qaic_unprepare_bo(qdev, bo);
>  	qaic_init_bo(bo, true);

[Severity: High]
This problem wasn't introduced by this patch, but do qaic_prepare_bo() and
qaic_unprepare_bo() call dma_buf_map_sgt() and dma_buf_unmap_sgt() on
imported DMA-BUFs without holding attach->dmabuf->resv [1]?

drivers/accel/qaic/qaic_data.c:qaic_prepare_import_bo() {
	...
	sgt = dma_buf_map_sgt(obj->import_attach, hdr->dir);
	...
}

drivers/accel/qaic/qaic_data.c:qaic_unprepare_import_bo() {
	dma_buf_unmap_sgt(bo->base.import_attach, bo->sgt, bo->dir);
	bo->sgt = NULL;
}

Both dma_buf_map_sgt() and dma_buf_unmap_sgt() assert
dma_resv_assert_held(attach->dmabuf->resv), whereas
qaic_attach_slice_bo_ioctl() and the detach paths only hold bo->lock and
SRCU read locks.  This triggers a lockdep warning and leaves buffer
pinning and exporter map/unmap callbacks unsynchronized across drivers
sharing the DMA-BUF.

In addition, qaic_prepare_bo() overwrites bo->dir, bo->dbc, and
bo->nr_slice even when qaic_prepare_import_bo() or
qaic_prepare_export_bo() fails, leaving stale metadata on bo.

[1] https://sashiko.dev/#/bug/linux-9761c613-05ad-4c51-acc6-da4c08a070fd

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129065740.864-1-AeeSec@126.com?part=1

      parent reply	other threads:[~2026-11-29  7:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  6:57 [PATCH] accel/qaic: Synchronize access to dbc->bo_lists Bilal Hashim
2026-11-29  6:57 ` [PATCH] accel/qaic: Hold bo->lock when checking bo->sliced and bo->dbc in qaic_wait_bo_ioctl() Bilal Hashim
2026-11-29  7:04   ` sashiko-bot
2026-11-29  7:10 ` sashiko-bot [this message]

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=sashiko-outbox-239357@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=AeeSec@126.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.