Re: [BUG] While changing the cpufreq governor, kernel hits a bug in workqueue.c

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Nageswara R Sastry <rnsastry@...>
Cc: <linux-kernel@...>, <balbir@...>, <ego@...>, <svaidy@...>, <davej@...>
Date: Monday, June 23, 2008 - 11:26 am

Hi,

Nageswara R Sastry <rnsastry@linux.vnet.ibm.com> writes:


Added Dave Jones to CC.

The work seems to be queued twice.  Might there be a race in the
activation of the governor?

proc #0					proc #1

				    	if (this_dbs_info->enable == 0)
					<PREEMPTED>
if (this_dbs_info->enable == 0)
  mutex_lock()		        	
  dbs_timer_init()	        	
    queue_delayed_work_on() 
  mutex_unlock()
...
					  mutex_lock()
					  dbs_timer_init()
					    queue_delayed_work_on()

If that might happen, would it be feasible to put the check for ->enable
within the mutex-protection?

	Hannes

---
From: Johannes Weiner <hannes@saeurebad.de>
Subject: cpufreq: Fix race in enabling ondemand/conservative governors

Prevent double activation of the governor if two processes race on the
check for whether the governor is already active.

Signed-off-by: Johannes Weiner <hannes@saeurebad.de>
---

diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 5d3a04b..a4902e4 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -486,10 +486,11 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
 		if ((!cpu_online(cpu)) || (!policy->cur))
 			return -EINVAL;
 
-		if (this_dbs_info->enable) /* Already enabled */
-			break;
-
 		mutex_lock(&dbs_mutex);
+		if (this_dbs_info->enable) {
+			mutex_unlock(&dbs_mutex);
+			break;
+		}
 
 		rc = sysfs_create_group(&policy->kobj, &dbs_attr_group);
 		if (rc) {
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index d2af20d..61705e1 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -508,10 +508,12 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
 		if ((!cpu_online(cpu)) || (!policy->cur))
 			return -EINVAL;
 
-		if (this_dbs_info->enable) /* Already enabled */
+		mutex_lock(&dbs_mutex);
+		if (this_dbs_info->enable) {
+			mutex_unlock(&dbs_mutex);
 			break;
+		}
 
-		mutex_lock(&dbs_mutex);
 		dbs_enable++;
 
 		rc = sysfs_create_group(&policy->kobj, &dbs_attr_group);
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[BUG] While changing the cpufreq governor, kernel hits a bug..., Nageswara R Sastry, (Mon Jun 23, 6:51 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Johannes Weiner, (Mon Jun 23, 11:26 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Tue Jun 24, 5:17 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Thu Jun 26, 8:18 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Mon Jul 7, 5:48 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Mon Jul 7, 7:19 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Tue Jul 8, 1:52 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Tue Aug 12, 4:12 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Tue Oct 7, 5:41 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Mon Oct 27, 11:29 pm)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Mon Jul 14, 11:42 pm)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Thu Jun 26, 9:31 am)
Re: [BUG] While changing the cpufreq governor, kernel hits a..., Nageswara R Sastry, (Fri Jun 27, 12:12 am)