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=1795953204; b=TE6SZbkF13DTGkPjOEBPmX9Ep4OXaeVFb/PQpykNQE6K5cBqSLguJjRRsTZcBLJqdZPf a28f5tnYKg4XjstXFqu1NefKHAvUQe0RjSER7w5DDj23u08abOmiBV/wV3dkb6EemyxI9 i7Rv8jD4EvhsJ5K0PjO0LHmyzaUvkzztmoaL3bsgKfFAC0x8nibddZtETMt475+aPtpWQ Om0nysaIGig/RXIOtRafrZBqLhXbu6FuZI0xGW9gs/srqVXeVKuEzp5dsxM91dBjHmrQx mfDleu5cGIaT6Rn+3KAyDXGOz140fHnJR0fOLjbMOZQb1DJUPEDXmsQtogggzW3EkxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795953204; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=9W52umYurqfuBFWC4pzaGyJvepW6ISWvbPIpdbaTFMU=; b=EhnIDUJ8+C0MQkcvAsJZUL4kLAXjnSWNNBTCRogfOScI4/o/nh1efwqOnW1Byjt2vLGY TXreToESg0zBqPrj46q0MpTJtYWJg/jcoeuB8+6kzbGP0LB0k3tEgpfSIXX+1+sWT/36Q gaXKMVq0O8u3UaPrtnIeeYCJRyL2R7b0HgOySUR5fVxvrpBZQ5HviMUAQ5cCFrI2BzfFr yg+yHy8JjYnPtNU3B+kNKbWsev1Fzj6/po4qwFRya3JvWavTw0oTbCLTw8hzmms/E7MFb ZJx2IyXdaiWKJrD1ua1P8pe13f9w+s7xCnGAbmoN16Pv2pRXDNqoxKD/4YmK0z6NDmQ== 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=V3mdVqoA; 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 6A6B9606A689 for ; Sun, 29 Nov 2026 11:53:24 +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: 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 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-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-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: - [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