From nobody Wed Dec 17 23:33:52 2025 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FgWbrj+/" 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-Disposition: inline In-Reply-To: <4b6724fb-2fb7-4081-ba1d-0797d746d9b8@paulmck-laptop> 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: 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 !=3D X86_VENDOR_INTEL) { /* assume multi socket systems are not synchronized: */ - if (num_possible_cpus() > 1) + if (topology_max_packages() > 1) return 1; }