From: Ville Syrjälä <[email protected]> The ownership of an event attached to a CRTC state is currently split three ways: drm_atomic_helper_setup_commit() allocated events are freed through drm_crtc_commit::event, events from the atomic uapi are freed by complete_signaling(), and a flag (drm_crtc_commit::abort_completion) is needed so the right party drops the reference the event holds on the commit.
Simplify this by having __drm_atomic_helper_crtc_destroy_state() throw away any event that is still in the state, since an event that was not consumed by the driver can only be there because the commit did not happen. drm_event_cancel_free() takes care of the file and fence bookkeeping, and of releasing the event's completion. This allows drm_crtc_commit::event, drm_crtc_commit::abort_completion and the cancelling in complete_signaling() to go away. All drivers clear the event from the CRTC state when they consume it, and drm_atomic_helper_commit_hw_done() already warns if they do not. Signed-off-by: Ville Syrjälä <[email protected]> --- drivers/gpu/drm/drm_atomic_helper.c | 10 ++------ drivers/gpu/drm/drm_atomic_state_helper.c | 29 ++++++++++------------- drivers/gpu/drm/drm_atomic_uapi.c | 24 ++++--------------- include/drm/drm_atomic.h | 15 ------------ 4 files changed, 19 insertions(+), 59 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 31e46f6ccd22..23b24d633f2e 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -2559,19 +2559,15 @@ int drm_atomic_helper_setup_commit(struct drm_atomic_commit *state, } if (!new_crtc_state->event) { - commit->event = kzalloc_obj(*commit->event); - if (!commit->event) + new_crtc_state->event = kzalloc_obj(*new_crtc_state->event); + if (!new_crtc_state->event) return -ENOMEM; - - new_crtc_state->event = commit->event; } new_crtc_state->event->base.completion = &commit->flip_done; new_crtc_state->event->base.completion_release = release_crtc_commit; drm_crtc_commit_get(commit); - commit->abort_completion = true; - state->crtcs[i].commit = commit; drm_crtc_commit_get(commit); } @@ -3340,8 +3336,6 @@ int drm_atomic_helper_swap_state(struct drm_atomic_commit *state, list_add(&new_crtc_state->commit->commit_entry, &crtc->commit_list); spin_unlock(&crtc->commit_lock); - - new_crtc_state->commit->event = NULL; } } diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 267f44330629..8ddf03cf521e 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -174,25 +174,20 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); */ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state) { - if (state->commit) { - /* - * In the event that a non-blocking commit returns - * -ERESTARTSYS before the commit_tail work is queued, we will - * have an extra reference to the commit object. Release it, if - * the event has not been consumed by the worker. - * - * state->event may be freed, so we can't directly look at - * state->event->base.completion. - */ - if (state->event && state->commit->abort_completion) - drm_crtc_commit_put(state->commit); - - kfree(state->commit->event); - state->commit->event = NULL; - - drm_crtc_commit_put(state->commit); + /* + * An event that is still here was never consumed, eg. because a + * non-blocking commit returned -ERESTARTSYS before the commit_tail + * work was queued. Throw it away, which also releases the extra + * reference to the commit that the event holds for its completion. + */ + if (state->event) { + drm_event_cancel_free(state->crtc->dev, &state->event->base); + state->event = NULL; } + if (state->commit) + drm_crtc_commit_put(state->commit); + drm_property_blob_put(state->mode_blob); drm_property_blob_put(state->degamma_lut); drm_property_blob_put(state->ctm); diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 1eebcf6f5e05..2884063513ad 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -1552,13 +1552,10 @@ static int prepare_signaling(struct drm_device *dev, } static void complete_signaling(struct drm_device *dev, - struct drm_atomic_commit *state, struct drm_out_fence_state *fence_state, unsigned int num_fences, bool install_fds) { - struct drm_crtc *crtc; - struct drm_crtc_state *crtc_state; int i; if (install_fds) { @@ -1570,21 +1567,10 @@ static void complete_signaling(struct drm_device *dev, return; } - for_each_new_crtc_in_state(state, crtc, crtc_state, i) { - struct drm_pending_vblank_event *event = crtc_state->event; - /* - * Free the allocated event. drm_atomic_helper_setup_commit - * can allocate an event too, so only free it if it's ours - * to prevent a double free in drm_atomic_commit_clear. - */ - if (event && (event->base.fence || event->base.file_priv)) { - if (crtc_state->commit && crtc_state->commit->abort_completion) - drm_crtc_commit_put(crtc_state->commit); - drm_event_cancel_free(dev, &event->base); - crtc_state->event = NULL; - } - } - + /* + * Any events that were not consumed are thrown away when the state + * is destroyed. + */ if (!fence_state) return; @@ -1778,7 +1764,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, } out: - complete_signaling(dev, state, fence_state, num_fences, !ret); + complete_signaling(dev, fence_state, num_fences, !ret); if (ret == -EDEADLK) { drm_atomic_commit_clear(state); diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 3ae35b09c0cf..33d21ffdfc68 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -140,21 +140,6 @@ struct drm_crtc_commit { */ struct list_head commit_entry; - /** - * @event: - * - * &drm_pending_vblank_event pointer to clean up private events. - */ - struct drm_pending_vblank_event *event; - - /** - * @abort_completion: - * - * A flag that's set after drm_atomic_helper_setup_commit() takes a - * second reference for the completion of $drm_crtc_state.event. It's - * used by the free code to remove the second reference if commit fails. - */ - bool abort_completion; }; struct __drm_colorops_state { -- 2.56.0
