Re: [PATCH] cpufreq: fix race on cpufreq online

From: Viresh Kumar
Date: Mon May 09 2022 - 23:53:17 EST


On 09-05-22, 23:06, Schspa Shi wrote:
> I am very sorry for this oversight.

No issues, I am partly to blame for not reviewing it as well.

> To fix this issue, there is no need to move cpufreq_driver->exit(policy)
> and cpufreq_driver->offline(policy) to inside of &policy->rwsem.
> I made this change because they are inside of &policy->rwsem write lock
> at cpufreq_offline. I think we should keep offline & exit call inside of
> policy->rwsem for better symmetry.
>
> static int cpufreq_offline(unsigned int cpu)
> {
> ...
> down_write(&policy->rwsem);
> ...
> /*
> * Perform the ->offline() during light-weight tear-down, as
> * that allows fast recovery when the CPU comes back.
> */
> if (cpufreq_driver->offline) {
> cpufreq_driver->offline(policy);
> } else if (cpufreq_driver->exit) {
> cpufreq_driver->exit(policy);
> policy->freq_table = NULL;
> }
>
> unlock:
> up_write(&policy->rwsem);
> return 0;
> }
>
> > The very first thing we need to do now is revert this patch. Lemme
> > send a patch for that and you can send a fresh fix over that once you
> > have a stable fix.
>
> For the next version of the stable fix, I'd be willing to keep exit and
> offline calls inside of policy->rwsem. But it's OK for me to keep offline
> & exit calls outside of policy->rwsem.

Just send a patch with whatever you think is the right fix and lets
take it from there.

--
viresh