From: Bowen You <youbowen2@huawei.com>
To: <tglx@linutronix.de>, <peterz@infradead.org>
Cc: <ldufour@linux.ibm.com>, <mpe@ellerman.id.au>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH] cpu/SMT: recover global num_threads after disable smt switch fail
Date: Tue, 30 Sep 2025 09:03:30 +0000 [thread overview]
Message-ID: <20250930090330.3633926-1-youbowen2@huawei.com> (raw)
When attempting to disable SMT with the following command:
`echo off > /sys/devices/system/cpu/smt/control`
if `cpuhp_smt_disable` fails due to a "resource busy" error, the global
variable `cpu_smt_num_threads` is incorrectly updated to the target value
despite the failure.
This state inconsistency leads to subsequent attempts to disable SMT being
ineffective since `cpu_smt_num_threads` equals `orig_threads`, preventing
`cpuhp_smt_disable` from being invoked. To recover functionality, users
must manually execute `echo on > /sys/devices/system/cpu/smt/control`,
which is undesirable.
This commit removes the `orig_threads` variable and update the global
`cpu_smt_num_threads` only after successfully switching the SMT state.
This ensures proper state management and prevents the system from entering
an inconsistent state.
Cc: stable@vger.kernel.org # v6.5+
Fixes: 7f48405c3c34 ("cpu/SMT: Allow enabling partial SMT states via sysfs")
Signed-off-by: Bowen You <youbowen2@huawei.com>
---
kernel/cpu.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index db9f6c539b28..a2420d8a6ae0 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2902,7 +2902,7 @@ static ssize_t
__store_smt_control(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- int ctrlval, ret, num_threads, orig_threads;
+ int ctrlval, ret, num_threads;
bool force_off;
if (cpu_smt_control == CPU_SMT_FORCE_DISABLED)
@@ -2935,16 +2935,16 @@ __store_smt_control(struct device *dev, struct device_attribute *attr,
if (ret)
return ret;
- orig_threads = cpu_smt_num_threads;
- cpu_smt_num_threads = num_threads;
-
force_off = ctrlval != cpu_smt_control && ctrlval == CPU_SMT_FORCE_DISABLED;
- if (num_threads > orig_threads)
+ if (num_threads > cpu_smt_num_threads)
ret = cpuhp_smt_enable();
- else if (num_threads < orig_threads || force_off)
+ else if (num_threads < cpu_smt_num_threads || force_off)
ret = cpuhp_smt_disable(ctrlval);
+ if (!ret)
+ cpu_smt_num_threads = num_threads;
+
unlock_device_hotplug();
return ret ? ret : count;
}
--
2.34.1
next reply other threads:[~2025-09-30 9:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 9:03 Bowen You [this message]
2025-11-26 3:56 ` youbowen (A)
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=20250930090330.3633926-1-youbowen2@huawei.com \
--to=youbowen2@huawei.com \
--cc=ldufour@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpe@ellerman.id.au \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®