Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2926576lqz; Wed, 3 Apr 2024 12:33:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWGF0hcQc3h0DPTX9hj+RY18X3f4vSF0no+FE/4mmz+D+fZ2S8m6VRZCr6BcJ6/EZDATmD792R/aDg8FBP4vuFqemzvSt4X2sWwaYWCfA== X-Google-Smtp-Source: AGHT+IFlErxxsu2+hN9WOXgjPMc875jQbqc4qsyT6jprCpy4br4GiPL5U06b6qKMfo8+yKHmwBrh X-Received: by 2002:a05:6a20:3c88:b0:1a5:7979:3349 with SMTP id b8-20020a056a203c8800b001a579793349mr752547pzj.6.1712172823868; Wed, 03 Apr 2024 12:33:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712172823; cv=pass; d=google.com; s=arc-20160816; b=xYeA303qli+S7fdCyDthffL49u0IVnKG+f8W5VxjFgqzJ4VVVfQ+ph8/IUpKrAqZUm p1tkFCu4DJqTqpl1vnsT+Vz5RCpswMlLBIZ7gK9lq/9KvEAdR2Gs9y4D6vJyxt3rDB5c U1vLd9BnSvkNjyEp/p7Teu2z7NWuSlWT23yVRu13vlD/1s+6UxCefNf4JWrJTP0qlwzw R8sG+CY9B33PrfYZwoAwqXtTPGyUJeQI8jwhTZlgfSBucmr/+R+as95nAzF8gSJGm9b6 kkM5zJptYJ7pk/Cdz/aAmVR4Mjgry+e0Uxm+vNeIHFRxRZyvpkA+ncJvqznkXrNffXIq q0BA== ARC-Message-Signature: i=2; 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=L/b+rfAicXVXKFrq0uTbj8sSkxQA0HwVxSmVKpr6sgY=; fh=Tnw9f4AbXkpGOKlKQOa1ERH2Uh3G7ABrchVJgFNHhBk=; b=wDvZWYrBrGv28KJ8sfsyYlX88q9e/IcjzaAmffNLQSjngkdZVj9eV3cUhx9DzsZ8fE q6FB7POvTmYjXclgdrTMPsx+NRkZ0B9NdfqmHy5K71lqSliDeRu3xz/qBUWn2CWsy1N6 c411w53WtTLH7RbIPypuBilmDd02OVX+FjzcTAG6mgmvR+bb7EHISOdQ4ZNv8g49gZiN J1+0u4sEwq9wyoexvdFY4XS9mgTDNz/2GxWWT1r26haywwR6sSLgwyz3clxzWvky/mKK raXDvc+nNMs/nmuHQ9rhUjbTwYALRT7hZKx00IagCUr0UnjotvZQG0NlWPPg2BvkoDZu okvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UXdSCBef; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-130487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130487-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 l9-20020a170903120900b001dcd642ab02si14001667plh.75.2024.04.03.12.33.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 12:33:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130487-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=UXdSCBef; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-130487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130487-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 F155FB27413 for ; Wed, 3 Apr 2024 19:10:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7D8A154C09; Wed, 3 Apr 2024 19:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UXdSCBef" 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 CF08553A7 for ; Wed, 3 Apr 2024 19:10:42 +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=1712171442; cv=none; b=F8NqpVH68mW1r0YwFiiggX7Ua2/6nnFYgIgMGM8+XymCBZ0gq6BfQwuQCyQE9uhWD31/JAAlRE/5IDwPxeaT/BK6a/6uft1TMXwmA2pBFVqRtODPgDgFgQW387tnQfrHKR0MSaPjqpOkm0hpXHZruNQGptQooeEP5/doBHkjRJo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712171442; c=relaxed/simple; bh=MY0qMhK+Ip066j30e2Fo5r+ntZnfCU7bAxLRrjL4Czw=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=UtBOX2FiMHocPcx1qMuBK8+HHVELuuBKoAUYzfELy8Bs4gjphfVWe1suSK2e0asVIKopi8YkCYGd3qNqJepHf1mmr28r99dLNCUslx7RDhVIR/gZEFufjgUtZvVkFOKgKrzKVckZhXbZEO0wou8c3yFM9XIfIkBlh2Pr8HG6a/M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UXdSCBef; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B90DC433C7; Wed, 3 Apr 2024 19:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712171442; bh=MY0qMhK+Ip066j30e2Fo5r+ntZnfCU7bAxLRrjL4Czw=; h=Date:From:To:Cc:Subject:Reply-To:From; b=UXdSCBefo6FnAJG45R4BUy0s90IK4srpa/j731QW3nACmIUJE2aGC/k1/eVvYbI3K HtfDdiyv/Em78GOCqVSzFp7wPzBArHqrd1XPGogosAJNhUGvQLNF8m0M000DW2x99w Sas2Bmm29rjoZ0vx7bfW72FLDVYYr5BpG5/kQZQCd+GfU8+9naplIqnJaJCNkA6T5m Tfarpk8HTb50zyuCxPbR4u1VJuMNz6MQ7uBHR+WxdRHdSqiJDesYI8G7Is9DHhEk97 oNDDMo7O1UGyQrHRITcND/ezoZ2qCRGRZtXyWw9VwkPWXXe6rtvy/Z6MQHMCHkJSBH L5OuSB5OeKyNQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 014CDCE0D85; Wed, 3 Apr 2024 12:10:41 -0700 (PDT) Date: Wed, 3 Apr 2024 12:10:41 -0700 From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Zhengxu Chen , Danielle Costantino , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , Feng Tang , Waiman Long , John Stultz , Boqun Feng , Neeraj Upadhyay Subject: [PATCH RFC v2 tsc] Check for sockets instead of CPUs to make code match comment Message-ID: <62a0a0cd-3103-4e8f-b4c8-a91f12121e92@paulmck-laptop> 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. Changes since v1: o Forward-port to v6.9-rc1. 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..e938b990bea19 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 (nr_online_nodes > 1) return 1; }