From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796477840; b=IUGibI89rw3y/sYIVgsubURGVoGj7eGEMCGGv42r6uNA829+BfCvTYxuiGgKNfn9C8T2 RiBdOsAwRcHR6xGPhWuKeexq9kutzCr3EppE28lAx20NLF/dfHKuCAPk7GkOotdce6Yd7 vL3v2A9l5GKhwRfIFa19uwTivIEhA74ub/3NT4BWzS/KbZSvZUEaCyhqtPfvO28iUwnsy pkCsrlES94G56DElQBbyMidzHpJBrF3GN0h5ZNlaNYyNXaMzU2+N/crou21rZtkJZusJu tixFokPistlwOFQzPgb0E1lMtlTSZeX4j81lczeFU1+ZR8Oa0RtjzPSuVc2MfsBS2rg== 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=vUDPXJRkxEZ1AI5Y2UtXrG39hUPKcUhk3yscFclM70DkX0TzNfMk/ly9qpwPURjGRqGk M7A1iBevPEfn7e1RNtHO6DqjFi15akUvgKVcN24+1pAIydZ0UDv/yDJQGdDBTKh5USDAH U9bqJuLf11/FRZs5tN3sMMDI0D7E2RL938uFqYq9c4AZZxQS8V7m9SIf8y1v0YogeVnMj eHbaGgbw7YYuRUEUqnpI42VlMFEQOS9vtQ9+3XXDt9ejJ74fyso5GSfXdyBOXDh+XxPt+ 17c+LwCLnT82QxLh4wZErU9YAksUZIvvvLX1V7FRmidJ3WMrJEiUXDK/dctPiOleRDg== 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=TA7TTHtp; arc=none smtp.remote-ip=209.85.210.199 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (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 74DFD606A682 for ; Sat, 5 Dec 2026 13:37:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 74DFD606A682 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=TA7TTHtp Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-8dfaa6ecb58so396755b3a.2 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=lists.linux.dev; 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=TA7TTHtpHtroBy+vfR3riKVk5BrQ6QmXZDC89pogPqXTG/0tMktGGdTZInY66xB7ab FemvNs/ySA9Zal/1ZbSoyuio17SLXtejKTalJ9VqqLBNf+8dl1gHG6cDzq/f3njF1PKy TZqu6IIy9i2Wxccm3QA+Iwg4grpiGdBYc3/r+zdeESfoO9MKC+IHPFpKqp0/K6haxigL n3fiCcfGa3+rcctbMVEnsFFEkZ5u8MJdVL75eyZmlPDPBI03pYKZ50zdmf8MtiYlXjQH NMkOZ0q0IfZ0wcjQHvUyoZBqsk3KDrJGGlyYEMPyKR26ZOrnA5dqUTnLBJeSC88kyKfe nIBw== 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=axccCVy/RHBW2pm/Kz7Vac1Pj65Vsk9+wJwNI07376R+7scH5XhBZlkGRhQt/BcEZg 5GgUv/smLa4S0Eo5uGzHj/pQ8wNYuXtMJ7fv+I1TSx3upMybpRl5JsnI5qNczlK26gVi 5zUSKwFQVMTO/HRSCq+ztKx1GppzUiqupkq4CCPJq7T2N70SeIq5QehYDeFUV2ANav/r XCe+9m2KlOen8lumCusHN8Ydr4p+gL9kVH0c8Oag89nUVd84kDUB/jwxdYKjQK7fmBOV +I5DaO/vufhwpqnGrK30KgyWfCVtHDzU1nOIMktTld9UHNR4XQpjvTEKksEPt9/ukzGq WCrg== X-Forwarded-Encrypted: i=1; AL+hErHrs6Dzr1LKW+3hboZ6tCS7R8M60/PbO9wQdaQ6jGn7SUtKIXC/w+PKg0c+T3mWd6mnIvIwbCizAuGptQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+NN6ujdynnMyvxxo/KyLrlaHGLjQHO3wBvYrUzgfnVCZs9eogJ Fl/mGyP0fVcvJilulibpQZmAKj9YdVANIe2DuXqueagVHpnG57Dm9Bk8kOFWwz6psyS2qrQpy5S uLg== 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: driver-core@lists.linux.dev 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