Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp407625lqb; Tue, 4 Jun 2024 15:26:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLczHMN29VeuE6dIqijxN0GgSK+aDPPBVFDnRZjPbWPa2k9SiMgQ2QALWCwvQ6mM7IpxdMy5Wf4n1hr8+lrUuSpOA1qPXIrBLE+c2Nug== X-Google-Smtp-Source: AGHT+IFChLjtUJFhmg6S8EMlikEdp3S6XeHPjRCfKU7277Yx3kzuolZghg+jvv8alszUWrifaTlP X-Received: by 2002:a17:902:e801:b0:1f2:fe82:21e9 with SMTP id d9443c01a7336-1f6a5a6af43mr10036735ad.46.1717539991759; Tue, 04 Jun 2024 15:26:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717539991; cv=pass; d=google.com; s=arc-20160816; b=E25UE8E4OeyhGwbZd/V8BFHPl58jzOMu/fmbPgyewMwfsaIGHH3lzmDz2Odh2VfQDI 92vxL7ZgRsXvYWkFpov7vtl+07WDX3Fm7ExbLyifuW2aW6K18FZhGEhTulwu8JYJzOCk Ct3cKh2/ECTOdiQhoRrCaoYLj0TQaAZcxGiV+9i3tRx+rc/CXC66Z+9qzXDk7cRzH+2f nE89PbvtglVxbDzx7ASdeq5Dxm8hqpWuh6BMUCzwHzNM3KxteGy/N4H05/xl1ClWUwKm gM9eKKcmaeLGIyBHTfksvMFWMJaxktq22srqAc+LZz3HaCdHOu/XNwIXGXZnmmxhgDma lliQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=Brrtkl/rJb+JygMPo0RSs8NGg61Zq/0E2Bg2mbGR5jg=; fh=8RyG5+2fMgScLOzqe4eipl6+OoKTMoDOp9FS+slVTq4=; b=qAnqrBZVl8rywk7mXxXknx+h+wbCuyhPbE/whdk2Gml/86MUJiJaFW/LGeJi3dzTMv Xyb4PWqeto+5vs9w7cadvdX/+ZDP4axYQfealiilpz25upHat0C54QAMshHIxHIw7q/Q 9CMfS5lhgqlu0k3QxJOEk0Jw2VwLqk4GZQT/bgLjhfnwovq9fbAERqyJaiv+cFVKDczv am+dWa7ZqbgcPOa9QoM38Lilu/4m4ib4lAGtK56J+eeiWqIAX7toZoI6+DwhdhZAyyZ3 fKRY7UJQqZzGvc6+IzkpbHzSQXERwMkAeyn6v7exi9fNy9rCfJ9jCObCTZ00Jf8SsGrX 0goA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RrZPatv2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201455-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f6721279d4si13891575ad.487.2024.06.04.15.26.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 15:26:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201455-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RrZPatv2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201455-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 71D70B27610 for ; Tue, 4 Jun 2024 22:20:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27F1114B078; Tue, 4 Jun 2024 22:20:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RrZPatv2" 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 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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=reliable, 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 != X86_VENDOR_INTEL) { /* assume multi socket systems are not synchronized: */ - if (num_possible_cpus() > 1) + if (topology_max_packages() > 1) return 1; }