public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Mark Brown <broonie@kernel.org>,
	Davide Ciminaghi <ciminaghi@gnudd.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] regmap: Make regmap-mmio usable from different contexts
Date: Thu, 23 May 2013 10:06:34 -0600	[thread overview]
Message-ID: <519E3E8A.2010704@wwwdotorg.org> (raw)
In-Reply-To: <519E3AB7.8020103@metafoo.de>

On 05/23/2013 09:50 AM, Lars-Peter Clausen wrote:
> On 05/23/2013 05:42 PM, Stephen Warren wrote:
>> On 05/23/2013 07:06 AM, Lars-Peter Clausen wrote:
>>> regmap-mmio uses a spinlock with spin_lock() and spin_unlock() for locking.
>>> Which means in order to avoid race conditions the lock always needs to be taken
>>> from the same context.
>>
>> I'm not really sure what this means. I assume contexts are
>> atomic-vs-nonatomic?
> 
> Yes.
> 
>> If so, spinlocks should work fine for this, right?
> 
> No, you have to take special care if you want to take the same spinlock from
> different contexts. And you have to take even more care if the code that
> takes the lock can run in different contexts.

OK, but what is that "special care" that must be taken? I assume from
this patch, you mean using spin_lock_irqsave() rather than spin_lock().
So the issue isn't so much that spin locks are used, but rather how
they're used. The code still has a spin_lock_t before and after...

>> I guess the core of the issue is that you want to replace spin_lock()
>> with spin_lock_irqsave(). I'd like to see that explicitly described in
>> the commit description, if that is the core aspect of this change.
> 
> Hm, it does.
> 
> 	regmap-mmio uses a spinlock with spin_lock() and spin_unlock() for
> 	locking.
> 	...
> 	This patch updates the adds a flags parameter to the regmap lock
> 	and unlock callbacks and uses spin_lock_irqsave() and
> 	spin_unlock_restore() ...

To me, that doesn't make me realize that the core part of this change is
to switch between the two different APIs that operate on the spin lock.
I'd expect the commit description to say something more like:

regmap-mmio uses a spinlock for locking. In order for this to work
correctly from different contexts (atomic vs non-atomic), this spinlock
must be locked using spin_lock_irqsave() rather than spin_lock(). To
support this, a spinlock_flags field is added to struct regmap to store
the flags between regmap_{,un}lock_spinlock().

  reply	other threads:[~2013-05-23 16:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-23 13:06 [PATCH 1/2] regmap: regcache: Fixup locking for custom lock callbacks Lars-Peter Clausen
2013-05-23 13:06 ` [PATCH 2/2] regmap: Make regmap-mmio usable from different contexts Lars-Peter Clausen
2013-05-23 14:05   ` Mark Brown
2013-05-23 14:20     ` Lars-Peter Clausen
2013-05-23 14:31       ` Mark Brown
2013-05-23 14:36         ` Lars-Peter Clausen
2013-05-23 15:14           ` Mark Brown
2013-05-23 15:42   ` Stephen Warren
2013-05-23 15:50     ` Lars-Peter Clausen
2013-05-23 16:06       ` Stephen Warren [this message]
2013-05-23 16:10       ` Mark Brown
2013-05-23 16:01     ` Mark Brown
2013-05-23 14:08 ` [PATCH 1/2] regmap: regcache: Fixup locking for custom lock callbacks Mark Brown

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=519E3E8A.2010704@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=broonie@kernel.org \
    --cc=ciminaghi@gnudd.com \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.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