From nobody Mon Feb 9 14:06:45 2026 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 AD4BA136327 for ; Fri, 2 Aug 2024 15:46:20 +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=1722613580; cv=none; b=hX1nHDgKRHd0UEBdjUJFcARj8GFeLQNTC8sgS8zKVmtRUIEN96/cT+qkaFbkxTAJF0RdBK8+7EZhxGwJtLihfhP4wEyr+HyGCIBYKwn64/j3GuCHso+xoSsbx0Y2Ae0+IudnWV9JcgVz1cZe6X6XnaSQftNTOBdZIi6U931ZPx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722613580; c=relaxed/simple; bh=gTzPjXYIttOOUwONwdIqZuA0ctMD+wdU/R7cWk5x6w0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NzHfmDDa8oHgxTV0y9zUUDK8Gx4nOr4rOJAaCuhOzooRG1VTzv0UAAGT5o5e2Ch/YCo3GgMVpucHAYdtto8v/YRg/+EV1JPJQ9Urh+ODOoUb9d3hXXTjXE+7TisUhnt/lvXMuEp3NOEjJ4UMygZT14YdkQZ8hSfnSgcVXgyFqR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wm9Rd7kE; 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="Wm9Rd7kE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38937C32782; Fri, 2 Aug 2024 15:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722613580; bh=gTzPjXYIttOOUwONwdIqZuA0ctMD+wdU/R7cWk5x6w0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wm9Rd7kERaYGURrfBPZ8OhDAbkUdcdWnvGV9YMNmTTphNstqN7VFAg4uExtLIumyZ 3bFczXVh5Aiz8BWsvF6hnhMy0TPTcv/bYK3uucyWS5vpkbykLdwdImCEe1Khdyy52B AetjL+IYFfUywPRGnZ+Y+1ss2AF5wITPyeRAcY4LpROHi8sUmfjh3oWe9vLEAIeJJ+ 1LbLYU8oJPejzy88zBwgjImR3R7EbEDUnj3BldR7NAz1wchnNylp9BnlSDWnlRBEa6 d0n8ajG+lBPiA5hiBsjlY70iYCdOgB3EvRihgvxomHtqEQNHMPwWWzTIkwseuyUsr0 kaO/NS4aEhUrA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F4178CE09DB; Fri, 2 Aug 2024 08:46:19 -0700 (PDT) From: "Paul E. McKenney" To: Ingo Molnar , Borislav Petkov , Dave Hansen Cc: "H. Peter Anvin" , John Stultz , Stephen Boyd , Peter Zijlstra , Feng Tang , Waiman Long , Neeraj Upadhyay , x86@kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, "Paul E . McKenney" , Thomas Gleixner Subject: [PATCH v2 TSC and clocksource-watchdog updates for v6.12 1/5] clocksource: Improve comments for watchdog skew bounds Date: Fri, 2 Aug 2024 08:46:14 -0700 Message-Id: <20240802154618.4149953-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Borislav Petkov Add more detail on the rationale for bounding the clocksource ->uncertainty_margin below at about 500ppm. Signed-off-by: Borislav Petkov Signed-off-by: Paul E. McKenney Cc: John Stultz Cc: Thomas Gleixner Cc: Stephen Boyd Cc: Feng Tang --- kernel/time/clocksource.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index d25ba49e313cc..9ca4e8d2a70f8 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -125,6 +125,13 @@ static u64 suspend_start; * * The default of 500 parts per million is based on NTP's limits. * If a clocksource is good enough for NTP, it is good enough for us! + * + * In other words, by default, even if a clocksource is extremely + * precise (for example, with a sub-nanosecond period), the maximum + * permissible skew between the clocksource watchdog and the clocksource + * under test is not permitted to go below the 500ppm minimum defined + * by MAX_SKEW_USEC. This 500ppm minimum may be overridden using the + * CLOCKSOURCE_WATCHDOG_MAX_SKEW_US Kconfig option. */ #ifdef CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US #define MAX_SKEW_USEC CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US @@ -1146,14 +1153,19 @@ void __clocksource_update_freq_scale(struct clockso= urce *cs, u32 scale, u32 freq } =20 /* - * If the uncertainty margin is not specified, calculate it. - * If both scale and freq are non-zero, calculate the clock - * period, but bound below at 2*WATCHDOG_MAX_SKEW. However, - * if either of scale or freq is zero, be very conservative and - * take the tens-of-milliseconds WATCHDOG_THRESHOLD value for the - * uncertainty margin. Allow stupidly small uncertainty margins - * to be specified by the caller for testing purposes, but warn - * to discourage production use of this capability. + * If the uncertainty margin is not specified, calculate it. If + * both scale and freq are non-zero, calculate the clock period, but + * bound below at 2*WATCHDOG_MAX_SKEW, that is, 500ppm by default. + * However, if either of scale or freq is zero, be very conservative + * and take the tens-of-milliseconds WATCHDOG_THRESHOLD value + * for the uncertainty margin. Allow stupidly small uncertainty + * margins to be specified by the caller for testing purposes, + * but warn to discourage production use of this capability. + * + * Bottom line: The sum of the uncertainty margins of the + * watchdog clocksource and the clocksource under test will be at + * least 500ppm by default. For more information, please see the + * comment preceding CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US above. */ if (scale && freq && !cs->uncertainty_margin) { cs->uncertainty_margin =3D NSEC_PER_SEC / (scale * freq); --=20 2.40.1 From nobody Mon Feb 9 14:06:45 2026 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 AD4742837A for ; Fri, 2 Aug 2024 15:46:20 +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=1722613580; cv=none; b=GsRTWS2nMiAlChIY5AO6erq8d0FnYEzDWws4+lQP9urpUd9MTTIkJ1ivVYF/zTjsNAoxxFTuSYeFglXuQ/dj98GsFdrZ4FqO1e7eGiHX7UI22LuVaAIZBBJZA0+8RdnyV/7K55We9etroHUQXra8maeGiQMW6FwJywRaDmxWBMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722613580; c=relaxed/simple; bh=wu/zhjKY8+yKuGmCQ0dFEhh5AEYVsRws4e6U2BZc7DU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HT2wsrvSVv0Q6yZPXRX5+knKFYzSE9oiqIQN4IhHVX05jzgtxRlepk5iQdN4C1IuUJFD1IFvA/FF+jMWXUtC5WZ+y1rkAYhSiXD4sMgiEIkmA9zBRHvCu4orwbD1TwJPr016zqzoBzFBunhIDkuKJKYuK4RTqEZo8izlc3Q/Wpc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fis4Egpi; 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="Fis4Egpi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56962C4AF0B; Fri, 2 Aug 2024 15:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722613580; bh=wu/zhjKY8+yKuGmCQ0dFEhh5AEYVsRws4e6U2BZc7DU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fis4Egpioj19AzzSD5qEkENsadf+v0dTZKLwbAHtgPzmjGk0yDPH5Vh646kJcZDCb X6vESJFXD1JxM/9kFGPTaCvvTy4A7vrHzRoUvw7eqFb8cAjf+qp5RvlmBzU+XPJK+H Aod5UVTcSOtApO6WBw8P354sz0ebSCMnyF2B2LP6zJ7HA3eeQ972JLJqKZaMZJ6C6b XyYYw5SKvqj+BzhTrKEcmdIrlOjQX9GRMxTNfAae8IQMYYwSVEksGOA0BCcRwQDTzs 5gGV5zxWqk7l5i6RC98YLQ+OcEa9RYxGM+nKIRc8HlpFhfd1STwnPfk6GOLntBmuhM V7YEtwyGSSg2w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 02E9CCE09DE; Fri, 2 Aug 2024 08:46:20 -0700 (PDT) From: "Paul E. McKenney" To: Ingo Molnar , Borislav Petkov , Dave Hansen Cc: "H. Peter Anvin" , John Stultz , Stephen Boyd , Peter Zijlstra , Feng Tang , Waiman Long , Neeraj Upadhyay , x86@kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, "Paul E. McKenney" Subject: [PATCH v2 TSC and clocksource-watchdog updates for v6.12 2/5] clocksource: Fix brown-bag boolean thinko in cs_watchdog_read() Date: Fri, 2 Aug 2024 08:46:15 -0700 Message-Id: <20240802154618.4149953-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current "nretries > 1 || nretries >=3D max_retries" check in cs_watchdog_read() will always evaluate to true, and thus pr_warn(), if nretries is greater than 1. The intent is instead to never warn on the first try, but otherwise warn if the successful retry was the last retry. Therefore, change that "||" to "&&". Reported-by: Borislav Petkov Fixes: db3a34e17433 ("clocksource: Retry clock read if long delays detected= ") Signed-off-by: Paul E. McKenney --- kernel/time/clocksource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 9ca4e8d2a70f8..581cdbb538448 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -253,7 +253,7 @@ static enum wd_read_status cs_watchdog_read(struct cloc= ksource *cs, u64 *csnow, =20 wd_delay =3D cycles_to_nsec_safe(watchdog, *wdnow, wd_end); if (wd_delay <=3D WATCHDOG_MAX_SKEW) { - if (nretries > 1 || nretries >=3D max_retries) { + if (nretries > 1 && nretries >=3D max_retries) { pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before suc= cess\n", smp_processor_id(), watchdog->name, nretries); } --=20 2.40.1 From nobody Mon Feb 9 14:06:45 2026 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 AD43E175D5F for ; Fri, 2 Aug 2024 15:46:20 +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=1722613580; cv=none; b=HsNGVWTR6ThPTjWAz+zkZTy/0PaROoAFdvL+Thyuot6gKm14lO+5FjeCjA26aFlQx06Om+O1p4Y3EEYXR7iV38j/Ur/efike6KyQsH/+P3LTh+ZB/FgZV44FrsAmnkCvxIzZRFTgNrC2NDrnAFeHF3PYqcvZTj1ii2CBYSmCXXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722613580; c=relaxed/simple; bh=NkGy99ttE/WMalc6vpGUP6nwyw6xu1BMaI7NQioFehE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=se4OLwhEwhL9lKawDDZ+eWD7wUSH9XfADY6NYfUhmxnEPLo4YS8GjcDQ+6Q2ql0qqkSM+Gv9XemDQqgdxSkm4OoYz0SoK5knwwVT9n2Ri/h8NxKIPHTOiNterUiZypRzZZ7VsiaPeeJ+LiJ0VQqDmjTegyzpmwEzTCDmRM/OIXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V4fkwL1R; 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="V4fkwL1R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D7ADC4AF11; Fri, 2 Aug 2024 15:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722613580; bh=NkGy99ttE/WMalc6vpGUP6nwyw6xu1BMaI7NQioFehE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V4fkwL1RLmMlC64WHE687M63QdWRYiVvJmzkbNELlaoQawaPeu8WwTVG2glAnHmI3 bZWRqn4scSiLorZhZwEWds1hSKImMyBWzimcsvcvno7BbhXJgrstvXGGAhEod+ZJ7F BeHRIiSutFe/ZLmqzjReBzvvWsc0haORn4illGdnYtl7RY6vnFn6Rc370p3vi66tOl bKCBeucmYHZBXN+/f+tzRJwDxbb6VN6ITaH1uNXS3MoYRRhH88yFWs+NDOTu6VNj9Y IZIpbVB6wjLqyDV61RAExyTCpaFnSQU7+xjsHxJE2oj8+7hVYx3Es71j5v0hcmDYCk IuoSkEebB1cqA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 05EEBCE0E5A; Fri, 2 Aug 2024 08:46:20 -0700 (PDT) From: "Paul E. McKenney" To: Ingo Molnar , Borislav Petkov , Dave Hansen Cc: "H. Peter Anvin" , John Stultz , Stephen Boyd , Peter Zijlstra , Feng Tang , Waiman Long , Neeraj Upadhyay , x86@kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, "Paul E. McKenney" Subject: [PATCH v2 TSC and clocksource-watchdog updates for v6.12 3/5] clocksource: Fix comments on WATCHDOG_THRESHOLD & WATCHDOG_MAX_SKEW Date: Fri, 2 Aug 2024 08:46:16 -0700 Message-Id: <20240802154618.4149953-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The WATCHDOG_THRESHOLD macro is no longer used to supply a default value for ->uncertainty_margin, but WATCHDOG_MAX_SKEW now is. Therefore, update the comments to reflect this change. Reported-by: Borislav Petkov Signed-off-by: Paul E. McKenney Acked-by: Borislav Petkov (AMD) --- kernel/time/clocksource.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 581cdbb538448..ee0ad5e4d5170 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -113,7 +113,6 @@ static u64 suspend_start; =20 /* * Threshold: 0.0312s, when doubled: 0.0625s. - * Also a default for cs->uncertainty_margin when registering clocks. */ #define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 5) =20 @@ -139,6 +138,13 @@ static u64 suspend_start; #define MAX_SKEW_USEC (125 * WATCHDOG_INTERVAL / HZ) #endif =20 +/* + * Default for maximum permissible skew when cs->uncertainty_margin is + * not specified, and the lower bound even when cs->uncertainty_margin + * is specified. This is also the default that is used when registering + * clocks with unspecifed cs->uncertainty_margin, so this macro is used + * even in CONFIG_CLOCKSOURCE_WATCHDOG=3Dn kernels. + */ #define WATCHDOG_MAX_SKEW (MAX_SKEW_USEC * NSEC_PER_USEC) =20 #ifdef CONFIG_CLOCKSOURCE_WATCHDOG --=20 2.40.1 From nobody Mon Feb 9 14:06:45 2026 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 8A70F175D3F for ; Fri, 2 Aug 2024 15:46:20 +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=1722613580; cv=none; b=etv+WCT7gQSiGvPXMzy0n9gADAYamXvN8adPXB4aLHHuRjar3AzVkX27QnsHGS09ErNSiJcvuZ1StZ1MovVAp1808gRKf0IcHoawdCRlz1p2tnUXC9hhusnDAepF05+emNtV8TtkqSj0icDn8gbqWeFnO7XCNHf/RHJE8Oav8Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722613580; c=relaxed/simple; bh=Smm79O1AfPjUYfDBORGT1d4YEJu4ZIjrym+47QxNb4c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V5GuDsycJCHWYz+suN1Hb9PIWSoi5N0kxgEveeZ4AO9VzONFTK+I7HshlKQnaxqM3Jd7KpUiNGDVEGuqT6JHdCEt2ISeM10mXOzFiT4rY737ICzpXEdbX/9DDA4H74MC3WabItkS0dtWOapvGaNYpBFVj/JmOZVTYUUlvGwCySk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WoSLA2up; 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="WoSLA2up" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65629C4AF0E; Fri, 2 Aug 2024 15:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722613580; bh=Smm79O1AfPjUYfDBORGT1d4YEJu4ZIjrym+47QxNb4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WoSLA2upoFepc9wR2pYBMrnAumboYzGPqk87EgVZ2ugrUQPSrMBiL5VVO5nnWSShP xK6+p3xCnlOWglxbLDwk/7MP4S5iu64GKfTqJNRx7aYnEybcLCsbGLMJyZAqnEjhs1 eABgQ+OHqMftKL21FvbJjgVZ69GItFXT/cZ2mqaUXslsmUAIYovr8m0CKEVn28/FkO KXomM6FqS+8knXf+RX/dsNY1Pn/eLL5pckyGNmQrEKS08pU86Y10Nur7jterFRUImM 5HjYKU/AV7tPbXbfXQLhdz+3icVxojfP/A931dco05iogzVBmfFSTtyJ14ImgSZ6vv UbF0rtxqIXUFQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0935ACE0F69; Fri, 2 Aug 2024 08:46:20 -0700 (PDT) From: "Paul E. McKenney" To: Ingo Molnar , Borislav Petkov , Dave Hansen Cc: "H. Peter Anvin" , John Stultz , Stephen Boyd , Peter Zijlstra , Feng Tang , Waiman Long , Neeraj Upadhyay , x86@kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, "Paul E. McKenney" , Thomas Gleixner Subject: [PATCH v2 TSC and clocksource-watchdog updates for v6.12 4/5] clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin Date: Fri, 2 Aug 2024 08:46:17 -0700 Message-Id: <20240802154618.4149953-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Right now, cs_watchdog_read() does clocksource sanity checks based on WATCHDOG_MAX_SKEW, which sets a floor on any clocksource's .uncertainty_margin. These sanity checks can therefore act inappropriately for clocksources with large uncertainty margins. One reason for a clocksource to have a large .uncertainty_margin is when that clocksource has long read-out latency, given that it does not make sense for the .uncertainty_margin to be smaller than the read-out latency. With the current checks, cs_watchdog_read() could reject all normal reads from a clocksource with long read-out latencies, such as those from legacy clocksources that are no longer implemented in hardware. Therefore, recast the cs_watchdog_read() checks in terms of the .uncertainty_margin values of the clocksources involved in the timespan in question. The first covers two watchdog reads and one cs read, so use twice the watchdog .uncertainty_margin plus that of the cs. The second covers only a pair of watchdog reads, so use twice the watchdog .uncertainty_margin. Reported-by: Borislav Petkov Signed-off-by: Paul E. McKenney Cc: John Stultz 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: Neeraj Upadhyay Cc: --- kernel/time/clocksource.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index ee0ad5e4d5170..23336eecb4f43 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -244,6 +244,7 @@ enum wd_read_status { =20 static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *c= snow, u64 *wdnow) { + int64_t md =3D 2 * watchdog->uncertainty_margin; unsigned int nretries, max_retries; int64_t wd_delay, wd_seq_delay; u64 wd_end, wd_end2; @@ -258,7 +259,7 @@ static enum wd_read_status cs_watchdog_read(struct cloc= ksource *cs, u64 *csnow, local_irq_enable(); =20 wd_delay =3D cycles_to_nsec_safe(watchdog, *wdnow, wd_end); - if (wd_delay <=3D WATCHDOG_MAX_SKEW) { + if (wd_delay <=3D md + cs->uncertainty_margin) { if (nretries > 1 && nretries >=3D max_retries) { pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before suc= cess\n", smp_processor_id(), watchdog->name, nretries); @@ -271,12 +272,12 @@ static enum wd_read_status cs_watchdog_read(struct cl= ocksource *cs, u64 *csnow, * there is too much external interferences that cause * significant delay in reading both clocksource and watchdog. * - * If consecutive WD read-back delay > WATCHDOG_MAX_SKEW/2, - * report system busy, reinit the watchdog and skip the current + * If consecutive WD read-back delay > md, report + * system busy, reinit the watchdog and skip the current * watchdog test. */ wd_seq_delay =3D cycles_to_nsec_safe(watchdog, wd_end, wd_end2); - if (wd_seq_delay > WATCHDOG_MAX_SKEW/2) + if (wd_seq_delay > md) goto skip_test; } =20 --=20 2.40.1 From nobody Mon Feb 9 14:06:45 2026 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 C667E13632B for ; Fri, 2 Aug 2024 15:46:20 +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=1722613580; cv=none; b=L+jxUOMCPATKswbp7pyR5+1U1j0BkIRdCPoME8/aqtEo1PGDidUEZmQrN3XMZ+UyiWh41AAExr+dE1BXFrilOXOSp8e5RpDHMS6FFnlHk/JTZj+4a6yHsdTR27mwrMUr5l54kVaAk7Tf19Nnh8HL4wX2UO2gvJcMs4r85tcYlDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722613580; c=relaxed/simple; bh=N+A1wc43BLC5mDm7eS+PYjhLx7Pij+P3OfOMl3FWjQM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GUrgf1h4aKfevaluiGvv1TMdwoGFErf0xqCC73eO2yKnRNGu8If6jWDAHn5XMaYCDtrT3Nuaj5xsaZTb/6ivYGU22cIWg8QRRZshPvFaRnWQCaiNiFAeDVjhSRP/aeOyNs4LhntJW7IbmYM3On9nHBzQqrKldG7XgGjK/+wETJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mz9HpLTV; 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="Mz9HpLTV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73AC2C4AF13; Fri, 2 Aug 2024 15:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722613580; bh=N+A1wc43BLC5mDm7eS+PYjhLx7Pij+P3OfOMl3FWjQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mz9HpLTVShk6sFHe0ZX2W/Fd1CHIzsE/A7AIP/JSagRDQf1+WRiGXv6+lEUg5D1cn QWtVDhpeWW8XWAgzF6FVUj0ZGWE2RE1RGxio+QBfgQX3Mdr8KSk1rg0gtzLzjNkZUD nXcgQWuoWVDBXWkayBhBdI8M6Cj53Y/7GBmuvPyK0w6UqFSguS3hmxEHTM9GsHaxmx BWGk4E9A0Ro/2JBpbmj5qCowy6E1YSEABgx4PoMF0MK8H3DFN+nVdEN6Naqyx7tBVy LciIyvEujrhPTpYZG0LDuxKfcvZiuU6psUnG1kJbF20eU9BnXXiFM+ZgEE6p7lXZD7 DyU8JVo5sJw/A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0C9ACCE0FA2; Fri, 2 Aug 2024 08:46:20 -0700 (PDT) From: "Paul E. McKenney" To: Ingo Molnar , Borislav Petkov , Dave Hansen Cc: "H. Peter Anvin" , John Stultz , Stephen Boyd , Peter Zijlstra , Feng Tang , Waiman Long , Neeraj Upadhyay , x86@kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, "Paul E. McKenney" , Zhengxu Chen , Danielle Costantino , Thomas Gleixner Subject: [PATCH v2 TSC and clocksource-watchdog updates for v6.12 5/5] tsc: Check for sockets instead of CPUs to make code match comment Date: Fri, 2 Aug 2024 08:46:18 -0700 Message-Id: <20240802154618.4149953-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: --- arch/x86/kernel/tsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index d4462fb262996..b7b050ca8baa1 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1290,7 +1290,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; } =20 --=20 2.40.1