linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled
@ 2017-12-22  9:46 Dong Aisheng
  2017-12-22  9:46 ` [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled Dong Aisheng
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dong Aisheng @ 2017-12-22  9:46 UTC (permalink / raw)
  To: linux-clk
  Cc: linux-kernel, linux-arm-kernel, sboyd, mturquette, Dong Aisheng,
	Ulf Hansson, Marek Szyprowski

Current clk_pm_runtime_put is using pm_runtime_put_sync which
is not safe to be called in clk_core_is_enabled as it should
be able to run in atomic context.

Thus use pm_runtime_put instead which is atomic safe.

Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Fixes: 9a34b45397e5 ("clk: Add support for runtime PM")
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
---
 drivers/clk/clk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5ec5809..e24968f 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -227,7 +227,8 @@ static bool clk_core_is_enabled(struct clk_core *core)
 
 	ret = core->ops->is_enabled(core->hw);
 done:
-	clk_pm_runtime_put(core);
+	if (core->dev)
+		pm_runtime_put(core->dev);
 
 	return ret;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled
  2017-12-22  9:46 [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled Dong Aisheng
@ 2017-12-22  9:46 ` Dong Aisheng
  2017-12-27  1:29   ` Stephen Boyd
  2017-12-22 12:51 ` [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled Ulf Hansson
  2017-12-27  1:38 ` Stephen Boyd
  2 siblings, 1 reply; 6+ messages in thread
From: Dong Aisheng @ 2017-12-22  9:46 UTC (permalink / raw)
  To: linux-clk; +Cc: linux-kernel, linux-arm-kernel, sboyd, mturquette, Dong Aisheng

According to design doc, .is_enabled should be protected by enable lock.
Then users don't have to protect it against enable/disable operation
in clock drivers.

See: Documentation/clk.txt
"The enable lock is a spinlock and is held across calls to the .enable,
.disable and .is_enabled operations."

Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Michael Turquette <mturquette@baylibre.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
---
 drivers/clk/clk.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e24968f..d6e2d5c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -198,14 +198,19 @@ static bool clk_core_is_prepared(struct clk_core *core)
 
 static bool clk_core_is_enabled(struct clk_core *core)
 {
+	unsigned long flags;
 	bool ret = false;
 
+	flags = clk_enable_lock();
+
 	/*
 	 * .is_enabled is only mandatory for clocks that gate
 	 * fall back to software usage counter if .is_enabled is missing
 	 */
-	if (!core->ops->is_enabled)
+	if (!core->ops->is_enabled) {
+		clk_enable_unlock(flags);
 		return core->enable_count;
+	}
 
 	/*
 	 * Check if clock controller's device is runtime active before
@@ -230,6 +235,8 @@ static bool clk_core_is_enabled(struct clk_core *core)
 	if (core->dev)
 		pm_runtime_put(core->dev);
 
+	clk_enable_unlock(flags);
+
 	return ret;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled
  2017-12-22  9:46 [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled Dong Aisheng
  2017-12-22  9:46 ` [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled Dong Aisheng
@ 2017-12-22 12:51 ` Ulf Hansson
  2017-12-27  1:38 ` Stephen Boyd
  2 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2017-12-22 12:51 UTC (permalink / raw)
  To: Dong Aisheng
  Cc: linux-clk, Linux Kernel Mailing List, linux-arm-kernel,
	Stephen Boyd, Mike Turquette, Marek Szyprowski

On 22 December 2017 at 10:46, Dong Aisheng <aisheng.dong@nxp.com> wrote:
> Current clk_pm_runtime_put is using pm_runtime_put_sync which
> is not safe to be called in clk_core_is_enabled as it should
> be able to run in atomic context.
>
> Thus use pm_runtime_put instead which is atomic safe.
>
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> Fixes: 9a34b45397e5 ("clk: Add support for runtime PM")
> Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

Kind regards
Uffe

> ---
>  drivers/clk/clk.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 5ec5809..e24968f 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -227,7 +227,8 @@ static bool clk_core_is_enabled(struct clk_core *core)
>
>         ret = core->ops->is_enabled(core->hw);
>  done:
> -       clk_pm_runtime_put(core);
> +       if (core->dev)
> +               pm_runtime_put(core->dev);
>
>         return ret;
>  }
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled
  2017-12-22  9:46 ` [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled Dong Aisheng
@ 2017-12-27  1:29   ` Stephen Boyd
  2018-01-17  2:57     ` Dong Aisheng
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2017-12-27  1:29 UTC (permalink / raw)
  To: Dong Aisheng; +Cc: linux-clk, linux-kernel, linux-arm-kernel, mturquette

On 12/22, Dong Aisheng wrote:
> According to design doc, .is_enabled should be protected by enable lock.
> Then users don't have to protect it against enable/disable operation
> in clock drivers.
> 
> See: Documentation/clk.txt
> "The enable lock is a spinlock and is held across calls to the .enable,
> .disable and .is_enabled operations."
> 
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: Michael Turquette <mturquette@baylibre.com>
> Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> ---
>  drivers/clk/clk.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index e24968f..d6e2d5c 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -198,14 +198,19 @@ static bool clk_core_is_prepared(struct clk_core *core)
>  
>  static bool clk_core_is_enabled(struct clk_core *core)
>  {
> +	unsigned long flags;
>  	bool ret = false;
>  
> +	flags = clk_enable_lock();
> +
>  	/*
>  	 * .is_enabled is only mandatory for clocks that gate
>  	 * fall back to software usage counter if .is_enabled is missing
>  	 */
> -	if (!core->ops->is_enabled)
> +	if (!core->ops->is_enabled) {
> +		clk_enable_unlock(flags);
>  		return core->enable_count;
> +	}
>  
>  	/*
>  	 * Check if clock controller's device is runtime active before
> @@ -230,6 +235,8 @@ static bool clk_core_is_enabled(struct clk_core *core)
>  	if (core->dev)
>  		pm_runtime_put(core->dev);
>  
> +	clk_enable_unlock(flags);
> +
>  	return ret;
>  }

It doesn't really make any sense to hold the enable lock inside
the clk_core_is_enabled() function, unless you want to do
something else with the information of the enable state with that
lock held. Otherwise, seeing if a clk is enabled is a one-shot
read of the enabled state, which could just as easily change
after the function returns because the lock is released.

We should update the documentation.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled
  2017-12-22  9:46 [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled Dong Aisheng
  2017-12-22  9:46 ` [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled Dong Aisheng
  2017-12-22 12:51 ` [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled Ulf Hansson
@ 2017-12-27  1:38 ` Stephen Boyd
  2 siblings, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2017-12-27  1:38 UTC (permalink / raw)
  To: Dong Aisheng
  Cc: linux-clk, linux-kernel, linux-arm-kernel, mturquette,
	Ulf Hansson, Marek Szyprowski

On 12/22, Dong Aisheng wrote:
> Current clk_pm_runtime_put is using pm_runtime_put_sync which
> is not safe to be called in clk_core_is_enabled as it should
> be able to run in atomic context.
> 
> Thus use pm_runtime_put instead which is atomic safe.
> 
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> Fixes: 9a34b45397e5 ("clk: Add support for runtime PM")
> Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> ---

Applied to clk-fixes

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled
  2017-12-27  1:29   ` Stephen Boyd
@ 2018-01-17  2:57     ` Dong Aisheng
  0 siblings, 0 replies; 6+ messages in thread
From: Dong Aisheng @ 2018-01-17  2:57 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Dong Aisheng, linux-clk, linux-kernel, linux-arm-kernel,
	mturquette, linux-imx

On Tue, Dec 26, 2017 at 05:29:18PM -0800, Stephen Boyd wrote:
> On 12/22, Dong Aisheng wrote:
> > According to design doc, .is_enabled should be protected by enable lock.
> > Then users don't have to protect it against enable/disable operation
> > in clock drivers.
> > 
> > See: Documentation/clk.txt
> > "The enable lock is a spinlock and is held across calls to the .enable,
> > .disable and .is_enabled operations."
> > 
> > Cc: Stephen Boyd <sboyd@codeaurora.org>
> > Cc: Michael Turquette <mturquette@baylibre.com>
> > Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> > ---
> >  drivers/clk/clk.c | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index e24968f..d6e2d5c 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -198,14 +198,19 @@ static bool clk_core_is_prepared(struct clk_core *core)
> >  
> >  static bool clk_core_is_enabled(struct clk_core *core)
> >  {
> > +	unsigned long flags;
> >  	bool ret = false;
> >  
> > +	flags = clk_enable_lock();
> > +
> >  	/*
> >  	 * .is_enabled is only mandatory for clocks that gate
> >  	 * fall back to software usage counter if .is_enabled is missing
> >  	 */
> > -	if (!core->ops->is_enabled)
> > +	if (!core->ops->is_enabled) {
> > +		clk_enable_unlock(flags);
> >  		return core->enable_count;
> > +	}
> >  
> >  	/*
> >  	 * Check if clock controller's device is runtime active before
> > @@ -230,6 +235,8 @@ static bool clk_core_is_enabled(struct clk_core *core)
> >  	if (core->dev)
> >  		pm_runtime_put(core->dev);
> >  
> > +	clk_enable_unlock(flags);
> > +
> >  	return ret;
> >  }
> 
> It doesn't really make any sense to hold the enable lock inside
> the clk_core_is_enabled() function, unless you want to do
> something else with the information of the enable state with that
> lock held. Otherwise, seeing if a clk is enabled is a one-shot
> read of the enabled state, which could just as easily change
> after the function returns because the lock is released.
> 
> We should update the documentation.
> 

Yes, you're absolutely right.
I could draft a patch to update it later.

Thanks

Regards
Dong Aisheng

> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
> --
> To unsubscribe from this list: send the line "unsubscribe linux-clk" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-17  2:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-22  9:46 [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled Dong Aisheng
2017-12-22  9:46 ` [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled Dong Aisheng
2017-12-27  1:29   ` Stephen Boyd
2018-01-17  2:57     ` Dong Aisheng
2017-12-22 12:51 ` [RFC PATCH V1 1/2] clk: use atomic runtime pm api in clk_core_is_enabled Ulf Hansson
2017-12-27  1:38 ` Stephen Boyd

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