Devicetree
 help / color / mirror / Atom feed
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 07/14] accel/thames: Add support for submitting DMA operations
Date: Sun, 29 Nov 2026 11:48:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-239557@kernel.org> (raw)
In-Reply-To: <20261129-thames-v4-7-003b1e3365bf@tomeuvizoso.net>

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 <tomeu@tomeuvizoso.net>

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/thames/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] = { TR_ADDR_LO, TR_DADDR_LO };
> +	const struct thames_transfer *records = table->records;
> +	const u16 *group_counts = table->group_counts;
> +	void *base = core->ipc->transfer_table_pool + table->offset;
> +	struct thames_dru_record *out = base;
> +	u8 *channels = base + THAMES_TRANSFER_TABLE_CHANNELS_OFFSET(table->count);
> +	u32 i, s;
> +
> +	for (i = 0; i < table->count; i++) {
> +		struct thames_dru_record record = records[i].record;
> +
> +		for (s = 0; s < 2; s++) {
> +			u32 *lo = &record.words[addr_word[s]];
> +			u64 addr;
> +
> +			if (records[i].side[s] == THAMES_TRANSFER_SIDE_DDR)
> +				continue;
> +
> +			addr = ((u64)lo[1] << 32 | lo[0]) +
> +			       thames_core_window(core, records[i].side[s])->start;
> +			lo[0] = lower_32_bits(addr);
> +			lo[1] = upper_32_bits(addr);
> +		}
> +
> +		memcpy(&out[i], &record, sizeof(record));
> +		channels[i] = 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 = 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 = tdev->caps.transfer_table_pool_size / THAMES_ABI_LINE_SIZE;
> +	unsigned long start, nr = table->size / THAMES_ABI_LINE_SIZE;
> +	u32 i;
> +
> +	guard(mutex)(&tdev->transfer_table_pool_lock);
> +
> +	start = bitmap_find_next_zero_area(tdev->transfer_table_pool_map, lines, 0, nr, 0);
> +	if (start + nr > lines)
> +		return -ENOSPC;
> +
> +	bitmap_set(tdev->transfer_table_pool_map, start, nr);
> +	table->offset = start * THAMES_ABI_LINE_SIZE;
> +
> +	for (i = 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-thames-v4-0-003b1e3365bf@tomeuvizoso.net?part=7

  reply	other threads:[~2026-11-29 11:48 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
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 [this message]
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-239557@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