LKML Archive on
 help / color / Atom feed
From: Arnd Bergmann <>
To: Kees Cook <>, Thomas Gleixner <>
Cc: Arnd Bergmann <>, Anton Vorontsov <>,
	Colin Cross <>, Tony Luck <>,
	John Stultz <>,
	Stephen Boyd <>,
	Ingo Molnar <>,
Subject: [PATCH] [v2] pstore: use ktime_get_real_fast_ns() instead of __getnstimeofday()
Date: Fri, 10 Nov 2017 16:25:04 +0100
Message-ID: <> (raw)

I noticed that __getnstimeofday() is a rather odd interface, with
a number of quirks:

- The caller may come from NMI context, but the implementation is not NMI safe,
  one way to get there from NMI is

      NMI handler:
        something bad

- The calling conventions are different from any other timekeeping functions,
  to deal with returning an error code during suspended timekeeping.
- The naming doesn't fit into the 'ktime_get_*()' scheme.

This addresses the above issues by using a completely different
method to get the time: ktime_get_real_fast_ns() is NMI safe and
has a reasonable behavior when timekeeping is suspended: it returns
the time at which it got suspended.
We can easily transform the result into a timespec structure. Since
ktime_get_real_fast_ns() was not exported to modules, I also add the

The behavior for the suspended case changes slightly, we now return the
time if we can find it out rather than setting it to zero. As Thomas
Gleixner explained, this is still safe, as we won't attempt to
call into the clocksource driver that might be suspended

I'm not trying to address y2038-safety at this point, but plan to
do that later with a more complex patch.

Cc: Kees Cook <>
Signed-off-by: Arnd Bergmann <>
v2: improved changelog
 fs/pstore/platform.c      | 5 +----
 kernel/time/timekeeping.c | 1 +
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index e3c1332dfb4c..423159abd501 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -482,10 +482,7 @@ void pstore_record_init(struct pstore_record *record,
 	record->psi = psinfo;
 	/* Report zeroed timestamp if called before timekeeping has resumed. */
-	if (__getnstimeofday(&record->time)) {
-		record->time.tv_sec = 0;
-		record->time.tv_nsec = 0;
-	}
+	record->time = ns_to_timespec(ktime_get_real_fast_ns());
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index af139aa615ca..8f0d1857b78d 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -536,6 +536,7 @@ u64 ktime_get_coarse_real_fast_ns(void)
 	return __ktime_get_real_fast_ns(&tk_fast_mono, true);
  * halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.

             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 15:25 Arnd Bergmann [this message]
2017-11-10 19:38 ` Kees Cook
2017-11-10 21:27   ` Thomas Gleixner
2017-11-12 14:10 ` [tip:timers/core] pstore: Use " tip-bot for Arnd Bergmann

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git
	git clone --mirror lkml/git/8.git
	git clone --mirror lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone