From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3911D606A32F for ; Sat, 5 Dec 2026 13:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fcieklWD; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=UbH4SjBi DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=3phJX1PiBSqAF7XIO/PRQkVkwGlGPR+o3oVGZ5/saUE=; b=fcieklWDT8HfWOxaMeLJpd8i2C c9z69O8tC+fZN7bnwvKj+2m4f0L1VE+TqS1Kfw0Lu0PB6Dr6CGbS9hy4Qbs2O+mHTQC/dyWu0LZVG KuGqQVzrg9zURLrR8G/n72BK6uoItU1nTf25ZF/8Ohpk5qfUFvXdcD6kHNq3X/ctMjljnI0Cs2ymS Lc6/FGRuqWeO/iZ/f0NK/gZWtHme9kQEFf9bUw4lU3+Agtb+W/aOAKy2x3BWkNBXJhEV2JZxes8Ds SOWaBK4qjzbuaHGgxjf/Q4EKWP5eVb1JeMg5ciIqUuXRvriZaXN4w42FJe1Fe8GXQB3ltzYFDR6A2 uzE17x8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZpx8-00000002UEB-0cOg; Sat, 05 Dec 2026 13:37:26 +0000 Received: from mail-pf1-x445.google.com ([2607:f8b0:4864:20::445]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZpx3-00000002UCV-1UjH for linux-arm-kernel@lists.infradead.org; Sat, 05 Dec 2026 13:37:24 +0000 Received: by mail-pf1-x445.google.com with SMTP id d2e1a72fcca58-89fb6a45c48so1424394b3a.1 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.infradead.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=UbH4SjBigPPdlqUmHS9c13ybXSlH4yBzytznbHCMzj2BJiQsALJhSwgqWidR0H9iym GeVRw/0hKwVNbuQNHcbjN6Mt+Ot9V4dvCmLZuy0GT5ZQ2lirjTD4ITfWKFVly4jJ0yEZ UVnmEgVvmcxaDu5GUPbxSb0MMuClle6r31RVUUdda/4QSj5F7vZzBAbDHaKTLzX6lE2a ULu/w3FQsOzNDogsdoyd3h/K4wdKIC+rHzZLpBVfUMLnu5MYapltqFua34KkFQkupdjI Z6D6goQswSPld6elSp5dYQsJ430k75EvFQCs1hKjPh2Mg+f+iMaxJypGS8aMjvL8cytv D+vg== 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=nJ4t8rPJIFXi5gzqc3PFXgCyA5j0C3iAu0U/4MUiS52N21wzWLqo0QCsUBbDiBNP0l QcAdFNVd3dSPPtHYU2xQTsUkZi8cKgCyejGPiQnU3oq4L9MQbXDCGCYCGkZ4+FTMUlqE WtaC7HZsIITi7S4bwL1IVO2hUJCgSjNBlVxuUeCOUf9aDgTIOpzdq7TMdbBlCM9lzyA0 AQmFRj/ooQMQb2ZJ3up/nf5I7YMRu153AyEWPKuk0jYbdgwhXTUR3J7IkORtukBWxY5o 9AccDJckooxb6FCOgSKXjcz2QzY8DdobLupTmU8ota0aFD6Kt2ny9RS3zfAt5vkQThA5 tnmA== X-Forwarded-Encrypted: i=1; AL+hErG2jWXT90tyFz+wLZmRiYSxdxGHaOq/daXNH1YXWRlZyJYlLhwD13awweqjfSQnapNjkBszZW9lcmZR1ZN/pdPu@lists.infradead.org X-Gm-Message-State: APuU4Z+alWabO8qaAAYYNrkEHtiszwOWIcQxz8HSNecfK/711Oi4mxGF LXY4SMN+76FmpMYs0dMb4RB92bG0koR0kR4zdQ1ycM2S22jXn1yVMEZKmgU1e83BosXhdrjQeoT OEg== 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-Archived-By: 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" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261205_053721_432767_94648817 X-CRM114-Status: GOOD ( 16.96 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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