Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/atomic_sro: missing drm_crtc_vblank_reset() in CRTC state
  readout
--

commit 3ceb67bab8b0a4cc05a31256122d1df0b3736c93
Author: Maxime Ripard <[email protected]>

drm/atomic_sro: Provide helpers to implement hardware state readout

This commit adds helper functions to read out KMS object states from
hardware and install them as the initial atomic state.

> diff --git a/drivers/gpu/drm/drm_atomic_state_readout_helper.c 
> b/drivers/gpu/drm/drm_atomic_state_readout_helper.c
> new file mode 100644
> index 0000000000000..1b6cf304702c2
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_atomic_state_readout_helper.c
[ ... ]
> +int drm_atomic_helper_sro_readout_state(struct drm_device *dev)
> +{
> +     const struct drm_mode_config_helper_funcs *funcs =
> +             dev->mode_config.helper_private;
> +     struct drm_atomic_sro_state *state;
> +     struct drm_colorop *colorop;
> +
> +     if (!drm_atomic_sro_device_can_readout(dev)) {
> +             drm_info(dev, "Device doesn't support hardware state readout.");
> +             return -ENOTSUPP;
> +     }
> +
> +     state = funcs->atomic_sro_build_state(dev, NULL);
> +     if (IS_ERR(state)) {
> +             drm_warn(dev, "Couldn't read out the hardware state: %pe\n",
> +                      state);
> +             return PTR_ERR(state);
> +     }
> +
> +     /* TODO: Add colorop state readout support */
> +     drm_for_each_colorop(colorop, dev) {
> +             struct drm_colorop_state *colorop_state;
> +
> +             /*
> +              * The colorop states are already initialized when the
> +              * colorops are created. Only create a pristine state for
> +              * the ones that don't have one, like
> +              * drm_mode_config_create_state() does.
> +              */
> +             if (colorop->state)
> +                     continue;
> +
> +             colorop_state = drm_atomic_helper_colorop_create_state(colorop);
> +             if (IS_ERR(colorop_state)) {
> +                     drm_atomic_sro_state_free(state);
> +                     return PTR_ERR(colorop_state);
> +             }
> +
> +             colorop->state = colorop_state;
> +     }
> +
> +     drm_atomic_sro_install_state(state);
> +     drm_atomic_sro_state_free(state);
> +
> +     return 0;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_sro_readout_state);

[Severity: High]
Does bypassing drm_mode_config_create_state() when readout succeeds leave
disabled CRTCs without a drm_crtc_vblank_reset() call?

On the non-readout path, drm_mode_config_crtc_create_state() resets each
CRTC's vblank state when drm_dev_has_vblank(crtc->dev) is true:

drivers/gpu/drm/drm_mode_config.c:drm_mode_config_crtc_create_state() {
    ...
        if (drm_dev_has_vblank(crtc->dev))
                drm_crtc_vblank_reset(crtc);
}

Because crtc_funcs->atomic_create_state() is side-effect-free and readout
skips drm_mode_config_create_state(), any CRTC that is read out as
inactive (or that falls back to a pristine state when drm.atomic_readout
skips missing readout hooks) is left with vblank->inmodeset == 0 and
vblank->refcount == 0 after drm_vblank_init().  If userspace issues
DRM_IOCTL_WAIT_VBLANK on that disabled CRTC before a modeset,
drm_vblank_get() transitions refcount from 0 to 1 and invokes
crtc->funcs->enable_vblank() on disabled hardware instead of returning
-EINVAL, and any call to drm_crtc_set_max_vblank_count() before
drm_crtc_vblank_on() will hit drm_WARN_ON(dev, !READ_ONCE(vblank->inmodeset)).

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=20

Reply via email to