From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795953142; b=Y6cxXO18xhzHWSkdD/JHiHafg3XGLmOQstdK1+ibeRtQS3NfNVBsrL1HZMVPNp7R/KLm A0sjKxQBhYc+M8VAxv60MiNCuIk6gzixtHq2Vmfqq9hLGnaUpoFd4APqpbT95+baBMNq6 CKNmsTQnj7LBzLahbfW7bAMh+XF0YJp9ll8f5/mOayL/2p2D4Jas+9hkF2LKnXgeYPaAQ DXXbz2WNtMmGgWl98VwtEhL0oRMBYTeKXPnnIM899wAA81YdIM9jIsBvsvzcIy1NYXHm8 mb2IddJfC0vqqxoYNhwdRbbRBHyFbx3kbcdVwvF19cEvQ5zFfL9Ex3k3k1JVWrjR/lQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795953142; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=5L9vOO5oflbl1fgnfcRs8oBPVlap1AMUoVMIQUU4Gv8=; b=w4Ht6OpbvYrukF0sBO0EO5G0KzSz5mvB7KWfxCvYD5hxC47KHfezF/vIK7vxuP4y6eLo ygDX31IugiBDdVug4cek/vixMiV0bFSD15fdEzvGk87gO72yNtVwRJGY5C7z63azcTECX hobpX+etPQT7cTeuwi//gJkAqVquKdK0psFfI4XoHRROaiPQSuU6wurQiCsWs+VlgxC92 650/KcQoZg+9fCu8zSHO/GJC1EPGhnKe94VjybRp0/IjWJn80DpANlPlpti1Uv4KCErtG faEl8mPQ24Cxj6zBC/Jz9/bIqRKZTwAQTo4Bb4Pz3zlvxkGGPBOLuZKG6EmdlvBup5A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=frldAG1I; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4007606A33B for ; Sun, 29 Nov 2026 11:52:21 +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=frldAG1I Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F6E91F00896; Sun, 29 Nov 2026 11:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795953141; bh=5L9vOO5oflbl1fgnfcRs8oBPVlap1AMUoVMIQUU4Gv8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=frldAG1IGQIp0XQaceifvoV1BwvHwXczH6lK1nVB924F+TKTaPS4a4ymz8o/XD3k7 fJiqPZrqwz5N0joIENi5xPkjCcIxLGxI2rkrEioTo1RZb4YjlV4FTYe65bMzUIP6QG xPkuuJ8v7bfo6z0jpGddvidw+mppo7j8To7dxSyWykGRG7Zuq3G01DBVMTSahnjvQo BVvzQQeEfaUv/i82EbxZzQ3o422LK921N/oI1REE4yidOJScqdSteohzPAbNnU15sW GuGz7cwGKTknsjXX/v6AeiUzzfsdjukOyIsinaXGnkn3OOjE4Mg13sHZODmC+alJAy qPaxIxmYq27mA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 06/14] accel/thames: Add IOCTLs for BO creation and mapping Reply-To: sashiko-reviews@lists.linux.dev To: "Tomeu Vizoso" Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org In-Reply-To: <20261129-thames-v4-6-003b1e3365bf@tomeuvizoso.net> References: <20261129-thames-v4-0-003b1e3365bf@tomeuvizoso.net> <20261129-thames-v4-6-003b1e3365bf@tomeuvizoso.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 11:52:21 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/tha= mes_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_pri= v *priv) > priv->context_id, priv->asid); > } > =20 [ ... ] > +static int thames_bo_bind(struct thames_file_priv *priv, struct thames_g= em_object *bo, > + u64 dsp_va) > +{ > + size_t size =3D bo->base.base.size; > + int prot =3D 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 =3D kzalloc_obj(*binding); > + if (!binding) > + return -ENOMEM; > + > + binding->bo =3D bo; > + binding->priv =3D priv; > + binding->mm.start =3D dsp_va; > + binding->mm.size =3D size; > + > + mutex_lock(&priv->tdev->bindings_lock); > + > + if (thames_bo_find_binding(bo, priv)) { > + ret =3D -EBUSY; > + goto err_unlock; > + } > + > + scoped_guard(mutex, &priv->mm_lock) > + ret =3D drm_mm_reserve_node(&priv->mm, &binding->mm); > + if (ret) > + goto err_unlock; > + > + if (bo->flags & DRM_THAMES_BO_CONTIGUOUS) > + ret =3D thames_context_map(priv, dsp_va, prot, bo->base.dma_addr, size= ); > + else > + ret =3D 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 =3D 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 =3D 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 =3D { > .vm_ops =3D &drm_gem_dma_vm_ops, > }; > =20 [ ... ] > +int thames_ioctl_bo_create(struct drm_device *ddev, void *data, struct d= rm_file *file) > +{ > + struct drm_thames_bo_create *args =3D 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 =3D 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=3D kernel parameter)\n", > + args->size); > + return PTR_ERR(mem); > + } > + bo =3D to_thames_bo(&mem->base); > + } else { > + bo =3D 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_t= hames_bind_op *op) > +{ > + struct thames_file_priv *priv =3D 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 =3D drm_gem_object_lookup(file, op->handle); > + if (!obj) > + return -ENOENT; > + > + if (op->flags & DRM_THAMES_BIND_OP_UNBIND) > + ret =3D thames_bo_unbind(priv, to_thames_bo(obj)); > + else > + ret =3D 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129-thames-v4-= 0-003b1e3365bf@tomeuvizoso.net?part=3D6