linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ntp: Fix RTC synchronization on 32-bit platforms
@ 2021-01-11 10:39 Geert Uytterhoeven
  2021-01-11 10:43 ` Geert Uytterhoeven
  2021-01-12 20:18 ` [tip: timers/urgent] " tip-bot2 for Geert Uytterhoeven
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2021-01-11 10:39 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner, Jason Gunthorpe, Alexandre Belloni
  Cc: Stephen Boyd, linux-kernel, Geert Uytterhoeven

Due to an integer overflow, RTC synchronization now happens every 2s
instead of the intended 11 minutes.  Fix this by forcing 64-bit
arithmetic for the sync period calculation.

Fixes: c9e6189fb03123a7 ("ntp: Make the RTC synchronization more reliable")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 kernel/time/ntp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 7404d38315276a96..54d52fab201d283e 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -498,7 +498,7 @@ int second_overflow(time64_t secs)
 static void sync_hw_clock(struct work_struct *work);
 static DECLARE_WORK(sync_work, sync_hw_clock);
 static struct hrtimer sync_hrtimer;
-#define SYNC_PERIOD_NS (11UL * 60 * NSEC_PER_SEC)
+#define SYNC_PERIOD_NS (11ULL * 60 * NSEC_PER_SEC)
 
 static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer)
 {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ntp: Fix RTC synchronization on 32-bit platforms
  2021-01-11 10:39 [PATCH] ntp: Fix RTC synchronization on 32-bit platforms Geert Uytterhoeven
@ 2021-01-11 10:43 ` Geert Uytterhoeven
  2021-01-12 20:18 ` [tip: timers/urgent] " tip-bot2 for Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2021-01-11 10:43 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: John Stultz, Jason Gunthorpe, Alexandre Belloni, Stephen Boyd,
	Linux Kernel Mailing List, Geert Uytterhoeven

On Mon, Jan 11, 2021 at 11:40 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> Due to an integer overflow, RTC synchronization now happens every 2s
> instead of the intended 11 minutes.  Fix this by forcing 64-bit
> arithmetic for the sync period calculation.
>
> Fixes: c9e6189fb03123a7 ("ntp: Make the RTC synchronization more reliable")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  kernel/time/ntp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
> index 7404d38315276a96..54d52fab201d283e 100644
> --- a/kernel/time/ntp.c
> +++ b/kernel/time/ntp.c
> @@ -498,7 +498,7 @@ int second_overflow(time64_t secs)
>  static void sync_hw_clock(struct work_struct *work);
>  static DECLARE_WORK(sync_work, sync_hw_clock);
>  static struct hrtimer sync_hrtimer;
> -#define SYNC_PERIOD_NS (11UL * 60 * NSEC_PER_SEC)
> +#define SYNC_PERIOD_NS (11ULL * 60 * NSEC_PER_SEC)
>
>  static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer)
>  {

While the line

    exp = ktime_add_ns(exp, 2 * NSEC_PER_SEC - offset_nsec);

is currently not an issue, it may be wise to change it to

    exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec);

in case someone wants to experiment with values larger then 4s?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: timers/urgent] ntp: Fix RTC synchronization on 32-bit platforms
  2021-01-11 10:39 [PATCH] ntp: Fix RTC synchronization on 32-bit platforms Geert Uytterhoeven
  2021-01-11 10:43 ` Geert Uytterhoeven
@ 2021-01-12 20:18 ` tip-bot2 for Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Geert Uytterhoeven @ 2021-01-12 20:18 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Geert Uytterhoeven, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     e3fab2f3de081e98c50b7b4ace1b040161d95310
Gitweb:        https://git.kernel.org/tip/e3fab2f3de081e98c50b7b4ace1b040161d95310
Author:        Geert Uytterhoeven <geert+renesas@glider.be>
AuthorDate:    Mon, 11 Jan 2021 11:39:56 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Tue, 12 Jan 2021 21:13:01 +01:00

ntp: Fix RTC synchronization on 32-bit platforms

Due to an integer overflow, RTC synchronization now happens every 2s
instead of the intended 11 minutes.  Fix this by forcing 64-bit
arithmetic for the sync period calculation.

Annotate the other place which multiplies seconds for consistency as well.

Fixes: c9e6189fb03123a7 ("ntp: Make the RTC synchronization more reliable")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20210111103956.290378-1-geert+renesas@glider.be

---
 kernel/time/ntp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 7404d38..87389b9 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -498,7 +498,7 @@ out:
 static void sync_hw_clock(struct work_struct *work);
 static DECLARE_WORK(sync_work, sync_hw_clock);
 static struct hrtimer sync_hrtimer;
-#define SYNC_PERIOD_NS (11UL * 60 * NSEC_PER_SEC)
+#define SYNC_PERIOD_NS (11ULL * 60 * NSEC_PER_SEC)
 
 static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer)
 {
@@ -512,7 +512,7 @@ static void sched_sync_hw_clock(unsigned long offset_nsec, bool retry)
 	ktime_t exp = ktime_set(ktime_get_real_seconds(), 0);
 
 	if (retry)
-		exp = ktime_add_ns(exp, 2 * NSEC_PER_SEC - offset_nsec);
+		exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec);
 	else
 		exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec);
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-12 21:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 10:39 [PATCH] ntp: Fix RTC synchronization on 32-bit platforms Geert Uytterhoeven
2021-01-11 10:43 ` Geert Uytterhoeven
2021-01-12 20:18 ` [tip: timers/urgent] " tip-bot2 for Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).