linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Robert Schöne" <robert.schoene@tu-dresden.de>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>
Subject: Re: PROBLEM: Kernel OOPS and possible system freeze after concurrent writing to cpufreq/scaling_governor (Resend)
Date: Mon, 08 Sep 2014 10:16:48 +0200	[thread overview]
Message-ID: <1410164208.6159.18.camel@x200t> (raw)
In-Reply-To: <CAKohpomDkU1nBP4+1EkSdDxQESD+1b6kmaELVfGEifqTL+ZOdg@mail.gmail.com>

(Sorry for the resend, I forgot to disable my S/MIME signature)

The patch you suggested did not work, so I introduced a new mutex in the
patch below.

I am not happy with adding just another mutex, but it fixes my problem
of changing governors concurrently.

Robert



This patch fixes a race condition when concurrently writing to cpufreq/scaling_governor


diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d9fdedd..2ad6b03 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -572,8 +572,15 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
 }
 
 /**
+ * This mutex guarantees, that a concurrent writing to cpuX/scaling_governor
+ * does not run into an OOPS.
+ */
+static DEFINE_MUTEX(cpufreq_store_governor_lock);
+
+/**
  * store_scaling_governor - store policy for the specified CPU
  */
+
 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
                                        const char *buf, size_t count)
 {
@@ -593,11 +600,15 @@ static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
                                                &new_policy.governor))
                return -EINVAL;
 
+       if (! mutex_trylock(&cpufreq_store_governor_lock))
+               return -EBUSY;
+
        ret = cpufreq_set_policy(policy, &new_policy);
 
        policy->user_policy.policy = policy->policy;
        policy->user_policy.governor = policy->governor;
 
+       mutex_unlock(&cpufreq_store_governor_lock);
        if (ret)
                return ret;
        else



-- 

Dipl.-Inf. Robert Schoene
Computer Scientist - R&D Energy Efficient Computing

Technische Universitaet Dresden
Center for Information Services and High Performance Computing
Distributed and Data Intensive Computing
01062 Dresden
Tel.: +49 (351) 463-42483
Fax : +49 (351) 463-37773
E-Mail: Robert.Schoene@tu-dresden.de


  parent reply	other threads:[~2014-09-08  8:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 14:53 PROBLEM: Kernel OOPS and possible system freeze after concurrent writing to cpufreq/scaling_governor Robert Schöne
2014-07-24  7:11 ` PROBLEM: Kernel OOPS and possible system freeze after concurrent writing to cpufreq/scaling_governor (Resend) Robert Schöne
2014-07-24  9:42   ` Viresh Kumar
2014-07-25  8:42     ` Robert Schöne
2014-07-25  9:03       ` Viresh Kumar
2014-07-25 13:19         ` Robert Schöne
2014-09-08  8:13         ` Robert Schöne
2014-09-08  8:16         ` Robert Schöne [this message]
2014-09-08 10:56           ` Viresh Kumar
2014-09-08 12:28             ` Robert Schöne
2014-09-08 12:57               ` Viresh Kumar
2014-09-08 21:14             ` Rafael J. Wysocki
2014-09-09  4:18               ` Viresh Kumar

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=1410164208.6159.18.camel@x200t \
    --to=robert.schoene@tu-dresden.de \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=srivatsa.bhat@linux.vnet.ibm.com \
    --cc=viresh.kumar@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 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).