All of lore.kernel.org
 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 05/14] accel/thames: Create a context per client on device open
Date: Sun, 29 Nov 2026 11:53:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-239559@kernel.org> (raw)
In-Reply-To: <20261129-thames-v4-5-003b1e3365bf@tomeuvizoso.net>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] accel/thames: broken multi-core DRU channel check in
  thames_core_read_caps()
- [Medium] accel/thames: race writing context entry in
  thames_context_create()
--

commit 7eb0354ce4ccbc601749105abe32aaddd5f51384
Author: Tomeu Vizoso <tomeu@tomeuvizoso.net>

accel/thames: Create a context per client on device open

This commit creates a per-client context on device open, managing an
LPAE I/O page table, ASID, VA allocator, user stack and save area GEM DMA
objects, and IPC context table entries across the DSP cores.

> diff --git a/drivers/accel/thames/thames_core.c b/drivers/accel/thames/thames_core.c
> index 8053eeeb39022..d1140a374bd62 100644
> --- a/drivers/accel/thames/thames_core.c
> +++ b/drivers/accel/thames/thames_core.c
> @@ -140,8 +141,16 @@ static int thames_core_read_caps(struct thames_core *core, struct thames_handsha
>  		return -EINVAL;
>  	}
>  
> -	if (tdev->has_caps && memcmp(caps, &tdev->caps, sizeof(*caps))) {
> -		dev_err(core->dev, "Capabilities or window sizes differ from the first core's\n");
> +	/*
> +	 * A Context maps every core's DRU channels when the Context is
> +	 * created, from channel 0 on a core that has not attached yet, so a
> +	 * core attaching later must report the first channel its Contexts map.
> +	 */
> +	if (tdev->has_caps &&
> +	    (memcmp(caps, &tdev->caps, sizeof(*caps)) ||
> +	     dru_kernel_channel_first != core->dru_kernel_channel_first)) {
> +		dev_err(core->dev,
> +			"Capabilities, window sizes or first DRU channel differ from those the device was set up with\n");
>  		return -EINVAL;
>  	}
>  

[Severity: High]
Does comparing dru_kernel_channel_first against
core->dru_kernel_channel_first reject the second core on initial attach
whenever the firmware reports a non-zero dru_kernel_channel_first?

tdev->has_caps is set as soon as the first core attaches, whereas
core->dru_kernel_channel_first on the second core is still 0 until the
assignment below this check.  When the second core attaches for the first
time with a non-zero dru_kernel_channel_first, this check compares it
against 0 and fails with -EINVAL, leaving the second core offline.

Because core->dru_kernel_channel_first is 0 on any unattached core,
thames_context_map_core_regions() also maps DRU channel 0 (the firmware's
private channels) for a core that has not attached yet instead of the
first core's dru_kernel_channel_first, and a second core reporting 0 would
pass 0 != 0 even when the first core reported a non-zero channel.  Storing
dru_kernel_channel_first in struct thames_caps and using
tdev->caps.dru_kernel_channel_first in thames_context_map_core_regions()
would fix both the comparison and the mapping.

[ ... ]

> diff --git a/drivers/accel/thames/thames_gem.c b/drivers/accel/thames/thames_gem.c
> new file mode 100644
> index 0000000000000..e1f36a0daf3b8
> --- /dev/null
> +++ b/drivers/accel/thames/thames_gem.c

[ ... ]

> +int thames_context_create(struct thames_file_priv *priv)
> +{
> +	struct thames_device *tdev = priv->tdev;
> +	int ret, asid;
> +
> +	ret = ida_alloc_range(&tdev->ctx_ida, 1, THAMES_MAX_CONTEXTS - 1, GFP_KERNEL);
> +	if (ret < 0)
> +		return ret;
> +
> +	priv->context_id = ret;
> +	priv->context_serial = atomic64_inc_return(&tdev->last_context_serial);
> +
> +	ret = thames_context_va_init(priv);
> +	if (ret)
> +		goto err_free_id;
> +
> +	ret = thames_context_pgtable_init(priv);
> +	if (ret)
> +		goto err_free_pgtable;
> +
> +	ret = thames_context_map_core_regions(priv);
> +	if (ret)
> +		goto err_free_pgtable;
> +
> +	ret = thames_context_map_user_pages(priv);
> +	if (ret)
> +		goto err_free_pgtable;
> +
> +	asid = thames_asid_alloc(tdev);
> +	if (asid < 0) {
> +		ret = asid;
> +		goto err_free_pgtable;
> +	}
> +	priv->asid = asid;
> +	dev_dbg(tdev->ddev.dev, "Context %u: ASID %d\n", priv->context_id, asid);
> +
> +	thames_context_write_entry(priv);
> +
> +	scoped_guard(mutex, &tdev->contexts_lock)
> +		list_add_tail(&priv->context_node, &tdev->contexts);

[Severity: Medium]
Can thames_context_write_entry() race with a core attaching or resuming
when it runs outside tdev->contexts_lock?

CPU0                                  CPU1
thames_open()
  thames_context_create()
    thames_context_write_entry(priv)
                                      thames_core_attach()
                                        /* firmware boots and clears IPC */
                                        thames_core_wait_handshake()
                                        thames_context_rewrite_entries()
                                          guard(mutex)(&tdev->contexts_lock)
                                          /* priv is not in tdev->contexts */
    scoped_guard(mutex, &tdev->contexts_lock)
      list_add_tail(&priv->context_node,
                    &tdev->contexts)
                                      /* priv's entry on core is missing */

Calling thames_context_write_entry(priv) under tdev->contexts_lock while
adding priv->context_node to tdev->contexts avoids this race.

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

  reply	other threads:[~2026-11-29 11:53 UTC|newest]

Thread overview: 26+ 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-12-01  8:33   ` Krzysztof Kozlowski
2026-12-01  8:33     ` Krzysztof Kozlowski
2026-11-29 11:35 ` [PATCH v4 02/14] dt-bindings: remoteproc: k3-dsp: Allow a second sub-mailbox Tomeu Vizoso
2026-12-01  8:33   ` Krzysztof Kozlowski
2026-12-01  8:33     ` Krzysztof Kozlowski
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 [this message]
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
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-239559@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.