Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arch_topology: Always call cpu_smt_set_num_threads() at init
@ 2026-12-05 13:37 Wake Liu
  0 siblings, 0 replies; only message in thread
From: Wake Liu @ 2026-12-05 13:37 UTC (permalink / raw)
  To: Sudeep Holla, Greg Kroah-Hartman, Rafael J . Wysocki
  Cc: Danilo Krummrich, Johan Hovold, Yicong Yang, Catalin Marinas,
	Dietmar Eggemann, Pierre Gondois, Jonathan Cameron, Hanjun Guo,
	linux-arm-kernel, driver-core, linux-kernel, Wake Liu

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@google.com>
---
 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



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05 13:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 13:37 [PATCH] arch_topology: Always call cpu_smt_set_num_threads() at init Wake Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox