All of lore.kernel.org
 help / color / mirror / Atom feed
From: mturquette@linaro.org (Mike Turquette)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/5] clk: allow reentrant calls into the clk framework
Date: Mon, 18 Mar 2013 14:35:06 -0700	[thread overview]
Message-ID: <20130318213506.8663.82637@quantum> (raw)
In-Reply-To: <20130318210011.GL4977@n2100.arm.linux.org.uk>

Quoting Russell King - ARM Linux (2013-03-18 14:00:11)
> On Mon, Mar 18, 2013 at 01:15:51PM -0700, Mike Turquette wrote:
> > Quoting Ulf Hansson (2013-02-28 01:54:34)
> > > On 28 February 2013 05:49, Mike Turquette <mturquette@linaro.org> wrote:
> > > > @@ -703,10 +744,29 @@ int clk_enable(struct clk *clk)
> > > >         unsigned long flags;
> > > >         int ret;
> > > >
> > > > +       /* this call re-enters if it is from the same context */
> > > > +       if (spin_is_locked(&enable_lock) || mutex_is_locked(&prepare_lock)) {
> > > > +               if ((void *) atomic_read(&context) == get_current()) {
> > > > +                       ret = __clk_enable(clk);
> > > > +                       goto out;
> > > > +               }
> > > > +       }
> > > 
> > > I beleive the clk_enable|disable code will be racy. What do you think
> > > about this scenario:
> > > 
> > > 1. Thread 1, calls clk_prepare -> clk is not reentrant -> mutex_lock
> > > -> set_context to thread1.
> > > 2. Thread 2, calls clk_enable -> above "if" will mean that get_current
> > > returns thread 1 context and then clk_enable continues ->
> > > spin_lock_irqsave -> set_context to thread 2.
> > > 3. Thread 1 continues and triggers a reentancy for clk_prepare -> clk
> > > is not reentrant (since thread 2 has set a new context) -> mutex_lock
> > > and we will hang forever.
> > > 
> > > Do you think above scenario could happen?
> > > 
> > > I think the solution would be to invent another "static atomic_t
> > > context;" which is used only for fast path functions
> > > (clk_enable|disable). That should do the trick I think.
> > 
> > Ulf,
> > 
> > You are correct.  In fact I have a branch that has two separate context
> > pointers, one for mutex-protected functions and one for
> > spinlock-protected functions.  Somehow I managed to discard that change
> > before settling on the final version that was published.
> 
> Err.
> 
> Do not forget one very important point.
> 
> Any clock which has clk_enable() called on it must have had clk_prepare()
> already called _and_ completed.  A second clk_prepare() call on the same
> clock should be a no-op other than to increase the prepare reference count
> on it.
> 
> If you do anything else, you are going to get into sticky problems.

Correct usage of the api is of course still necessary.  The reentrancy
patch doesn't change api usage by drivers and does not violate the
sequencing of clk_prepare/clk_enable and clk_disable/clk_unprepare.  In
Ulf's example thread 2 should have already called clk_prepare before
calling clk_enable.

Ulf has correctly pointed out a bug in the locking/context logic due to
having two distinct lock's for fast/slow operations.  It will be fixed
in the next verison.

Thanks,
Mike

  reply	other threads:[~2013-03-18 21:35 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-28  4:49 [PATCH v3 0/5] common clk framework reentrancy & dvfs, take 3 Mike Turquette
2013-02-28  4:49 ` Mike Turquette
2013-02-28  4:49 ` [PATCH 1/5] clk: allow reentrant calls into the clk framework Mike Turquette
2013-02-28  4:49   ` Mike Turquette
2013-02-28  9:54   ` Ulf Hansson
2013-02-28  9:54     ` Ulf Hansson
2013-03-18 20:15     ` Mike Turquette
2013-03-18 21:00       ` Russell King - ARM Linux
2013-03-18 21:00         ` Russell King - ARM Linux
2013-03-18 21:35         ` Mike Turquette [this message]
2013-03-27  3:33   ` Bill Huang
2013-03-27  3:33     ` Bill Huang
2013-03-27  8:38     ` Mike Turquette
2013-02-28  4:49 ` [PATCH 2/5] clk: notifier handler for dynamic voltage scaling Mike Turquette
2013-02-28  4:49   ` Mike Turquette
2013-03-01  9:41   ` Bill Huang
2013-03-01  9:41     ` Bill Huang
2013-03-01 18:22     ` Mike Turquette
2013-03-01 20:48       ` Mike Turquette
2013-03-02  2:55         ` Bill Huang
2013-03-02  2:55           ` Bill Huang
2013-03-02  8:22           ` Richard Zhao
2013-03-02  8:22             ` Richard Zhao
2013-03-03 10:54             ` Mike Turquette
2013-03-03 10:54               ` Mike Turquette
2013-03-03 13:27               ` Richard Zhao
2013-03-03 13:27                 ` Richard Zhao
2013-03-04  7:25                 ` Mike Turquette
2013-03-13 13:59                   ` Ulf Hansson
2013-03-13 13:59                     ` Ulf Hansson
2013-03-01 20:49     ` Stephen Warren
2013-03-01 20:49       ` Stephen Warren
2013-03-02  2:58       ` Bill Huang
2013-03-02  2:58         ` Bill Huang
2013-03-10 10:21   ` Francesco Lavra
2013-03-10 10:21     ` Francesco Lavra
2013-04-02 17:49   ` Taras Kondratiuk
2013-04-02 17:49     ` Taras Kondratiuk
2013-02-28  4:49 ` [PATCH 3/5] cpufreq: omap: scale regulator from clk notifier Mike Turquette
2013-02-28  4:49   ` Mike Turquette
2013-02-28  4:49 ` [PATCH 4/5] HACK: set_parent callback for OMAP4 non-core DPLLs Mike Turquette
2013-02-28  4:49   ` Mike Turquette
2013-02-28  4:49 ` [PATCH 5/5] HACK: omap: opp: add fake 400MHz OPP to bypass MPU Mike Turquette
2013-02-28  4:49   ` Mike Turquette

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=20130318213506.8663.82637@quantum \
    --to=mturquette@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.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 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.