<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/cpufreq/cpufreq.c, branch linux-5.19.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.19.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.19.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2022-09-15T08:47:09Z</updated>
<entry>
<title>cpufreq: check only freq_table in __resolve_freq()</title>
<updated>2022-09-15T08:47:09Z</updated>
<author>
<name>Lukasz Luba</name>
</author>
<published>2022-08-16T12:01:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=73085208dd6b1a83bc38aa74d79efaa5741c3436'/>
<id>urn:sha1:73085208dd6b1a83bc38aa74d79efaa5741c3436</id>
<content type='text'>
[ Upstream commit 6ca7076fbfaeccce173aeab832d76b9e49e1034b ]

There is no need to check if the cpufreq driver implements callback
cpufreq_driver::target_index. The logic in the __resolve_freq uses
the frequency table available in the policy. It doesn't matter if the
driver provides 'target_index' or 'target' callback. It just has to
populate the 'policy-&gt;freq_table'.

Thus, check only frequency table during the frequency resolving call.

Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Signed-off-by: Lukasz Luba &lt;lukasz.luba@arm.com&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>cpufreq: make interface functions and lock holding state clear</title>
<updated>2022-05-17T19:39:05Z</updated>
<author>
<name>Schspa Shi</name>
</author>
<published>2022-05-16T03:02:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=514ff1bcd98d7f57361025e2200b803d3ddde6c8'/>
<id>urn:sha1:514ff1bcd98d7f57361025e2200b803d3ddde6c8</id>
<content type='text'>
cpufreq_offline() calls offline() and exit() under the policy rwsem
But they are called outside the rwsem in cpufreq_online().

Make cpufreq_online() call offline() and exit() as well as online() and
init() under the policy rwsem to achieve a clear lock relationship.

All of the init() and online() implementations in the tree only
initialize the policy object without attempting to acquire the policy
rwsem and they won't call cpufreq APIs attempting to acquire it.

Signed-off-by: Schspa Shi &lt;schspa@gmail.com&gt;
Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>cpufreq: Abort show()/store() for half-initialized policies</title>
<updated>2022-05-17T19:39:04Z</updated>
<author>
<name>Schspa Shi</name>
</author>
<published>2022-05-16T03:02:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d4627a287e251efed59f2b4bda82c5950768c963'/>
<id>urn:sha1:d4627a287e251efed59f2b4bda82c5950768c963</id>
<content type='text'>
If policy initialization fails after the sysfs files are created,
there is a possibility to end up running show()/store() callbacks
for half-initialized policies, which may have unpredictable
outcomes.

Abort show()/store() in such a case by making sure the policy is active.

Also dectivate the policy on such failures.

Signed-off-by: Schspa Shi &lt;schspa@gmail.com&gt;
Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>cpufreq: Rearrange locking in cpufreq_remove_dev()</title>
<updated>2022-05-12T15:11:57Z</updated>
<author>
<name>Rafael J. Wysocki</name>
</author>
<published>2022-05-11T15:51:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f339f3541701d824a0256ad4bf14c26ceb6d79c3'/>
<id>urn:sha1:f339f3541701d824a0256ad4bf14c26ceb6d79c3</id>
<content type='text'>
Currently, cpufreq_remove_dev() invokes the -&gt;exit() driver callback
without holding the policy rwsem which is inconsistent with what
happens if -&gt;exit() is invoked directly from cpufreq_offline().

It also manipulates the real_cpus mask and removes the CPU device
symlink without holding the policy rwsem, but cpufreq_offline() holds
the rwsem around the modifications thereof.

For consistency, modify cpufreq_remove_dev() to hold the policy rwsem
until the -&gt;exit() callback has been called (or it has been determined
that it is not necessary to call it).

Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
</content>
</entry>
<entry>
<title>cpufreq: Split cpufreq_offline()</title>
<updated>2022-05-12T15:11:57Z</updated>
<author>
<name>Rafael J. Wysocki</name>
</author>
<published>2022-05-11T15:50:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fddd8f86dff4a24742a7f0322ccbb34c6c1c9850'/>
<id>urn:sha1:fddd8f86dff4a24742a7f0322ccbb34c6c1c9850</id>
<content type='text'>
Split the "core" part running under the policy rwsem out of
cpufreq_offline() to allow the locking in cpufreq_remove_dev() to be
rearranged more easily.

As a side-effect this eliminates the unlock label that's not needed
any more.

No expected functional impact.

Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
</content>
</entry>
<entry>
<title>cpufreq: Reorganize checks in cpufreq_offline()</title>
<updated>2022-05-12T15:11:57Z</updated>
<author>
<name>Rafael J. Wysocki</name>
</author>
<published>2022-05-11T15:48:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e1e962c5b9edbc628a335bcdbd010331a12d3e5b'/>
<id>urn:sha1:e1e962c5b9edbc628a335bcdbd010331a12d3e5b</id>
<content type='text'>
Notice that cpufreq_offline() only needs to check policy_is_inactive()
once and rearrange the code in there to make that happen.

No expected functional impact.

Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
</content>
</entry>
<entry>
<title>cpufreq: Clear real_cpus mask from remove_cpu_dev_symlink()</title>
<updated>2022-05-11T17:23:10Z</updated>
<author>
<name>Viresh Kumar</name>
</author>
<published>2022-05-11T09:06:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5c84c1b84bd80a735b2c7804e7be86d043fca595'/>
<id>urn:sha1:5c84c1b84bd80a735b2c7804e7be86d043fca595</id>
<content type='text'>
add_cpu_dev_symlink() is responsible for setting the CPUs in the
real_cpus mask, the reverse of which should be done from
remove_cpu_dev_symlink() to make it look clean and avoid any breakage
later on.

Move the call to clear the mask to remove_cpu_dev_symlink().

Signed-off-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>Revert "cpufreq: Fix possible race in cpufreq online error path"</title>
<updated>2022-05-09T16:51:54Z</updated>
<author>
<name>Viresh Kumar</name>
</author>
<published>2022-05-09T03:57:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=85f0e42bd65d01b351d561efb38e584d4c596553'/>
<id>urn:sha1:85f0e42bd65d01b351d561efb38e584d4c596553</id>
<content type='text'>
This reverts commit f346e96267cd76175d6c201b40f770c0116a8a04.

The commit tried to fix a possible real bug but it made it even worse.
The fix was simply buggy as now an error out to out_offline_policy or
out_exit_policy will try to release a semaphore which was never taken in
the first place. This works fine only if we failed late, i.e. via
out_destroy_policy.

Fixes: f346e96267cd ("cpufreq: Fix possible race in cpufreq online error path")
Signed-off-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>cpufreq: Avoid unnecessary frequency updates due to mismatch</title>
<updated>2022-05-06T18:56:21Z</updated>
<author>
<name>Viresh Kumar</name>
</author>
<published>2022-05-04T08:21:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f55ae08c89873e140c7cac2a7fa161d31a0d60cf'/>
<id>urn:sha1:f55ae08c89873e140c7cac2a7fa161d31a0d60cf</id>
<content type='text'>
For some platforms, the frequency returned by hardware may be slightly
different from what is provided in the frequency table. For example,
hardware may return 499 MHz instead of 500 MHz. In such cases it is
better to avoid getting into unnecessary frequency updates, as we may
end up switching policy-&gt;cur between the two and sending unnecessary
pre/post update notifications, etc.

This patch has chosen allows the hardware frequency and table frequency
to deviate by 1 MHz for now, we may want to increase it a bit later on
if someone still complains.

Reported-by: Rex-BC Chen &lt;rex-bc.chen@mediatek.com&gt;
Signed-off-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Tested-by: Jia-wei Chang &lt;jia-wei.chang@mediatek.com&gt;
Reviewed-by: Matthias Brugger &lt;matthias.bgg@gmail.com&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>cpufreq: Fix possible race in cpufreq online error path</title>
<updated>2022-04-22T16:17:48Z</updated>
<author>
<name>Schspa Shi</name>
</author>
<published>2022-04-20T19:15:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f346e96267cd76175d6c201b40f770c0116a8a04'/>
<id>urn:sha1:f346e96267cd76175d6c201b40f770c0116a8a04</id>
<content type='text'>
When cpufreq online fails, the policy-&gt;cpus mask is not cleared and
policy-&gt;rwsem is released too early, so the driver can be invoked
via the cpuinfo_cur_freq sysfs attribute while its -&gt;offline() or
-&gt;exit() callbacks are being run.

Take policy-&gt;clk as an example:

static int cpufreq_online(unsigned int cpu)
{
  ...
  // policy-&gt;cpus != 0 at this time
  down_write(&amp;policy-&gt;rwsem);
  ret = cpufreq_add_dev_interface(policy);
  up_write(&amp;policy-&gt;rwsem);

  return 0;

out_destroy_policy:
	for_each_cpu(j, policy-&gt;real_cpus)
		remove_cpu_dev_symlink(policy, get_cpu_device(j));
    up_write(&amp;policy-&gt;rwsem);
...
out_exit_policy:
  if (cpufreq_driver-&gt;exit)
    cpufreq_driver-&gt;exit(policy);
      clk_put(policy-&gt;clk);
      // policy-&gt;clk is a wild pointer
...
                                    ^
                                    |
                            Another process access
                            __cpufreq_get
                              cpufreq_verify_current_freq
                                cpufreq_generic_get
                                  // acces wild pointer of policy-&gt;clk;
                                    |
                                    |
out_offline_policy:                 |
  cpufreq_policy_free(policy);      |
    // deleted here, and will wait for no body reference
    cpufreq_policy_put_kobj(policy);
}

Address this by modifying cpufreq_online() to release policy-&gt;rwsem
in the error path after the driver callbacks have run and to clear
policy-&gt;cpus before releasing the semaphore.

Fixes: 7106e02baed4 ("cpufreq: release policy-&gt;rwsem on error")
Signed-off-by: Schspa Shi &lt;schspa@gmail.com&gt;
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
</feed>
