All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Steven Price <steven.price@arm.com>
Cc: "Chia-I Wu" <olvaffe@gmail.com>,
	"Liviu Dudau" <liviu.dudau@arm.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] drm/panthor: Driver-wide xxx_[un]lock -> [scoped_]guard replacement
Date: Wed, 20 May 2026 17:43:24 +0200	[thread overview]
Message-ID: <20260520174324.1dfafa0c@fedora> (raw)
In-Reply-To: <6923c228-b81e-4d02-b59c-a21b2212318e@arm.com>

On Wed, 20 May 2026 16:26:42 +0100
Steven Price <steven.price@arm.com> wrote:

> On 18/05/2026 09:43, Boris Brezillon wrote:
> > On Thu, 14 May 2026 10:09:10 -0700
> > Chia-I Wu <olvaffe@gmail.com> wrote:
> >   
> >> On Thu, May 14, 2026 at 6:24 AM Steven Price <steven.price@arm.com> wrote:  
> >>>
> >>> On 13/05/2026 17:58, Boris Brezillon wrote:    
> >>>> Right now panthor is mixed bag of manual locks and guards. Let's
> >>>> make that more consitent and thus encourage new submissions to go
> >>>> for guards.    
> >>>
> >>> I'm fine with encouraging guards for future code - but I'm a little wary
> >>> of a big change like this - it's hard to review it and check that
> >>> everything works the same. And it's a little dubious that the mechanical
> >>> refactoring produces more readable code in some cases.    
> >> I agree with Steven in general, although I am in favor of landing now
> >> that you've gone through the trouble.  
> > 
> > Honestly, I agree with you. The only reason I went for it is
> > because the mix we have right now is pretty confusing. This has to do
> > with the fact the scopes are often loosely defined unless you used
> > scoped_guard(), so it's pretty easy to mess up the lock/unlock
> > ordering. For instance,
> > 
> > 	mutex_lock(locka);
> > 	guard(lockb);
> > 	mutex_unlock(locka);
> > 
> > 	...
> > 
> > once expanded, turns into inconsistent locked sections, where the inner
> > lock (lockb) is released after the outer one (locka).  
> 
> I think that's a good argument for getting all the guard forms available
> before tackling the conversion.

Yep, makes sense. The reason I didn't go for that in v1 is because I
wasn't sure how well the new guard definition would be received. Now
that we know there's a general consensus to define those, I'll re-order
the patches accordingly.

> Mostly I feel like it would be benefit
> from being split up into multiple patches (maybe one per file?) so that
> there are smaller units to review.

Sure, I can do that.

> 
> >>
> >> I also have mixed feelings about some of the non-scoped guards. Their
> >> scopes are extended slightly than before, supposedly to avoid adding
> >> another level of indentation. But other than slightly slower,  
> > 
> > I tried to used scoped_guard()s every where the extra non-guarded
> > section could be CPU heavy (the only bits left are some very simple
> > bit/arithmetic ops, and a couple queue_work() IIRC).
> >   
> >> it also
> >> becomes less clear what exactly do the guards protect.  
> > 
> > I know, and I have pretty much the same feeling, but we've crossed that
> > bridge when we started accepting non-scoped guard()s, unfortunately.  
> 
> The problem with scoped guards is the extra level of indentation.

Yep.

> Personally I find a mixture of all three is appropriate depending on the
> case.
> 
> E.g.
> 
> int small_simple_function() {
> 	if (simple_condition)
> 		return early;
> 
> 	guard(lock);
> 
> 	if (condition_that_needs_lock)
> 		return early;
> 	/* more work */
> 	return late;
> }
> 
> Here it's easy to reason because the lock is just held for the duration
> of the function after the initial early-out condition is checked.
> 
> int short_lock() {
> 	/* bunch of work */
> 
> 	scoped_guard(lock) {
> 		tmp = read_value();
> 		if (tmp == 42)
> 			return -ESOLONGANDTHANKSFORALLTHEFISH;
> 		tmp++;
> 		write_value(tmp);
> 	}
> 
> 	/* more work */
> }
> 
> Here there's a small section of code which is working on the lock, so it
> makes sense to indent it to show the boundaries of it. The other nice
> thing is that the error return handles the locks for us.
> 
> int old_fashioned() {
> 	if (lock_required)
> 		mutex_lock(lock);
> 
> 	/* some work */
> 
> 	if (lock_required)
> 		mutex_unlock(lock);
> }
> 
> Generally a pattern to be avoided if possible,

Yeah, honestly I try my best to never end up with that sort of
conditional locks.

> but IMHO this is much
> better than the equivalent of:
> 
> int dodgy_function() {
> 	/* some work */
> }
> 
> int outer_function() {
> 	if (lock_required) {
> 		scoped_guard(lock)
> 			dodgy_function();
> 	} else {
> 		dodgy_function();
> 	}
> }

If I were to choose, I'd probably go for this version, but luckily we
don't seem to have this conditional-locking pattern in panthor.

  reply	other threads:[~2026-05-20 15:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 16:58 [PATCH 0/6] drm/panthor: Use guards Boris Brezillon
2026-05-13 16:58 ` [PATCH 1/6] drm/panthor: Driver-wide xxx_[un]lock -> [scoped_]guard replacement Boris Brezillon
2026-05-14 13:16   ` Steven Price
2026-05-14 17:09     ` Chia-I Wu
2026-05-18  8:43       ` Boris Brezillon
2026-05-20 15:26         ` Steven Price
2026-05-20 15:43           ` Boris Brezillon [this message]
2026-05-18  8:57     ` Boris Brezillon
2026-05-18 23:50       ` [Linaro-mm-sig] " Chia-I Wu
2026-05-13 16:58 ` [PATCH 2/6] dma-resv: Define guards for context-less dma_resv locks Boris Brezillon
2026-05-14 18:23   ` Chia-I Wu
2026-05-18  7:10   ` Christian König
2026-05-18  9:14     ` Boris Brezillon
2026-05-18 12:18       ` Christian König
2026-05-18 14:15         ` Boris Brezillon
2026-05-21  8:36           ` Christian König
2026-05-21  8:54             ` Boris Brezillon
2026-05-21  9:01               ` Boris Brezillon
2026-05-21 12:19                 ` Christian König
2026-05-21 12:14               ` Christian König
2026-05-20 15:26   ` Steven Price
2026-05-13 16:58 ` [PATCH 3/6] drm: Define a conditional guard for drm_dev_{enter,exit}() Boris Brezillon
2026-05-14 18:34   ` Chia-I Wu
2026-05-14 18:34     ` [PATCH 3/6] drm: Define a conditional guard for drm_dev_{enter, exit}() Chia-I Wu
2026-05-18  8:28     ` [PATCH 3/6] drm: Define a conditional guard for drm_dev_{enter,exit}() Boris Brezillon
2026-05-18  9:16       ` Christian König
2026-05-18  9:35         ` Boris Brezillon
2026-05-13 16:58 ` [PATCH 4/6] drm/panthor: Use guards for resv locking Boris Brezillon
2026-05-14 18:35   ` Chia-I Wu
2026-05-13 16:58 ` [PATCH 5/6] drm/panthor: Use the drm_dev_access guard Boris Brezillon
2026-05-14 18:36   ` Chia-I Wu
2026-05-13 16:58 ` [PATCH 6/6] drm/panthor: Add a new guard for our custom resume_and_get() PM helper Boris Brezillon
2026-05-14 18:39   ` Chia-I Wu

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=20260520174324.1dfafa0c@fedora \
    --to=boris.brezillon@collabora.com \
    --cc=airlied@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=olvaffe@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=sumit.semwal@linaro.org \
    --cc=tzimmermann@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.