Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/atomic: skipping all no-op planes breaks CRTC-only async
  flips
- [Medium] drm/atomic: stale FB_DAMAGE_CLIPS read in
  drm_atomic_set_property()
--

commit 64d10f48b65296ed20fc62e81d5d8b357f0e8b51
Author: Ville Syrjälä <[email protected]>

drm/atomic/uapi: Make async flips a bit more palatable through atomic

This commit filters out no-op property changes during atomic async flips
in drm_atomic_set_property() before duplicating plane and connector states,
while still adding the associated CRTCs to the commit.

> diff --git a/drivers/gpu/drm/drm_atomic_uapi.c 
> b/drivers/gpu/drm/drm_atomic_uapi.c
> index 7517950d2e515..87181aba14514 100644
> --- a/drivers/gpu/drm/drm_atomic_uapi.c
> +++ b/drivers/gpu/drm/drm_atomic_uapi.c

[ ... ]

> @@ -1285,16 +1326,19 @@ int drm_atomic_set_property(struct drm_atomic_commit 
> *state,
>               struct drm_plane_state *plane_state;
>               struct drm_mode_config *config = &plane->dev->mode_config;
>               const struct drm_plane_helper_funcs *plane_funcs = 
> plane->helper_private;
> -
> -             plane_state = drm_atomic_get_plane_state(state, plane);
> -             if (IS_ERR(plane_state)) {
> -                     ret = PTR_ERR(plane_state);
> -                     break;
> -             }
> +             bool is_noop = false;
>  
>               if (async_flip) {
> -                     /* no-op changes are always allowed */
> -                     ret = drm_atomic_plane_get_property(plane, plane_state,
> +                     const struct drm_plane_state *current_plane_state;
> +
> +                     current_plane_state =
> +                             __drm_atomic_get_current_plane_state(state, 
> plane);
> +                     if (IS_ERR(current_plane_state)) {
> +                             ret = PTR_ERR(current_plane_state);
> +                             break;
> +                     }
> +
> +                     ret = drm_atomic_plane_get_property(plane, 
> current_plane_state,
>                                                           prop, &old_val);

[Severity: Medium]
Does reading prop_fb_damage_clips from current_plane_state return the
previous commit's damage blob ID instead of 0?

Unlike IN_FENCE_FD (which always reports -1), drm_atomic_plane_get_property()
returns state->fb_damage_clips->base.id, and state->fb_damage_clips is only
cleared to NULL when __drm_atomic_helper_plane_duplicate_state() duplicates
the state for a new commit.  Before this change, drm_atomic_get_plane_state()
ran first, so old_val was always 0 on a fresh plane state.

When current_plane_state is the un-duplicated plane->state from a previous
commit that attached damage clips, passing FB_DAMAGE_CLIPS = 0 on a
non-primary plane (such as a cursor plane) looks like a property change
(old_val != 0) and fails the async flip with -EINVAL.  Conversely, if
userspace passes the same blob ID as the previous commit before FB_ID in the
property list, FB_DAMAGE_CLIPS is skipped as a no-op and then wiped to NULL
when FB_ID duplicates the plane state.

>                       if (ret)
>                               break;
> @@ -1318,25 +1362,40 @@ int drm_atomic_set_property(struct drm_atomic_commit 
> *state,
>                               break;
>                       }
>  
> -                     /*
> -                      * FIXME this is in the wrong place. Whether to do a
> -                      * bypass commit for async flips would is a driver
> -                      * decision. Drivers that want this need to just do
> -                      * these checks themselves somewhere.
> -                      */
> -                     if (old_val != prop_value && plane->type != 
> DRM_PLANE_TYPE_PRIMARY) {
> -                             /* ask the driver if this non-primary plane is 
> supported */
> -                             if (plane_funcs && 
> plane_funcs->atomic_bypass_check)
> -                                     ret = 
> plane_funcs->atomic_bypass_check(plane, state, true);
> -                             else
> -                                     ret = -EINVAL;
> -
> -                             if (ret) {
> -                                     drm_dbg_atomic(prop->dev,
> -                                                    "[PLANE:%d:%s] does not 
> support async flips\n",
> -                                                    obj->id, plane->name);
> -                                     break;
> -                             }
> +                     if (old_val == prop_value)
> +                             is_noop = true;
> +             }
> +
> +             /* No-op plane property changes can be fully skipped */
> +             if (is_noop) {
> +                     ret = 0;
> +                     break;
> +             }

[Severity: High]
What happens when all plane property updates in an async flip commit are
no-ops (for example, primary plane FB_ID set to the current FB_ID)?

__drm_atomic_get_current_plane_state() adds the CRTC to the commit and
set_async_flip() sets crtc_state->async_flip = true, but skipping all planes
leaves the commit with zero planes in state.

On i915/xe, crtc_state->do_async_flip is only set in
intel_plane_atomic_calc_changes(), which only runs for planes in state.
With no planes in state, do_async_flip stays false:

1. If the first async flip on a pipe is a no-op, uapi.async_flip becomes
   true in crtc->state without switching the primary plane to minimal
   wm0/DDB.  On the next async flip where FB_ID actually changes,
   intel_plane_do_async_flip() sees old_crtc_state->uapi.async_flip == true
   and sets do_async_flip = true, while skl_compute_wm() tries to switch to
   minimal wm0/DDB for the first time; skl_ddb_add_affected_planes() and
   skl_wm_add_affected_planes() then reject that and all subsequent async
   flips with -EINVAL because watermarks/DDB cannot change during an async
   flip.

2. intel_crtc_complete_noop_async_flip() from commit "drm/i915: Complete
   no-op async flips by hand" returns early on !crtc_state->do_async_flip,
   so a no-op async flip falls through to a vblank-waited sync commit.

3. On amdgpu_dm, a commit with no planes skips pageflip event arming in
   amdgpu_dm_commit_planes() and falls back to drm_send_event_locked() in
   amdgpu_dm_atomic_commit_tail(), sending DRM_EVENT_FLIP_COMPLETE with a
   zeroed sequence and timestamp.

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=11

Reply via email to