From: Thomas Gleixner <tglx@linutronix.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org
Subject: [GIT pull] timers/urgent for 5.3-rc5
Date: Sun, 25 Aug 2019 09:43:00 -0000 [thread overview]
Message-ID: <156672618029.19810.11392026209249158095.tglx@nanos.tec.linutronix.de> (raw)
In-Reply-To: 156672618029.19810.8479315461492191933.tglx@nanos.tec.linutronix.de
Linus,
please pull the latest timers-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers-urgent-for-linus
up to: b99328a60a48: timekeeping/vsyscall: Prevent math overflow in BOOTTIME update
A single fix for a regression caused by the generic VDSO implementation
where a math overflow causes CLOCK_BOOTTIME to become a random number
generator.
Thanks,
tglx
------------------>
Thomas Gleixner (1):
timekeeping/vsyscall: Prevent math overflow in BOOTTIME update
include/linux/timekeeper_internal.h | 5 +++++
kernel/time/timekeeping.c | 5 +++++
kernel/time/vsyscall.c | 22 +++++++++++++---------
3 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index 7acb953298a7..84ff2844df2a 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -57,6 +57,7 @@ struct tk_read_base {
* @cs_was_changed_seq: The sequence number of clocksource change events
* @next_leap_ktime: CLOCK_MONOTONIC time value of a pending leap-second
* @raw_sec: CLOCK_MONOTONIC_RAW time in seconds
+ * @monotonic_to_boot: CLOCK_MONOTONIC to CLOCK_BOOTTIME offset
* @cycle_interval: Number of clock cycles in one NTP interval
* @xtime_interval: Number of clock shifted nano seconds in one NTP
* interval.
@@ -84,6 +85,9 @@ struct tk_read_base {
*
* wall_to_monotonic is no longer the boot time, getboottime must be
* used instead.
+ *
+ * @monotonic_to_boottime is a timespec64 representation of @offs_boot to
+ * accelerate the VDSO update for CLOCK_BOOTTIME.
*/
struct timekeeper {
struct tk_read_base tkr_mono;
@@ -99,6 +103,7 @@ struct timekeeper {
u8 cs_was_changed_seq;
ktime_t next_leap_ktime;
u64 raw_sec;
+ struct timespec64 monotonic_to_boot;
/* The following members are for timekeeping internal use */
u64 cycle_interval;
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index d911c8470149..ca69290bee2a 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -146,6 +146,11 @@ static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec64 wtm)
static inline void tk_update_sleep_time(struct timekeeper *tk, ktime_t delta)
{
tk->offs_boot = ktime_add(tk->offs_boot, delta);
+ /*
+ * Timespec representation for VDSO update to avoid 64bit division
+ * on every update.
+ */
+ tk->monotonic_to_boot = ktime_to_timespec64(tk->offs_boot);
}
/*
diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c
index 8cf3596a4ce6..4bc37ac3bb05 100644
--- a/kernel/time/vsyscall.c
+++ b/kernel/time/vsyscall.c
@@ -17,7 +17,7 @@ static inline void update_vdso_data(struct vdso_data *vdata,
struct timekeeper *tk)
{
struct vdso_timestamp *vdso_ts;
- u64 nsec;
+ u64 nsec, sec;
vdata[CS_HRES_COARSE].cycle_last = tk->tkr_mono.cycle_last;
vdata[CS_HRES_COARSE].mask = tk->tkr_mono.mask;
@@ -45,23 +45,27 @@ static inline void update_vdso_data(struct vdso_data *vdata,
}
vdso_ts->nsec = nsec;
- /* CLOCK_MONOTONIC_RAW */
- vdso_ts = &vdata[CS_RAW].basetime[CLOCK_MONOTONIC_RAW];
- vdso_ts->sec = tk->raw_sec;
- vdso_ts->nsec = tk->tkr_raw.xtime_nsec;
+ /* Copy MONOTONIC time for BOOTTIME */
+ sec = vdso_ts->sec;
+ /* Add the boot offset */
+ sec += tk->monotonic_to_boot.tv_sec;
+ nsec += (u64)tk->monotonic_to_boot.tv_nsec << tk->tkr_mono.shift;
/* CLOCK_BOOTTIME */
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_BOOTTIME];
- vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
- nsec = tk->tkr_mono.xtime_nsec;
- nsec += ((u64)(tk->wall_to_monotonic.tv_nsec +
- ktime_to_ns(tk->offs_boot)) << tk->tkr_mono.shift);
+ vdso_ts->sec = sec;
+
while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
nsec -= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift);
vdso_ts->sec++;
}
vdso_ts->nsec = nsec;
+ /* CLOCK_MONOTONIC_RAW */
+ vdso_ts = &vdata[CS_RAW].basetime[CLOCK_MONOTONIC_RAW];
+ vdso_ts->sec = tk->raw_sec;
+ vdso_ts->nsec = tk->tkr_raw.xtime_nsec;
+
/* CLOCK_TAI */
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_TAI];
vdso_ts->sec = tk->xtime_sec + (s64)tk->tai_offset;
next prev parent reply other threads:[~2019-08-25 9:45 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-25 9:43 [GIT pull] irq/urgent for 5.3-rc5 Thomas Gleixner
2019-08-25 9:43 ` [GIT pull] x86/urgent " Thomas Gleixner
2019-08-25 17:18 ` Linus Torvalds
2019-08-25 17:30 ` Borislav Petkov
2019-08-25 17:37 ` Linus Torvalds
2019-08-25 18:29 ` Borislav Petkov
2019-08-25 18:38 ` Linus Torvalds
2019-08-25 19:32 ` Borislav Petkov
2019-08-25 19:35 ` Linus Torvalds
2019-08-25 19:49 ` Borislav Petkov
2019-08-25 19:59 ` Linus Torvalds
2019-08-25 20:17 ` Borislav Petkov
2019-08-26 12:53 ` Borislav Petkov
2019-08-27 16:55 ` Linus Torvalds
2019-08-27 17:39 ` Borislav Petkov
2019-08-27 17:46 ` Linus Torvalds
2019-08-27 17:59 ` Borislav Petkov
2019-08-28 15:20 ` David Sterba
2019-08-28 15:53 ` David Sterba
2019-10-02 19:09 ` [tip: x86/cpu] x86/rdrand: Sanity-check RDRAND output tip-bot2 for Borislav Petkov
2019-08-25 17:40 ` [GIT pull] x86/urgent for 5.3-rc5 pr-tracker-bot
2019-08-25 9:43 ` Thomas Gleixner [this message]
2019-08-25 17:40 ` [GIT pull] timers/urgent " pr-tracker-bot
2019-08-25 9:43 ` [GIT pull] perf/urgent " Thomas Gleixner
2019-08-25 17:40 ` pr-tracker-bot
2019-08-25 9:43 ` [GIT pull] sched/urgent " Thomas Gleixner
2019-08-25 17:40 ` pr-tracker-bot
2019-08-25 17:40 ` [GIT pull] irq/urgent " pr-tracker-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=156672618029.19810.11392026209249158095.tglx@nanos.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).