Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp786678lqm; Wed, 1 May 2024 16:16:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUueY0LB8w+TimJ0LBKvzg7ZXAKg6Se99d3pkCh9QtYUTQNYOEY2Y6ZiZWGFc74I5dw+SUKr4jH4ZjLmPnfTPjHPBgNWP5RNk9nrq0qLw== X-Google-Smtp-Source: AGHT+IGsaJ588fmFp8szpzfhip7PXluYgn3QRWvtFTz2dhv+8K12y6cicq5F9UMvZsnPJsFplbF9 X-Received: by 2002:a17:903:18e:b0:1e3:ce12:ef77 with SMTP id z14-20020a170903018e00b001e3ce12ef77mr1449732plg.11.1714605390451; Wed, 01 May 2024 16:16:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714605390; cv=pass; d=google.com; s=arc-20160816; b=Ejo5URiqkvqcggKZdISrXMZFpoOoIjLHyrUkq/GhVHBAk6vYjp3cxIku/ZxDvbm8nd hGxu115ERIplUcmqHRt3eSVzICJPMsHzSV2sUFXMVThTiSgN/rODBTM/v1+s/pMhKJbm wlc6aEABWUMbAE2hx1gN32w5z+5C5HaYMLfippEj4uSUH7zCjaxJfLY4N/KrlWH5RK40 DCOP9LrgAjsCHt6EcuO/X3xVjjzP/UbWINnHvwFMIdNa1IWtYOyi1+UYY5ThlnPhr1RP nb+CY6eqMtuh80NI5KfdXxB0PLXWxAbMh9TO2RQKvu+cn/gumJyFoOtSx9ztUgjx4dGq 7amA== 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=NIIOF4QBmQe+bW6Lik3Wq5pNcrt+XbSJFCKlaGQTYTw=; fh=8RyG5+2fMgScLOzqe4eipl6+OoKTMoDOp9FS+slVTq4=; b=Fjxulz6pwqeg3PrllZoKVHckYO/MuXyGv0OHxCi3RBVmZzzOJeYcDCNid6iY5wvl4o kK22SdK4dTsEScsbUOoGW7M58FOKv8Hb4YiBecX5nEAWiFLe89jrjnxyDB0O7np+gn2L AA5+jlIhN7k7qK5DWuWPsslpSRcLPxlEd3KwubrVt4ITZlLSyQnV/oT1l5yaQzson1HX 6zBe5oM2C2vXsHpbn2BhF6YvionZ6oa1WbJS6TPv+l1w0R0pn951+bjeMYM0uHR89+Cl Uv7Gnw4XBk+AudZegMFgwkAEbvcabPclzvPuvTyJaOViy5G0SDXeV9bnINtcUyTP03xo L6KA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="FgWbrj+/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-165829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165829-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. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k6-20020a170902ba8600b001e500c3a269si24614828pls.418.2024.05.01.16.16.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 16:16:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="FgWbrj+/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-165829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165829-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 C4F8FB215EE for ; Wed, 1 May 2024 23:16:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E220168AE4; Wed, 1 May 2024 23:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FgWbrj+/" 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 AA2371649A8 for ; Wed, 1 May 2024 23:16:19 +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=1714605379; cv=none; b=UV58mRMV/GLBgd8B96b0H86aWAflOCK+4lgOm5I0c3XBw7GKhjy/7AzPf8XQZLEZJ/lMOwwZ2vdTjypp9xa1K8xkawWGTsMD28GiBhfBI7pUPdM/yDwK7n32gfPKQzxZhPHq0n0qqvUoQQYJGEyf2b0pAMmWBmjrVi4oRUNmuns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605379; c=relaxed/simple; bh=eA6Bqgpezupf42/4NRslV+u8V0YsI2GtSGd5jtItFeU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SATBF9PNtuZZKnM94G5k+rupZs9v3GsHaWlJmowJ4KozEjLgv5y+Q2FBfnUNNG8n3Z4SWk8CpjDm2HzjhY/a8FtVXbPHuydmMLDIxDLAkH99agbZvc4ZqNmHh1zfjC/wR3XVM7ki2QF7fYQUwCScN1bp7uP9HknekEsYAX1wXxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FgWbrj+/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3141AC072AA; Wed, 1 May 2024 23:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714605379; bh=eA6Bqgpezupf42/4NRslV+u8V0YsI2GtSGd5jtItFeU=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=FgWbrj+/kOawgLC90GqWNy8Kk5jt+0MFAIZTysPeA2G69ytKHorfEZpaI2uxbgs35 mpA57QN4Xh9Fs+28Tprtf1lLnY2SnPQihr5+43s7E+NefhhgEbju81aNxdCYUiBSPm sSbMyXRPf6lf+SmF+0Wo5tIb9Z3wY4X4f+8NOS0sF4DFhkgCoHojoq3N5NOPu3WA7B 7qXd3KutxhPdmcLzUJ1aYtAF6W6nJlJpLIMvDN/cNT30lu8/g/mFbSAroFFfEdY3Yx sHq/zB6oqbEAiRxrV3pzLfbldswirdE/ow1gnQblqe/mLobZtnwNliEPGeT2D/fDf6 Z1l+jrITVe8Jw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CAA9CCE1073; Wed, 1 May 2024 16:16:18 -0700 (PDT) Date: Wed, 1 May 2024 16:16:18 -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 v3 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: <4b6724fb-2fb7-4081-ba1d-0797d746d9b8@paulmck-laptop> 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: diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 5a69a49acc963..0e7f44cc168e2 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; }