drm/atomic: Add accessor macros for all atomic state.
Subsystems (3)
Maarten Lankhorst
maintainerv2 cover drm/atomic: Add accessor macros for all atomic state.
Second approach. Instead of trying to convert all drivers straight away, implement all macros that are required to get state working.
Current situation:
Use obj->state, which can refer to old or new state.
Use drm_atomic_get_(existing_)obj_state, which can refer to new or old state. Use for_each_obj_in_state, which refers to new or old state.
New situation:
When doing some dereferencing outside atomic_state, use drm_atomic_get_current_obj_state which has locking checks, instead of obj->state.
During atomic check:
- Use drm_atomic_get_obj_state to add a object to the atomic state, or get the new state.
- Use drm_atomic_get_(old/new)_obj_state to peek at the new/old state, without adding the object if it's not part of the state. For planes and connectors the relevant crtc_state is added, so this will work to get the crtc_state from foo_state->crtc too, saves some error handling. :)
During atomic commit:
- Do not use drm_atomic_get_obj_state, obj->state or drm_atomic_get_(existing_)obj_state any more, replace with drm_atomic_get_old/new_obj_state calls as required.
During both:
- Use for_each_(new,old,oldnew)_obj_in_state to get the old or new state as needed. oldnew will be renamed to for_each_obj_in_state after all callers are converted to the new api.
This will give the correct state regardless of swapping.
Maarten Lankhorst (4):
drm/atomic: Add new iterators over all state, v2. drm/atomic: Add accessor macros for the current state. drm/atomic: Add macros to access existing old/new state drm/atomic: Add checks to ensure get_state is not called after
swapping.
drivers/gpu/drm/drm_atomic.c | 24 +++- drivers/gpu/drm/drm_atomic_helper.c | 47 ++++++- drivers/gpu/drm/i915/intel_display.c | 11 +- include/drm/drm_atomic.h | 247 ++++++++++++++++++++++++++++++++++- include/drm/drm_atomic_helper.h | 2 + include/drm/drm_modeset_lock.h | 21 +++ 6 files changed, 338 insertions(+), 14 deletions(-)
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerPATCH v2 1/4 drm/atomic: Add new iterators over all state, v2.
Add for_each_(old)(new)_(plane,connector,crtc)_in_state iterators to replace the old for_each_xxx_in_state ones. This is useful for >1 flip depth and getting rid of all xxx->state dereferences.
This requires extra fixups done when committing a state after duplicating, which in general isn't valid but is used by suspend/resume. To handle these, introduce drm_atomic_helper_commit_duplicated_state which performs those fixups before checking & committing the state.
Changes since v1:
- Remove nonblock parameter for commit_duplicated_state.
--- drivers/gpu/drm/drm_atomic.c | 6 +++ drivers/gpu/drm/drm_atomic_helper.c | 47 +++++++++++++++++++-- drivers/gpu/drm/i915/intel_display.c | 11 ++--- include/drm/drm_atomic.h | 81 ++++++++++++++++++++++++++++++++++-- include/drm/drm_atomic_helper.h | 2 + 5 files changed, 136 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_atomic.c +6 -0
@@ -279,6 +279,8 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,return ERR_PTR (-ENOMEM ); state->crtcs[index].state = crtc_state; + state->crtcs[index].old_state = crtc->state; + state->crtcs[index].new_state = crtc_state; state->crtcs[index].ptr = crtc; crtc_state->state = state;
@@ -666,6 +668,8 @@ drm_atomic_get_plane_state(struct drm_atomic_state *state, state->planes[index].state = plane_state; state->planes[index].ptr = plane; + state->planes[index].old_state = plane->state; + state->planes[index].new_state = plane_state; plane_state->state = state; DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
@@ -993,6 +997,8 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state,drm_connector_reference (connector); state->connectors[index].state = connector_state; + state->connectors[index].old_state = connector->state; + state->connectors[index].new_state = connector_state; state->connectors[index].ptr = connector; connector_state->state = state;
drivers/gpu/drm/drm_atomic_helper.c +44 -3
66 lines not on this page · raw message
drivers/gpu/drm/i915/intel_display.c +6 -5
@@ -3496,7 +3496,8 @@ static void intel_update_primary_planes(struct drm_device *dev)static int __intel_display_resume (struct drm_device *dev, -struct drm_atomic_state *state) +struct drm_atomic_state *state, +struct drm_modeset_acquire_ctx *ctx) {struct drm_crtc_state *crtc_state;struct drm_crtc *crtc;
@@ -3520,7 +3521,7 @@ __intel_display_resume(struct drm_device *dev,/* ignore any reset values/BIOS leftovers in the WM registers */ to_intel_atomic_state (state)->skip_intermediate_wm = true; - ret =drm_atomic_commit (state); + ret =drm_atomic_helper_commit_duplicated_state (state, ctx);WARN_ON (ret == -EDEADLK );return ret;
@@ -3614,7 +3615,7 @@ void intel_finish_reset(struct drm_i915_private *dev_priv)*/ intel_update_primary_planes (dev); }else { - ret =__intel_display_resume (dev, state); + ret =__intel_display_resume (dev, state, ctx);if (ret)DRM_ERROR ("Restoring old state failed with %i\n" , ret); }
@@ -3634,7 +3635,7 @@ void intel_finish_reset(struct drm_i915_private *dev_priv) dev_priv->display.hpd_irq_setup (dev_priv);spin_unlock_irq (&dev_priv->irq_lock); - ret =__intel_display_resume (dev, state); + ret =__intel_display_resume (dev, state, ctx);if (ret)DRM_ERROR ("Restoring old state failed with %i\n" , ret);
@@ -17061,7 +17062,7 @@ void intel_display_resume(struct drm_device *dev) }if (!ret) - ret =__intel_display_resume (dev, state); + ret =__intel_display_resume (dev, state, &ctx);drm_modeset_drop_locks (&ctx);drm_modeset_acquire_fini (&ctx);
include/drm/drm_atomic.h +78 -3
114 lines not on this page · raw message
include/drm/drm_atomic_helper.h +2 -0
@@ -108,6 +108,8 @@ int __drm_atomic_helper_set_config(struct drm_mode_set *set,int drm_atomic_helper_disable_all (struct drm_device *dev,struct drm_modeset_acquire_ctx *ctx);struct drm_atomic_state *drm_atomic_helper_suspend (struct drm_device *dev); +int drm_atomic_helper_commit_duplicated_state (struct drm_atomic_state *state, +struct drm_modeset_acquire_ctx *ctx);int drm_atomic_helper_resume (struct drm_device *dev,struct drm_atomic_state *state);
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerPATCH v2 2/4 drm/atomic: Add accessor macros for the current state.
In reply to Maarten LankhorstWith checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)
include/drm/drm_atomic.h +66 -0
@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ +static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex); + +return plane_state; +} + +/** +* drm_atomic_get_current_crtc_state - get current crtc state +* @crtc: crtc to grab +* +* This function returns the current crtc state for the given crtc, +* with extra locking checks to make sure that the crtc state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current crtc state. +*/ +static inline struct drm_crtc_state * +drm_atomic_get_current_crtc_state (struct drm_crtc *crtc) +{ +drm_modeset_lock_assert_held (&crtc->mutex); + +return crtc->state; +} + +/** +* drm_atomic_get_current_connector_state - get current connector state +* @connector: connector to grab +* +* This function returns the current connector state for the given connector, +* with extra locking checks to make sure that the connector state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current connector state. +*/ +#define drm_atomic_get_current_connector_state(connector) \ +({ /* Implemented as macro to avoid including drmP for struct drm_device */ \ + struct drm_connector *con__ = (connector); \ + drm_modeset_lock_assert_held(&con__->dev->mode_config.connection_mutex); \ + con__->state; \ +}) +int __must_check drm_atomic_set_mode_for_crtc (struct drm_crtc_state *state,struct drm_display_mode *mode);
include/drm/drm_modeset_lock.h +21 -0
@@ -109,6 +109,27 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)return ww_mutex_is_locked (&lock->mutex); } +static inline void drm_modeset_lock_assert_held (struct drm_modeset_lock *lock) +{ +#ifdef CONFIG_LOCKDEP +lockdep_assert_held (&lock->mutex.base); +#else +WARN_ON (!drm_modeset_is_locked (lock)); +#endif +} + +static inline void drm_modeset_lock_assert_one_held (struct drm_modeset_lock *lock1, +struct drm_modeset_lock *lock2) +{ +#ifdef CONFIG_LOCKDEP +WARN_ON (debug_locks && + !lockdep_is_held (&lock1->mutex.base) && + !lockdep_is_held (&lock2->mutex.base)); +#else +WARN_ON (!drm_modeset_is_locked (lock1) && !drm_modeset_is_locked (lock2)); +#endif +} +int drm_modeset_lock (struct drm_modeset_lock *lock,struct drm_modeset_acquire_ctx *ctx); int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Quoted 30 lines · Maarten Lankhorst
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/
include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);
Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing object->state isn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?
I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Quoted 85 lines
include/drm/drm_atomic.h +43
-0+ +return plane_state; +} + +/** +* drm_atomic_get_current_crtc_state - get current crtc state +* @crtc: crtc to grab +* +* This function returns the current crtc state for the given crtc, +* with extra locking checks to make sure that the crtc state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current crtc state. +*/ +static inline struct drm_crtc_state * +drm_atomic_get_current_crtc_state (struct drm_crtc *crtc) +{ +drm_modeset_lock_assert_held (&crtc->mutex); + +return crtc->state; +} + +/** +* drm_atomic_get_current_connector_state - get current connector state +* @connector: connector to grab +* +* This function returns the current connector state for the given connector, +* with extra locking checks to make sure that the connector state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current connector state. +*/ +#define drm_atomic_get_current_connector_state(connector) \ +({ /* Implemented as macro to avoid including drmP for struct drm_device */ \ + struct drm_connector *con__ = (connector); \ + drm_modeset_lock_assert_held(&con__->dev->mode_config.connection_mutex); \ + con__->state; \ +}) +int __must_check drm_atomic_set_mode_for_crtc (struct drm_crtc_state *state,struct drm_display_mode *mode);include/drm/drm_modeset_lock.h +21
-0@@ -109,6 +109,27 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)return ww_mutex_is_locked (&lock->mutex); } +static inline void drm_modeset_lock_assert_held (struct drm_modeset_lock *lock) +{ +#ifdef CONFIG_LOCKDEP +lockdep_assert_held (&lock->mutex.base); +#else +WARN_ON (!drm_modeset_is_locked (lock)); +#endif +} + +static inline void drm_modeset_lock_assert_one_held (struct drm_modeset_lock *lock1, +struct drm_modeset_lock *lock2) +{ +#ifdef CONFIG_LOCKDEP +WARN_ON (debug_locks && + !lockdep_is_held (&lock1->mutex.base) && + !lockdep_is_held (&lock2->mutex.base)); +#else +WARN_ON (!drm_modeset_is_locked (lock1) && !drm_modeset_is_locked (lock2)); +#endif +} +int drm_modeset_lock (struct drm_modeset_lock *lock,struct drm_modeset_acquire_ctx *ctx); int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Quoted 46 lines · Ville Syrjälä
Quoted 30 lines · Maarten Lankhorst
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?
Quoted 7 lines
I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Yep, need at least a lockdep check for the plane->mutex. And imo also a check that we're indeed in atomic_check per the idea I dropped on the cover letter.
And +1 on const * for these, that seems like a very important check. -Daniel
Quoted 94 lines
Quoted 86 lines
include/drm/drm_atomic.h +43
-0+ +return plane_state; +} + +/** +* drm_atomic_get_current_crtc_state - get current crtc state +* @crtc: crtc to grab +* +* This function returns the current crtc state for the given crtc, +* with extra locking checks to make sure that the crtc state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current crtc state. +*/ +static inline struct drm_crtc_state * +drm_atomic_get_current_crtc_state (struct drm_crtc *crtc) +{ +drm_modeset_lock_assert_held (&crtc->mutex); + +return crtc->state; +} + +/** +* drm_atomic_get_current_connector_state - get current connector state +* @connector: connector to grab +* +* This function returns the current connector state for the given connector, +* with extra locking checks to make sure that the connector state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current connector state. +*/ +#define drm_atomic_get_current_connector_state(connector) \ +({ /* Implemented as macro to avoid including drmP for struct drm_device */ \ + struct drm_connector *con__ = (connector); \ + drm_modeset_lock_assert_held(&con__->dev->mode_config.connection_mutex); \ + con__->state; \ +}) +int __must_check drm_atomic_set_mode_for_crtc (struct drm_crtc_state *state,struct drm_display_mode *mode);include/drm/drm_modeset_lock.h +21
-0@@ -109,6 +109,27 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)return ww_mutex_is_locked (&lock->mutex); } +static inline void drm_modeset_lock_assert_held (struct drm_modeset_lock *lock) +{ +#ifdef CONFIG_LOCKDEP +lockdep_assert_held (&lock->mutex.base); +#else +WARN_ON (!drm_modeset_is_locked (lock)); +#endif +} + +static inline void drm_modeset_lock_assert_one_held (struct drm_modeset_lock *lock1, +struct drm_modeset_lock *lock2) +{ +#ifdef CONFIG_LOCKDEP +WARN_ON (debug_locks && + !lockdep_is_held (&lock1->mutex.base) && + !lockdep_is_held (&lock2->mutex.base)); +#else +WARN_ON (!drm_modeset_is_locked (lock1) && !drm_modeset_is_locked (lock2)); +#endif +} +int drm_modeset_lock (struct drm_modeset_lock *lock,struct drm_modeset_acquire_ctx *ctx); int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-develSignature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
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
Maarten Lankhorst
maintainerRe: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Op 16-11-16 om 16:04 schreef Daniel Vetter:
Quoted 51 lines · Ville Syrjälä
Quoted 50 lines · Maarten Lankhorst
Quoted 30 lines
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
Quoted 7 lines
Quoted 2 lines
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Yep, need at least a lockdep check for the
plane->mutex. And imo also a check that we're indeed inatomic_checkper the idea I dropped on the cover letter.And +1 on const * for these, that seems like a very important check.
Well I allowed for crtc lock held because the __ function uses crtc->mutex as safety lock.
I thought of const, but some code like i915_page_flip manipulates the current state with the right locks held. Perhaps we should disallow that. :)
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Quoted 58 lines · Maarten Lankhorst
Op 16-11-16 om 16:04 schreef Daniel Vetter:
Quoted 57 lines · Ville Syrjälä
Quoted 45 lines · Maarten Lankhorst
Quoted 30 lines
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?Quoted 7 lines
I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Yep, need at least a lockdep check for the
plane->mutex. And imo also a check that we're indeed inatomic_checkper the idea I dropped on the cover letter.
Quoted 5 lines
Quoted 1 line
And +1 on const * for these, that seems like a very important check.
Well I allowed for crtc lock held because the __ function uses
crtc->mutexas safety lock.I thought of const, but some code like
i915_page_flipmanipulates the current state with the right locks held. Perhaps we should disallow that. :)
Yup, since that code is going to die anyway. And if any driver has a need for this, then they better open code (and have lots of answers for lots of questions really).
-Daniel
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
Re: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
In reply to Maarten LankhorstQuoted 52 lines · Maarten Lankhorst
Op 16-11-16 om 16:04 schreef Daniel Vetter:
Quoted 51 lines · Ville Syrjälä
Quoted 50 lines · Maarten Lankhorst
Quoted 30 lines
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Yep, need at least a lockdep check for the
plane->mutex. And imo also a check that we're indeed inatomic_checkper the idea I dropped on the cover letter.And +1 on const * for these, that seems like a very important check.
Well I allowed for crtc lock held because the __ function uses
crtc->mutexas safety lock.
What is this so called __ function exactly?
Quoted 5 lines
I thought of const, but some code like
i915_page_flipmanipulates the current state with the right locks held. Perhaps we should disallow that. :)~Maarten
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerRe: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Op 16-11-16 om 17:32 schreef Ville Syrjälä:
Quoted 55 lines · Maarten Lankhorst
Quoted 54 lines
Op 16-11-16 om 16:04 schreef Daniel Vetter:
Quoted 53 lines · Ville Syrjälä
Quoted 52 lines · Maarten Lankhorst
Quoted 30 lines
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Yep, need at least a lockdep check for the
plane->mutex. And imo also a check that we're indeed inatomic_checkper the idea I dropped on the cover letter.And +1 on const * for these, that seems like a very important check.
Well I allowed for crtc lock held because the __ function uses
crtc->mutexas safety lock.What is this so called __ function exactly?
__drm_atomic_get_current_plane_state, which is only used by drm_atomic_crtc_state_for_each_plane_state.
It iterates over crtc_state->plane_mask and then gets new_plane_state if available, or plane->state if the plane is not part of the state. This is mostly used for watermark calculations.
Quoted 4 lines
Quoted 4 lines
I thought of const, but some code like
i915_page_flipmanipulates the current state with the right locks held. Perhaps we should disallow that. :)~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Quoted 60 lines · Maarten Lankhorst
Op 16-11-16 om 17:32 schreef Ville Syrjälä:
Quoted 59 lines · Maarten Lankhorst
Quoted 58 lines
Op 16-11-16 om 16:04 schreef Daniel Vetter:
Quoted 57 lines · Ville Syrjälä
Quoted 45 lines · Maarten Lankhorst
Quoted 30 lines
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?Quoted 7 lines
I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Yep, need at least a lockdep check for the
plane->mutex. And imo also a check that we're indeed inatomic_checkper the idea I dropped on the cover letter.
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
And +1 on const * for these, that seems like a very important check.
Well I allowed for crtc lock held because the __ function uses
crtc->mutexas safety lock.What is this so called __ function exactly?
__drm_atomic_get_current_plane_state, which is only used bydrm_atomic_crtc_state_for_each_plane_state.It iterates over
crtc_state->plane_maskand then getsnew_plane_stateif available, orplane->stateif the plane is not part of the state. This is mostly used for watermark calculations.
Sounds like we should kill that sucker and make things clearer by enforcing the "want to access foo->state? then grab foo->lock first" rule.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
I thought of const, but some code like
i915_page_flipmanipulates the current state with the right locks held. Perhaps we should disallow that. :)~Maarten
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerRe: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Op 17-11-16 om 13:26 schreef Ville Syrjälä:
Quoted 63 lines · Maarten Lankhorst
Quoted 62 lines
Op 16-11-16 om 17:32 schreef Ville Syrjälä:
Quoted 61 lines · Maarten Lankhorst
Quoted 60 lines
Op 16-11-16 om 16:04 schreef Daniel Vetter:
Quoted 51 lines · Ville Syrjälä
Quoted 50 lines · Maarten Lankhorst
Quoted 30 lines
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
Quoted 7 lines
Quoted 2 lines
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Yep, need at least a lockdep check for the
plane->mutex. And imo also a check that we're indeed inatomic_checkper the idea I dropped on the cover letter.And +1 on const * for these, that seems like a very important check.
Well I allowed for crtc lock held because the __ function uses
crtc->mutexas safety lock.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
What is this so called __ function exactly?
__drm_atomic_get_current_plane_state, which is only used bydrm_atomic_crtc_state_for_each_plane_state.It iterates over
crtc_state->plane_maskand then getsnew_plane_stateif available, orplane->stateif the plane is not part of the state. This is mostly used for watermark calculations.Sounds like we should kill that sucker and make things clearer by enforcing the "want to access
foo->state? then grabfoo->lockfirst" rule.
Except adding all planes to cursor updates would result in unintended behavior.
And there are already patches to use the sprite plane instead of the cursor plane for skylake, so it's not just theoretical. :)
Testcases:
flip-vs-cursor-busy-crc-legacy
flip-vs-cursor-busy-crc-atomic
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Quoted 65 lines · Maarten Lankhorst
Op 17-11-16 om 13:26 schreef Ville Syrjälä:
Quoted 64 lines · Maarten Lankhorst
Quoted 63 lines
Op 16-11-16 om 17:32 schreef Ville Syrjälä:
Quoted 62 lines · Maarten Lankhorst
Quoted 52 lines
Op 16-11-16 om 16:04 schreef Daniel Vetter:
Quoted 51 lines · Ville Syrjälä
Quoted 50 lines · Maarten Lankhorst
Quoted 30 lines
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Signed-off-by Maarten Lankhorst <[email protected]>--- include/drm/drm_atomic.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 21 ++++++++++++++ 2 files changed, 87 insertions(+)include/drm/drm_atomic.h +13
-0@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 359
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+static inline struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_crtc *crtc = plane_state ? plane_state->crtc :NULL ; + +if (crtc) +drm_modeset_lock_assert_one_held (&plane->mutex, &crtc->mutex); +else +drm_modeset_lock_assert_held (&plane->mutex);Hmm. Daniel recently smashed me on the head with a big clue bat to point out that accessing
object->stateisn't safe unless you hold the object lock. So this thing seems suspicious. What's the use case for this?I guess in this case it might be safe since a parallel update would lock the crtc as well. But it does feel like promoting potentially dangerous behaviour. Also there are no barriers so I'm not sure this would be guaranteed to give us the correct answer anyway.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
As far as all of these functions go, should they return const*? Presumably you wouldn't want to allow changes to the current state.
Yep, need at least a lockdep check for the
plane->mutex. And imo also a check that we're indeed inatomic_checkper the idea I dropped on the cover letter.And +1 on const * for these, that seems like a very important check.
Well I allowed for crtc lock held because the __ function uses
crtc->mutexas safety lock.What is this so called __ function exactly?
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
__drm_atomic_get_current_plane_state, which is only used bydrm_atomic_crtc_state_for_each_plane_state.It iterates over
crtc_state->plane_maskand then getsnew_plane_stateif available, orplane->stateif the plane is not part of the state. This is mostly used for watermark calculations.Sounds like we should kill that sucker and make things clearer by enforcing the "want to access
foo->state? then grabfoo->lockfirst" rule.Except adding all planes to cursor updates would result in unintended behavior.
That wasn't my suggestion.
Quoted 7 lines
And there are already patches to use the sprite plane instead of the cursor plane for skylake, so it's not just theoretical. :)
Testcases:
flip-vs-cursor-busy-crc-legacy
flip-vs-cursor-busy-crc-atomic~Maarten
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerPATCH v2 2/4 drm/atomic: Add accessor macros for the current state, v2.
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Changes since v1:
- Constify returned states.
- Require plane lock to return plane state, don't allow crtc_lock to be sufficient.
---
include/drm/drm_atomic.h +60 -0
@@ -334,6 +334,66 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ +static inline const struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +drm_modeset_lock_assert_held (&plane->mutex); + +return plane->state; +} + +/** +* drm_atomic_get_current_crtc_state - get current crtc state +* @crtc: crtc to grab +* +* This function returns the current crtc state for the given crtc, +* with extra locking checks to make sure that the crtc state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current crtc state. +*/ +static inline const struct drm_crtc_state * +drm_atomic_get_current_crtc_state (struct drm_crtc *crtc) +{ +drm_modeset_lock_assert_held (&crtc->mutex); + +return crtc->state; +} + +/** +* drm_atomic_get_current_connector_state - get current connector state +* @connector: connector to grab +* +* This function returns the current connector state for the given connector, +* with extra locking checks to make sure that the connector state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current connector state. +*/ +#define drm_atomic_get_current_connector_state(connector) \ +({ /* Implemented as macro to avoid including drmP for struct drm_device */ \ + struct drm_connector *con__ = (connector); \ + drm_modeset_lock_assert_held(&con__->dev->mode_config.connection_mutex); \ + (const struct drm_connector_state *)con__->state; \ +}) +int __must_check drm_atomic_set_mode_for_crtc (struct drm_crtc_state *state,struct drm_display_mode *mode);
include/drm/drm_modeset_lock.h +9 -0
@@ -109,6 +109,15 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)return ww_mutex_is_locked (&lock->mutex); } +static inline void drm_modeset_lock_assert_held (struct drm_modeset_lock *lock) +{ +#ifdef CONFIG_LOCKDEP +lockdep_assert_held (&lock->mutex.base); +#else +WARN_ON (!drm_modeset_is_locked (lock)); +#endif +} +int drm_modeset_lock (struct drm_modeset_lock *lock,struct drm_modeset_acquire_ctx *ctx); int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2.1 2/4] drm/atomic: Add accessor macros for the current state, v2.
Quoted 9 lines · Maarten Lankhorst
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Changes since v1:
- Constify returned states.
- Require plane lock to return plane state, don't allowcrtc_lockto be sufficient.Signed-off-by Maarten Lankhorst <[email protected]>
I wanted to add some more docs to drm_atomic_state and related code and realized this series here hasn't landed. What's the status? Anything pending from this long discussion, Ville?
Or should I go through it and do some review&merging? -Daniel
Quoted 93 lines
---
include/drm/drm_atomic.h +60
-0@@ -334,6 +334,66 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ +static inline const struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +drm_modeset_lock_assert_held (&plane->mutex); + +return plane->state; +} + +/** +* drm_atomic_get_current_crtc_state - get current crtc state +* @crtc: crtc to grab +* +* This function returns the current crtc state for the given crtc, +* with extra locking checks to make sure that the crtc state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current crtc state. +*/ +static inline const struct drm_crtc_state * +drm_atomic_get_current_crtc_state (struct drm_crtc *crtc) +{ +drm_modeset_lock_assert_held (&crtc->mutex); + +return crtc->state; +} + +/** +* drm_atomic_get_current_connector_state - get current connector state +* @connector: connector to grab +* +* This function returns the current connector state for the given connector, +* with extra locking checks to make sure that the connector state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current connector state. +*/ +#define drm_atomic_get_current_connector_state(connector) \ +({ /* Implemented as macro to avoid including drmP for struct drm_device */ \ + struct drm_connector *con__ = (connector); \ + drm_modeset_lock_assert_held(&con__->dev->mode_config.connection_mutex); \ + (const struct drm_connector_state *)con__->state; \ +}) +int __must_check drm_atomic_set_mode_for_crtc (struct drm_crtc_state *state,struct drm_display_mode *mode);include/drm/drm_modeset_lock.h +9
-0@@ -109,6 +109,15 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)return ww_mutex_is_locked (&lock->mutex); } +static inline void drm_modeset_lock_assert_held (struct drm_modeset_lock *lock) +{ +#ifdef CONFIG_LOCKDEP +lockdep_assert_held (&lock->mutex.base); +#else +WARN_ON (!drm_modeset_is_locked (lock)); +#endif +} +int drm_modeset_lock (struct drm_modeset_lock *lock,struct drm_modeset_acquire_ctx *ctx); int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
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
Re: [PATCH v2.1 2/4] drm/atomic: Add accessor macros for the current state, v2.
In reply to Maarten LankhorstQuoted 63 lines · Maarten Lankhorst
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Changes since v1:
- Constify returned states.
- Require plane lock to return plane state, don't allowcrtc_lockto be sufficient.Signed-off-by Maarten Lankhorst <[email protected]>---
include/drm/drm_atomic.h +45
-0@@ -334,6 +334,66 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ +static inline const struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +drm_modeset_lock_assert_held (&plane->mutex); + +return plane->state; +} + +/** +* drm_atomic_get_current_crtc_state - get current crtc state +* @crtc: crtc to grab +* +* This function returns the current crtc state for the given crtc, +* with extra locking checks to make sure that the crtc state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current crtc state. +*/ +static inline const struct drm_crtc_state * +drm_atomic_get_current_crtc_state (struct drm_crtc *crtc) +{ +drm_modeset_lock_assert_held (&crtc->mutex); + +return crtc->state; +} + +/** +* drm_atomic_get_current_connector_state - get current connector state +* @connector: connector to grab +*
include/drm/drm_atomic.h __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, · line 391
Quoted 10 lines
include/drm/drm_atomic.h +10
-0+* This function returns the current connector state for the given connector, +* with extra locking checks to make sure that the connector state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current connector state. +*/ +#define drm_atomic_get_current_connector_state (connector) \ +({/* Implemented as macro to avoid including drmP for struct drm_device */ \
Imo that's not a terrible good reason. Eventually will split drm_device.h out from drmP.h, and then we can nuke the additional include. Can you pls respin?
-Daniel
Quoted 29 lines
include/drm/drm_atomic.h +5
-0+struct drm_connector *con__ = (connector); \ +drm_modeset_lock_assert_held (&con__->dev->mode_config.connection_mutex); \ + (const struct drm_connector_state *)con__->state; \ +}) +int __must_check drm_atomic_set_mode_for_crtc (struct drm_crtc_state *state,struct drm_display_mode *mode);include/drm/drm_modeset_lock.h +9
-0@@ -109,6 +109,15 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)return ww_mutex_is_locked (&lock->mutex); } +static inline void drm_modeset_lock_assert_held (struct drm_modeset_lock *lock) +{ +#ifdef CONFIG_LOCKDEP +lockdep_assert_held (&lock->mutex.base); +#else +WARN_ON (!drm_modeset_is_locked (lock)); +#endif +} +int drm_modeset_lock (struct drm_modeset_lock *lock,struct drm_modeset_acquire_ctx *ctx); int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
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
Maarten Lankhorst
maintainerPATCH v2 2/4 drm/atomic: Add accessor macros for the current state, v3.
With checks! This will allow safe access to the current state, while ensuring that the correct locks are held.
Changes since v1:
- Constify returned states.
- Require plane lock to return plane state, don't allow crtc_lock to be sufficient.
Changes since v2:
- Include drmP.h for drm_device, change the macro drm_atomic_get_current_connector_state back to a function.
--- include/drm/drm_atomic.h | 62 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 9 ++++++ 2 files changed, 71 insertions(+)
include/drm/drm_atomic.h +62 -0
@@ -29,6 +29,7 @@#define DRM_ATOMIC_H_ #include <drm/drm_crtc.h> +#include <drm/drmP.h> /** * struct drm_crtc_commit - track modeset commits on a CRTC
@@ -335,6 +336,67 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,return plane->state; } + +/** +* drm_atomic_get_current_plane_state - get current plane state +* @plane: plane to grab +* +* This function returns the current plane state for the given plane, +* with extra locking checks to make sure that the plane state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current plane state. +*/ +static inline const struct drm_plane_state * +drm_atomic_get_current_plane_state (struct drm_plane *plane) +{ +drm_modeset_lock_assert_held (&plane->mutex); + +return plane->state; +} + +/** +* drm_atomic_get_current_crtc_state - get current crtc state +* @crtc: crtc to grab +* +* This function returns the current crtc state for the given crtc, +* with extra locking checks to make sure that the crtc state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current crtc state. +*/ +static inline const struct drm_crtc_state * +drm_atomic_get_current_crtc_state (struct drm_crtc *crtc) +{ +drm_modeset_lock_assert_held (&crtc->mutex); + +return crtc->state; +} + +/** +* drm_atomic_get_current_connector_state - get current connector state +* @connector: connector to grab +* +* This function returns the current connector state for the given connector, +* with extra locking checks to make sure that the connector state can be +* retrieved safely. +* +* Returns: +* +* Pointer to the current connector state. +*/ +static inline const struct drm_connector_state * +drm_atomic_get_current_connector_state (struct drm_connector *connector) +{ +drm_modeset_lock_assert_held (&connector->dev->mode_config.connection_mutex); + +return connector->state; +} +int __must_check drm_atomic_set_mode_for_crtc (struct drm_crtc_state *state,struct drm_display_mode *mode);
include/drm/drm_modeset_lock.h +9 -0
@@ -109,6 +109,15 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)return ww_mutex_is_locked (&lock->mutex); } +static inline void drm_modeset_lock_assert_held (struct drm_modeset_lock *lock) +{ +#ifdef CONFIG_LOCKDEP +lockdep_assert_held (&lock->mutex.base); +#else +WARN_ON (!drm_modeset_is_locked (lock)); +#endif +} +int drm_modeset_lock (struct drm_modeset_lock *lock,struct drm_modeset_acquire_ctx *ctx); int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerPATCH v2 3/4 drm/atomic: Add macros to access existing old/new state
In reply to Maarten LankhorstDuring atomic check/commit, these macros should be used in place of get_existing_state.
We also ban the use of get_xx_state after atomic check, because at that point no new locks should be taken and get_new/old_state should be used instead.
--- include/drm/drm_atomic.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+)
include/drm/drm_atomic.h +100 -0
@@ -264,6 +264,36 @@ drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state, }/** +* drm_atomic_get_old_crtc_state - get old crtc state, if it exists +* @state: global atomic state object +* @crtc: crtc to grab +* +* This function returns the old crtc state for the given crtc, or +* NULL if the crtc is not part of the global atomic state. +*/ +static inline struct drm_crtc_state * +drm_atomic_get_old_crtc_state (struct drm_atomic_state *state, +struct drm_crtc *crtc) +{ +return state->crtcs[drm_crtc_index (crtc)].old_state; +} + +/** +* drm_atomic_get_new_crtc_state - get new crtc state, if it exists +* @state: global atomic state object +* @crtc: crtc to grab +* +* This function returns the new crtc state for the given crtc, or +* NULL if the crtc is not part of the global atomic state. +*/ +static inline struct drm_crtc_state * +drm_atomic_get_new_crtc_state (struct drm_atomic_state *state, +struct drm_crtc *crtc) +{ +return state->crtcs[drm_crtc_index (crtc)].new_state; +} + +/** * drm_atomic_get_existing_plane_state - get plane state, if it exists * @state: global atomic state object * @plane: plane to grab
@@ -279,6 +309,36 @@ drm_atomic_get_existing_plane_state(struct drm_atomic_state *state, }/** +* drm_atomic_get_old_plane_state - get plane state, if it exists +* @state: global atomic state object +* @plane: plane to grab +* +* This function returns the old plane state for the given plane, or +* NULL if the plane is not part of the global atomic state. +*/ +static inline struct drm_plane_state * +drm_atomic_get_old_plane_state (struct drm_atomic_state *state, +struct drm_plane *plane) +{ +return state->planes[drm_plane_index (plane)].old_state; +} + +/** +* drm_atomic_get_new_plane_state - get plane state, if it exists +* @state: global atomic state object +* @plane: plane to grab +* +* This function returns the new plane state for the given plane, or +* NULL if the plane is not part of the global atomic state. +*/ +static inline struct drm_plane_state * +drm_atomic_get_new_plane_state (struct drm_atomic_state *state, +struct drm_plane *plane) +{ +return state->planes[drm_plane_index (plane)].new_state; +} + +/** * drm_atomic_get_existing_connector_state - get connector state, if it exists * @state: global atomic state object * @connector: connector to grab
@@ -299,6 +359,46 @@ drm_atomic_get_existing_connector_state(struct drm_atomic_state *state, }/** +* drm_atomic_get_old_connector_state - get connector state, if it exists +* @state: global atomic state object +* @connector: connector to grab +* +* This function returns the old connector state for the given connector, +* or NULL if the connector is not part of the global atomic state. +*/ +static inline struct drm_connector_state * +drm_atomic_get_old_connector_state (struct drm_atomic_state *state, +struct drm_connector *connector) +{ +int index =drm_connector_index (connector); + +if (index >= state->num_connector) +return NULL ; + +return state->connectors[index].old_state; +} + +/** +* drm_atomic_get_new_connector_state - get connector state, if it exists +* @state: global atomic state object +* @connector: connector to grab +* +* This function returns the new connector state for the given connector, +* or NULL if the connector is not part of the global atomic state. +*/ +static inline struct drm_connector_state * +drm_atomic_get_new_connector_state (struct drm_atomic_state *state, +struct drm_connector *connector) +{ +int index =drm_connector_index (connector); + +if (index >= state->num_connector) +return NULL ; + +return state->connectors[index].new_state; +} + +/** * __drm_atomic_get_current_plane_state - get current plane state * @state: global atomic state object * @plane: plane to grab
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 3/4] drm/atomic: Add macros to access existing old/new state
Quoted 8 lines · Maarten Lankhorst
During atomic check/commit, these macros should be used in place of
get_existing_state.We also ban the use of
get_xx_stateafter atomic check, because at that point no new locks should be taken and get_new/old_state should be used instead.Signed-off-by Maarten Lankhorst <[email protected]>
So one slightly annoying thing with the new/old split is that const-ness of these changes. In atomic_check the old state should be const, in atomic_commit the new state. By going to the new/old split we're losing that safeguard. Otoh we have lots and lots of exceptions to that rule ... not sure how much aiming for const correctness is worth it. -Daniel
Quoted 136 lines
--- include/drm/drm_atomic.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+)include/drm/drm_atomic.h +100
-0@@ -264,6 +264,36 @@ drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state, }/** +* drm_atomic_get_old_crtc_state - get old crtc state, if it exists +* @state: global atomic state object +* @crtc: crtc to grab +* +* This function returns the old crtc state for the given crtc, or +* NULL if the crtc is not part of the global atomic state. +*/ +static inline struct drm_crtc_state * +drm_atomic_get_old_crtc_state (struct drm_atomic_state *state, +struct drm_crtc *crtc) +{ +return state->crtcs[drm_crtc_index (crtc)].old_state; +} + +/** +* drm_atomic_get_new_crtc_state - get new crtc state, if it exists +* @state: global atomic state object +* @crtc: crtc to grab +* +* This function returns the new crtc state for the given crtc, or +* NULL if the crtc is not part of the global atomic state. +*/ +static inline struct drm_crtc_state * +drm_atomic_get_new_crtc_state (struct drm_atomic_state *state, +struct drm_crtc *crtc) +{ +return state->crtcs[drm_crtc_index (crtc)].new_state; +} + +/** * drm_atomic_get_existing_plane_state - get plane state, if it exists * @state: global atomic state object * @plane: plane to grab @@ -279,6 +309,36 @@ drm_atomic_get_existing_plane_state(struct drm_atomic_state *state, }/** +* drm_atomic_get_old_plane_state - get plane state, if it exists +* @state: global atomic state object +* @plane: plane to grab +* +* This function returns the old plane state for the given plane, or +* NULL if the plane is not part of the global atomic state. +*/ +static inline struct drm_plane_state * +drm_atomic_get_old_plane_state (struct drm_atomic_state *state, +struct drm_plane *plane) +{ +return state->planes[drm_plane_index (plane)].old_state; +} + +/** +* drm_atomic_get_new_plane_state - get plane state, if it exists +* @state: global atomic state object +* @plane: plane to grab +* +* This function returns the new plane state for the given plane, or +* NULL if the plane is not part of the global atomic state. +*/ +static inline struct drm_plane_state * +drm_atomic_get_new_plane_state (struct drm_atomic_state *state, +struct drm_plane *plane) +{ +return state->planes[drm_plane_index (plane)].new_state; +} + +/** * drm_atomic_get_existing_connector_state - get connector state, if it exists * @state: global atomic state object * @connector: connector to grab @@ -299,6 +359,46 @@ drm_atomic_get_existing_connector_state(struct drm_atomic_state *state, }/** +* drm_atomic_get_old_connector_state - get connector state, if it exists +* @state: global atomic state object +* @connector: connector to grab +* +* This function returns the old connector state for the given connector, +* or NULL if the connector is not part of the global atomic state. +*/ +static inline struct drm_connector_state * +drm_atomic_get_old_connector_state (struct drm_atomic_state *state, +struct drm_connector *connector) +{ +int index =drm_connector_index (connector); + +if (index >= state->num_connector) +return NULL ; + +return state->connectors[index].old_state; +} + +/** +* drm_atomic_get_new_connector_state - get connector state, if it exists +* @state: global atomic state object +* @connector: connector to grab +* +* This function returns the new connector state for the given connector, +* or NULL if the connector is not part of the global atomic state. +*/ +static inline struct drm_connector_state * +drm_atomic_get_new_connector_state (struct drm_atomic_state *state, +struct drm_connector *connector) +{ +int index =drm_connector_index (connector); + +if (index >= state->num_connector) +return NULL ; + +return state->connectors[index].new_state; +} + +/** * __drm_atomic_get_current_plane_state - get current plane state * @state: global atomic state object * @plane: plane to grab Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
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
Maarten Lankhorst
maintainerPATCH v2 4/4 drm/atomic: Add checks to ensure get_state is not called after swapping.
In reply to Maarten LankhorstThis isn't allowed, callers should use get_new_state or get_old_state, but lets be paranoid..
--- drivers/gpu/drm/drm_atomic.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic.c +15 -3
@@ -267,8 +267,12 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,WARN_ON (!state->acquire_ctx); crtc_state =drm_atomic_get_existing_crtc_state (state, crtc); -if (crtc_state) +if (crtc_state) { +WARN (state->crtcs[index].state == state->crtcs[index].old_state, +"drm_atomic_get_crtc_state() used after swapping state!\n" ); +return crtc_state; + } ret =drm_modeset_lock (&crtc->mutex, state->acquire_ctx);if (ret)
@@ -655,8 +659,12 @@ drm_atomic_get_plane_state(struct drm_atomic_state *state,WARN_ON (!state->acquire_ctx); plane_state =drm_atomic_get_existing_plane_state (state, plane); -if (plane_state) +if (plane_state) { +WARN (state->planes[index].state == state->planes[index].old_state, +"drm_atomic_get_plane_state() used after swapping state!\n" ); +return plane_state; + } ret =drm_modeset_lock (&plane->mutex, state->acquire_ctx);if (ret)
@@ -988,8 +996,12 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state, state->num_connector = alloc; } -if (state->connectors[index].state) +if (state->connectors[index].state) { +WARN (state->connectors[index].state == state->connectors[index].old_state, +"drm_atomic_get_connector_state() used after swapping state!\n" ); +return state->connectors[index].state; + } connector_state = connector->funcs->atomic_duplicate_state (connector);if (!connector_state)
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 13 lines · Maarten Lankhorst
Second approach. Instead of trying to convert all drivers straight away, implement all macros that are required to get state working.
Current situation:
Useobj->state, which can refer to old or new state.
Use drm_atomic_get_(existing_)obj_state, which can refer to new or old state. Usefor_each_obj_in_state, which refers to new or old state.New situation:
When doing some dereferencing outsideatomic_state, usedrm_atomic_get_current_obj_statewhich has locking checks, instead ofobj->state.
Quoted 7 lines
During atomic check:
- Usedrm_atomic_get_obj_stateto add a object to the atomic state, or get the new state.
- Use drm_atomic_get_(old/new)_obj_state to peek at the new/old state, without adding the object if it's not part of the state. For planes and connectors the relevantcrtc_stateis added, so this will work to get thecrtc_statefromfoo_state->crtctoo, saves some error handling. :)
Hm, this needs to check looking, somehow. Otherwise everyone just randomly peeks at state and all hell breaks loose once more. Or why do you want to avoid adding state for CRTCs?
Quoted 3 lines
During atomic commit:
- Do not usedrm_atomic_get_obj_state,obj->stateor drm_atomic_get_(existing_)obj_state any more, replace with drm_atomic_get_old/new_obj_state calls as required.
Wild idea, can we enforce this? E.g. with a drm_mode_config->in_atomic_check atomic counter that we inc/dec around the atomic_check call, and then a WARN_ON(!dev->mode_config.in_atomic_check); It will have some false positives when concurrent atomic commits happen, but for testing it should catch all offenders.
Of course this won't catch obj->state access, but we can fix that by renaming to obj->_state ...
Quoted 6 lines
During both:
- Use for_each_(new,old,oldnew)_obj_in_state to get the old or new state as needed. oldnew will be renamed tofor_each_obj_in_stateafter all callers are converted to the new api.This will give the correct state regardless of swapping.
Otherwise sounds like a reasonable plan I think.
-Daniel
Quoted 22 lines
Maarten Lankhorst (4):
drm/atomic: Add new iterators over all state, v2. drm/atomic: Add accessor macros for the current state. drm/atomic: Add macros to access existing old/new state drm/atomic: Add checks to ensureget_stateis not called after
swapping.drivers/gpu/drm/drm_atomic.c | 24 +++- drivers/gpu/drm/drm_atomic_helper.c | 47 ++++++- drivers/gpu/drm/i915/intel_display.c | 11 +- include/drm/drm_atomic.h | 247 ++++++++++++++++++++++++++++++++++- include/drm/drm_atomic_helper.h | 2 + include/drm/drm_modeset_lock.h | 21 +++ 6 files changed, 338 insertions(+), 14 deletions(-)Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
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
Maarten Lankhorst
maintainerOp 16-11-16 om 15:18 schreef Daniel Vetter:
Quoted 21 lines · Maarten Lankhorst
Quoted 13 lines
Second approach. Instead of trying to convert all drivers straight away, implement all macros that are required to get state working.
Current situation:
Useobj->state, which can refer to old or new state.
Use drm_atomic_get_(existing_)obj_state, which can refer to new or old state. Usefor_each_obj_in_state, which refers to new or old state.New situation:
When doing some dereferencing outsideatomic_state, usedrm_atomic_get_current_obj_statewhich has locking checks, instead ofobj->state.Quoted 7 lines
During atomic check:
- Usedrm_atomic_get_obj_stateto add a object to the atomic state, or get the new state.
- Use drm_atomic_get_(old/new)_obj_state to peek at the new/old state, without adding the object if it's not part of the state. For planes and connectors the relevantcrtc_stateis added, so this will work to get thecrtc_statefromfoo_state->crtctoo, saves some error handling. :)
Quoted 3 lines
Hm, this needs to check looking, somehow. Otherwise everyone just randomly peeks at state and all hell breaks loose once more. Or why do you want to avoid adding state for CRTCs?
We don't avoid adding state for crtc's, we always add them as required.
Some ->check_plane callbacks do things like:
if (plane_state->crtc) {crtc_state = get_crtc_state(plane_state->crtc);
ret = PTR_ERR_OR_ZERO(crtc_state);
if (ret)
return ret;
}
which can be simplified to
if (plane_state->crtc) crtc_state = get_crtc_state(plane_state->crtc); /* No need to null check */
Same for grabbing crtc_state from connector_state.
No changes in locking required. In fact when called from atomic_commit_tail all locks may have been dropped already.
Quoted 11 lines
Quoted 3 lines
During atomic commit:
- Do not usedrm_atomic_get_obj_state,obj->stateor drm_atomic_get_(existing_)obj_state any more, replace with drm_atomic_get_old/new_obj_state calls as required.Wild idea, can we enforce this? E.g. with a
drm_mode_config->in_atomic_checkatomic counter that we inc/dec around theatomic_checkcall, and then aWARN_ON(!dev->mode_config.in_atomic_check); It will have some false positives when concurrent atomic commits happen, but for testing it should catch all offenders.Of course this won't catch
obj->stateaccess, but we can fix that by renaming toobj->_state...
drm_atomic_get_existing is allowed for now, but should be converted. Patch 4 adds WARNS if used after swap_state, which is probably where most offenders are.
Relatedly.. can we revive the ww_acquire_done patch again? Needs a fix for i915 load detect though..
Quoted 7 lines
Quoted 6 lines
During both:
- Use for_each_(new,old,oldnew)_obj_in_state to get the old or new state as needed. oldnew will be renamed tofor_each_obj_in_stateafter all callers are converted to the new api.This will give the correct state regardless of swapping.
Otherwise sounds like a reasonable plan I think.
Ok good. :)
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 52 lines · Maarten Lankhorst
Op 16-11-16 om 15:18 schreef Daniel Vetter:
Quoted 21 lines · Maarten Lankhorst
Quoted 13 lines
Second approach. Instead of trying to convert all drivers straight away, implement all macros that are required to get state working.
Current situation:
Useobj->state, which can refer to old or new state.
Use drm_atomic_get_(existing_)obj_state, which can refer to new or old state. Usefor_each_obj_in_state, which refers to new or old state.New situation:
When doing some dereferencing outsideatomic_state, usedrm_atomic_get_current_obj_statewhich has locking checks, instead ofobj->state.Quoted 7 lines
During atomic check:
- Usedrm_atomic_get_obj_stateto add a object to the atomic state, or get the new state.
- Use drm_atomic_get_(old/new)_obj_state to peek at the new/old state, without adding the object if it's not part of the state. For planes and connectors the relevantcrtc_stateis added, so this will work to get thecrtc_statefromfoo_state->crtctoo, saves some error handling. :)Quoted 3 lines
Hm, this needs to check looking, somehow. Otherwise everyone just randomly peeks at state and all hell breaks loose once more. Or why do you want to avoid adding state for CRTCs?
We don't avoid adding state for crtc's, we always add them as required.
Some ->check_plane callbacks do things like:
if (
plane_state->crtc) {crtc_state=get_crtc_state(plane_state->crtc);
ret =PTR_ERR_OR_ZERO(crtc_state);
if (ret)
return ret;
}which can be simplified to
if (
plane_state->crtc)crtc_state=get_crtc_state(plane_state->crtc); /* No need to null check */Same for grabbing
crtc_statefromconnector_state.No changes in locking required. In fact when called from
atomic_commit_tailall locks may have been dropped already.Quoted 9 lines
Quoted 3 lines
During atomic commit:
- Do not usedrm_atomic_get_obj_state,obj->stateor drm_atomic_get_(existing_)obj_state any more, replace with drm_atomic_get_old/new_obj_state calls as required.Wild idea, can we enforce this? E.g. with a
drm_mode_config->in_atomic_checkatomic counter that we inc/dec around theatomic_checkcall, and then aWARN_ON(!dev->mode_config.in_atomic_check); It will have some false positives when concurrent atomic commits happen, but for testing it should catch all offenders.
Quoted 6 lines
Quoted 2 lines
Of course this won't catch
obj->stateaccess, but we can fix that by renaming toobj->_state...
drm_atomic_get_existingis allowed for now, but should be converted. Patch 4 adds WARNS if used afterswap_state, which is probably where most offenders are.Relatedly.. can we revive the
ww_acquire_donepatch again? Needs a fix for i915 load detect though..
Yeah, just bring it on.
-Daniel
Quoted 12 lines
Quoted 9 lines
Quoted 8 lines
During both:
- Use for_each_(new,old,oldnew)_obj_in_state to get the old or new state as needed. oldnew will be renamed tofor_each_obj_in_stateafter all callers are converted to the new api.This will give the correct state regardless of swapping.
Otherwise sounds like a reasonable plan I think.
Ok good. :)
~Maarten
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 25 lines · Maarten Lankhorst
Second approach. Instead of trying to convert all drivers straight away, implement all macros that are required to get state working.
Current situation:
Useobj->state, which can refer to old or new state.
Use drm_atomic_get_(existing_)obj_state, which can refer to new or old state. Usefor_each_obj_in_state, which refers to new or old state.New situation:
When doing some dereferencing outsideatomic_state, usedrm_atomic_get_current_obj_statewhich has locking checks, instead ofobj->state.During atomic check:
- Usedrm_atomic_get_obj_stateto add a object to the atomic state, or get the new state.
- Use drm_atomic_get_(old/new)_obj_state to peek at the new/old state, without adding the object if it's not part of the state. For planes and connectors the relevantcrtc_stateis added, so this will work to get thecrtc_statefromfoo_state->crtctoo, saves some error handling. :)During atomic commit:
- Do not usedrm_atomic_get_obj_state,obj->stateor drm_atomic_get_(existing_)obj_state any more, replace with drm_atomic_get_old/new_obj_state calls as required.
Quoted 6 lines
During both:
- Use for_each_(new,old,oldnew)_obj_in_state to get the old or new state as needed. oldnew will be renamed tofor_each_obj_in_stateafter all callers are converted to the new api.This will give the correct state regardless of swapping.
So this is all nice, but fundamentally it's pile of new code with 0 users. Where are those patches? I think at least converting all the core+helpers to use it consistently would be needed to justify this. -Daniel
Quoted 23 lines
Maarten Lankhorst (4):
drm/atomic: Add new iterators over all state, v2. drm/atomic: Add accessor macros for the current state. drm/atomic: Add macros to access existing old/new state drm/atomic: Add checks to ensureget_stateis not called after
swapping.drivers/gpu/drm/drm_atomic.c | 24 +++- drivers/gpu/drm/drm_atomic_helper.c | 47 ++++++- drivers/gpu/drm/i915/intel_display.c | 11 +- include/drm/drm_atomic.h | 247 ++++++++++++++++++++++++++++++++++- include/drm/drm_atomic_helper.h | 2 + include/drm/drm_modeset_lock.h | 21 +++ 6 files changed, 338 insertions(+), 14 deletions(-)Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
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
Maarten Lankhorst
maintainerOp 14-12-16 om 14:17 schreef Daniel Vetter:
Quoted 31 lines · Maarten Lankhorst
Quoted 30 lines
Second approach. Instead of trying to convert all drivers straight away, implement all macros that are required to get state working.
Current situation:
Useobj->state, which can refer to old or new state.
Use drm_atomic_get_(existing_)obj_state, which can refer to new or old state. Usefor_each_obj_in_state, which refers to new or old state.New situation:
When doing some dereferencing outsideatomic_state, usedrm_atomic_get_current_obj_statewhich has locking checks, instead ofobj->state.During atomic check:
- Usedrm_atomic_get_obj_stateto add a object to the atomic state, or get the new state.
- Use drm_atomic_get_(old/new)_obj_state to peek at the new/old state, without adding the object if it's not part of the state. For planes and connectors the relevantcrtc_stateis added, so this will work to get thecrtc_statefromfoo_state->crtctoo, saves some error handling. :)During atomic commit:
- Do not usedrm_atomic_get_obj_state,obj->stateor drm_atomic_get_(existing_)obj_state any more, replace with drm_atomic_get_old/new_obj_state calls as required.During both:
- Use for_each_(new,old,oldnew)_obj_in_state to get the old or new state as needed. oldnew will be renamed tofor_each_obj_in_stateafter all callers are converted to the new api.
Quoted 4 lines
Quoted 1 line
This will give the correct state regardless of swapping.
So this is all nice, but fundamentally it's pile of new code with 0 users. Where are those patches? I think at least converting all the core+helpers to use it consistently would be needed to justify this.
I deliberately didn't send those patches this time because the drivers and atomic core change all the time. I would have had to respin this whole series at least 4 times. :) I have the patches for conversion in my tree based on -tip.
https://cgit.freedesktop.org/~mlankhorst/linux/log/?h=nightly
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel