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 <[email protected]>

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/[email protected]?part=10

Reply via email to