Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Wake Liu <wakel@google.com>
To: Sudeep Holla <sudeep.holla@kernel.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>,
	Johan Hovold <johan@kernel.org>,
	 Yicong Yang <yangyicong@hisilicon.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Pierre Gondois <pierre.gondois@arm.com>,
	 Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Hanjun Guo <guohanjun@huawei.com>,
	 linux-arm-kernel@lists.infradead.org,
	driver-core@lists.linux.dev,  linux-kernel@vger.kernel.org,
	Wake Liu <wakel@google.com>
Subject: [PATCH] arch_topology: Always call cpu_smt_set_num_threads() at init
Date: Sat,  5 Dec 2026 13:37:17 +0000	[thread overview]
Message-ID: <20261205133717.1004788-1-wakel@google.com> (raw)

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



                 reply	other threads:[~2026-12-05 13:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261205133717.1004788-1-wakel@google.com \
    --to=wakel@google.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=catalin.marinas@arm.com \
    --cc=dakr@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=guohanjun@huawei.com \
    --cc=johan@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pierre.gondois@arm.com \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@kernel.org \
    --cc=yangyicong@hisilicon.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