From: Saravana Kannan <skannan@codeaurora.org>
To: Peter De Schrijver <pdeschrijver@nvidia.com>,
Mark Brown <broonie@opensource.wolfsonmicro.com>,
Russell King <linux@arm.linux.org.uk>,
Shawn Guo <shawn.guo@freescale.com>
Cc: Andrew Lunn <andrew@lunn.ch>, Paul Walmsley <paul@pwsan.com>,
Linus Walleij <linus.walleij@stericsson.com>,
Stephen Boyd <sboyd@codeaurora.org>,
Stephen Warren <swarren@wwwdotorg.org>,
"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Magnus Damm <magnus.damm@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Rob Herring <rob.herring@calxeda.com>,
Richard Zhao <richard.zhao@linaro.org>,
Grant Likely <grant.likely@secretlab.ca>,
Deepak Saxena <dsaxena@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Amit Kucheria <amit.kucheria@linaro.org>,
Jamie Iles <jamie@jamieiles.com>,
Jeremy Kerr <jeremy.kerr@canonical.com>,
Arnd Bergman <arnd.bergmann@linaro.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"Turquette, Mike" <mturquette@ti.com>
Subject: Re: [PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable()
Date: Wed, 30 May 2012 20:46:57 -0700 [thread overview]
Message-ID: <4FC6E9B1.10605@codeaurora.org> (raw)
In-Reply-To: <20120523091617.GZ8730@tbergstrom-lnx.Nvidia.com>
On 05/23/2012 02:16 AM, Peter De Schrijver wrote:
> 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@nvidia.com> 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.
Mark, Shawn, Russell,
Can you guys please respond? I'm surprised that no one seem to care
about fixing race conditions between clk_set_parent/clk_set_rate() and
clk_enable() that will result in incorrect enable count propagation and
have the SW get out of sync with HW.
If we absolutely need to support clocks that where the ops->set_parent()
is not atomic and can't go with the CLK_SET_PARENT_GATE option, then
maybe we can add a "I promise the consumers of this clock won't call
clk_set_parent() and clk_enable() in a racy way" clock flag
(CLK_IGNORE_PARENT_ENABLE_RACE). Yes, it would be a hack for such
clocks, but that's still better than leaving a gaping hole for all the
clocks.
-Saravana
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
WARNING: multiple messages have this Message-ID (diff)
From: skannan@codeaurora.org (Saravana Kannan)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable()
Date: Wed, 30 May 2012 20:46:57 -0700 [thread overview]
Message-ID: <4FC6E9B1.10605@codeaurora.org> (raw)
In-Reply-To: <20120523091617.GZ8730@tbergstrom-lnx.Nvidia.com>
On 05/23/2012 02:16 AM, Peter De Schrijver wrote:
> 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@nvidia.com> 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.
Mark, Shawn, Russell,
Can you guys please respond? I'm surprised that no one seem to care
about fixing race conditions between clk_set_parent/clk_set_rate() and
clk_enable() that will result in incorrect enable count propagation and
have the SW get out of sync with HW.
If we absolutely need to support clocks that where the ops->set_parent()
is not atomic and can't go with the CLK_SET_PARENT_GATE option, then
maybe we can add a "I promise the consumers of this clock won't call
clk_set_parent() and clk_enable() in a racy way" clock flag
(CLK_IGNORE_PARENT_ENABLE_RACE). Yes, it would be a hack for such
clocks, but that's still better than leaving a gaping hole for all the
clocks.
-Saravana
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
WARNING: multiple messages have this Message-ID (diff)
From: Saravana Kannan <skannan@codeaurora.org>
To: Peter De Schrijver <pdeschrijver@nvidia.com>,
Mark Brown <broonie@opensource.wolfsonmicro.com>,
Russell King <linux@arm.linux.org.uk>,
Shawn Guo <shawn.guo@freescale.com>
Cc: "Turquette, Mike" <mturquette@ti.com>,
Andrew Lunn <andrew@lunn.ch>,
Grant Likely <grant.likely@secretlab.ca>,
Jamie Iles <jamie@jamieiles.com>,
Jeremy Kerr <jeremy.kerr@canonical.com>,
Magnus Damm <magnus.damm@gmail.com>,
Deepak Saxena <dsaxena@linaro.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
Arnd Bergman <arnd.bergmann@linaro.org>,
Stephen Warren <swarren@wwwdotorg.org>,
"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Rob Herring <rob.herring@calxeda.com>,
Thomas Gleixner <tglx@linutronix.de>,
Richard Zhao <richard.zhao@linaro.org>,
Paul Walmsley <paul@pwsan.com>,
Linus Walleij <linus.walleij@stericsson.com>,
Stephen Boyd <sboyd@codeaurora.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Amit Kucheria <amit.kucheria@linaro.org>
Subject: Re: [PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable()
Date: Wed, 30 May 2012 20:46:57 -0700 [thread overview]
Message-ID: <4FC6E9B1.10605@codeaurora.org> (raw)
In-Reply-To: <20120523091617.GZ8730@tbergstrom-lnx.Nvidia.com>
On 05/23/2012 02:16 AM, Peter De Schrijver wrote:
> 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@nvidia.com> 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.
Mark, Shawn, Russell,
Can you guys please respond? I'm surprised that no one seem to care
about fixing race conditions between clk_set_parent/clk_set_rate() and
clk_enable() that will result in incorrect enable count propagation and
have the SW get out of sync with HW.
If we absolutely need to support clocks that where the ops->set_parent()
is not atomic and can't go with the CLK_SET_PARENT_GATE option, then
maybe we can add a "I promise the consumers of this clock won't call
clk_set_parent() and clk_enable() in a racy way" clock flag
(CLK_IGNORE_PARENT_ENABLE_RACE). Yes, it would be a hack for such
clocks, but that's still better than leaving a gaping hole for all the
clocks.
-Saravana
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
next prev parent reply other threads:[~2012-05-31 3:46 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-12 4:59 [PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable() Saravana Kannan
2012-05-12 4:59 ` Saravana Kannan
2012-05-15 18:20 ` Saravana Kannan
2012-05-15 18:20 ` Saravana Kannan
2012-05-22 13:58 ` Peter De Schrijver
2012-05-22 13:58 ` Peter De Schrijver
2012-05-22 13:58 ` Peter De Schrijver
2012-05-22 18:06 ` Turquette, Mike
2012-05-22 18:06 ` Turquette, Mike
2012-05-22 18:06 ` Turquette, Mike
2012-05-23 9:16 ` Peter De Schrijver
2012-05-23 9:16 ` Peter De Schrijver
2012-05-23 9:16 ` Peter De Schrijver
2012-05-31 3:46 ` Saravana Kannan [this message]
2012-05-31 3:46 ` Saravana Kannan
2012-05-31 3:46 ` Saravana Kannan
2012-05-15 19:42 ` Sascha Hauer
2012-05-15 19:42 ` Sascha Hauer
2012-05-15 19:42 ` Sascha Hauer
2012-05-15 19:51 ` Saravana Kannan
2012-05-15 19:51 ` Saravana Kannan
2012-05-15 20:00 ` Sascha Hauer
2012-05-15 20:00 ` Sascha Hauer
2012-05-15 20:00 ` Sascha Hauer
2012-05-15 20:09 ` Saravana Kannan
2012-05-15 20:09 ` Saravana Kannan
2012-05-16 5:59 ` Turquette, Mike
2012-05-16 5:59 ` Turquette, Mike
2012-05-16 9:19 ` skannan
2012-05-16 9:19 ` skannan
2012-05-16 9:19 ` skannan at codeaurora.org
2012-05-15 20:43 ` [PATCH] clk: Fix CLK_SET_RATE_GATE flag validation in clk_set_rate() Saravana Kannan
2012-05-15 20:43 ` Saravana Kannan
2012-05-15 22:31 ` Richard Zhao
2012-05-15 22:31 ` Richard Zhao
2012-05-16 0:25 ` Richard Zhao
2012-05-16 0:25 ` Richard Zhao
2012-05-16 0:25 ` Richard Zhao
2012-05-16 5:40 ` Turquette, Mike
2012-05-16 5:40 ` Turquette, Mike
2012-05-16 6:00 ` [PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable() Turquette, Mike
2012-05-16 6:00 ` Turquette, Mike
2012-05-16 7:30 ` Linus Walleij
2012-05-16 7:30 ` Linus Walleij
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=4FC6E9B1.10605@codeaurora.org \
--to=skannan@codeaurora.org \
--cc=amit.kucheria@linaro.org \
--cc=andrew@lunn.ch \
--cc=arnd.bergmann@linaro.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=dsaxena@linaro.org \
--cc=grant.likely@secretlab.ca \
--cc=jamie@jamieiles.com \
--cc=jeremy.kerr@canonical.com \
--cc=linus.walleij@stericsson.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=magnus.damm@gmail.com \
--cc=mturquette@ti.com \
--cc=paul@pwsan.com \
--cc=pdeschrijver@nvidia.com \
--cc=richard.zhao@linaro.org \
--cc=rob.herring@calxeda.com \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@codeaurora.org \
--cc=shawn.guo@freescale.com \
--cc=swarren@wwwdotorg.org \
--cc=tglx@linutronix.de \
/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.