linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Collins <collinsd@codeaurora.org>
To: Liam Girdwood <lrg@slimlogic.co.uk>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Deadlock scenario in regulator core
Date: Tue, 22 Mar 2011 15:02:01 -0700	[thread overview]
Message-ID: <4D891C59.1030009@codeaurora.org> (raw)

Hi Liam and Mark,

I was analyzing the mutex lock usage in drivers/regulator/core.c and found
at least one way to reach deadlock: regulator_enable is called for a
regulator at the same time that regulator_disable is called for that
regulator's supply.  Consider this simple example.  There are two
regulators: S1 and L2, as well as two consumers: A and B.  They are
connected as follows:

S1 --> L2 --> B
|
|--> A

Assume that A has already called regulator_enable for S1 some time in the
past.

Consumer A thread execution:
	regulator_disable(S1)
	mutex_lock(S1)
	_regulator_disable(S1)
	_notifier_call_chain(S1)
	mutex_lock(L2)

Consumer B thread execution:
	regulator_enable(L2)
	mutex_lock(L2)
	_regulator_enable(L2)
	mutex_lock(S1)

The locks for S1 and L2 are taken in opposite orders in the two threads;
therefore, it is possible to achieve deadlock.  I am not sure about the
best way to resolve this situation.  Is there a correctness requirement
that regulator_enable holds the child regulator's lock when it attempts to
enable the parent regulator?  Likewise, is the lock around
_notifier_call_chain required?

Thanks,
David Collins

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

             reply	other threads:[~2011-03-22 22:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22 22:02 David Collins [this message]
2011-03-22 22:31 ` Deadlock scenario in regulator core Mark Brown
2011-03-22 23:30   ` David Collins
2011-03-22 23:45     ` Mark Brown
2011-03-22 22:37 ` Steven Rostedt
2011-03-22 23:08   ` David Collins
2011-03-22 23:19     ` Steven Rostedt
2011-03-22 23:41       ` David Collins
2011-03-23  0:07         ` Steven Rostedt
2011-03-23  0:11           ` Mark Brown
2011-03-25 10:55           ` Peter Zijlstra
2011-03-23  0:01       ` Mark Brown
2011-03-23  0:38         ` Steven Rostedt
2011-03-23 10:42           ` Mark Brown
2011-03-25 10:59             ` Peter Zijlstra
2011-03-22 22:43 ` 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=4D891C59.1030009@codeaurora.org \
    --to=collinsd@codeaurora.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@slimlogic.co.uk \
    /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;
as well as URLs for NNTP newsgroup(s).