linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: <broonie@kernel.org>, <digetx@gmail.com>, <l.stach@pengutronix.de>
Cc: <lgirdwood@gmail.com>, <linux-kernel@vger.kernel.org>
Subject: Regulator Potential Deadlock
Date: Wed, 3 Apr 2019 14:55:31 +0100	[thread overview]
Message-ID: <20190403135531.GB81578@ediswmail.ad.cirrus.com> (raw)

Hi Guys,

Was testing some of my hardware and hit this potential lockup:

Possible unsafe locking scenario:

CPU0                    CPU1
----                    ----
lock((work_completion)(&(&rdev->disable_work)->work));
                        lock(regulator_list_mutex);
                        lock((work_completion)(&(&rdev->disable_work)->work));
lock(regulator_list_mutex);

***
DEADLOCK
***

Looks like it comes from this patch:

commit f8702f9e4aa7 ("regulator: core: Use ww_mutex for regulators locking")

The basic problem appears to be that regulator_unregister takes
the regulator_list_mutex and then calls flush_work on
disable_work. But regulator_disable_work calls
regulator_lock_dependent which will also take the
regulator_list_mutex. Resulting in a deadlock if the flush_work
call actually needs to flush the work.

The locking appears to have got quite complex since last time I
looked at it and I am having a little difficulty working out
exactly is protecting what.

I am wondering if the flush_work can just be moved outside the
regulator_list_mutex in regulator_unregister since that mutex
doesn't seem to protect the against the work being queued anyway?
I will keep looking into this over the next couple of days,
any pointers or ideas anyone has would be greatly appreciated.
Finally, as it looks like it might take a couple of days to
figure out the locking, I am leaving on holiday on Saturday
so if you don't see a fix from my by then it might be a couple
of weeks before I can look at it again.

Thanks,
Charles

                 reply	other threads:[~2019-04-03 13:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190403135531.GB81578@ediswmail.ad.cirrus.com \
    --to=ckeepax@opensource.cirrus.com \
    --cc=broonie@kernel.org \
    --cc=digetx@gmail.com \
    --cc=l.stach@pengutronix.de \
    --cc=lgirdwood@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).