AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mario Limonciello" <mario.limonciello@amd.com>
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v12 10/12] drm/gud: add connector luminance support
Date: Thu, 19 Nov 2026 23:43:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-224212@kernel.org> (raw)
In-Reply-To: <20261119-superm1-backlight-property-v12-10-89d5217d3618@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/gud: race on staged state in
  gud_connector_set_luminance()
--

commit 5745bfa73995dabc57cdf0005257260438071d7c
Author: Mario Limonciello <mario.limonciello@amd.com>

drm/gud: add connector luminance support

This commit exposes GUD display brightness through the connector LUMINANCE
property when CONFIG_DRM_LUMINANCE is enabled, resending the current
display state and committing it from the .set_luminance callback on
luminance-only updates.

> diff --git a/drivers/gpu/drm/gud/gud_connector.c b/drivers/gpu/drm/gud/gud_connector.c
> index ddbf3b3ebbca8..f00272f030c1c 100644
> --- a/drivers/gpu/drm/gud/gud_connector.c
> +++ b/drivers/gpu/drm/gud/gud_connector.c
> @@ -13,6 +13,7 @@
>  #include <drm/drm_edid.h>
>  #include <drm/drm_encoder.h>
>  #include <drm/drm_file.h>
> +#include <drm/drm_framebuffer.h>
>  #include <drm/drm_modeset_helper_vtables.h>
>  #include <drm/drm_print.h>
>  #include <drm/drm_probe_helper.h>
> @@ -314,17 +315,52 @@ static int gud_connector_atomic_check(struct drm_connector *connector,
>  	return 0;
>  }
>  
> +/*
> + * The device receives brightness as part of its display state, there is no
> + * dedicated request. Resend the current configuration with the new luminance
> + * and apply it, so that a luminance change doesn't need a modeset.
> + */
> +static void gud_connector_set_luminance(const struct drm_connector_state *conn_state)
> +{
> +	struct drm_connector *connector = conn_state->connector;
> +	struct gud_device *gdrm = to_gud_device(connector->dev);
> +	struct drm_crtc_state *crtc_state = conn_state->crtc->state;
> +	struct drm_plane_state *plane_state = gdrm->plane.state;
> +	int idx, ret;
> +
> +	/*
> +	 * gud_plane_atomic_check() sent the committed luminance with
> +	 * GUD_REQ_SET_STATE_CHECK for these changes and gud_crtc_atomic_enable()
> +	 * applied it. A modeset that only changed the active state didn't.
> +	 */
> +	if (crtc_state->mode_changed || crtc_state->connectors_changed)
> +		return;
> +
> +	if (drm_WARN_ON_ONCE(connector->dev, !plane_state->fb))
> +		return;
> +
> +	ret = gud_state_check(gdrm, &crtc_state->mode, plane_state->fb->format,
> +			      plane_state->rotation, conn_state);
> +	if (!ret && drm_dev_enter(connector->dev, &idx)) {
> +		ret = gud_usb_set(gdrm, GUD_REQ_SET_STATE_COMMIT, 0, NULL, 0);
> +		drm_dev_exit(idx);
> +	}
> +	if (ret)
> +		gud_conn_err(connector, "Failed to set luminance", ret);
> +}

[Severity: Medium]
Can a nonblocking luminance commit race with gud_plane_atomic_check() and
clobber the display state staged on the device with GUD_REQ_SET_STATE_CHECK?

For commits where mode_changed or connectors_changed is set,
gud_plane_atomic_check() stages the new configuration on the device during
drm_atomic_check_only(), before drm_atomic_helper_swap_state() waits for an
in-flight nonblocking commit's hw_done completion, and
gud_crtc_atomic_enable() later applies it with a payload-less
GUD_REQ_SET_STATE_COMMIT.  Because commit_work runs
gud_connector_set_luminance() after modeset locks are dropped, it can
interleave with a subsequent modeset or property commit:

CPU0 (commit B: modeset/rotation)   kworker (commit A: nonblocking luminance)
drm_mode_atomic_ioctl()
  drm_atomic_check_only()
    gud_plane_atomic_check()
      gud_state_check()
        /* stages B on device */
  drm_atomic_helper_commit()
    drm_atomic_helper_swap_state()
      wait_for_completion(A->hw_done)
                                    commit_tail()
                                      ...
                                      gud_connector_set_luminance()
                                        gud_state_check()
                                          /* overwrites device with A */
                                        gud_usb_set(SET_STATE_COMMIT)
                                      drm_atomic_helper_commit_hw_done()
    ...
    gud_crtc_atomic_enable()
      gud_usb_set(SET_STATE_COMMIT)
        /* re-commits A; B is lost */
    gud_connector_set_luminance()
      if (mode_changed || ...)
        return;

Similarly, because gud_connector_set_luminance() drops gdrm->ctrl_lock
between gud_state_check() and gud_usb_set(GUD_REQ_SET_STATE_COMMIT), a
concurrent DRM_MODE_ATOMIC_TEST_ONLY ioctl can run gud_plane_atomic_check()
-> gud_state_check() between the two transfers and have its test-only state
committed to the device.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-superm1-backlight-property-v12-0-89d5217d3618@amd.com?part=10

  reply	other threads:[~2026-11-19 23:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 23:27 [PATCH v12 00/12] Add support for a DRM backlight capability Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 01/12] drm: add connector LUMINANCE property Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 02/12] drm/amd/display: Pass up errors reading actual brightness Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 03/12] drm/amdgpu: Check bios_scratch_reg_offset in backlight level helper Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 04/12] drm/amd: add luminance property support Mario Limonciello
2026-11-19 23:52   ` sashiko-bot
2026-11-19 23:27 ` [PATCH v12 05/12] drm/i915/display: " Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 06/12] drm/bridge: add connector luminance operations Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 07/12] drm/panel: add connector luminance forwarding Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 08/12] drm/bridge_connector: add luminance support Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 09/12] drm/nouveau: add connector " Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 10/12] drm/gud: " Mario Limonciello
2026-11-19 23:43   ` sashiko-bot [this message]
2026-11-19 23:27 ` [PATCH v12 11/12] drm/bridge: add PS8622 " Mario Limonciello
2026-11-19 23:27 ` [PATCH v12 12/12] drm/solomon: add SSD130x " Mario Limonciello

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-224212@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=mario.limonciello@amd.com \
    --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