[PATCH] arch_topology: Always call cpu_smt_set_num_threads() at init

From: Wake Liu

Date: Sat Dec 05 2026 - 08:37:27 EST


Currently cpu_smt_set_num_threads() is only called at the end of
parse_socket() and parse_acpi_topology(). Several initialization paths
in init_cpu_topology() return without ever calling it, including DT
systems without a /cpus or /cpus/cpu-map node (such as arm64 virtual
machines without a DT topology map), early error returns in
parse_socket() when parse_cluster() fails on a socket node, early error
returns in parse_acpi_topology() when PPTT is absent or invalid, and
systems with neither ACPI nor a populated DT.

In addition, if parse_dt_topology() fails after parse_socket() succeeds
(for example, when a possible CPU has package_id < 0),
init_cpu_topology() discards the topology via reset_cpu_topology() but
leaves SMT control enabled with the discarded max_smt_thread_num.

When cpu_smt_set_num_threads() is never called on an architecture that
selects CONFIG_HOTPLUG_SMT (such as arm64), kernel/cpu.c leaves
cpu_smt_control as CPU_SMT_ENABLED, cpu_smt_max_threads as 0, and
cpu_smt_num_threads as UINT_MAX. Reading
/sys/devices/system/cpu/smt/control then hits control_show() and prints
"-1" instead of "notsupported", violating the sysfs ABI and failing LTP
sys_cpu_smt01.

Have parse_acpi_topology() update the file-scope max_smt_thread_num
instead of a shadowed local variable, reset max_smt_thread_num to 1
alongside reset_cpu_topology() on any topology parsing error, and call
cpu_smt_set_num_threads() unconditionally once in init_cpu_topology().

Fixes: 5deb9c789ae4 ("arch_topology: Support SMT control for OF based system")
Fixes: e6b18ebfaf63 ("arm64: topology: Support SMT control on ACPI based system")
Signed-off-by: Wake Liu <wakel@xxxxxxxxxx>
---
drivers/base/arch_topology.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index e51fc9f5e976..816099269116 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -639,17 +639,6 @@ static int __init parse_socket(struct device_node *socket)
if (!has_socket)
ret = parse_cluster(socket, 0, -1, 0);

- /*
- * Reset the max_smt_thread_num to 1 on failure. Since on failure
- * we need to notify the framework the SMT is not supported, but
- * max_smt_thread_num can be initialized to the SMT thread number
- * of the cores which are successfully parsed.
- */
- if (ret)
- max_smt_thread_num = 1;
-
- cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num);
-
return ret;
}

@@ -854,7 +843,6 @@ static bool __init acpi_cpu_is_threaded(int cpu)
*/
__weak int __init parse_acpi_topology(void)
{
- unsigned int max_smt_thread_num = 1;
struct cpu_smt_info *entry;
struct xarray hetero_cpu;
unsigned long hetero_id;
@@ -923,7 +911,6 @@ __weak int __init parse_acpi_topology(void)
kfree(entry);
}

- cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num);
xa_destroy(&hetero_cpu);
return 0;
}
@@ -944,8 +931,11 @@ void __init init_cpu_topology(void)
* arch-specific early cache level detection a chance to run.
*/
reset_cpu_topology();
+ max_smt_thread_num = 1;
}

+ cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num);
+
for_each_possible_cpu(cpu) {
ret = fetch_cache_info(cpu);
if (!ret)
--
2.56.1.915.g69d5ec7298-goog