LKML Archive on
help / color / mirror / Atom feed
From: Joel Stanley <>
To: Lei YU <>
Cc: Eddie James <>,
	Linux Kernel Mailing List <>,,
	Michael Turquette <>,, Ryan Chen <>,
	Jeremy Kerr <>
Subject: Re: [PATCH v2 2/2] clk: aspeed: Prevent reset if clock is enabled
Date: Fri, 9 Mar 2018 15:32:48 +1030	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Hi Lei,

On Fri, Mar 9, 2018 at 1:49 PM, Lei YU <> wrote:
>>  static int aspeed_clk_enable(struct clk_hw *hw)
>>  {
>>         struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
>> @@ -215,6 +227,11 @@ static int aspeed_clk_enable(struct clk_hw *hw)
>>         spin_lock_irqsave(gate->lock, flags);
>> +       if (aspeed_clk_is_enabled(hw)) {
>> +               spin_unlock_irqrestore(gate->lock, flags);
>> +               return 0;
>> +       }
>> +
> I think this piece of code can be run before spin_lock_irqsave(), so it is
> able to just return without spin_unlock_irqrestore()?

As far as I understand, we are not running under any kind of lock when
calling into the clock framework.

Consider two clock consumer (any old driver) attempting an operation
to change the state of a clock. The first consumer calls
aspeed_clk_enable, and run the aspeed_clk_is_enabled function. This
consumer is then preempted, and the second consume calls
aspeed_clk_disable, taking the lock, they then disable the clock. They
return out of aspeed_clk_disable and the first consumer can run again.

The first consumer has already checked that the clock was disabled, so
they execute the 'return 0', without enabling it. However, their
information is out of date, so they are now in a state where the clock
hardware is disabled, but the clock framework and the consumer think
it is enabled.

By doing the check under a lock, the second consumer won't be able to
perform it's operation until after the first has finished (and as we
disable IRQs, the first bit of code will run to completion without
being preempted).

I might have missed something, so if you're confident we don't need to
check the value under a lock then please let me know :)



  parent reply	other threads:[~2018-03-09  5:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-08 20:57 [PATCH v2 0/2] clk: aspeed: Fix is_enabled and prevent reset if clock enabled Eddie James
2018-03-08 20:57 ` [PATCH v2 1/2] clk: aspeed: Fix is_enabled for certain clocks Eddie James
2018-03-13  5:40   ` Joel Stanley
2018-03-15 18:14   ` Stephen Boyd
2018-03-08 20:57 ` [PATCH v2 2/2] clk: aspeed: Prevent reset if clock is enabled Eddie James
2018-03-09  3:23   ` Lei YU
     [not found]   ` <>
2018-03-09  5:02     ` Joel Stanley [this message]
2018-03-13  5:42   ` Joel Stanley
2018-03-15 18:14   ` Stephen Boyd
2018-03-10  0:41 ` [PATCH v2 0/2] clk: aspeed: Fix is_enabled and prevent reset if clock enabled Stephen Boyd
2018-03-14 19:11   ` Eddie James

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \ \ \ \ \ \ \ \

* 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).