Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1259434 > unrolled thread

[PATCH] PM / OPP: Protect updates to list_dev with mutex

Started byViresh Kumar <viresh.kumar@linaro.org>
First post2015-10-30 13:00 +0100
Last post2015-10-31 03:20 +0100
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] PM / OPP: Protect updates to list_dev with mutex Viresh Kumar <viresh.kumar@linaro.org> - 2015-10-30 13:00 +0100
    Re: [PATCH] PM / OPP: Protect updates to list_dev with mutex Dan Carpenter <dan.carpenter@oracle.com> - 2015-10-30 13:10 +0100
      [PATCH] PM / OPP: Propagate error properly from dev_pm_opp_set_sharing_cpus() Viresh Kumar <viresh.kumar@linaro.org> - 2015-10-30 13:50 +0100
        Re: [PATCH] PM / OPP: Propagate error properly from  dev_pm_opp_set_sharing_cpus() Stephen Boyd <sboyd@codeaurora.org> - 2015-10-30 22:00 +0100
    Re: [PATCH] PM / OPP: Protect updates to list_dev with mutex Stephen Boyd <sboyd@codeaurora.org> - 2015-10-30 18:10 +0100
      Re: [PATCH] PM / OPP: Protect updates to list_dev with mutex Viresh Kumar <viresh.kumar@linaro.org> - 2015-10-31 03:20 +0100

#1259434 — [PATCH] PM / OPP: Protect updates to list_dev with mutex

FromViresh Kumar <viresh.kumar@linaro.org>
Date2015-10-30 13:00 +0100
Subject[PATCH] PM / OPP: Protect updates to list_dev with mutex
Message-ID<qpgvE-5lJ-5@gated-at.bofh.it>
dev_opp_list_lock is used everywhere to protect device and OPP lists,
but dev_pm_opp_set_sharing_cpus() is missed somehow. And instead we used
rcu-lock, which wouldn't help here as we are adding a new list_dev.

This also fixes a problem where we have called kzalloc(..., GFP_KERNEL)
from within rcu-lock, which isn't allowed as kzalloc can sleep when
called with GFP_KERNEL.

With CONFIG_DEBUG_ATOMIC_SLEEP set, we will see the caller vomiting.

Fixes: 8d4d4e98acd6 ("PM / OPP: Add helpers for initializing CPU OPPs")
Reported-by: Michael Turquette <mturquette@baylibre.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Mike: Can you please verify if this fixes it for you..

 drivers/base/power/opp/core.c | 2 +-
 drivers/base/power/opp/cpu.c  | 8 ++++----
 drivers/base/power/opp/opp.h  | 3 +++
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index d5c1149ff123..69f83cbe37b2 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -27,7 +27,7 @@
  */
 static LIST_HEAD(dev_opp_list);
 /* Lock to allow exclusive modification to the device and opp lists */
-static DEFINE_MUTEX(dev_opp_list_lock);
+DEFINE_MUTEX(dev_opp_list_lock);
 
 #define opp_rcu_lockdep_assert()					\
 do {									\
diff --git a/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c
index 7654c5606307..91f15b2e25ee 100644
--- a/drivers/base/power/opp/cpu.c
+++ b/drivers/base/power/opp/cpu.c
@@ -124,12 +124,12 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
 	struct device *dev;
 	int cpu, ret = 0;
 
-	rcu_read_lock();
+	mutex_lock(&dev_opp_list_lock);
 
 	dev_opp = _find_device_opp(cpu_dev);
 	if (IS_ERR(dev_opp)) {
 		ret = -EINVAL;
-		goto out_rcu_read_unlock;
+		goto unlock;
 	}
 
 	for_each_cpu(cpu, cpumask) {
@@ -150,8 +150,8 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
 			continue;
 		}
 	}
-out_rcu_read_unlock:
-	rcu_read_unlock();
+unlock:
+	mutex_unlock(&dev_opp_list_lock);
 
 	return 0;
 }
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h
index dcb38f78dae4..7366b2aa8997 100644
--- a/drivers/base/power/opp/opp.h
+++ b/drivers/base/power/opp/opp.h
@@ -21,6 +21,9 @@
 #include <linux/rculist.h>
 #include <linux/rcupdate.h>
 
+/* Lock to allow exclusive modification to the device and opp lists */
+extern struct mutex dev_opp_list_lock;
+
 /*
  * Internal data structure organization with the OPP layer library is as
  * follows:
-- 
2.6.2.198.g614a2ac

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1259447

FromDan Carpenter <dan.carpenter@oracle.com>
Date2015-10-30 13:10 +0100
Message-ID<qpgFj-5Eg-17@gated-at.bofh.it>
In reply to#1259434
On Fri, Oct 30, 2015 at 05:26:06PM +0530, Viresh Kumar wrote:
> --- a/drivers/base/power/opp/cpu.c
> +++ b/drivers/base/power/opp/cpu.c
> @@ -124,12 +124,12 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
>  	struct device *dev;
>  	int cpu, ret = 0;
>  
> -	rcu_read_lock();
> +	mutex_lock(&dev_opp_list_lock);
>  
>  	dev_opp = _find_device_opp(cpu_dev);
>  	if (IS_ERR(dev_opp)) {
>  		ret = -EINVAL;
> -		goto out_rcu_read_unlock;
> +		goto unlock;
>  	}
>  
>  	for_each_cpu(cpu, cpumask) {
> @@ -150,8 +150,8 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
>  			continue;
>  		}
>  	}
> -out_rcu_read_unlock:
> -	rcu_read_unlock();
> +unlock:
> +	mutex_unlock(&dev_opp_list_lock);
>  
>  	return 0;

Not introduced by your patch, but this should be "return ret;"

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1259472 — [PATCH] PM / OPP: Propagate error properly from dev_pm_opp_set_sharing_cpus()

FromViresh Kumar <viresh.kumar@linaro.org>
Date2015-10-30 13:50 +0100
Subject[PATCH] PM / OPP: Propagate error properly from dev_pm_opp_set_sharing_cpus()
Message-ID<qphi1-5Rm-7@gated-at.bofh.it>
In reply to#1259447
We are returning 0 even in case of errors, fix it.

Fixes: 8d4d4e98acd6 ("PM / OPP: Add helpers for initializing CPU OPPs")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/power/opp/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c
index 91f15b2e25ee..2122543e769d 100644
--- a/drivers/base/power/opp/cpu.c
+++ b/drivers/base/power/opp/cpu.c
@@ -153,7 +153,7 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
 unlock:
 	mutex_unlock(&dev_opp_list_lock);
 
-	return 0;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus);
 
-- 
2.6.2.198.g614a2ac

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1259788 — Re: [PATCH] PM / OPP: Propagate error properly from dev_pm_opp_set_sharing_cpus()

FromStephen Boyd <sboyd@codeaurora.org>
Date2015-10-30 22:00 +0100
SubjectRe: [PATCH] PM / OPP: Propagate error properly from dev_pm_opp_set_sharing_cpus()
Message-ID<qpoWe-25R-11@gated-at.bofh.it>
In reply to#1259472
On 10/30, Viresh Kumar wrote:
> We are returning 0 even in case of errors, fix it.
> 
> Fixes: 8d4d4e98acd6 ("PM / OPP: Add helpers for initializing CPU OPPs")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---

Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>

-- 
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-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1259638

FromStephen Boyd <sboyd@codeaurora.org>
Date2015-10-30 18:10 +0100
Message-ID<qpllD-5l-5@gated-at.bofh.it>
In reply to#1259434
On 10/30, Viresh Kumar wrote:
> dev_opp_list_lock is used everywhere to protect device and OPP lists,
> but dev_pm_opp_set_sharing_cpus() is missed somehow. And instead we used
> rcu-lock, which wouldn't help here as we are adding a new list_dev.
> 
> This also fixes a problem where we have called kzalloc(..., GFP_KERNEL)
> from within rcu-lock, which isn't allowed as kzalloc can sleep when
> called with GFP_KERNEL.

Care to share the splat here?

> diff --git a/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c
> index 7654c5606307..91f15b2e25ee 100644
> --- a/drivers/base/power/opp/cpu.c
> +++ b/drivers/base/power/opp/cpu.c
> @@ -124,12 +124,12 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
>  	struct device *dev;
>  	int cpu, ret = 0;
>  
> -	rcu_read_lock();
> +	mutex_lock(&dev_opp_list_lock);
>  
>  	dev_opp = _find_device_opp(cpu_dev);

So does _find_device_opp() need to be called with rcu_read_lock()
held or not? The comment above the function makes it sound like
we need RCU, but we don't do that here anymore.

-- 
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-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1259905

FromViresh Kumar <viresh.kumar@linaro.org>
Date2015-10-31 03:20 +0100
Message-ID<qptVU-5mo-7@gated-at.bofh.it>
In reply to#1259638
On 30-10-15, 10:06, Stephen Boyd wrote:
> On 10/30, Viresh Kumar wrote:
> > dev_opp_list_lock is used everywhere to protect device and OPP lists,
> > but dev_pm_opp_set_sharing_cpus() is missed somehow. And instead we used
> > rcu-lock, which wouldn't help here as we are adding a new list_dev.
> > 
> > This also fixes a problem where we have called kzalloc(..., GFP_KERNEL)
> > from within rcu-lock, which isn't allowed as kzalloc can sleep when
> > called with GFP_KERNEL.
> 
> Care to share the splat here?

I don't know what is wrong (or right) with my exynos 5250 board, but I
didn't got any splat here even with the right config options (yes I
should have mentioned that earlier). I have seen this at other times
as well, while we were running after some cpufreq traces..

But, the case in hand is pretty straight forward and Mike T. did get a
splat as that's what he told me. We are calling a sleep-able function
from rcu_lock and that's obviously wrong.

> > diff --git a/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c
> > index 7654c5606307..91f15b2e25ee 100644
> > --- a/drivers/base/power/opp/cpu.c
> > +++ b/drivers/base/power/opp/cpu.c
> > @@ -124,12 +124,12 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
> >  	struct device *dev;
> >  	int cpu, ret = 0;
> >  
> > -	rcu_read_lock();
> > +	mutex_lock(&dev_opp_list_lock);
> >  
> >  	dev_opp = _find_device_opp(cpu_dev);
> 
> So does _find_device_opp() need to be called with rcu_read_lock()
> held or not? The comment above the function makes it sound like
> we need RCU, but we don't do that here anymore.

That is more for the readers, as this function is going to return a
pointer to the device OPP, and to make sure it isn't freed behind
their back, they need to take the RCU lock.

There are other writer code paths as well, like add-opp, where we just
take the mutex as there can't be anything stronger than that :)

-- 
viresh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web