linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: 'Guanjun' <guanjun@linux.alibaba.com>
To: schspa@gmail.com, rafael@kernel.org, viresh.kumar@linaro.org
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	guanjun@linux.alibaba.com, zelin.deng@linux.alibaba.com
Subject: [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU
Date: Wed, 19 Oct 2022 16:40:45 +0800	[thread overview]
Message-ID: <1666168845-67690-2-git-send-email-guanjun@linux.alibaba.com> (raw)
In-Reply-To: <1666168845-67690-1-git-send-email-guanjun@linux.alibaba.com>

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


  reply	other threads:[~2022-10-19  8:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19  8:40 [PATCH 0/1] cpufreq: Fix show()/store() issue for hotplugging 'Guanjun'
2022-10-19  8:40 ` 'Guanjun' [this message]
2022-10-19 11:47   ` [PATCH 1/1] cpufreq: Fix show()/store() issue for hotplugging offline CPU Rafael J. Wysocki
2022-10-21  6:11     ` guanjun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1666168845-67690-2-git-send-email-guanjun@linux.alibaba.com \
    --to=guanjun@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=schspa@gmail.com \
    --cc=viresh.kumar@linaro.org \
    --cc=zelin.deng@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).