From mboxrd@z Thu Jan 1 00:00:00 1970 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 93B71606A69D for ; Sun, 29 Nov 2026 11:48:26 +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=ZdKhVnrj Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E34010E326; Sun, 29 Nov 2026 11:48:21 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id A0FBA10E326 for ; Sun, 29 Nov 2026 11:48:14 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5B3224362A; Sun, 29 Nov 2026 11:48:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDB5E1F00896; Sun, 29 Nov 2026 11:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795952894; bh=jhPYe/u/XCF2alszaoZJ2HvhFtS1iHooA+6ZpIJsG50=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ZdKhVnrjkwJfIvGRAppZib6hp1mZC+z3V3BbW+Zr+Nrde/ZDs82Vcbfrr/pxreg2f 1/sxOUVWt8NUF9NAfNERqxykm1iMNvbV/zIe1QID3QTvmeq2Ajgo9TSXnSOogZ0KJY +tIkd148uC9KqRwL+yApI5W4tbeHBSukY/tGTCBX+WYuhZplSwRqsg9Yqgx1oedWRQ v/lIdtIZzO9qv6eAQWn4q8lyXwr5D7fEafE2KfF9B3Bwu73pF/B6hhZsCg6KOz4tJC K9J/2fYEEHyS9M9A2UeICNpSAGq3rI1pRZFovF3dKQ3JVZCpeU5j8RyF0NGGq6Y+Vb qbPMcbZlRpqjw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 07/14] accel/thames: Add support for submitting DMA operations 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-7-003b1e3365bf@tomeuvizoso.net> References: <20261129-thames-v4-0-003b1e3365bf@tomeuvizoso.net> <20261129-thames-v4-7-003b1e3365bf@tomeuvizoso.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 11:48:13 +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=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 2 potential issues to consider: - [Medium] accel/thames: out-of-bounds IPC write in thames_transfers_alloc_table() - [Medium] accel/thames: missing wmb() after WC IPC writes in thames_transfers_write_table() -- commit b506c4c5faf43e8de930635840dc32e5769eb0c2 Author: Tomeu Vizoso accel/thames: Add support for submitting DMA operations This commit adds validation, address translation, and IPC transfer table pool management for C7x DRU DMA transfer records. > diff --git a/drivers/accel/thames/thames_transfers.c b/drivers/accel/tham= es/thames_transfers.c > new file mode 100644 > index 0000000000000..113f0b73875cc > --- /dev/null > +++ b/drivers/accel/thames/thames_transfers.c [ ... ] > +static void thames_transfers_write_table(struct thames_core *core, > + const struct thames_transfer_table *table) > +{ > + static const unsigned int addr_word[2] =3D { TR_ADDR_LO, TR_DADDR_LO }; > + const struct thames_transfer *records =3D table->records; > + const u16 *group_counts =3D table->group_counts; > + void *base =3D core->ipc->transfer_table_pool + table->offset; > + struct thames_dru_record *out =3D base; > + u8 *channels =3D base + THAMES_TRANSFER_TABLE_CHANNELS_OFFSET(table->co= unt); > + u32 i, s; > + > + for (i =3D 0; i < table->count; i++) { > + struct thames_dru_record record =3D records[i].record; > + > + for (s =3D 0; s < 2; s++) { > + u32 *lo =3D &record.words[addr_word[s]]; > + u64 addr; > + > + if (records[i].side[s] =3D=3D THAMES_TRANSFER_SIDE_DDR) > + continue; > + > + addr =3D ((u64)lo[1] << 32 | lo[0]) + > + thames_core_window(core, records[i].side[s])->start; > + lo[0] =3D lower_32_bits(addr); > + lo[1] =3D upper_32_bits(addr); > + } > + > + memcpy(&out[i], &record, sizeof(record)); > + channels[i] =3D records[i].channel; > + } > + > + memcpy(base + THAMES_TRANSFER_TABLE_GROUPS_OFFSET(table->count), group_= counts, > + table->group_count * sizeof(u16)); > +} > + > +/* Same offsets, so the Ring entries of the Jobs still queued stay valid= . */ > +void thames_transfers_rewrite(struct thames_core *core) > +{ > + struct thames_device *tdev =3D core->tdev; > + struct thames_transfer_table *table; > + > + guard(mutex)(&tdev->transfer_table_pool_lock); > + > + list_for_each_entry(table, &tdev->transfer_tables, node) > + thames_transfers_write_table(core, table); > +} > + > +static int thames_transfers_alloc_table(struct thames_device *tdev, > + struct thames_transfer_table *table) > +{ > + const unsigned long lines =3D tdev->caps.transfer_table_pool_size / THA= MES_ABI_LINE_SIZE; > + unsigned long start, nr =3D table->size / THAMES_ABI_LINE_SIZE; > + u32 i; > + > + guard(mutex)(&tdev->transfer_table_pool_lock); > + > + start =3D bitmap_find_next_zero_area(tdev->transfer_table_pool_map, lin= es, 0, nr, 0); > + if (start + nr > lines) > + return -ENOSPC; > + > + bitmap_set(tdev->transfer_table_pool_map, start, nr); > + table->offset =3D start * THAMES_ABI_LINE_SIZE; > + > + for (i =3D 0; i < tdev->num_cores; i++) > + thames_transfers_write_table(&tdev->cores[i], table); > + > + list_add_tail(&table->node, &tdev->transfer_tables); > + return 0; > +} [Severity: Medium] Does thames_transfers_write_table() need a trailing wmb() after writing to core->ipc->transfer_table_pool? core->ipc is mapped with MEMREMAP_WC, and unlike thames_context_bump_generation(), neither thames_transfers_alloc_table() nor thames_transfers_rewrite() issues a wmb() before releasing transfer_table_pool_lock. If a job is created on one CPU and submitted to the ring by a scheduler worker on another CPU (or if a core comes online after thames_transfers_rewrite()), the DSP can observe stale or partially written DRU transfer records in the write-combined IPC pool. [Severity: Medium] Can thames_transfers_alloc_table() write past the end of core->ipc when cores have different ipc_size values or a core has not attached? thames_platform_probe() sizes the bitmap from the largest core->ipc_size using max() and keeps offline or failed-attach cores in tdev->cores[0 .. tdev->num_cores - 1]. When the first core attaches, thames_core_read_caps() checks caps->transfer_table_pool_size only against that core's ipc_size: drivers/accel/thames/thames_core.c:thames_core_read_caps() { ... if (!caps->transfer_table_pool_size || !IS_ALIGNED(caps->transfer_table_pool_size, THAMES_ABI_LINE_SIZE) || pool_offset + caps->transfer_table_pool_size > core->ipc_size) { ... } Because thames_transfers_alloc_table() writes at table->offset into every core in tdev->cores[], any other core whose ipc_size is smaller than pool_offset + table->offset + table->size will suffer an out-of-bounds write past its memremap()ed core->ipc mapping. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129-thames-v4-= 0-003b1e3365bf@tomeuvizoso.net?part=3D7