drm: Clear state->acquire_ctx before leaving drm_atomic_helper_commit_duplicated_state()
Subsystems (2)
PATCH v2 1/4 drm: Clear state->acquire_ctx before leaving drm_atomic_helper_commit_duplicated_state()
From: Sean Paul <[email protected]>
drm_atomic_helper_commit_duplicated_state() sets state->acquire_ctx to the context given in the argument and leaves it in state after it quits. The lifetime of state and context are not guaranteed to be the same, so we shouldn't leave that pointer hanging around. This patch resets the context to NULL to avoid any oopses.
Changes in v2:
- Added to the set
--- drivers/gpu/drm/drm_atomic_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +6 -2
@@ -3225,7 +3225,7 @@ EXPORT_SYMBOL(drm_atomic_helper_suspend);int drm_atomic_helper_commit_duplicated_state (struct drm_atomic_state *state,struct drm_modeset_acquire_ctx *ctx) { -int i; +int i, ret;struct drm_plane *plane;struct drm_plane_state *new_plane_state;struct drm_connector *connector;
@@ -3244,7 +3244,11 @@ int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,for_each_new_connector_in_state (state, connector, new_conn_state, i) state->connectors[i].old_state = connector->state; -return drm_atomic_commit (state); + ret =drm_atomic_commit (state); + + state->acquire_ctx =NULL ; + +return ret; }EXPORT_SYMBOL (drm_atomic_helper_commit_duplicated_state);
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 2/4 drm: Move drm_mode_setcrtc() local re-init to failure path
From: Sean Paul <[email protected]>
Instead of always re-initializing the variables we need to clean up on out, move the re-initialization into the branch that goes back to retry label.
This is a lateral move right now, but will allow us to pull out the modeset locking into common code. I kept this change separate to make things easier to review.
Changes in v2:
- None
--- drivers/gpu/drm/drm_crtc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_crtc.c +9 -7
@@ -570,9 +570,9 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,struct drm_mode_crtc *crtc_req = data;struct drm_crtc *crtc;struct drm_plane *plane; -struct drm_connector **connector_set, *connector; -struct drm_framebuffer *fb; -struct drm_display_mode *mode; +struct drm_connector **connector_set =NULL , *connector; +struct drm_framebuffer *fb =NULL ; +struct drm_display_mode *mode =NULL ;struct drm_mode_set set;uint32_t __user *set_connectors_ptr;struct drm_modeset_acquire_ctx ctx;
@@ -601,10 +601,6 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,mutex_lock (&crtc->dev->mode_config.mutex);drm_modeset_acquire_init (&ctx,DRM_MODESET_ACQUIRE_INTERRUPTIBLE ); retry: - connector_set =NULL ; - fb =NULL ; - mode =NULL ; - ret =drm_modeset_lock_all_ctx (crtc->dev, &ctx);if (ret) goto out;
@@ -766,6 +762,12 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, }kfree (connector_set);drm_mode_destroy (dev, mode); + +/* In case we need to retry... */ + connector_set =NULL ; + fb =NULL ; + mode =NULL ; +if (ret == -EDEADLK ) { ret =drm_modeset_backoff (&ctx);if (!ret)
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 3/4 drm: Move atomic_state_put after locks are dropped
In reply to Sean PaulFrom: Sean Paul <[email protected]>
drm_atomic_state_put doesn't require any locking, and this makes things easier for switching to modeset_lock_all helpers in a future patch
Changes in v2:
- Moved state->acquire_ctx clear to a separate patch (Daniel)
--- drivers/gpu/drm/drm_atomic_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_helper.c +1 -1
@@ -3290,9 +3290,9 @@ int drm_atomic_helper_resume(struct drm_device *dev,drm_modeset_backoff (&ctx); } -drm_atomic_state_put (state);drm_modeset_drop_locks (&ctx);drm_modeset_acquire_fini (&ctx); +drm_atomic_state_put (state);return err; }
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 4/4 drm: Add DRM_MODESET_LOCK_BEGIN/END helpers
In reply to Sean PaulFrom: Sean Paul <[email protected]>
This patch adds a couple of helpers to remove the boilerplate involved in grabbing all of the modeset locks.
I've also converted the obvious cases in drm core to use the helpers.
The only remaining instance of drm_modeset_lock_all_ctx() is in drm_framebuffer. It's complicated by the state clear that occurs on deadlock. ATM, there's no way to inject code in the deadlock path with the helpers, so it's unfit for conversion.
Changes in v2:
- Relocate ret argument to the end of the list (Daniel)
- Incorporate Daniel's doc suggestions (Daniel)
--- drivers/gpu/drm/drm_atomic_helper.c | 51 +++++-------------------- drivers/gpu/drm/drm_color_mgmt.c | 14 +------ drivers/gpu/drm/drm_crtc.c | 15 ++------ drivers/gpu/drm/drm_modeset_lock.c | 6 +++ drivers/gpu/drm/drm_plane.c | 16 ++------ include/drm/drm_modeset_lock.h | 59 +++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 78 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +10 -41
@@ -3124,23 +3124,13 @@ void drm_atomic_helper_shutdown(struct drm_device *dev)struct drm_modeset_acquire_ctx ctx;int ret; -drm_modeset_acquire_init (&ctx,0 ); -while (1 ) { - ret =drm_modeset_lock_all_ctx (dev, &ctx); -if (!ret) - ret =__drm_atomic_helper_disable_all (dev, &ctx, true); - -if (ret != -EDEADLK ) -break ; - -drm_modeset_backoff (&ctx); - } +DRM_MODESET_LOCK_ALL_BEGIN (dev, ctx,0 , ret); + ret =__drm_atomic_helper_disable_all (dev, &ctx, true);if (ret)DRM_ERROR ("Disabling all crtc's during unload failed with %i\n" , ret); -drm_modeset_drop_locks (&ctx); -drm_modeset_acquire_fini (&ctx); +DRM_MODESET_LOCK_ALL_END (ctx, ret); }EXPORT_SYMBOL (drm_atomic_helper_shutdown);
@@ -3175,14 +3165,7 @@ struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev)struct drm_atomic_state *state;int err; -drm_modeset_acquire_init (&ctx,0 ); - -retry: - err =drm_modeset_lock_all_ctx (dev, &ctx); -if (err <0 ) { - state =ERR_PTR (err); - goto unlock; - } +DRM_MODESET_LOCK_ALL_BEGIN (dev, ctx,0 , err); state =drm_atomic_helper_duplicate_state (dev, &ctx);if (IS_ERR (state))
@@ -3196,13 +3179,10 @@ struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev) } unlock: -if (PTR_ERR (state) == -EDEADLK ) { -drm_modeset_backoff (&ctx); - goto retry; - } +DRM_MODESET_LOCK_ALL_END (ctx, err); +if (err) +return ERR_PTR (err); -drm_modeset_drop_locks (&ctx); -drm_modeset_acquire_fini (&ctx);return state; }EXPORT_SYMBOL (drm_atomic_helper_suspend);
@@ -3276,22 +3256,11 @@ int drm_atomic_helper_resume(struct drm_device *dev,drm_mode_config_reset (dev); -drm_modeset_acquire_init (&ctx,0 ); -while (1 ) { - err =drm_modeset_lock_all_ctx (dev, &ctx); -if (err) - goto out; +DRM_MODESET_LOCK_ALL_BEGIN (dev, ctx,0 , err); - err =drm_atomic_helper_commit_duplicated_state (state, &ctx); -out: -if (err != -EDEADLK ) -break ; - -drm_modeset_backoff (&ctx); - } + err =drm_atomic_helper_commit_duplicated_state (state, &ctx); -drm_modeset_drop_locks (&ctx); -drm_modeset_acquire_fini (&ctx); +DRM_MODESET_LOCK_ALL_END (ctx, err);drm_atomic_state_put (state);return err;
drivers/gpu/drm/drm_color_mgmt.c +2 -12
@@ -255,11 +255,7 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,if (crtc_lut->gamma_size != crtc->gamma_size)return -EINVAL ; -drm_modeset_acquire_init (&ctx,0 ); -retry: - ret =drm_modeset_lock_all_ctx (dev, &ctx); -if (ret) - goto out; +DRM_MODESET_LOCK_ALL_BEGIN (dev, ctx,0 , ret); size = crtc_lut->gamma_size * (sizeof (uint16_t )); r_base = crtc->gamma_store;
@@ -284,13 +280,7 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev, crtc->gamma_size, &ctx); out: -if (ret == -EDEADLK ) { -drm_modeset_backoff (&ctx); - goto retry; - } -drm_modeset_drop_locks (&ctx); -drm_modeset_acquire_fini (&ctx); - +DRM_MODESET_LOCK_ALL_END (ctx, ret);return ret; }
drivers/gpu/drm/drm_crtc.c +3 -12
@@ -599,11 +599,8 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, plane = crtc->primary;mutex_lock (&crtc->dev->mode_config.mutex); -drm_modeset_acquire_init (&ctx,DRM_MODESET_ACQUIRE_INTERRUPTIBLE ); -retry: - ret =drm_modeset_lock_all_ctx (crtc->dev, &ctx); -if (ret) - goto out; +DRM_MODESET_LOCK_ALL_BEGIN (dev, ctx, +DRM_MODESET_ACQUIRE_INTERRUPTIBLE , ret);if (crtc_req->mode_valid) {/* If we have a mode we need a framebuffer. */
@@ -768,13 +765,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, fb =NULL ; mode =NULL ; -if (ret == -EDEADLK ) { - ret =drm_modeset_backoff (&ctx); -if (!ret) - goto retry; - } -drm_modeset_drop_locks (&ctx); -drm_modeset_acquire_fini (&ctx); +DRM_MODESET_LOCK_ALL_END (ctx, ret);mutex_unlock (&crtc->dev->mode_config.mutex);return ret;
drivers/gpu/drm/drm_modeset_lock.c +6 -0
@@ -56,6 +56,10 @@* drm_modeset_drop_locks(ctx); * drm_modeset_acquire_fini(ctx); * +* For convenience this control flow is implemented in +* DRM_MODESET_LOCK_ALL_BEGIN() and DRM_MODESET_LOCK_ALL_END() for the case +* where all modeset locks need to be taken through drm_modeset_lock_all_ctx(). +* * If all that is needed is a single modeset lock, then the &struct * drm_modeset_acquire_ctx is not needed and the locking can be simplified * by passing a NULL instead of ctx in the drm_modeset_lock() call or
@@ -383,6 +387,8 @@ EXPORT_SYMBOL(drm_modeset_unlock);* Locks acquired with this function should be released by calling the * drm_modeset_drop_locks() function on @ctx. * +* See also: DRM_MODESET_LOCK_ALL_BEGIN() and DRM_MODESET_LOCK_ALL_END() +* * Returns: 0 on success or a negative error-code on failure. */ int drm_modeset_lock_all_ctx(struct drm_device *dev,
drivers/gpu/drm/drm_plane.c +3 -13
@@ -767,11 +767,8 @@ static int setplane_internal(struct drm_plane *plane,struct drm_modeset_acquire_ctx ctx;int ret; -drm_modeset_acquire_init (&ctx,DRM_MODESET_ACQUIRE_INTERRUPTIBLE ); -retry: - ret =drm_modeset_lock_all_ctx (plane->dev, &ctx); -if (ret) - goto fail; +DRM_MODESET_LOCK_ALL_BEGIN (plane->dev, ctx, +DRM_MODESET_ACQUIRE_INTERRUPTIBLE , ret);if (drm_drv_uses_atomic_modeset (plane->dev)) ret = __setplane_atomic(plane, crtc, fb,
@@ -782,14 +779,7 @@ static int setplane_internal(struct drm_plane *plane, crtc_x, crtc_y, crtc_w, crtc_h, src_x, src_y, src_w, src_h, &ctx); -fail: -if (ret == -EDEADLK ) { - ret =drm_modeset_backoff (&ctx); -if (!ret) - goto retry; - } -drm_modeset_drop_locks (&ctx); -drm_modeset_acquire_fini (&ctx); +DRM_MODESET_LOCK_ALL_END (ctx, ret);return ret; }
include/drm/drm_modeset_lock.h +59 -0
63 lines not on this page · raw message
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Sean Paul
From: Sean Paul <[email protected]>
drm_atomic_helper_commit_duplicated_state()setsstate->acquire_ctxto the context given in the argument and leaves it in state after it quits. The lifetime of state and context are not guaranteed to be the same, so we shouldn't leave that pointer hanging around. This patch resets the context to NULL to avoid any oopses.
Quoted 5 lines
Changes in v2:
- Added to the setSuggested-by Daniel Vetter <[email protected]>Signed-off-by Sean Paul <[email protected]>
Quoted 33 lines
--- drivers/gpu/drm/drm_atomic_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +6
-2@@ -3225,7 +3225,7 @@ EXPORT_SYMBOL(drm_atomic_helper_suspend);int drm_atomic_helper_commit_duplicated_state (struct drm_atomic_state *state,struct drm_modeset_acquire_ctx *ctx) { -int i; +int i, ret;struct drm_plane *plane;struct drm_plane_state *new_plane_state;struct drm_connector *connector;@@ -3244,7 +3244,11 @@ int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,for_each_new_connector_in_state (state, connector, new_conn_state, i) state->connectors[i].old_state = connector->state; -return drm_atomic_commit (state); + ret =drm_atomic_commit (state); + + state->acquire_ctx =NULL ; + +return ret; }EXPORT_SYMBOL (drm_atomic_helper_commit_duplicated_state);Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 9 lines · Daniel Vetter
Quoted 8 lines · Sean Paul
From: Sean Paul <[email protected]>
drm_atomic_helper_commit_duplicated_state()setsstate->acquire_ctxto the context given in the argument and leaves it in state after it quits. The lifetime of state and context are not guaranteed to be the same, so we shouldn't leave that pointer hanging around. This patch resets the context to NULL to avoid any oopses.
Quoted 7 lines
Quoted 5 lines
Changes in v2:
- Added to the setSuggested-by Daniel Vetter <[email protected]>Signed-off-by Sean Paul <[email protected]>Reviewed-by Daniel Vetter <[email protected]>
Thanks for your reviews! The series is pushed to drm-misc-next.
Sean
Quoted 39 lines
Quoted 34 lines
--- drivers/gpu/drm/drm_atomic_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +6
-2@@ -3225,7 +3225,7 @@ EXPORT_SYMBOL(drm_atomic_helper_suspend);int drm_atomic_helper_commit_duplicated_state (struct drm_atomic_state *state,struct drm_modeset_acquire_ctx *ctx) { -int i; +int i, ret;struct drm_plane *plane;struct drm_plane_state *new_plane_state;struct drm_connector *connector;@@ -3244,7 +3244,11 @@ int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,for_each_new_connector_in_state (state, connector, new_conn_state, i) state->connectors[i].old_state = connector->state; -return drm_atomic_commit (state); + ret =drm_atomic_commit (state); + + state->acquire_ctx =NULL ; + +return ret; }EXPORT_SYMBOL (drm_atomic_helper_commit_duplicated_state);Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OSSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel