- To: "Turquette, Mike" <mturquette@xxxxxx>
- Subject: Re: [PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable()
- From: Peter De Schrijver <pdeschrijver@xxxxxxxxxx>
- Date: Wed, 23 May 2012 12:16:17 +0300
- Cc: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>, Saravana Kannan <skannan@xxxxxxxxxxxxxx>, Andrew Lunn <andrew@xxxxxxx>, Grant Likely <grant.likely@xxxxxxxxxxxx>, Jamie Iles <jamie@xxxxxxxxxxxxx>, Jeremy Kerr <jeremy.kerr@xxxxxxxxxxxxx>, Magnus Damm <magnus.damm@xxxxxxxxx>, Deepak Saxena <dsaxena@xxxxxxxxxx>, "linux-arm-kernel@xxxxxxxxxxxxxxxxxxx" <linux-arm-kernel@xxxxxxxxxxxxxxxxxxx>, Arnd Bergman <arnd.bergmann@xxxxxxxxxx>, Stephen Warren <swarren@xxxxxxxxxxxxx>, "linux-arm-msm@xxxxxxxxxxxxxxx" <linux-arm-msm@xxxxxxxxxxxxxxx>, Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>, Rob Herring <rob.herring@xxxxxxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Richard Zhao <richard.zhao@xxxxxxxxxx>, Shawn Guo <shawn.guo@xxxxxxxxxxxxx>, Paul Walmsley <paul@xxxxxxxxx>, Linus Walleij <linus.walleij@xxxxxxxxxxxxxx>, Stephen Boyd <sboyd@xxxxxxxxxxxxxx>, "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>, Amit Kucheria <amit.kucheria@xxxxxxxxxx>
- In-reply-to: <CAJOA=zOcEQc70gg+4U2jNaNRTB5YeyOwgsL12YWNoviQ5qFjaQ@mail.gmail.com>
- User-agent: Mutt/1.5.20 (2009-06-14)
On Tue, May 22, 2012 at 08:06:45PM +0200, Turquette, Mike wrote:
> On Tue, May 22, 2012 at 6:58 AM, Peter De Schrijver
> <pdeschrijver@xxxxxxxxxx> wrote:
> > On Tue, May 15, 2012 at 08:20:44PM +0200, Saravana Kannan wrote:
> >> On 05/11/2012 09:59 PM, 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.
> >> >
> >
> > This looks correct to me. Is there any usecase where enabling/disabling a
> > clock would require sleeping but changing the parent would not?
> >
>
> clk_enable & clk_disable must never sleep. clk_prepare and
> clk_unprepare may sleep.
>
In that case the clock is actually enabled in clk_prepare and disabled in
clk_unprepare I guess (and clk_enable/clk_disable are dummy functions)?
What I'm trying to say is that I don't think there are clocks which can be
enabled/disabled using non blocking operations, but where a parent change
would require a blocking operation.
Cheers,
Peter.
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Linux ARM Kernel]
[Linux ARM]
[Linux Omap]
[Fedora ARM]
[Linux for Sparc]
[IETF Annouce]
[Security]
[Bugtraq]
[Linux OMAP]
[Linux MIPS]
[ECOS]
[Asterisk Internet PBX]
[Linux API]