* [PATCH] cpufreq: schedutil: Fix sugov_start versus sugov_update_shared race
@ 2017-07-06 17:53 Vikram Mulukutla
2017-07-06 20:48 ` Rafael J. Wysocki
2017-07-07 3:25 ` Viresh Kumar
0 siblings, 2 replies; 4+ messages in thread
From: Vikram Mulukutla @ 2017-07-06 17:53 UTC (permalink / raw)
To: rafael.j.wysocki, viresh.kumar
Cc: juri.lelli, skannan, linux-pm, Vikram Mulukutla
With a shared policy in place, when one of the CPUs in the policy is
hotplugged out and then brought back online, sugov_stop and
sugov_start are called in order.
sugov_stop removes utilization hooks for each CPU in the policy and
does nothing else in the for_each_cpu loop. sugov_start on the other
hand iterates through the CPUs in the policy and re-initializes the
per-cpu structure _and_ adds the utilization hook. This implies that
the scheduler is allowed to invoke a CPU's utilization update hook
when the rest of the per-cpu structures have yet to be re-inited.
Apart from some strange values in tracepoints this doesn't cause a
problem, but if we do end up accessing a pointer from the per-cpu
sugov_cpu structure somewhere in the sugov_update_shared path,
we will likely see crashes since the memset for another CPU in the
policy is free to race with sugov_update_shared from the CPU that is
ready to go. So let's fix this now to first init all per-cpu
structures, and then add the per-cpu utilization update hooks all at
once.
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
---
kernel/sched/cpufreq_schedutil.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 076a2e3..29a3970 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -610,6 +610,11 @@ static int sugov_start(struct cpufreq_policy *policy)
sg_cpu->sg_policy = sg_policy;
sg_cpu->flags = SCHED_CPUFREQ_RT;
sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
+ }
+
+ for_each_cpu(cpu, policy->cpus) {
+ struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
+
cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,
policy_is_shared(policy) ?
sugov_update_shared :
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq: schedutil: Fix sugov_start versus sugov_update_shared race
2017-07-06 17:53 [PATCH] cpufreq: schedutil: Fix sugov_start versus sugov_update_shared race Vikram Mulukutla
@ 2017-07-06 20:48 ` Rafael J. Wysocki
2017-07-07 3:25 ` Viresh Kumar
1 sibling, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2017-07-06 20:48 UTC (permalink / raw)
To: Vikram Mulukutla
Cc: rafael.j.wysocki, viresh.kumar, juri.lelli, skannan, linux-pm
On Thursday, July 06, 2017 10:53:20 AM Vikram Mulukutla wrote:
> With a shared policy in place, when one of the CPUs in the policy is
> hotplugged out and then brought back online, sugov_stop and
> sugov_start are called in order.
>
> sugov_stop removes utilization hooks for each CPU in the policy and
> does nothing else in the for_each_cpu loop. sugov_start on the other
> hand iterates through the CPUs in the policy and re-initializes the
> per-cpu structure _and_ adds the utilization hook. This implies that
> the scheduler is allowed to invoke a CPU's utilization update hook
> when the rest of the per-cpu structures have yet to be re-inited.
>
> Apart from some strange values in tracepoints this doesn't cause a
> problem, but if we do end up accessing a pointer from the per-cpu
> sugov_cpu structure somewhere in the sugov_update_shared path,
> we will likely see crashes since the memset for another CPU in the
> policy is free to race with sugov_update_shared from the CPU that is
> ready to go. So let's fix this now to first init all per-cpu
> structures, and then add the per-cpu utilization update hooks all at
> once.
>
> Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
OK
Any objections anyone?
> ---
> kernel/sched/cpufreq_schedutil.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> index 076a2e3..29a3970 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -610,6 +610,11 @@ static int sugov_start(struct cpufreq_policy *policy)
> sg_cpu->sg_policy = sg_policy;
> sg_cpu->flags = SCHED_CPUFREQ_RT;
> sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
> + }
> +
> + for_each_cpu(cpu, policy->cpus) {
> + struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
> +
> cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,
> policy_is_shared(policy) ?
> sugov_update_shared :
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq: schedutil: Fix sugov_start versus sugov_update_shared race
2017-07-06 17:53 [PATCH] cpufreq: schedutil: Fix sugov_start versus sugov_update_shared race Vikram Mulukutla
2017-07-06 20:48 ` Rafael J. Wysocki
@ 2017-07-07 3:25 ` Viresh Kumar
2017-07-12 21:33 ` Rafael J. Wysocki
1 sibling, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2017-07-07 3:25 UTC (permalink / raw)
To: Vikram Mulukutla; +Cc: rafael.j.wysocki, juri.lelli, skannan, linux-pm
On 06-07-17, 10:53, Vikram Mulukutla wrote:
> With a shared policy in place, when one of the CPUs in the policy is
> hotplugged out and then brought back online, sugov_stop and
> sugov_start are called in order.
>
> sugov_stop removes utilization hooks for each CPU in the policy and
> does nothing else in the for_each_cpu loop. sugov_start on the other
> hand iterates through the CPUs in the policy and re-initializes the
> per-cpu structure _and_ adds the utilization hook. This implies that
> the scheduler is allowed to invoke a CPU's utilization update hook
> when the rest of the per-cpu structures have yet to be re-inited.
>
> Apart from some strange values in tracepoints this doesn't cause a
> problem, but if we do end up accessing a pointer from the per-cpu
> sugov_cpu structure somewhere in the sugov_update_shared path,
> we will likely see crashes since the memset for another CPU in the
> policy is free to race with sugov_update_shared from the CPU that is
> ready to go. So let's fix this now to first init all per-cpu
> structures, and then add the per-cpu utilization update hooks all at
> once.
>
> Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
> ---
> kernel/sched/cpufreq_schedutil.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> index 076a2e3..29a3970 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -610,6 +610,11 @@ static int sugov_start(struct cpufreq_policy *policy)
> sg_cpu->sg_policy = sg_policy;
> sg_cpu->flags = SCHED_CPUFREQ_RT;
> sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
> + }
> +
> + for_each_cpu(cpu, policy->cpus) {
> + struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
> +
> cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,
> policy_is_shared(policy) ?
> sugov_update_shared :
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq: schedutil: Fix sugov_start versus sugov_update_shared race
2017-07-07 3:25 ` Viresh Kumar
@ 2017-07-12 21:33 ` Rafael J. Wysocki
0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2017-07-12 21:33 UTC (permalink / raw)
To: Viresh Kumar, Vikram Mulukutla; +Cc: juri.lelli, skannan, linux-pm
On Friday, July 07, 2017 08:55:09 AM Viresh Kumar wrote:
> On 06-07-17, 10:53, Vikram Mulukutla wrote:
> > With a shared policy in place, when one of the CPUs in the policy is
> > hotplugged out and then brought back online, sugov_stop and
> > sugov_start are called in order.
> >
> > sugov_stop removes utilization hooks for each CPU in the policy and
> > does nothing else in the for_each_cpu loop. sugov_start on the other
> > hand iterates through the CPUs in the policy and re-initializes the
> > per-cpu structure _and_ adds the utilization hook. This implies that
> > the scheduler is allowed to invoke a CPU's utilization update hook
> > when the rest of the per-cpu structures have yet to be re-inited.
> >
> > Apart from some strange values in tracepoints this doesn't cause a
> > problem, but if we do end up accessing a pointer from the per-cpu
> > sugov_cpu structure somewhere in the sugov_update_shared path,
> > we will likely see crashes since the memset for another CPU in the
> > policy is free to race with sugov_update_shared from the CPU that is
> > ready to go. So let's fix this now to first init all per-cpu
> > structures, and then add the per-cpu utilization update hooks all at
> > once.
> >
> > Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
> > ---
> > kernel/sched/cpufreq_schedutil.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> > index 076a2e3..29a3970 100644
> > --- a/kernel/sched/cpufreq_schedutil.c
> > +++ b/kernel/sched/cpufreq_schedutil.c
> > @@ -610,6 +610,11 @@ static int sugov_start(struct cpufreq_policy *policy)
> > sg_cpu->sg_policy = sg_policy;
> > sg_cpu->flags = SCHED_CPUFREQ_RT;
> > sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
> > + }
> > +
> > + for_each_cpu(cpu, policy->cpus) {
> > + struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
> > +
> > cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,
> > policy_is_shared(policy) ?
> > sugov_update_shared :
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Applied, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-12 21:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-06 17:53 [PATCH] cpufreq: schedutil: Fix sugov_start versus sugov_update_shared race Vikram Mulukutla
2017-07-06 20:48 ` Rafael J. Wysocki
2017-07-07 3:25 ` Viresh Kumar
2017-07-12 21:33 ` Rafael J. Wysocki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.