mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Andrej Gelenberg <andrej.gelenberg@udo.edu>
Cc: linux@brodo.de, ashok.raj@intel.com, jacob.shin@amd.com,
	linux-kernel@vger.kernel.org, cpufreq@vger.kernel.org
Subject: Re: [PATCH] [CPUFREQ] fix race condition in store_scaling_governor
Date: Wed, 12 May 2010 15:00:39 -0700	[thread overview]
Message-ID: <20100512150039.b5b2729d.akpm@linux-foundation.org> (raw)
In-Reply-To: <4BE967B9.5050107@udo.edu>

On Tue, 11 May 2010 16:20:41 +0200
Andrej Gelenberg <andrej.gelenberg@udo.edu> wrote:

> Wrap store_scaling_governor with mutex lock cpufreq_governor_mutex.
> Fix kernel panic if switch scaling governor very fast.
> Bug in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=15948
> 

Looks sane, I guess.

I am afraid of moving all those functions inside
cpufreq_governor_mutex.  Not for any specific reason, apart from a long
history of nasty deadlocks with cpufreq global locks :(

Has this change been well-tested with lockdep enabled?

> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 75d293e..6ba42f9 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -403,8 +403,6 @@ static int cpufreq_parse_governor(char 
> *str_governor, unsigned int *policy,
>   	} else if (cpufreq_driver->target) {
>   		struct cpufreq_governor *t;
> 
> -		mutex_lock(&cpufreq_governor_mutex);
> -
>   		t = __find_governor(str_governor);
> 
>   		if (t == NULL) {
> @@ -429,8 +427,6 @@ static int cpufreq_parse_governor(char 
> *str_governor, unsigned int *policy,
>   			*governor = t;
>   			err = 0;
>   		}
> -
> -		mutex_unlock(&cpufreq_governor_mutex);
>   	}
>   out:
>   	return err;
> @@ -521,7 +517,7 @@ static ssize_t show_scaling_governor(struct 
> cpufreq_policy *policy, char *buf)
>   /**
>    * store_scaling_governor - store policy for the specified CPU
>    */
> -static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
> +static ssize_t _store_scaling_governor(struct cpufreq_policy *policy,
>   					const char *buf, size_t count)
>   {
>   	unsigned int ret = -EINVAL;
> @@ -553,6 +549,16 @@ static ssize_t store_scaling_governor(struct 
> cpufreq_policy *policy,
>   		return count;
>   }
> 
> +static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
> +                                        const char *buf, size_t count)
> +{
> +        ssize_t ret;
> +	mutex_lock(&cpufreq_governor_mutex);
> +        ret = _store_scaling_governor(policy, buf, count);
> +	mutex_unlock(&cpufreq_governor_mutex);
> +        return ret;
> +}
> +
>   /**
>    * show_scaling_driver - show the cpufreq driver currently loaded
>    */

Your email client replaces tabs with spaces and is wordwrapping the
text.  I fixed that up in my copy of the patch.


  parent reply	other threads:[~2010-05-12 22:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-11 14:20 Andrej Gelenberg
2010-05-12  8:08 ` Américo Wang
2010-05-12  9:01   ` Andrej Gelenberg
2010-05-14 10:48   ` Andrej Gelenberg
2010-05-12 22:00 ` Andrew Morton [this message]
2010-05-12 23:58   ` Andrej Gelenberg
2010-05-13  9:13     ` Américo Wang

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=20100512150039.b5b2729d.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andrej.gelenberg@udo.edu \
    --cc=ashok.raj@intel.com \
    --cc=cpufreq@vger.kernel.org \
    --cc=jacob.shin@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@brodo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome