From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796477840; b=tzpX4RwxbMbFe9d/jcdAAww/1alsENgZFwyWlrqkahw1NQK2ujmRx794LjUau7A5AOUa N+NQZ31BvUHy+hBtO6VRtl1mxNxsNrXVL3ZEaCMZZHxY/Trlr/BIDE8YINayLFCkTgTrY aAGNjfcF8xmzpET1wI6jv9ceKTwVvwC3JEEkR6gfLzUx0Tqfwg1D9fpqAI3e5al66zEBm YzCMd9XWDjfoD76D0wr8Vmi6kVpZzFoKFdXuNMZWglP1e/q3QyHMH1yhZ0sW6O9Fe0Z77 X5W/s0i13dawCe4bRIvhVCwrErR/NZnybjUu5krUYEj2S1UAu/NGi5F72csMvdpxSrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796477840; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=3phJX1PiBSqAF7XIO/PRQkVkwGlGPR+o3oVGZ5/saUE=; b=IovnHlDi1noozZM2B8lkzAigsbzOK3ytcGgtzIdbWPt/aSGsxkheXsBjcEX8NT31kdhL isoznjJsW4WUt7MrtqsOSN/88pxxSP5zexrCrGSruBvyZiB4+oWpvG32l8Ex+hldbTGhO UsFdoeNgwXM/CfFsVavR9060GrpdkKEUGP1N+nKlhWER6SunPedwnomVdC2/qaXSmldfl kk6on8UiQePcQHBomfzUGL6PUMLZtalVh/na/YE4BeiKNU5ZfEJcW+aDFzgWkUxXyX4uT WFpXBSefXJXio8kuCucSEX2XlckVcGhcEorIQTiH0d14zHQvUvGSfSTgkailrmhw/zA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=QZUNoMAy; arc=none smtp.remote-ip=209.85.210.197 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 759B2606A683 for ; Sat, 5 Dec 2026 13:37:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 759B2606A683 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=QZUNoMAy Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-8a0522cdaf3so1279362b3a.0 for ; Sat, 05 Dec 2026 05:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796477840; x=1797082640; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3phJX1PiBSqAF7XIO/PRQkVkwGlGPR+o3oVGZ5/saUE=; b=QZUNoMAyQkTjp5lHInfo48TqhHjJDBba1vNuQ1am/KXJgE2gsmntcEnMQ7dve/IOsL suUPuaURTPmltPKsGfprDEpy9ZH7J/LxxDionbxo7eAHu2vem1RF3DJE6C7aAx33xFIV wxe+EdeRIfL+3NpsdI98TUZO9g9uXTFHP40O14AZknFMjkJMpb56u/SxTfre6NA934KG uhFGhbzMe24oJTh+LnZuzgq8B+lpIK7PmBxN3yy9UrOYAcYKzI1vvwkzb7WADYtBxNT8 S7syRMr9W3XWd2+Yan3aiY2AdAvKOtyaCm6y2jC2IfQuPwBnlNhS9CO6604mShgAOb7j xWnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796477840; x=1797082640; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3phJX1PiBSqAF7XIO/PRQkVkwGlGPR+o3oVGZ5/saUE=; b=viZ9jaobjBRH+fjV28WA+y61Tr1MsHALU69LLayAoi1mBm0P2kzxrxgavZFfmuETud uRES4EMv/4r3q2yCBq8sMBxY7tO7k5KOZi9NdzsbA8CzWpSslDV70GpThx9C7kos1eQZ 0sBNiJNBhmgPcT2IqI+XTAJawIcxo9sB0VCluaFW2z4VsyGt2vr0FFl151gC7zgE3tKy ZC1qt5ouKoeyeuyaYG2JSAqSAmVaNz3bSCsLWMYjwYAxi+d8wtn/58dnoUi4Z9zUdrtC AE0M6weKe0UcImjS8XeLQ9FE5S4xXKx9vyN+3jfCCi6ufVZ1tbLaMBB+fRqxnaQvat0q i0kw== X-Forwarded-Encrypted: i=1; AL+hErHR09+Tb4UGDXgFUSaHroPOf+wlchW8der5k2Ek/FmFIWCWeGknRmkqpYXsmjAa+ni2sJD5c4Vtpn+bPBM=@vger.kernel.org X-Gm-Message-State: APuU4Z+5+3MmURtmA65/PYlSNMNsrMD1bD+/LNtRvpi73ZG2XD3aSpXo +lXrCElCMHLlFbzbnmBG2y4vha842ugpnqJk1lxPcqOtycFpEws7ngwoZ3MPhyE+G+SVWiucuCW z/w== X-Received: from pfgu33.prod.google.com ([2002:a05:6a00:9a1:b0:88f:3126:fa44]) (user=wakel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:22c8:b0:89f:d9b2:4a1c with SMTP id d2e1a72fcca58-8de2d52a9eemr4438188b3a.28.1796477839479; Sat, 05 Dec 2026 05:37:19 -0800 (PST) Date: Sat, 5 Dec 2026 13:37:17 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261205133717.1004788-1-wakel@google.com> Subject: [PATCH] arch_topology: Always call cpu_smt_set_num_threads() at init From: Wake Liu 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@lists.infradead.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, Wake Liu Content-Type: text/plain; charset="UTF-8" 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 --- 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