From: Ville Syrjälä <[email protected]>

The fake commit is used for planes and connectors that are not bound to
any CRTC. There is no event or flip for it, so its flip_done can not
mean anything more than "hw_done is on its way". Since
commit 2de42f79bb21 ("drm/atomic-helper: Complete fake_commit->flip_done
potentially earlier") it is completed after
drm_atomic_helper_wait_for_flip_done(), but that still leaves a window
in which a nonblocking commit touching the same planes/connectors gets
a spurious -EBUSY, eg. when the previous commit was a nonblocking
modeset that has sent out its event but still has not reached hw_done,
or when multiple CRTCs' vblanks don't line up.

Close the window by completing flip_done already when the fake commit is
created in drm_atomic_helper_setup_commit(), like is done for CRTCs that
stay off. Nothing relies on the late completion:

- ordering and the lifetime of the old state are guaranteed by hw_done,
  which drm_atomic_helper_swap_state() and
  drm_atomic_helper_wait_for_dependencies() still wait for
- a nonblocking commit that touches only unbound planes/connectors now
  stalls in drm_atomic_helper_swap_state() until the previous commit
  reaches hw_done, instead of failing with -EBUSY
- commits that include a CRTC already stall there for the CRTC's commit,
  whose hw_done completes together with the fake commit's

Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/work_items/13410
Cc: Maarten Lankhorst <[email protected]>
Signed-off-by: Ville Syrjälä <[email protected]>
---
 drivers/gpu/drm/drm_atomic_helper.c | 17 +++++++++++------
 include/drm/drm_atomic.h            |  6 ++++--
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 3baca28b5cb8..1ef1bc06ad5c 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1967,9 +1967,6 @@ void drm_atomic_helper_wait_for_flip_done(struct 
drm_device *dev,
                        drm_err(dev, "[CRTC:%d:%s] flip_done timed out\n",
                                crtc->base.id, crtc->name);
        }
-
-       if (state->fake_commit)
-               complete_all(&state->fake_commit->flip_done);
 }
 EXPORT_SYMBOL(drm_atomic_helper_wait_for_flip_done);
 
@@ -2492,6 +2489,16 @@ crtc_or_fake_commit(struct drm_atomic_commit *state, 
struct drm_crtc *crtc)
                        return NULL;
 
                init_commit(state->fake_commit, NULL);
+
+               /*
+                * There is no event nor flip for the fake commit, so
+                * flip_done has nothing to wait for. Completing it here
+                * avoids spurious -EBUSY from nonblocking commits that
+                * touch the same planes/connectors while the previous commit
+                * is still being committed. The ordering is still guaranteed
+                * by hw_done, which the later commits wait for.
+                */
+               complete_all(&state->fake_commit->flip_done);
        }
 
        return state->fake_commit;
@@ -2795,10 +2802,8 @@ void drm_atomic_helper_commit_hw_done(struct 
drm_atomic_commit *state)
                complete_all(&commit->hw_done);
        }
 
-       if (state->fake_commit) {
+       if (state->fake_commit)
                complete_all(&state->fake_commit->hw_done);
-               complete_all(&state->fake_commit->flip_done);
-       }
 }
 EXPORT_SYMBOL(drm_atomic_helper_commit_hw_done);
 
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 3ae35b09c0cf..5d075763c445 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -653,8 +653,10 @@ struct drm_atomic_commit {
         * When a connector or plane is not bound to any CRTC, it's still 
important
         * to preserve linearity to prevent the atomic states from being freed 
too early.
         *
-        * This commit (if set) is not bound to any CRTC, but will be completed 
when
-        * drm_atomic_helper_commit_hw_done() is called.
+        * This commit (if set) is not bound to any CRTC, and there is no flip
+        * for it to wait for, so its &drm_crtc_commit.flip_done is completed
+        * already by drm_atomic_helper_setup_commit(). &drm_crtc_commit.hw_done
+        * is completed when drm_atomic_helper_commit_hw_done() is called.
         */
        struct drm_crtc_commit *fake_commit;
 
-- 
2.56.0

Reply via email to