public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH 09/11] drm: Amend connector/encoder list locking rules
Date: Wed, 24 Jun 2015 10:36:59 +0200	[thread overview]
Message-ID: <20150624083659.GW25769@phenom.ffwll.local> (raw)
In-Reply-To: <20150624075723.GV12403@nuc-i3427.alporthouse.com>

On Wed, Jun 24, 2015 at 08:57:23AM +0100, Chris Wilson wrote:
> On Tue, Jun 23, 2015 at 10:46:00PM +0200, Daniel Vetter wrote:
> > Now that dp mst hotplug takes all locks we can amend the locking rules
> > for the iterators. This is needed before we can roll these out in the
> > atomic code to avoid getting burried in WARNINGs.
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > ---
> >  include/drm/drm_crtc.h | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> > index 3646c47b43de..c1c4f16f01ca 100644
> > --- a/include/drm/drm_crtc.h
> > +++ b/include/drm/drm_crtc.h
> > @@ -1588,14 +1588,16 @@ static inline struct drm_property *drm_property_find(struct drm_device *dev,
> >  	list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
> >  
> >  #define drm_for_each_connector(connector, dev) \
> > -	for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.mutex)),		\
> > +	for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.mutex) &&		\
> > +		     !drm_modeset_is_locked(&(dev)->mode_config.connection_mutex)), \
> >  	     connector = list_first_entry(&(dev)->mode_config.connector_list,	\
> >  					  struct drm_connector, head);		\
> >  	     &connector->head != (&(dev)->mode_config.connector_list);		\
> >  	     connector = list_next_entry(connector, head))
> >  
> >  #define drm_for_each_encoder(encoder, dev) \
> > -	for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.mutex)),		\
> > +	for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.mutex) &&		\
> > +		     !drm_modeset_is_locked(&(dev)->mode_config.connection_mutex)), \
> >  	     encoder = list_first_entry(&(dev)->mode_config.encoder_list,	\
> >  					  struct drm_encoder, head);		\
> >  	     &encoder->head != (&(dev)->mode_config.encoder_list);		\
> 
> Maybe something like:
> 
> 	// not sure how specifc each lock will end up being
> 	static inline void assert_drm_mode_list_locked(dev)
> 	{
> 		/* lockdep for accuracy and verbose debug reportts,
> 		 * WARN_ON for warnings everywhere.
> 		 */
> 		lockdep_assert_held(&dev->mode_config.mutex);
> 		WARN_ON(!(mutex_is_locked(&dev->mode_config.mutex) &&
> 			  drm_modeset_is_locked(&dev->mode_config.connection_mutex)));
> 
> 		// Daniel, it is not clear from context whether you mean
> 		// !a && !b, or !(a && b)

Write access holds both locks, which means for read access it's ok to just
hold one. But since that's caused confusions I fully agree that extracting
this into a static inline and commenting properly is a good idea.
-Daniel

> 	}
> 
> 	static inline struct drm_connector *drm_first_connector(dev)
> 	{
> 		assert_drm_mode_list_locked(dev);
> 		return list_first_entry(&dev->mode_config.connector_list,
> 					struct drm_connector, head);
> 	}
> 
> 	#define drm_for_each_connector(connector, dev) \
> 		for (connector = drm_first_connector(dev); \
> 		     &connector->head != (&(dev)->mode_config.connector_list);		\
> 		     connector = list_next_entry(connector, head))
> 
> 	static inline struct drm_encoder *drm_first_encoder(dev)
> 	{
> 		assert_drm_mode_list_locked(dev);
> 		return list_first_entry(&dev->mode_config.encoder_list,
> 					struct drm_encoder, head);
> 	}
> 
> 	#define drm_for_each_encoder(encoder, dev) \
> 		for (encoder = drm_first_encoder(dev); \
> 		     &encoder->head != (&(dev)->mode_config.encoder_list);		\
> 		     encoder = list_next_entry(encoder, head))
> 
> Usual arguments of reusing code for clarity.
> -Chris
> 
> -- 
> Chris Wilson, Intel Open Source Technology Centre
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-06-24  8:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-23 20:45 [PATCH 00/11] [RFC] drm_for_each_* macros and list locking Daniel Vetter
2015-06-23 20:45 ` [PATCH 01/11] drm: Simplify drm_for_each_legacy_plane arguments Daniel Vetter
2015-06-23 20:45 ` [PATCH 02/11] drm: Add modeset object iterators Daniel Vetter
2015-06-23 20:45 ` [PATCH 03/11] drm/probe-helper: Grab mode_config.mutex in poll_init/enable Daniel Vetter
2015-06-23 20:45 ` [PATCH 04/11] drm/fbdev-helper: Grab mode_config.mutex in drm_fb_helper_single_add_all_connectors Daniel Vetter
2015-06-23 20:45 ` [PATCH 05/11] drm: Check locking in drm_for_each_encoder/connector Daniel Vetter
2015-06-23 20:45 ` [PATCH 06/11] drm/i915: Use drm_for_each_fb in i915_debugfs.c Daniel Vetter
2015-06-23 20:45 ` [PATCH 07/11] drm: Check locking in drm_for_each_fb Daniel Vetter
2015-06-23 20:45 ` [PATCH 08/11] drm/i915: Take all modeset locks for DP MST hotplug Daniel Vetter
2015-06-23 20:46 ` [PATCH 09/11] drm: Amend connector/encoder list locking rules Daniel Vetter
2015-06-24  7:57   ` Chris Wilson
2015-06-24  8:36     ` Daniel Vetter [this message]
2015-06-23 20:46 ` [PATCH 10/11] drm: Roll out drm_for_each_connector more Daniel Vetter
2015-06-23 20:46 ` [PATCH 11/11] drm: Roll out drm_for_each_{plane, crtc, encoder} Daniel Vetter
2015-06-29  3:41   ` shuang.he
2015-06-24  7:44 ` [PATCH 00/11] [RFC] drm_for_each_* macros and list locking Chris Wilson
2015-06-24  8:35   ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150624083659.GW25769@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox