All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] cpufreq: Fix show()/store() issue for hotplugging
@ 2022-10-19  8:40 'Guanjun'
  2022-10-19  8:40 ` [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU 'Guanjun'
  0 siblings, 1 reply; 4+ messages in thread
From: 'Guanjun' @ 2022-10-19  8:40 UTC (permalink / raw)
  To: schspa, rafael, viresh.kumar; +Cc: linux-pm, linux-kernel, guanjun, zelin.deng

From: Zelin Deng <zelin.deng@linux.alibaba.com>

Hello maintainers,

After I brought one CPU (64) offline, I got failure when I used lscpu:
lscpu: cannot read /sys/devices/system/cpu/cpu64/cpufreq/cpuinfo_max_freq: Device or resource busy

I found in commit d4627a287e251, policy_is_inactive() check was added to
avoid the case in which policy initialization failed. However it didn't
consider the situation in which policy has been created successfully but
is not inactive: CPU is hotplugging offline.

This patch just add an addtional check whether CPU is online or not to
fix the issue.

Zelin Deng (1):
  cpufreq: Fix show()/store() issue for hotplugging offline CPU

 drivers/cpufreq/cpufreq.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

-- 
2.32.0.GIT


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU
  2022-10-19  8:40 [PATCH 0/1] cpufreq: Fix show()/store() issue for hotplugging 'Guanjun'
@ 2022-10-19  8:40 ` 'Guanjun'
  2022-10-19 11:47   ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: 'Guanjun' @ 2022-10-19  8:40 UTC (permalink / raw)
  To: schspa, rafael, viresh.kumar; +Cc: linux-pm, linux-kernel, guanjun, zelin.deng

From: Zelin Deng <zelin.deng@linux.alibaba.com>

After brought one CPU offline, lscpu returned failure:

lscpu: cannot read /sys/devices/system/cpu/cpu64/cpufreq/cpuinfo_max_freq: Device or resource busy

which had blocked all outputs of lscpu.

This is not the case mentioned in commit d4627a287e251, as the policy
had been created successfully but is inactive due to CPU gets offline.
To fix this issue, just add an addtional check whether CPU is online or
not.

Fixes: d4627a287e251 ("cpufreq: Abort show()/store() for half-initialized policies")
Signed-off-by: Zelin Deng <zelin.deng@linux.alibaba.com>
Signed-off-by: Guanjun <guanjun@linux.alibaba.com>
---
 drivers/cpufreq/cpufreq.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 69b3d61852ac..aa238ba7d2fe 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -956,8 +956,12 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
 		return -EIO;
 
 	down_read(&policy->rwsem);
-	if (likely(!policy_is_inactive(policy)))
-		ret = fattr->show(policy, buf);
+	if (unlikely(policy_is_inactive(policy) && cpu_online(policy->cpu)))
+		goto err;
+
+	ret = fattr->show(policy, buf);
+
+err:
 	up_read(&policy->rwsem);
 
 	return ret;
@@ -974,8 +978,12 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
 		return -EIO;
 
 	down_write(&policy->rwsem);
-	if (likely(!policy_is_inactive(policy)))
-		ret = fattr->store(policy, buf, count);
+	if (unlikely(policy_is_inactive(policy) && cpu_online(policy->cpu)))
+		goto err;
+
+	ret = fattr->store(policy, buf, count);
+
+err:
 	up_write(&policy->rwsem);
 
 	return ret;
-- 
2.32.0.GIT


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU
  2022-10-19  8:40 ` [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU 'Guanjun'
@ 2022-10-19 11:47   ` Rafael J. Wysocki
  2022-10-21  6:11     ` guanjun
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2022-10-19 11:47 UTC (permalink / raw)
  To: Guanjun; +Cc: schspa, rafael, viresh.kumar, linux-pm, linux-kernel, zelin.deng

On Wed, Oct 19, 2022 at 10:40 AM Guanjun <guanjun@linux.alibaba.com> wrote:
>
> From: Zelin Deng <zelin.deng@linux.alibaba.com>
>
> After brought one CPU offline, lscpu returned failure:
>
> lscpu: cannot read /sys/devices/system/cpu/cpu64/cpufreq/cpuinfo_max_freq: Device or resource busy
>
> which had blocked all outputs of lscpu.

OK, so the policy->cpus mask is empty and -EBUSY is returned.

What's wrong?

> This is not the case mentioned in commit d4627a287e251, as the policy
> had been created successfully but is inactive due to CPU gets offline.

Yes, that's when policy_is_inactive(policy) returns "true" IIUC.

> To fix this issue, just add an addtional check whether CPU is online or
> not.

Which is racy.

Please explain the problem in the first place.

> Fixes: d4627a287e251 ("cpufreq: Abort show()/store() for half-initialized policies")
> Signed-off-by: Zelin Deng <zelin.deng@linux.alibaba.com>
> Signed-off-by: Guanjun <guanjun@linux.alibaba.com>
> ---
>  drivers/cpufreq/cpufreq.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 69b3d61852ac..aa238ba7d2fe 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -956,8 +956,12 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
>                 return -EIO;
>
>         down_read(&policy->rwsem);
> -       if (likely(!policy_is_inactive(policy)))
> -               ret = fattr->show(policy, buf);
> +       if (unlikely(policy_is_inactive(policy) && cpu_online(policy->cpu)))
> +               goto err;
> +
> +       ret = fattr->show(policy, buf);
> +
> +err:
>         up_read(&policy->rwsem);
>
>         return ret;
> @@ -974,8 +978,12 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
>                 return -EIO;
>
>         down_write(&policy->rwsem);
> -       if (likely(!policy_is_inactive(policy)))
> -               ret = fattr->store(policy, buf, count);
> +       if (unlikely(policy_is_inactive(policy) && cpu_online(policy->cpu)))
> +               goto err;
> +
> +       ret = fattr->store(policy, buf, count);
> +
> +err:
>         up_write(&policy->rwsem);
>
>         return ret;
> --
> 2.32.0.GIT
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU
  2022-10-19 11:47   ` Rafael J. Wysocki
@ 2022-10-21  6:11     ` guanjun
  0 siblings, 0 replies; 4+ messages in thread
From: guanjun @ 2022-10-21  6:11 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: schspa, viresh.kumar, linux-pm, linux-kernel, zelin.deng


Hi Rafael,

> 2022年10月19日 下午7:47,Rafael J. Wysocki <rafael@kernel.org> 写道:
> 
> On Wed, Oct 19, 2022 at 10:40 AM Guanjun <guanjun@linux.alibaba.com> wrote:
>> 
>> From: Zelin Deng <zelin.deng@linux.alibaba.com>
>> 
>> After brought one CPU offline, lscpu returned failure:
>> 
>> lscpu: cannot read /sys/devices/system/cpu/cpu64/cpufreq/cpuinfo_max_freq: Device or resource busy
>> 
>> which had blocked all outputs of lscpu.
> 
> OK, so the policy->cpus mask is empty and -EBUSY is returned.
> 
> What's wrong?

Here is all right.
The problem is that when I offline one cpu manually and lscpu will fail.
The reproduce process is as follows:
1. lscpu (success)
2. echo 0 > /sys/devices/system/cpu/cpu63/online (offline cpu63)
3. lscpu (fail, and print the error message, “lscpu: cannot read /sys/devices/system/cpu/cpu64/cpufreq/cpuinfo_max_freq: Device or resource busy”)

I think this failure doesn’t make sense.

Maybe I should make the commit message more readable.

Thanks,
Guanjun

> 
>> This is not the case mentioned in commit d4627a287e251, as the policy
>> had been created successfully but is inactive due to CPU gets offline.
> 
> Yes, that's when policy_is_inactive(policy) returns "true" IIUC.
> 
>> To fix this issue, just add an addtional check whether CPU is online or
>> not.
> 
> Which is racy.
> 
> Please explain the problem in the first place.
> 
>> Fixes: d4627a287e251 ("cpufreq: Abort show()/store() for half-initialized policies")
>> Signed-off-by: Zelin Deng <zelin.deng@linux.alibaba.com>
>> Signed-off-by: Guanjun <guanjun@linux.alibaba.com>
>> ---
>> drivers/cpufreq/cpufreq.c | 16 ++++++++++++----
>> 1 file changed, 12 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index 69b3d61852ac..aa238ba7d2fe 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -956,8 +956,12 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
>>                return -EIO;
>> 
>>        down_read(&policy->rwsem);
>> -       if (likely(!policy_is_inactive(policy)))
>> -               ret = fattr->show(policy, buf);
>> +       if (unlikely(policy_is_inactive(policy) && cpu_online(policy->cpu)))
>> +               goto err;
>> +
>> +       ret = fattr->show(policy, buf);
>> +
>> +err:
>>        up_read(&policy->rwsem);
>> 
>>        return ret;
>> @@ -974,8 +978,12 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
>>                return -EIO;
>> 
>>        down_write(&policy->rwsem);
>> -       if (likely(!policy_is_inactive(policy)))
>> -               ret = fattr->store(policy, buf, count);
>> +       if (unlikely(policy_is_inactive(policy) && cpu_online(policy->cpu)))
>> +               goto err;
>> +
>> +       ret = fattr->store(policy, buf, count);
>> +
>> +err:
>>        up_write(&policy->rwsem);
>> 
>>        return ret;
>> --
>> 2.32.0.GIT


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-21  6:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19  8:40 [PATCH 0/1] cpufreq: Fix show()/store() issue for hotplugging 'Guanjun'
2022-10-19  8:40 ` [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU 'Guanjun'
2022-10-19 11:47   ` Rafael J. Wysocki
2022-10-21  6:11     ` guanjun

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.