[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4FB2B3AA.3010903@codeaurora.org>
Date: Tue, 15 May 2012 12:51:06 -0700
From: Saravana Kannan <skannan@...eaurora.org>
To: Sascha Hauer <s.hauer@...gutronix.de>
CC: Mike Turquette <mturquette@...aro.org>,
Arnd Bergman <arnd.bergmann@...aro.org>,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
linux-arm-msm@...r.kernel.org, Andrew Lunn <andrew@...n.ch>,
Rob Herring <rob.herring@...xeda.com>,
Russell King <linux@....linux.org.uk>,
Jeremy Kerr <jeremy.kerr@...onical.com>,
Thomas Gleixner <tglx@...utronix.de>,
Paul Walmsley <paul@...an.com>,
Shawn Guo <shawn.guo@...escale.com>,
Jamie Iles <jamie@...ieiles.com>,
Richard Zhao <richard.zhao@...aro.org>,
Magnus Damm <magnus.damm@...il.com>,
Mark Brown <broonie@...nsource.wolfsonmicro.com>,
Linus Walleij <linus.walleij@...ricsson.com>,
Stephen Boyd <sboyd@...eaurora.org>,
Amit Kucheria <amit.kucheria@...aro.org>,
Deepak Saxena <dsaxena@...aro.org>,
Grant Likely <grant.likely@...retlab.ca>
Subject: Re: [PATCH] clk: Fix race conditions between clk_set_parent() and
clk_enable()
On 05/15/2012 12:42 PM, Sascha Hauer wrote:
> Hi Saravana,
>
> On Fri, May 11, 2012 at 09:59:56PM -0700, Saravana Kannan wrote:
>> Without this patch, the following race conditions are possible.
>>
>> Race condition 1:
>> * clk-A has two parents - clk-X and clk-Y.
>> * All three are disabled and clk-X is current parent.
>> * Thread A: clk_set_parent(clk-A, clk-Y).
>> * Thread A:<snip execution flow>
>> * Thread A: Grabs enable lock.
>> * Thread A: Sees enable count of clk-A is 0, so doesn't enable clk-Y.
>> * Thread A: Releases enable lock.
>> * Thread B: Calls clk_enable(clk-A), which in turn enables clk-X.
>> * Thread A: Switches clk-A's parent to clk-Y in hardware.
>>
>> clk-A is now enabled in software, but not clocking in hardware.
>>
>> Race condition 2:
>> * clk-A has two parents - clk-X and clk-Y.
>> * All three are disabled and clk-X is current parent.
>> * Thread A: clk_set_parent(clk-A, clk-Y).
>> * Thread A:<snip execution flow>
>> * Thread A: Switches parent in hardware to clk-Y.
>> * Thread A: Grabs enable lock.
>> * Thread A: Sees enable count of clk-A is 0, so doesn't disable clk-X.
>> * Thread A: Releases enable lock.
>> * Thread B: Calls clk_enable(clk-A)
>> * Thread B: Software state still says parent is clk-X.
>> * Thread B: So, enables clk-X and then itself.
>> * Thread A: Updates parent in software state to clk-Y.
>
> Had a look at this and I can follow your reasoning and you patch seems
> to fix this. However, there is a problem,
>
>>
>> /* migrate prepare and enable */
>> @@ -1092,23 +1098,23 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
>>
>> /* FIXME replace with clk_is_enabled(clk) someday */
>> spin_lock_irqsave(&enable_lock, flags);
>> +
>> if (clk->enable_count)
>> __clk_enable(parent);
>> - spin_unlock_irqrestore(&enable_lock, flags);
>>
>> /* change clock input source */
>> ret = clk->ops->set_parent(clk->hw, i);
>
> You call ->set_parent while holding a spinlock. This won't work with i2c
> clocks.
I did account for that. I explained it in the commit text. Please let me
know if any part of that is not clear or is not correct.
Thanks,
Saravana
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists