All of lore.kernel.org
 help / color / mirror / Atom feed
From: Saravana Kannan <skannan@codeaurora.org>
To: Mike Turquette <mturquette@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
	Paul Walmsley <paul@pwsan.com>,
	Shawn Guo <shawn.guo@freescale.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Rob Herring <rob.herring@calxeda.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Russell King <linux@arm.linux.org.uk>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Tomasz Figa <tomasz.figa@gmail.com>,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	Andrew Lunn <andrew@lunn.ch>,
	Jeremy Kerr <jeremy.kerr@canonical.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Arnd Bergman <arnd.bergmann@linaro.org>,
	Jamie Iles <jamie@jamieiles.com>,
	Richard Zhao <richard.zhao@linaro.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Linus Walleij <linus.walleij@stericsson.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Amit Kucheria <amit.kucheria@linaro.org>,
	Deepak Saxena <dsaxena@linaro.org>,
	Grant Likely <grant.likely@secretlab.ca>
Subject: Re: [PATCH v2] clk: Fix race condition between clk_set_parent and clk_enable()
Date: Thu, 16 May 2013 14:31:23 -0700	[thread overview]
Message-ID: <5195502B.3070003@codeaurora.org> (raw)
In-Reply-To: <20130516204455.12127.75296@quantum>

On 05/16/2013 01:44 PM, Mike Turquette wrote:
> Quoting Saravana Kannan (2013-05-15 21:07:24)
>> Without this patch, the following race condition is possible.
>> * 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: Updates clk-A SW parent to clk-Y
>> * Thread A: Releases enable lock.
>> * Thread B: clk_enable(clk-A).
>> * Thread B: clk_enable() enables clk-Y, then enabled clk-A and returns.
>>
>> clk-A is now enabled in software, but not clocking in hardware since the
>> hardware parent is still clk-X.
>>
>> The only way to avoid race conditions between clk_set_parent() and
>> clk_enable/disable() is to ensure that clk_enable/disable() calls don't
>> require changes to hardware enable state between changes to software clock
>> topology and hardware clock topology.
>>
>> The options to achieve the above are:
>> 1. Grab the enable lock before changing software/hardware topology and
>>     release it afterwards.
>> 2. Keep the clock enabled for the duration of software/hardware topology
>>     change so that any additional enable/disable calls don't try to change
>>     the hardware state. Once the topology change is complete, the clock can
>>     be put back in its original enable state.
>>
>> Option (1) is not an acceptable solution since the set_parent() ops might
>> need to sleep.
>>
>> Therefore, this patch implements option (2).
>>
>> This patch doesn't violate any API semantics. clk_disable() doesn't
>> guarantee that the clock is actually disabled. So, no clients of a clock
>> can assume that a clock is disabled after their last call to clk_disable().
>> So, enabling the clock during a parent change is not a violation of any API
>> semantics.
>>
>> This also has the nice side effect of simplifying the error handling code.
>>
>> Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
>
> Updated to this version in clk-next.
>

Thanks Mike. I forgot to add the Ack by Ulf. Would be nice if you can 
put that in.

Btw, I did send this email to the list. But looks like this mail is 
wedged in the series of tubes in the arm mailing list.

-Saravana


-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

WARNING: multiple messages have this Message-ID (diff)
From: skannan@codeaurora.org (Saravana Kannan)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] clk: Fix race condition between clk_set_parent and clk_enable()
Date: Thu, 16 May 2013 14:31:23 -0700	[thread overview]
Message-ID: <5195502B.3070003@codeaurora.org> (raw)
In-Reply-To: <20130516204455.12127.75296@quantum>

On 05/16/2013 01:44 PM, Mike Turquette wrote:
> Quoting Saravana Kannan (2013-05-15 21:07:24)
>> Without this patch, the following race condition is possible.
>> * 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: Updates clk-A SW parent to clk-Y
>> * Thread A: Releases enable lock.
>> * Thread B: clk_enable(clk-A).
>> * Thread B: clk_enable() enables clk-Y, then enabled clk-A and returns.
>>
>> clk-A is now enabled in software, but not clocking in hardware since the
>> hardware parent is still clk-X.
>>
>> The only way to avoid race conditions between clk_set_parent() and
>> clk_enable/disable() is to ensure that clk_enable/disable() calls don't
>> require changes to hardware enable state between changes to software clock
>> topology and hardware clock topology.
>>
>> The options to achieve the above are:
>> 1. Grab the enable lock before changing software/hardware topology and
>>     release it afterwards.
>> 2. Keep the clock enabled for the duration of software/hardware topology
>>     change so that any additional enable/disable calls don't try to change
>>     the hardware state. Once the topology change is complete, the clock can
>>     be put back in its original enable state.
>>
>> Option (1) is not an acceptable solution since the set_parent() ops might
>> need to sleep.
>>
>> Therefore, this patch implements option (2).
>>
>> This patch doesn't violate any API semantics. clk_disable() doesn't
>> guarantee that the clock is actually disabled. So, no clients of a clock
>> can assume that a clock is disabled after their last call to clk_disable().
>> So, enabling the clock during a parent change is not a violation of any API
>> semantics.
>>
>> This also has the nice side effect of simplifying the error handling code.
>>
>> Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
>
> Updated to this version in clk-next.
>

Thanks Mike. I forgot to add the Ack by Ulf. Would be nice if you can 
put that in.

Btw, I did send this email to the list. But looks like this mail is 
wedged in the series of tubes in the arm mailing list.

-Saravana


-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

  reply	other threads:[~2013-05-16 21:31 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-01  4:42 [PATCH] clk: Fix race condition between clk_set_parent and clk_enable() Saravana Kannan
2013-05-01  4:42 ` Saravana Kannan
2013-05-14 18:54 ` Mike Turquette
2013-05-14 18:54   ` Mike Turquette
2013-05-14 21:03   ` Saravana Kannan
2013-05-14 21:03     ` Saravana Kannan
2013-05-14 22:10   ` Tomasz Figa
2013-05-14 22:10     ` Tomasz Figa
2013-05-14 22:10     ` Tomasz Figa
2013-05-14 22:46     ` Saravana Kannan
2013-05-14 22:46       ` Saravana Kannan
2013-05-15  0:10       ` Tomasz Figa
2013-05-15  0:10         ` Tomasz Figa
2013-05-15 19:24 ` Ulf Hansson
2013-05-15 19:24   ` Ulf Hansson
2013-05-16  4:17   ` Saravana Kannan
2013-05-16  4:17     ` Saravana Kannan
2013-05-16  4:07 ` [PATCH v2] " Saravana Kannan
2013-05-16  4:07   ` Saravana Kannan
2013-05-16 20:44   ` Mike Turquette
2013-05-16 20:44     ` Mike Turquette
2013-05-16 21:31     ` Saravana Kannan [this message]
2013-05-16 21:31       ` Saravana Kannan
2013-05-16 22:29       ` Mike Turquette
2013-05-16 22:29         ` 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=5195502B.3070003@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@linaro.org \
    --cc=paul@pwsan.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=tglx@linutronix.de \
    --cc=tomasz.figa@gmail.com \
    --cc=ulf.hansson@linaro.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.