Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6853686rdb; Tue, 2 Jan 2024 16:31:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEE7jQ3LLi6n52XOTH0vf33FvlWBFD64UIQ/2fXkLnCj1Y1USMbwUGFczHxJIKKw9Sjf9cS X-Received: by 2002:a05:6a20:7a29:b0:196:39c2:3bf0 with SMTP id t41-20020a056a207a2900b0019639c23bf0mr233810pzh.22.1704241914634; Tue, 02 Jan 2024 16:31:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704241914; cv=none; d=google.com; s=arc-20160816; b=VCXRnd5Y4ka56tQyDaTlR2gEz5LN/WC37+Rz7+/DmX2beRzhJDUoweoJ01N0ft/cpp o7gpm77mjjktiBdxVI24YmiNyILJJbFUHEBiqIh0pxa99SntONYdmkzwZhTZuWf6bjdf w3SdxSxJlPTUdBXpu9sCDjx0anHdcuZujJtwS4nTAGTWzpoOaGOBqt4qcEaIM0xAzdlH 3tEPCjPsRqxQTKKtnsG6mid/i5T9jxEf3lPsjrn3+T1vcAvn+0t8/1Zs25fpR6XOM0q8 Soanr2bN2VGIH/9+9al27bpyyZbcBB8Sj6J9Hb1ZKeW+tRib+WjPXI25T1MtABmRjs7G n3LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=QjNkQAhusaOQTc56iP3ktEhJKnVc4JnoApSOmiw8y8E=; fh=AHzoIEtFTrZ5qQudBgIGjY66cZaOVH4xzttwc0Gd+hQ=; b=irgFsyhknBmu+1nFs+pZn1zRxFp/SppOjrrLeD+JAsuvP8aTzYqFxJ7rPYwEE/9EGq xJLCYjmWIOfsVCKMM8bZJ+ZfVIbLfru0wG/ePWSLNOmgdZEZ2TemBuCI5nu8M9ZpD8Kl RZGmiBcCz8mXcghVs76qIr3phl2vMBoLjf2CrB8CRQWvVwfrItF2d7pq2FSUHDurdH5D MduVZ+Gpa/AdSilc+k16SNxiDTrgQtg+2dRVxY7kYpeb/MQ82BhFijgbGdwXu2dqtK2e E754MkjGhZYYYtrS5/URE8soQA+RvSaytyRNkG2ELfhXLl5U66Oh9gg7OpF10sXRGHqD 981Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=toCVBpww; spf=pass (google.com: domain of linux-kernel+bounces-15001-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15001-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 x9-20020a654149000000b005a9fde46fa0si20230716pgp.130.2024.01.02.16.31.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 16:31:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15001-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=toCVBpww; spf=pass (google.com: domain of linux-kernel+bounces-15001-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15001-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 87250B2277E for ; Wed, 3 Jan 2024 00:31:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B8FF7F1; Wed, 3 Jan 2024 00:31:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="toCVBpww" X-Original-To: linux-kernel@vger.kernel.org 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 6161863C for ; Wed, 3 Jan 2024 00:31:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C52C2C433C8; Wed, 3 Jan 2024 00:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704241902; bh=c0hwMhIsCKXtfxkXFf6Gq2t1ll9WqyctEcwEz2UIEzo=; h=Date:From:To:Cc:Subject:Reply-To:From; b=toCVBpwwe1KnDV9/ZLIg406/wJF600ZU0JSCrpOfr4XneRIJiu2+tXkSsaQHZ4Hyi Vgg0jBeumqWujmxRLxhqm4j9Sq+twZdIngDDEd03T9nWrPcmD1DITLPu2B9kJAdPS0 FGh1MU8SKjFKu8thStTnxhWmKEsJoTBZQanQ/bI4hWmjRhJ46A84JrvnQ6Kbq/BpCx ctHlKoHbHf9nqfHOlJCYj0aXueWfijSBld5LMyM3fJn/oGB6Kqtl5/CK/8N+WC1gt7 YjcorpTd/Uk0K6ZHXts1iGdyahPbmB4GwswSz2+uah18QV68dr6ZF1b3aIR6Dcp9tQ ro9DjrJf3kLpQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 5A15FCE16DA; Tue, 2 Jan 2024 16:31:42 -0800 (PST) Date: Tue, 2 Jan 2024 16:31:42 -0800 From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: zhxchen17@meta.com, dcostantino@meta.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, feng.tang@intel.com, longman@redhat.com, jstultz@google.com Subject: [PATCH RFC tsc] Check for sockets instead of CPUs to make code match comment Message-ID: Reply-To: paulmck@kernel.org 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 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. 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: diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 15f97c0abc9d..d45084c6a15e 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1287,7 +1287,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 (nr_online_nodes > 1) return 1; }