Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2505B606A31C for ; Sun, 29 Nov 2026 07:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Lk3G4mm9 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2515910E11B; Sun, 29 Nov 2026 07:10:42 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB28B10E11B for ; Sun, 29 Nov 2026 07:10:35 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 9D240418F5; Sun, 29 Nov 2026 07:10:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BDD41F00896; Sun, 29 Nov 2026 07:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795936235; bh=0mtVmkDOrTGjUnUB+S1cyO+RCrL8mCujdMrCmBCgWPs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Lk3G4mm9KWtlySOAUak6bo9KjwckwcoYBVoNDQKAG6NeM/CJtiSeFw/+kaIlcFalZ ZC9B0ocMse+tweVbXPp2YoYCMmOkraC4RUNKvUMkkannk8WvoodocNdK241pX2EANN zLrGEIFA8Kwl1mNwg8d6JO4UYaDGoxr5IZetI9QKacS5ci8PNYuBSlXLDT9HzKXeVG v6WDwJ0QYqXsJYHpObkQDB83pySrsk2yTiNh7uzbEYXEjVvDbA4q6cTnqL/PqCerhI 3nR2b1/kFyh/GLqq9+KnqAs5eIzRc9EnnXqDxbtqG+iIYu1pw8PXeHOlVw+vOGenPb LsFpdZ+ws/+nQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] accel/qaic: Synchronize access to dbc->bo_lists To: "Bilal Hashim" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261129065740.864-1-AeeSec@126.com> References: <20261129065740.864-1-AeeSec@126.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 07:10:34 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 > 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 [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_dat= a.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 *d= ev, void *data, struct drm_file > =20 > static void detach_slice_bo(struct qaic_device *qdev, struct qaic_bo *bo) > { > + struct dma_bridge_chan *dbc =3D 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 =3D 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 =3D 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 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129065740.864-= 1-AeeSec@126.com?part=3D1