lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 17 Jan 2018 10:57:18 +0800
From:   Dong Aisheng <dongas86@...il.com>
To:     Stephen Boyd <sboyd@...eaurora.org>
Cc:     Dong Aisheng <aisheng.dong@....com>, linux-clk@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
        mturquette@...libre.com, linux-imx@....com
Subject: Re: [RFC PATCH V1 2/2] clk: add lock for clk_core_is_enabled

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@...eaurora.org>
> > Cc: Michael Turquette <mturquette@...libre.com>
> > Signed-off-by: Dong Aisheng <aisheng.dong@....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@...r.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ