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 C855F606A683 for ; Sun, 29 Nov 2026 11:53:35 +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=V3mdVqoA Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A61910E7EA; Sun, 29 Nov 2026 11:53:30 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 66F1510E7EA for ; Sun, 29 Nov 2026 11:53:24 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 1DAE2417BD; Sun, 29 Nov 2026 11:53:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F3491F00898; Sun, 29 Nov 2026 11:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795953203; bh=9W52umYurqfuBFWC4pzaGyJvepW6ISWvbPIpdbaTFMU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=V3mdVqoAfHh05s0+wWs9bNItOU+c5sBfiXKjty9EhG1qTbgJwO8kHSndvWDTVYYTD rzqsS/LVViJn8YL+jlA69KbQteMZaVKf71ewQ2fDCNarTxkB1hwrW//cmxKSxWAt7l 1buhwo29K6niwazkBl1VIZFwPwfkjuIRVe/cTdOiQ2Xi3S09Hb0bPSnhjuNHf46cOK NKxYtG7T9Xxe4fjv9ArE5qaNZM68Fic7k//XlNB2cE9GOfLbWC7QOrQVIUuYcTYkxB Z144ncFH1P8EALg+SjVuy4KSpquolFyprMKuPFfqWd9LmmU5F65Lk+7Sd5ymMvugZ6 pQLXCe695hh6Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 05/14] accel/thames: Create a context per client on device open 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-5-003b1e3365bf@tomeuvizoso.net> References: <20261129-thames-v4-0-003b1e3365bf@tomeuvizoso.net> <20261129-thames-v4-5-003b1e3365bf@tomeuvizoso.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 11:53:22 +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: - [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 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/th= ames_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; > } > =20 > - 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 !=3D core->dru_kernel_channel_first)) { > + dev_err(core->dev, > + "Capabilities, window sizes or first DRU channel differ from those th= e device was set up with\n"); > return -EINVAL; > } > =20 [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 !=3D 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/tha= mes_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 =3D priv->tdev; > + int ret, asid; > + > + ret =3D ida_alloc_range(&tdev->ctx_ida, 1, THAMES_MAX_CONTEXTS - 1, GFP= _KERNEL); > + if (ret < 0) > + return ret; > + > + priv->context_id =3D ret; > + priv->context_serial =3D atomic64_inc_return(&tdev->last_context_serial= ); > + > + ret =3D thames_context_va_init(priv); > + if (ret) > + goto err_free_id; > + > + ret =3D thames_context_pgtable_init(priv); > + if (ret) > + goto err_free_pgtable; > + > + ret =3D thames_context_map_core_regions(priv); > + if (ret) > + goto err_free_pgtable; > + > + ret =3D thames_context_map_user_pages(priv); > + if (ret) > + goto err_free_pgtable; > + > + asid =3D thames_asid_alloc(tdev); > + if (asid < 0) { > + ret =3D asid; > + goto err_free_pgtable; > + } > + priv->asid =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129-thames-v4-= 0-003b1e3365bf@tomeuvizoso.net?part=3D5