* [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount @ 2020-01-19 7:09 qiwuchen55 2020-01-20 5:32 ` Viresh Kumar 0 siblings, 1 reply; 9+ messages in thread From: qiwuchen55 @ 2020-01-19 7:09 UTC (permalink / raw) To: mmayer, rjw, viresh.kumar, f.fainelli Cc: chenqiwu, bcm-kernel-feedback-list, linux-kernel, linux-arm-kernel, linux-pm From: chenqiwu <chenqiwu@xiaomi.com> brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, meanwhile, it also increments the kobject reference count to mark it busy. However, a corresponding call of cpufreq_cpu_put() is ignored to decrement the kobject reference count back, which may lead to a potential stuck risk that the cpuhp thread deadly waits for dropping of kobject refcount when cpufreq policy free. For fixing this bug, cpufreq_get_policy() is referenced to do a proper cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. If the policy return NULL, we just return 0 to hit the code path of cpufreq_driver->get. Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> --- drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c index 77b0e5d..ee0d404 100644 --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) { - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); - struct private_data *priv = policy->driver_data; + struct cpufreq_policy policy; + struct private_data *priv; + + /* + * In case cpufreq policy has been released, just return 0. + */ + if (cpufreq_get_policy(&policy, cpu)) + return 0; + + priv = policy.driver_data; return brcm_avs_get_frequency(priv->base); } -- 1.9.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-19 7:09 [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount qiwuchen55 @ 2020-01-20 5:32 ` Viresh Kumar 2020-01-20 5:58 ` chenqiwu 0 siblings, 1 reply; 9+ messages in thread From: Viresh Kumar @ 2020-01-20 5:32 UTC (permalink / raw) To: qiwuchen55 Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > From: chenqiwu <chenqiwu@xiaomi.com> > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > meanwhile, it also increments the kobject reference count to mark it busy. > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > the kobject reference count back, which may lead to a potential stuck risk > that the cpuhp thread deadly waits for dropping of kobject refcount when > cpufreq policy free. > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > If the policy return NULL, we just return 0 to hit the code path of > cpufreq_driver->get. > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > --- > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > index 77b0e5d..ee0d404 100644 > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > { > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > - struct private_data *priv = policy->driver_data; > + struct cpufreq_policy policy; > + struct private_data *priv; > + > + /* > + * In case cpufreq policy has been released, just return 0. > + */ > + if (cpufreq_get_policy(&policy, cpu)) > + return 0; Why did you move away from the previous implementation of cpufreq_cpu_get() ? > + > + priv = policy.driver_data; > > return brcm_avs_get_frequency(priv->base); > } > -- > 1.9.1 -- viresh _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-20 5:32 ` Viresh Kumar @ 2020-01-20 5:58 ` chenqiwu 2020-01-20 6:01 ` Viresh Kumar 0 siblings, 1 reply; 9+ messages in thread From: chenqiwu @ 2020-01-20 5:58 UTC (permalink / raw) To: Viresh Kumar Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > From: chenqiwu <chenqiwu@xiaomi.com> > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > meanwhile, it also increments the kobject reference count to mark it busy. > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > the kobject reference count back, which may lead to a potential stuck risk > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > cpufreq policy free. > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > If the policy return NULL, we just return 0 to hit the code path of > > cpufreq_driver->get. > > > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > > --- > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > index 77b0e5d..ee0d404 100644 > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > { > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), meanwhile fills a policy copy for the user. It equals to using cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access to the policy pointer. I think both methods are fine here. What do you think? > > - struct private_data *priv = policy->driver_data; > > + struct cpufreq_policy policy; > > + struct private_data *priv; > > + > > + /* > > + * In case cpufreq policy has been released, just return 0. > > + */ > > + if (cpufreq_get_policy(&policy, cpu)) > > + return 0; > > Why did you move away from the previous implementation of cpufreq_cpu_get() ? > > > + > > + priv = policy.driver_data; > > > > return brcm_avs_get_frequency(priv->base); > > } > > -- > > 1.9.1 > > -- > viresh Qiwu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-20 5:58 ` chenqiwu @ 2020-01-20 6:01 ` Viresh Kumar 2020-01-20 6:13 ` chenqiwu 0 siblings, 1 reply; 9+ messages in thread From: Viresh Kumar @ 2020-01-20 6:01 UTC (permalink / raw) To: chenqiwu Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On 20-01-20, 13:58, chenqiwu wrote: > On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > > From: chenqiwu <chenqiwu@xiaomi.com> > > > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > > meanwhile, it also increments the kobject reference count to mark it busy. > > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > > the kobject reference count back, which may lead to a potential stuck risk > > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > > cpufreq policy free. > > > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > > If the policy return NULL, we just return 0 to hit the code path of > > > cpufreq_driver->get. > > > > > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > > > --- > > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > index 77b0e5d..ee0d404 100644 > > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > > { > > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > > > > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), > meanwhile fills a policy copy for the user. It equals to using > cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access > to the policy pointer. I think both methods are fine here. > What do you think? cpufreq_get_policy() does an extra memcpy as well, which isn't required at all in your case. -- viresh _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-20 6:01 ` Viresh Kumar @ 2020-01-20 6:13 ` chenqiwu 2020-01-20 6:21 ` Viresh Kumar 0 siblings, 1 reply; 9+ messages in thread From: chenqiwu @ 2020-01-20 6:13 UTC (permalink / raw) To: Viresh Kumar Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On Mon, Jan 20, 2020 at 11:31:34AM +0530, Viresh Kumar wrote: > On 20-01-20, 13:58, chenqiwu wrote: > > On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > > > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > > > From: chenqiwu <chenqiwu@xiaomi.com> > > > > > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > > > meanwhile, it also increments the kobject reference count to mark it busy. > > > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > > > the kobject reference count back, which may lead to a potential stuck risk > > > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > > > cpufreq policy free. > > > > > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > > > If the policy return NULL, we just return 0 to hit the code path of > > > > cpufreq_driver->get. > > > > > > > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > > > > --- > > > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > index 77b0e5d..ee0d404 100644 > > > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > > > { > > > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > > > > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > > > > > > > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), > > meanwhile fills a policy copy for the user. It equals to using > > cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access > > to the policy pointer. I think both methods are fine here. > > What do you think? > > cpufreq_get_policy() does an extra memcpy as well, which isn't required at all > in your case. > > -- > viresh Huha..Do you worry about the race conditon with cpufreq policy free path? If the policy has been released, cpufreq_get_policy() will return -EINVAL, it won't do an extra memcpy. Qiwu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-20 6:13 ` chenqiwu @ 2020-01-20 6:21 ` Viresh Kumar 2020-01-20 6:27 ` chenqiwu 0 siblings, 1 reply; 9+ messages in thread From: Viresh Kumar @ 2020-01-20 6:21 UTC (permalink / raw) To: chenqiwu Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On 20-01-20, 14:13, chenqiwu wrote: > On Mon, Jan 20, 2020 at 11:31:34AM +0530, Viresh Kumar wrote: > > On 20-01-20, 13:58, chenqiwu wrote: > > > On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > > > > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > > > > From: chenqiwu <chenqiwu@xiaomi.com> > > > > > > > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > > > > meanwhile, it also increments the kobject reference count to mark it busy. > > > > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > > > > the kobject reference count back, which may lead to a potential stuck risk > > > > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > > > > cpufreq policy free. > > > > > > > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > > > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > > > > If the policy return NULL, we just return 0 to hit the code path of > > > > > cpufreq_driver->get. > > > > > > > > > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > > > > > --- > > > > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > > > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > index 77b0e5d..ee0d404 100644 > > > > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > > > > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > > > > { > > > > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > > > > > > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > > > > > > > > > > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), > > > meanwhile fills a policy copy for the user. It equals to using > > > cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access > > > to the policy pointer. I think both methods are fine here. > > > What do you think? > > > > cpufreq_get_policy() does an extra memcpy as well, which isn't required at all > > in your case. > > > > -- > > viresh > > Huha..Do you worry about the race conditon with cpufreq policy free path? No. I just worry about an unnecessary memcpy, nothing else. -- viresh _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-20 6:21 ` Viresh Kumar @ 2020-01-20 6:27 ` chenqiwu 2020-01-20 6:30 ` Viresh Kumar 0 siblings, 1 reply; 9+ messages in thread From: chenqiwu @ 2020-01-20 6:27 UTC (permalink / raw) To: Viresh Kumar Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On Mon, Jan 20, 2020 at 11:51:26AM +0530, Viresh Kumar wrote: > On 20-01-20, 14:13, chenqiwu wrote: > > On Mon, Jan 20, 2020 at 11:31:34AM +0530, Viresh Kumar wrote: > > > On 20-01-20, 13:58, chenqiwu wrote: > > > > On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > > > > > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > > > > > From: chenqiwu <chenqiwu@xiaomi.com> > > > > > > > > > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > > > > > meanwhile, it also increments the kobject reference count to mark it busy. > > > > > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > > > > > the kobject reference count back, which may lead to a potential stuck risk > > > > > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > > > > > cpufreq policy free. > > > > > > > > > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > > > > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > > > > > If the policy return NULL, we just return 0 to hit the code path of > > > > > > cpufreq_driver->get. > > > > > > > > > > > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > > > > > > --- > > > > > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > > > > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > index 77b0e5d..ee0d404 100644 > > > > > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > > > > > > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > > > > > { > > > > > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > > > > > > > > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > > > > > > > > > > > > > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), > > > > meanwhile fills a policy copy for the user. It equals to using > > > > cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access > > > > to the policy pointer. I think both methods are fine here. > > > > What do you think? > > > > > > cpufreq_get_policy() does an extra memcpy as well, which isn't required at all > > > in your case. > > > > > > -- > > > viresh > > > > Huha..Do you worry about the race conditon with cpufreq policy free path? > > No. I just worry about an unnecessary memcpy, nothing else. > Is there any question about this extra memcpy? Qiwu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-20 6:27 ` chenqiwu @ 2020-01-20 6:30 ` Viresh Kumar 2020-01-20 6:50 ` chenqiwu 0 siblings, 1 reply; 9+ messages in thread From: Viresh Kumar @ 2020-01-20 6:30 UTC (permalink / raw) To: chenqiwu Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On 20-01-20, 14:27, chenqiwu wrote: > On Mon, Jan 20, 2020 at 11:51:26AM +0530, Viresh Kumar wrote: > > On 20-01-20, 14:13, chenqiwu wrote: > > > On Mon, Jan 20, 2020 at 11:31:34AM +0530, Viresh Kumar wrote: > > > > On 20-01-20, 13:58, chenqiwu wrote: > > > > > On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > > > > > > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > > > > > > From: chenqiwu <chenqiwu@xiaomi.com> > > > > > > > > > > > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > > > > > > meanwhile, it also increments the kobject reference count to mark it busy. > > > > > > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > > > > > > the kobject reference count back, which may lead to a potential stuck risk > > > > > > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > > > > > > cpufreq policy free. > > > > > > > > > > > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > > > > > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > > > > > > If the policy return NULL, we just return 0 to hit the code path of > > > > > > > cpufreq_driver->get. > > > > > > > > > > > > > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > > > > > > > --- > > > > > > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > > > > > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > > > > > > > > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > index 77b0e5d..ee0d404 100644 > > > > > > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > > > > > > > > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > > > > > > { > > > > > > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > > > > > > > > > > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > > > > > > > > > > > > > > > > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), > > > > > meanwhile fills a policy copy for the user. It equals to using > > > > > cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access > > > > > to the policy pointer. I think both methods are fine here. > > > > > What do you think? > > > > > > > > cpufreq_get_policy() does an extra memcpy as well, which isn't required at all > > > > in your case. > > > > > > > > -- > > > > viresh > > > > > > Huha..Do you worry about the race conditon with cpufreq policy free path? > > > > No. I just worry about an unnecessary memcpy, nothing else. > > > Is there any question about this extra memcpy? What do you mean by that? The whole point I am trying to make is that for your specific case, doing an explicit cpufreq_cpu_get() and cpufreq_cpu_put() is far more efficient than calling cpufreq_get_policy() which has a different purpose and usecase. -- viresh _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount 2020-01-20 6:30 ` Viresh Kumar @ 2020-01-20 6:50 ` chenqiwu 0 siblings, 0 replies; 9+ messages in thread From: chenqiwu @ 2020-01-20 6:50 UTC (permalink / raw) To: Viresh Kumar Cc: f.fainelli, linux-pm, rjw, linux-kernel, bcm-kernel-feedback-list, mmayer, chenqiwu, linux-arm-kernel On Mon, Jan 20, 2020 at 12:00:04PM +0530, Viresh Kumar wrote: > On 20-01-20, 14:27, chenqiwu wrote: > > On Mon, Jan 20, 2020 at 11:51:26AM +0530, Viresh Kumar wrote: > > > On 20-01-20, 14:13, chenqiwu wrote: > > > > On Mon, Jan 20, 2020 at 11:31:34AM +0530, Viresh Kumar wrote: > > > > > On 20-01-20, 13:58, chenqiwu wrote: > > > > > > On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > > > > > > > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > > > > > > > From: chenqiwu <chenqiwu@xiaomi.com> > > > > > > > > > > > > > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > > > > > > > meanwhile, it also increments the kobject reference count to mark it busy. > > > > > > > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > > > > > > > the kobject reference count back, which may lead to a potential stuck risk > > > > > > > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > > > > > > > cpufreq policy free. > > > > > > > > > > > > > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > > > > > > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > > > > > > > If the policy return NULL, we just return 0 to hit the code path of > > > > > > > > cpufreq_driver->get. > > > > > > > > > > > > > > > > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com> > > > > > > > > --- > > > > > > > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > > > > > > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > > > > > > > > > > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > > index 77b0e5d..ee0d404 100644 > > > > > > > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > > > > > > > > > > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > > > > > > > { > > > > > > > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > > > > > > > > > > > > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > > > > > > > > > > > > > > > > > > > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), > > > > > > meanwhile fills a policy copy for the user. It equals to using > > > > > > cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access > > > > > > to the policy pointer. I think both methods are fine here. > > > > > > What do you think? > > > > > > > > > > cpufreq_get_policy() does an extra memcpy as well, which isn't required at all > > > > > in your case. > > > > > > > > > > -- > > > > > viresh > > > > > > > > Huha..Do you worry about the race conditon with cpufreq policy free path? > > > > > > No. I just worry about an unnecessary memcpy, nothing else. > > > > > Is there any question about this extra memcpy? > > What do you mean by that? > > The whole point I am trying to make is that for your specific case, doing an > explicit cpufreq_cpu_get() and cpufreq_cpu_put() is far more efficient than > calling cpufreq_get_policy() which has a different purpose and usecase. > For efficiency, I agree your idea. So we have change as follows: diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c index 77b0e5d..b2ddde3 100644 --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c @@ -455,6 +455,11 @@ static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); struct private_data *priv = policy->driver_data; + if (!policy) + return 0; + + cpufreq_cpu_put(policy); + return brcm_avs_get_frequency(priv->base); } Qiwu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-01-20 6:50 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-01-19 7:09 [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount qiwuchen55 2020-01-20 5:32 ` Viresh Kumar 2020-01-20 5:58 ` chenqiwu 2020-01-20 6:01 ` Viresh Kumar 2020-01-20 6:13 ` chenqiwu 2020-01-20 6:21 ` Viresh Kumar 2020-01-20 6:27 ` chenqiwu 2020-01-20 6:30 ` Viresh Kumar 2020-01-20 6:50 ` chenqiwu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox