Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/atomic: lost driver state in
  drm_atomic_commit_fill_with_defaults()
--

commit 5edb49cfe4c7062b503d63439cf904e87048fe2c
Author: Maxime Ripard <[email protected]>

drm/atomic: Allow filling a commit with pristine object states

This commit adds drm_atomic_commit_fill_with_defaults() to populate an
atomic commit with freshly created default object states via the
atomic_create_state() hooks while carrying over adjusted_mode and
best_encoder.

> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 7a77051096c91..43df13aaef1eb 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1649,6 +1649,327 @@ bool drm_atomic_implements_create_state(struct 
> drm_device *dev)
>  }
>  EXPORT_SYMBOL(drm_atomic_implements_create_state);
>  
[ ... ]
> +int drm_atomic_commit_fill_with_defaults(struct drm_file *file_priv,
> +                                      struct drm_atomic_commit *commit)
> +{
[ ... ]
> +     drm_for_each_crtc(crtc, dev) {
> +             struct drm_crtc_state *crtc_state;
[ ... ]
> +             crtc_state = crtc->funcs->atomic_create_state(crtc);
> +             if (IS_ERR(crtc_state))
> +                     return PTR_ERR(crtc_state);
[ ... ]
> +             drm_mode_copy(&crtc_state->adjusted_mode,
> +                           &crtc->state->adjusted_mode);
> +
> +             /*
> +              * The planes come back with the default zpos, which the
> +              * atomic helpers only normalize when the planes bound to a
> +              * CRTC or one of their zpos changed. Re-applying the same
> +              * configuration on top of the reset wouldn't trigger
> +              * either, so ask for a normalization explicitly.
> +              */
> +             crtc_state->zpos_changed = true;
> +
> +             drm_atomic_commit_set_crtc_state(commit, crtc, crtc_state);
> +     }
> +
> +     drm_for_each_plane(plane, dev) {
> +             struct drm_plane_state *plane_state;
[ ... ]
> +             plane_state = plane->funcs->atomic_create_state(plane);
> +             if (IS_ERR(plane_state))
> +                     return PTR_ERR(plane_state);
[ ... ]
> +             drm_atomic_commit_set_plane_state(commit, plane, plane_state);
> +     }
> +
> +     ret = drm_modeset_lock(&config->connection_mutex, commit->acquire_ctx);
> +     if (ret)
> +             return ret;
> +
> +     drm_connector_list_iter_begin(dev, &conn_iter);
> +     drm_for_each_connector_iter(connector, &conn_iter) {
> +             struct drm_connector_state *connector_state;
[ ... ]
> +             connector_state = 
> connector->funcs->atomic_create_state(connector);
> +             if (IS_ERR(connector_state)) {
> +                     drm_connector_list_iter_end(&conn_iter);
> +                     ret = PTR_ERR(connector_state);
> +                     return ret;
> +             }
> +
> +             /*
> +              * best_encoder is a routing information maintained by the
> +              * atomic helpers rather than a userspace property, and it
> +              * is only carried over to a new state when that state is a
> +              * duplicate of the current one. Since
> +              * update_connector_routing() uses it to detect the commits
> +              * that keep the connector routing unchanged, carry the
> +              * encoder currently in use over so that a reset on which
> +              * userspace re-applies the exact same configuration doesn't
> +              * require a modeset.
> +              */
> +             connector_state->best_encoder = connector->state->best_encoder;

[Severity: High]
Does building the commit from atomic_create_state() while carrying over
adjusted_mode and best_encoder lose driver-private state in drivers where
drm_atomic_implements_create_state() is true?

When userspace re-applies the current mode and connector routing on top of
a reset, carrying over adjusted_mode and best_encoder keeps mode_changed
and connectors_changed false, while the new CRTC, plane, and connector
states have their driver-private fields zero-initialized instead of copied
from the current state.

In msm/mdp5 (which implements mdp5_crtc_create_state(),
mdp5_plane_create_state(), and drm_bridge_connector_create_state()),
mdp5_plane_atomic_check_with_state() releases the old hardware pipes from
mdp5_state->hwpipe and mdp5_state->r_hwpipe on the new plane state.
Because mdp5_plane_create_state() leaves those pointers NULL, resetting an
active plane passes NULL to mdp5_pipe_release() and permanently leaks the
assigned pipes in mdp5_global_state->hwpipe.hwpipe_to_plane[].  If a reset
keeps a CRTC active with no visible planes, mdp5_crtc_atomic_check() also
returns before mdp5_crtc_setup_pipeline(), leaving
mdp5_cstate->pipeline.mixer NULL and causing a NULL pointer dereference in
blend_setup() during mdp5_crtc_atomic_flush().

In nouveau dispnv50 (nv50_head_create_state(), nv50_wndw_create_state(),
and nouveau_conn_atomic_create_state()), skipping a modeset leaves
asyh->mode, asyh->view, asyh->or, and asyh->wndw.owned zeroed in the CRTC
state because nv50_outp_atomic_check() and nv50_head_atomic_check() only
recompute them when mode_changed or connectors_changed is set.  On planes
kept enabled with the same framebuffer, nv50_wndw_atomic_check_acquire()
skips populating asyw->image when modeset is false, causing
curs507a_acquire() to reject cursor commits with -EINVAL (asyw->image.w ==
0) and zeroing asyw->ntfy.handle, asyw->sema.handle, and asyw->xlut.handle
so they are not cleaned up on later disables.  Resetting a modified
connector property back to its default without a modeset also leaves
asyc->set.mask at 0 because nouveau_conn_atomic_set_property() compares
against the newly created default state, skipping hardware reprogramming.

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

Reply via email to