From nobody Mon Feb 9 11:31:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51BDB13777A for ; Tue, 4 Jun 2024 22:20:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717539605; cv=none; b=is1gSnxW0dA2uc/cx+Z4UQk62XvZcQX1hQPW215w5b4zzL4tm2eN6qf3O4laffzGOU5VTJyok2oXvIOpd7shETmzhCPjy1q5kWmv77s/Uhi9O8ZZi33ZkXsrHHh91lbdCnFIWIxjZqKdxfHy2dIgW0X9FOCtb379SdYJPQxsuhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717539605; c=relaxed/simple; bh=8TiUNaMaAWC+yYz8ZOZ+uSMGvJ3zugJcjEr8p3x049k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mGc5I76IgwpbM/0vKyLvltQWYlcY51vmE0YuCIM91VaEnyJiTQvdhCbN8Bnx0Lq2+26e7ypR/kkhmDFVbcjs61GeviUHI59ItfwrHNiRq8rFlhcR/iLtrn/FRj2u2GDFqASQ4xW6wtfslaC3FAYOBkpFnxAu+z3c6LAomDeHxgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RrZPatv2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RrZPatv2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B07BC2BBFC; Tue, 4 Jun 2024 22:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717539605; bh=8TiUNaMaAWC+yYz8ZOZ+uSMGvJ3zugJcjEr8p3x049k=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=RrZPatv2/4me2R2HIf4eY2RWuUH+HNEwQYbCVvVij+b2+dHQKxu+ycV6D+TjS1rFm 9yoyqE3CfEZPw2ipUf/bQ3NwRLJ1Ms7ZvkkgIxMLIRb9ePi3atyUFeSyb2T5m1tHNX +XAUITBdeMXDWc6ELdZ774c6WRKJJ5c2ZMN6dYwNcpuSuKxPauEquzIDWgH4d93ZGa HXrXFPsNYneke0Fbo0hjlQhgVfGZWwvddqGIFi4r/VVisICcsVBaxpuuln/iLaPp9r w8UekpL+YL+9BfZUVJeSD2rpmYvRjAorQdNBazVdTmQ9jtPHkDaT3ZKxh9M7zd7cGT mxI4qbN4BlB5A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B4B51CE3ED6; Tue, 4 Jun 2024 15:20:04 -0700 (PDT) Date: Tue, 4 Jun 2024 15:20:04 -0700 From: "Paul E. McKenney" To: Feng Tang Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Zhengxu Chen , Danielle Costantino , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , Waiman Long , John Stultz , Boqun Feng , Neeraj Upadhyay Subject: [PATCH RFC v4 tsc] Check for sockets instead of CPUs to make code match comment Message-ID: Reply-To: paulmck@kernel.org References: <62a0a0cd-3103-4e8f-b4c8-a91f12121e92@paulmck-laptop> <4b6724fb-2fb7-4081-ba1d-0797d746d9b8@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The unsynchronized_tsc() eventually checks num_possible_cpus(), and if the system is non-Intel and the number of possible CPUs is greater than one, assumes that TSCs are unsynchronized. This despite the comment saying "assume multi socket systems are not synchronized", that is, socket rather than CPU. This behavior was preserved by commit 8fbbc4b45ce3 ("x86: merge tsc_init and clocksource code") and by the previous relevant commit 7e69f2b1ead2 ("clocksource: Remove the update callback"). The clocksource drivers were added by commit 5d0cf410e94b ("Time: i386 Clocksource Drivers") back in 2006, and the comment still said "socket" rather than "CPU". Therefore, bravely (and perhaps foolishly) make the code match the comment. Note that it is possible to bypass both code and comment by booting with tsc=3Dreliable, but this also disables the clocksource watchdog, which is undesirable when trust in the TSC is strictly limited. [ paulmck: Switch from nr_online_nodes to topology_max_packages() per Feng = Tang feedback. ] Reported-by: Zhengxu Chen Reported-by: Danielle Costantino Signed-off-by: Paul E. McKenney Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Peter Zijlstra Cc: Feng Tang Cc: Waiman Long Cc: John Stultz Cc: Neeraj Upadhyay Cc: --- The only change since v3 is forward-porting to v6.10-rc1. diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 06b170759e5bf..3640bf119f127 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1289,7 +1289,7 @@ int unsynchronized_tsc(void) */ if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL) { /* assume multi socket systems are not synchronized: */ - if (num_possible_cpus() > 1) + if (topology_max_packages() > 1) return 1; }