From: sashiko-bot@kernel.org
To: "Tomeu Vizoso" <tomeu@tomeuvizoso.net>
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v4 06/14] accel/thames: Add IOCTLs for BO creation and mapping
Date: Sun, 29 Nov 2026 11:52:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-239558@kernel.org> (raw)
In-Reply-To: <20261129-thames-v4-6-003b1e3365bf@tomeuvizoso.net>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] accel/thames: race between thames_bo_bind() and
thames_gem_close()
- [Medium] accel/thames: missing size overflow check in
thames_ioctl_bo_create()
--
commit 8fe848e1127a19686a4f17b2a469e560c388e5ec
Author: Tomeu Vizoso <tomeu@tomeuvizoso.net>
accel/thames: Add IOCTLs for BO creation and mapping
This commit adds the BO_CREATE, BO_MMAP_OFFSET, and BO_BIND ioctls for
creating shmem- or DMA-backed buffer objects and binding them into DSP
context page tables.
> diff --git a/drivers/accel/thames/thames_gem.c b/drivers/accel/thames/thames_gem.c
> index e1f36a0daf3b8..fd1ee8429e0c9 100644
> --- a/drivers/accel/thames/thames_gem.c
> +++ b/drivers/accel/thames/thames_gem.c
[ ... ]
> @@ -489,13 +677,166 @@ void thames_context_destroy(struct thames_file_priv *priv)
> priv->context_id, priv->asid);
> }
>
[ ... ]
> +static int thames_bo_bind(struct thames_file_priv *priv, struct thames_gem_object *bo,
> + u64 dsp_va)
> +{
> + size_t size = bo->base.base.size;
> + int prot = thames_bo_flags_to_prot(bo->flags);
> + struct thames_binding *binding;
> + int ret;
> +
> + if (!IS_ALIGNED(dsp_va, PAGE_SIZE))
> + return -EINVAL;
> +
> + if (dsp_va < THAMES_BIND_VA_START || dsp_va > THAMES_BIND_VA_END ||
> + size > THAMES_BIND_VA_END - dsp_va)
> + return -EINVAL;
> +
> + binding = kzalloc_obj(*binding);
> + if (!binding)
> + return -ENOMEM;
> +
> + binding->bo = bo;
> + binding->priv = priv;
> + binding->mm.start = dsp_va;
> + binding->mm.size = size;
> +
> + mutex_lock(&priv->tdev->bindings_lock);
> +
> + if (thames_bo_find_binding(bo, priv)) {
> + ret = -EBUSY;
> + goto err_unlock;
> + }
> +
> + scoped_guard(mutex, &priv->mm_lock)
> + ret = drm_mm_reserve_node(&priv->mm, &binding->mm);
> + if (ret)
> + goto err_unlock;
> +
> + if (bo->flags & DRM_THAMES_BO_CONTIGUOUS)
> + ret = thames_context_map(priv, dsp_va, prot, bo->base.dma_addr, size);
> + else
> + ret = thames_context_map_sgt(priv, dsp_va, prot, bo->shmem.sgt);
> + if (ret) {
> + scoped_guard(mutex, &priv->mm_lock)
> + drm_mm_remove_node(&binding->mm);
> + goto err_unlock;
> + }
> +
> + drm_gem_object_get(&bo->base.base);
> + list_add_tail(&binding->bo_link, &bo->bindings);
> + list_add_tail(&binding->context_link, &priv->bindings);
> + mutex_unlock(&priv->tdev->bindings_lock);
> +
> + return 0;
> +
> +err_unlock:
> + mutex_unlock(&priv->tdev->bindings_lock);
> + kfree(binding);
> + return ret;
> +}
[ ... ]
> +static void thames_gem_close(struct drm_gem_object *obj, struct drm_file *file)
> +{
> + struct thames_file_priv *priv = file->driver_priv;
> + struct thames_binding *binding;
> + LIST_HEAD(put);
> +
> + if (thames_file_has_other_handle(file, obj))
> + return;
> +
> + scoped_guard(mutex, &priv->tdev->bindings_lock) {
> + binding = thames_bo_find_binding(to_thames_bo(obj), priv);
> + if (binding)
> + thames_binding_remove(binding, &put);
> + }
> +
> + thames_bindings_put(&put);
> +}
[ ... ]
> @@ -503,3 +844,131 @@ static const struct drm_gem_object_funcs thames_gem_funcs = {
> .vm_ops = &drm_gem_dma_vm_ops,
> };
>
[ ... ]
> +int thames_ioctl_bo_create(struct drm_device *ddev, void *data, struct drm_file *file)
> +{
> + struct drm_thames_bo_create *args = data;
> + struct thames_gem_object *bo;
> + struct drm_gem_dma_object *mem;
> + int ret;
> +
> + if (args->handle)
> + return -EINVAL;
> +
> + if (!args->size)
> + return -EINVAL;
> +
> + if (args->flags & ~(DRM_THAMES_BO_READ_ONLY | DRM_THAMES_BO_EXECUTABLE |
> + DRM_THAMES_BO_CONTIGUOUS))
> + return -EINVAL;
> +
> + if (args->flags & DRM_THAMES_BO_CONTIGUOUS) {
> + mem = drm_gem_dma_create(ddev, args->size);
[Severity: Medium]
Can an oversized args->size overflow PAGE_ALIGN() or trigger uncleaned
object destruction?
When args->size > SIZE_MAX - PAGE_SIZE + 1, PAGE_ALIGN(size) in
thames_gem_create_shmem() and round_up(size, PAGE_SIZE) in
drm_gem_dma_create() wrap to 0, creating a 0-byte shmem file and failing
later in drm_vma_offset_add() with -ENOSPC instead of -EINVAL.
For args->size in [0x8000000000000000, 0xfffffffffffff000] with
DRM_THAMES_BO_CONTIGUOUS set, __drm_gem_dma_create() calls
drm_gem_object_init(), which initializes gem_obj->gpuva.lock and
gem_obj->_resv before shmem_file_setup() rejects the negative loff_t with
-EINVAL, and __drm_gem_dma_create() then frees dma_obj with kfree() without
destroying the initialized mutex and dma_resv. On 32-bit COMPILE_TEST
builds, passing u64 args->size to size_t also truncates the upper 32 bits.
> + if (IS_ERR(mem)) {
> + dev_err_ratelimited(ddev->dev,
> + "Failed to allocate a contiguous buffer of %llu bytes, the CMA pool may be too small (see the cma= kernel parameter)\n",
> + args->size);
> + return PTR_ERR(mem);
> + }
> + bo = to_thames_bo(&mem->base);
> + } else {
> + bo = thames_gem_create_shmem(ddev, args->size);
> + if (IS_ERR(bo))
> + return PTR_ERR(bo);
> + }
[ ... ]
> +static int thames_bind_exec_op(struct drm_file *file, const struct drm_thames_bind_op *op)
> +{
> + struct thames_file_priv *priv = file->driver_priv;
> + struct drm_gem_object *obj;
> + int ret;
> +
> + if (op->flags & ~DRM_THAMES_BIND_OP_UNBIND)
> + return -EINVAL;
> +
> + if ((op->flags & DRM_THAMES_BIND_OP_UNBIND) && op->dsp_va)
> + return -EINVAL;
> +
> + obj = drm_gem_object_lookup(file, op->handle);
> + if (!obj)
> + return -ENOENT;
> +
> + if (op->flags & DRM_THAMES_BIND_OP_UNBIND)
> + ret = thames_bo_unbind(priv, to_thames_bo(obj));
> + else
> + ret = thames_bo_bind(priv, to_thames_bo(obj), op->dsp_va);
[Severity: Medium]
Can a concurrent DRM_IOCTL_GEM_CLOSE race with thames_bo_bind() and leave
a buffer permanently bound until the file is closed?
CPU0 CPU1
thames_bind_exec_op()
obj = drm_gem_object_lookup(...)
drm_gem_handle_delete()
/* removes handle from object_idr */
thames_gem_close()
mutex_lock(&tdev->bindings_lock)
thames_bo_find_binding() -> NULL
mutex_unlock(&tdev->bindings_lock)
thames_bo_bind()
mutex_lock(&tdev->bindings_lock)
drm_gem_object_get(&bo->base.base)
list_add_tail(..., &priv->bindings) <-- bound with no handle left
Because the file no longer holds a GEM handle to the buffer and
DRM_THAMES_BIND_OP_UNBIND looks up buffers by handle, the client cannot
unbind it (and re-importing the same buffer cannot bind it at a new
address due to -EBUSY), keeping the DSP VA range reserved and the GEM
object pinned until the file is closed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-thames-v4-0-003b1e3365bf@tomeuvizoso.net?part=6
next prev parent reply other threads:[~2026-11-29 11:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 11:35 [PATCH v4 00/14] New DRM accel driver for Texas Instruments' C7x DSPs Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 01/14] dt-bindings: remoteproc: k3-dsp: Add the L2 auxiliary and DRU regions Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 02/14] dt-bindings: remoteproc: k3-dsp: Allow a second sub-mailbox Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 03/14] accel/thames: Add header with IPC definitions Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 04/14] accel/thames: Add driver for the C7x DSPs in TI SoCs Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 05/14] accel/thames: Create a context per client on device open Tomeu Vizoso
2026-11-29 11:53 ` sashiko-bot
2026-11-29 11:35 ` [PATCH v4 06/14] accel/thames: Add IOCTLs for BO creation and mapping Tomeu Vizoso
2026-11-29 11:52 ` sashiko-bot [this message]
2026-11-29 11:35 ` [PATCH v4 07/14] accel/thames: Add support for submitting DMA operations Tomeu Vizoso
2026-11-29 11:48 ` sashiko-bot
2026-11-29 11:35 ` [PATCH v4 08/14] accel/thames: Add IOCTLs for job creation and submission Tomeu Vizoso
2026-11-29 11:58 ` sashiko-bot
2026-11-29 11:35 ` [PATCH v4 09/14] accel/thames: Recover from faults and timeouts Tomeu Vizoso
2026-11-29 12:00 ` sashiko-bot
2026-11-29 11:35 ` [PATCH v4 10/14] accel/thames: Add IOCTL for memory synchronization Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 11/14] accel/thames: Install memory mappings populated and dirty Tomeu Vizoso
2026-11-29 11:56 ` sashiko-bot
2026-11-29 11:35 ` [PATCH v4 12/14] Documentation: accel/thames: Add initial docs Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 13/14] arm64: dts: ti: k3-j722s: Add the AUX L2 SRAM and DRU regions Tomeu Vizoso
2026-11-29 11:35 ` [PATCH v4 14/14] arm64: dts: ti: k3-j722s: Add second submailbox to the C7x cores Tomeu Vizoso
2026-11-29 12:06 ` 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-239558@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@tomeuvizoso.net \
/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