public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Chanwoo Choi <cw00.choi@samsung•com>
To: Leonard Crestez <leonard.crestez@nxp•com>,
	Matthias Kaehlcke <mka@chromium•org>,
	MyungJoo Ham <myungjoo.ham@samsung•com>,
	Kyungmin Park <kyungmin.park@samsung•com>
Cc: "Artur Świgoń" <a.swigon@partner•samsung.com>,
	linux-pm@vger•kernel.org, "Krzysztof Kozlowski" <krzk@kernel•org>,
	"Lukasz Luba" <l.luba@partner•samsung.com>,
	"NXP Linux Team" <linux-imx@nxp•com>,
	"Georgi Djakov" <georgi.djakov@linaro•org>,
	linux-arm-kernel@lists•infradead.org
Subject: Re: [PATCH] PM / devfreq: Lock devfreq in trans_stat_show
Date: Tue, 24 Sep 2019 11:11:47 +0900	[thread overview]
Message-ID: <979d107f-0a52-3aa4-a397-acb0ff754a3c@samsung.com> (raw)
In-Reply-To: <714675448e7fbf3c930b0dca6fbe54fa5f87211b.1569256001.git.leonard.crestez@nxp.com>

Hi,

On 19. 9. 24. 오전 1:27, Leonard Crestez wrote:
> There is no locking in this sysfs show function so stats printing can
> race with a devfreq_update_status called as part of freq switching or
> with initialization.
> 
> Also add an assert in devfreq_update_status to make it clear that lock
> must be held by caller.
> 
> Signed-off-by: Leonard Crestez <leonard.crestez@nxp•com>
> ---
>  drivers/devfreq/devfreq.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> Changes since v1:
> * Split from series: low-priority bugfix not strictly required for PM QoS
> * Only keep lock during update, release before sprintf
> Link to v1: https://patchwork.kernel.org/patch/11149493/
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 4c58fbf7d4e4..00fc23fea5b2 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -206,10 +206,11 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
>  {
>  	int lev, prev_lev, ret = 0;
>  	unsigned long cur_time;
>  
>  	cur_time = jiffies;
> +	lockdep_assert_held(&devfreq->lock);

It better to move lock checking before 'cur_time = jiffies'
in order to reduce the redundant code execution.

>  
>  	/* Immediately exit if previous_freq is not initialized yet. */
>  	if (!devfreq->previous_freq)
>  		goto out;
>  
> @@ -1507,16 +1508,22 @@ static ssize_t trans_stat_show(struct device *dev,
>  	struct devfreq *devfreq = to_devfreq(dev);
>  	ssize_t len;
>  	int i, j;
>  	unsigned int max_state = devfreq->profile->max_state;
>  
> -	if (!devfreq->stop_polling &&
> -			devfreq_update_status(devfreq, devfreq->previous_freq))
> -		return 0;
>  	if (max_state == 0)
>  		return sprintf(buf, "Not Supported.\n");
>  
> +	/* lock and update */

It is not necessary. Anyone can know that this code is related to mutex lock/unlock.

> +	mutex_lock(&devfreq->lock);
> +	if (!devfreq->stop_polling &&
> +			devfreq_update_status(devfreq, devfreq->previous_freq)) {
> +		mutex_unlock(&devfreq->lock);
> +		return 0;
> +	}
> +	mutex_unlock(&devfreq->lock);
> +
>  	len = sprintf(buf, "     From  :   To\n");
>  	len += sprintf(buf + len, "           :");
>  	for (i = 0; i < max_state; i++)
>  		len += sprintf(buf + len, "%10lu",
>  				devfreq->profile->freq_table[i]);
> 

Basically, it is necessary. Please edit it by my comments.
Also, you have to add the following 'fixes' as following:
and send it stable mailing list.

Fixes: 39688ce6facd ("PM / devfreq: account suspend/resume for stats")

If you edit it by my comments, feel free to add my tag:
Reviewed-by: Chanwoo Choi <cw00.choi@samsung•com>


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists•infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-09-24  2:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190923162736epcas3p2c1db3bf767a07f17b609bc91fbbd9648@epcas3p2.samsung.com>
2019-09-23 16:27 ` [PATCH] PM / devfreq: Lock devfreq in trans_stat_show Leonard Crestez
2019-09-23 18:54   ` Matthias Kaehlcke
2019-09-23 23:34   ` Matthias Kaehlcke
2019-09-24  2:11   ` Chanwoo Choi [this message]
2019-09-24  7:44     ` Leonard Crestez
2019-09-24 15:44       ` Matthias Kaehlcke
2019-09-25  1:21       ` Chanwoo Choi
2019-09-25 19:36         ` Leonard Crestez

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=979d107f-0a52-3aa4-a397-acb0ff754a3c@samsung.com \
    --to=cw00.choi@samsung$(echo .)com \
    --cc=a.swigon@partner$(echo .)samsung.com \
    --cc=georgi.djakov@linaro$(echo .)org \
    --cc=krzk@kernel$(echo .)org \
    --cc=kyungmin.park@samsung$(echo .)com \
    --cc=l.luba@partner$(echo .)samsung.com \
    --cc=leonard.crestez@nxp$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-imx@nxp$(echo .)com \
    --cc=linux-pm@vger$(echo .)kernel.org \
    --cc=mka@chromium$(echo .)org \
    --cc=myungjoo.ham@samsung$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox