From: sashiko-bot@kernel.org
To: "Tomeu Vizoso" <tomeu.vizoso@gmail.com>
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v3 11/16] accel/thames: Add IOCTL for memory synchronization
Date: Fri, 23 Oct 2026 06:53:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-182369@kernel.org> (raw)
In-Reply-To: <20261023-thames-v3-11-3ab40aa17157@tomeuvizoso.net>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] accel/thames: thames_ioctl_bo_prep() syncs caches when wait fails
- [Medium] accel/thames: DMA direction mismatch when syncing contiguous BOs
--
commit 85aeec13be820dd1a0897aae141a1833daad8267
Author: Tomeu Vizoso <tomeu.vizoso@gmail.com>
accel/thames: Add IOCTL for memory synchronization
This commit adds DRM_THAMES_BO_PREP and DRM_THAMES_BO_FINI ioctls to the
thames accel driver so userspace can wait for in-flight jobs and synchronize
CPU caches with non-coherent DSP memory.
> diff --git a/drivers/accel/thames/thames_gem.c b/drivers/accel/thames/thames_gem.c
> index c9fd08c7aaf4d..5a4dc497768f8 100644
> --- a/drivers/accel/thames/thames_gem.c
> +++ b/drivers/accel/thames/thames_gem.c
> @@ -942,3 +942,66 @@ int thames_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data, struct drm_
> return 0;
> }
>
> +int thames_ioctl_bo_prep(struct drm_device *ddev, void *data, struct drm_file *file)
> +{
> + struct drm_thames_bo_prep *args = data;
> + struct thames_gem_object *bo;
> + struct drm_gem_object *gem_obj;
> + unsigned long timeout = drm_timeout_abs_to_jiffies(args->timeout_ns);
> + long ret = 0;
> +
> + if (args->reserved != 0)
> + return -EINVAL;
> +
> + gem_obj = drm_gem_object_lookup(file, args->handle);
> + if (!gem_obj)
> + return -ENOENT;
> +
> + ret = dma_resv_wait_timeout(gem_obj->resv, DMA_RESV_USAGE_READ, true, timeout);
> + if (ret == 0)
> + ret = timeout ? -ETIMEDOUT : -EBUSY;
> + else if (ret > 0)
> + ret = 0;
> +
> + bo = to_thames_bo(gem_obj);
> + if (bo->flags & DRM_THAMES_BO_CONTIGUOUS)
> + dma_sync_single_for_cpu(ddev->dev, bo->base.dma_addr, gem_obj->size,
> + DMA_BIDIRECTIONAL);
> + else
> + dma_sync_sgtable_for_cpu(ddev->dev, bo->shmem.sgt, DMA_BIDIRECTIONAL);
[Severity: High]
Should thames_ioctl_bo_prep() skip the cache invalidation when
dma_resv_wait_timeout() fails?
If the wait times out (-ETIMEDOUT), is polled while fences are still active
(-EBUSY), or is interrupted by a signal (-ERESTARTSYS), ret is negative, yet
the code still calls dma_sync_single_for_cpu() or dma_sync_sgtable_for_cpu().
This transfers DMA buffer ownership to the CPU and invalidates CPU cache
lines while the DSP or DRU DMA engine is still actively accessing the buffer.
It also performs full-buffer cache maintenance on every non-blocking poll or
signal-interrupted retry, and contradicts the struct drm_thames_bo_prep
comment in include/uapi/drm/thames_accel.h:
include/uapi/drm/thames_accel.h:
* Waits for the DSP to be done with the buffer and invalidates the CPU caches,
* so that what the DSP wrote is visible to the CPU. The DSP is not coherent
* with the CPU, and the wait and the cache invalidation are deliberately the
* same operation: userspace has no way of skipping the wait and keeping the
* invalidation, so a mapping is never handed out with stale cache lines.
> + /* Order the cache maintenance before the CPU reads. */
> + mb();
> +
> + drm_gem_object_put(gem_obj);
> +
> + return ret;
> +}
> +
> +int thames_ioctl_bo_fini(struct drm_device *ddev, void *data, struct drm_file *file)
> +{
> + struct drm_thames_bo_fini *args = data;
> + struct thames_gem_object *bo;
> + struct drm_gem_object *gem_obj;
> +
> + if (args->reserved != 0)
> + return -EINVAL;
> +
> + gem_obj = drm_gem_object_lookup(file, args->handle);
> + if (!gem_obj)
> + return -ENOENT;
> +
> + bo = to_thames_bo(gem_obj);
> + if (bo->flags & DRM_THAMES_BO_CONTIGUOUS) {
> + dma_sync_single_for_device(ddev->dev, bo->base.dma_addr, gem_obj->size,
> + DMA_BIDIRECTIONAL);
[Severity: Medium]
Does syncing contiguous buffer objects with DMA_BIDIRECTIONAL in
thames_ioctl_bo_prep() and thames_ioctl_bo_fini() mismatch the direction used
when allocating them?
In drivers/accel/thames/thames_gem.c, contiguous buffers are allocated and
initially synced in thames_gem_create() with DMA_TO_DEVICE:
drivers/accel/thames/thames_gem.c:thames_gem_create() {
...
bo->alloc_vaddr = dma_alloc_noncoherent(dev, bo->alloc_size, &bo->alloc_dma,
DMA_TO_DEVICE, GFP_KERNEL | __GFP_NOWARN);
...
dma_sync_single_for_device(dev, bo->alloc_dma, bo->alloc_size, DMA_TO_DEVICE);
}
And freed in thames_gem_bo_free() with DMA_TO_DEVICE:
drivers/accel/thames/thames_gem.c:thames_gem_bo_free() {
...
if (bo->alloc_vaddr)
dma_free_noncoherent(drm_dev_dma_dev(obj->dev), bo->alloc_size, bo->alloc_vaddr,
bo->alloc_dma, DMA_TO_DEVICE);
}
When CONFIG_DMA_API_DEBUG is enabled, calling dma_sync_single_for_cpu() and
dma_sync_single_for_device() with DMA_BIDIRECTIONAL on an allocation created
with DMA_TO_DEVICE triggers check_sync() warnings for direction mismatch and
for syncing device read-only DMA memory for the CPU.
Should thames_gem_create() and thames_gem_bo_free() use DMA_BIDIRECTIONAL for
contiguous BOs as well?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261023-thames-v3-0-3ab40aa17157@tomeuvizoso.net?part=11
next prev parent reply other threads:[~2026-10-23 6:53 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 6:39 [PATCH v3 00/16] New DRM accel driver for Texas Instruments' C7x DSPs Tomeu Vizoso
2026-10-23 6:39 ` [PATCH v3 01/16] dt-bindings: remoteproc: k3-dsp: Add the L2 auxiliary and DRU regions Tomeu Vizoso
2026-10-23 6:39 ` [PATCH v3 02/16] dt-bindings: remoteproc: k3-dsp: Allow a second sub-mailbox Tomeu Vizoso
2026-10-26 7:49 ` Krzysztof Kozlowski
2026-10-23 6:39 ` [PATCH v3 03/16] dt-bindings: remoteproc: k3-dsp: Allow referencing the timers' power domains Tomeu Vizoso
2026-10-23 6:48 ` sashiko-bot
2026-10-26 7:51 ` Krzysztof Kozlowski
2026-10-23 6:39 ` [PATCH v3 04/16] accel/thames: Add header with IPC definitions Tomeu Vizoso
2026-10-23 6:39 ` [PATCH v3 05/16] accel/thames: Add driver for the C7x DSPs in TI SoCs Tomeu Vizoso
2026-10-23 7:37 ` sashiko-bot
2026-10-23 6:39 ` [PATCH v3 06/16] accel/thames: Create a context per client on device open Tomeu Vizoso
2026-10-23 7:27 ` sashiko-bot
2026-10-23 6:39 ` [PATCH v3 07/16] accel/thames: Add IOCTLs for BO creation and mapping Tomeu Vizoso
2026-10-23 7:40 ` sashiko-bot
2026-10-26 10:07 ` Christian König
2026-10-23 6:39 ` [PATCH v3 08/16] accel/thames: Add support for submitting DMA operations Tomeu Vizoso
2026-10-23 7:16 ` sashiko-bot
2026-10-23 6:39 ` [PATCH v3 09/16] accel/thames: Add IOCTLs for job creation and submission Tomeu Vizoso
2026-10-26 10:10 ` Christian König
2026-10-23 6:39 ` [PATCH v3 10/16] accel/thames: Recover from faults and timeouts Tomeu Vizoso
2026-10-23 6:39 ` [PATCH v3 11/16] accel/thames: Add IOCTL for memory synchronization Tomeu Vizoso
2026-10-23 6:53 ` sashiko-bot [this message]
2026-10-23 6:39 ` [PATCH v3 12/16] accel/thames: Install memory mappings populated and dirty Tomeu Vizoso
2026-10-23 7:34 ` sashiko-bot
2026-10-23 6:39 ` [PATCH v3 13/16] Documentation: accel/thames: Add initial docs Tomeu Vizoso
2026-10-23 6:39 ` [PATCH v3 14/16] arm64: dts: ti: k3-j722s: Add the AUX L2 SRAM and DRU regions Tomeu Vizoso
2026-10-23 6:39 ` [PATCH v3 15/16] arm64: dts: ti: k3-j722s: Add second submailbox to the C7x cores Tomeu Vizoso
2026-10-23 6:39 ` [PATCH v3 16/16] arm64: dts: ti: k3-j722s: Reference the power domains of the C7x timers Tomeu Vizoso
2026-10-23 7:17 ` sashiko-bot
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-182369@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=media-ci@linuxtv.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tomeu.vizoso@gmail.com \
/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