dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: zoan37 <agentzoan@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/mediatek: mtk_crtc: Pick the connector route on every CRTC enable
Date: Sun, 11 Oct 2026 00:56:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-166953@kernel.org> (raw)
In-Reply-To: <20261011004248.1117649-4-agentzoan@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/mediatek: data race on ddp_comp array in mtk_crtc_mode_valid
--

commit 932f98864769c15d84bbf97b7de7de8b563c5923
Author: zoan37 <agentzoan@gmail.com>

drm/mediatek: mtk_crtc: Pick the connector route on every CRTC enable

mtk_crtc_update_output() only picks the output component of a CRTC
with connector routes when connectors_changed is set in the commit that
enables the CRTC. But connectors_changed only says that the connectors
changed in that commit, not since the CRTC was last enabled. A connector
can be attached to (or moved to) the CRTC while it is inactive, and the
later commit that only sets ACTIVE then has active_changed but not
connectors_changed:

- If the CRTC had never been enabled, the route slot is still NULL and
  mtk_crtc_ddp_hw_init() dereferences it (mtk_ddp_comp_clk_enable()
  and so on).
- If the CRTC was driven through another route before, e.g. a CRTC
  shared by an HDMI bridge on DSI and a DisplayPort output that is
  switched off (DPMS) while the monitor moves from one to the other,
  the pipeline is set up for the old output.

update_output() only runs from atomic_enable and the lookup is a short
loop over the routes, so do it on every enable.

> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index 704931b369b6f..0bfd17f682826 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -695,9 +695,6 @@ static void mtk_crtc_update_output(struct drm_crtc *crtc,
>  	struct mtk_drm_private *priv;
>  	unsigned int encoder_mask = crtc_state->encoder_mask;
>  
> -	if (!crtc_state->connectors_changed)
> -		return;
> -

[Severity: Medium]
Does removing this guard expose a data race on the ddp_comp array in
mtk_crtc_mode_valid()?

A non-blocking atomic commit executes mtk_crtc_atomic_enable() asynchronously
via the commit_tail worker, which does not hold dev->mode_config.mutex.

This calls mtk_crtc_update_output(), which modifies the array using plain
non-atomic assignment:

mtk_crtc_update_output()
	mtk_crtc->ddp_comp[mtk_crtc->ddp_comp_nr - 1] = comp;

Concurrently, unprivileged userspace can issue DRM_IOCTL_MODE_GETCONNECTOR,
which acquires mode_config.mutex and invokes
drm_helper_probe_single_connector_modes().

This iterates over all possible CRTCs and calls mtk_crtc_mode_valid(), which
reads the entire ddp_comp array without READ_ONCE():

mtk_crtc_mode_valid()
	for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
		status = mtk_ddp_comp_mode_valid(mtk_crtc->ddp_comp[i], mode);

Could this lead to undefined behavior, KCSAN splats, or a crash if compiler
optimization splits the pointer read in the inlined mtk_ddp_comp_mode_valid()
function?

>  	if (!mtk_crtc->num_conn_routes)
>  		return;
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261011004248.1117649-1-agentzoan@gmail.com?part=3

      reply	other threads:[~2026-10-11  0:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11  0:42 [PATCH 0/3] drm/mediatek: mtk_crtc: Fix connector route handling zoan37
2026-10-11  0:42 ` [PATCH 1/3] drm/mediatek: mtk_crtc: Look up connector routes in the CRTC's own mmsys zoan37
2026-10-11  0:42 ` [PATCH 2/3] drm/mediatek: mtk_crtc: Skip the empty connector route slot in destroy zoan37
2026-10-11  0:42 ` [PATCH 3/3] drm/mediatek: mtk_crtc: Pick the connector route on every CRTC enable zoan37
2026-10-11  0:56   ` sashiko-bot [this message]

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-166953@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agentzoan@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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