Skip to content

Commit df27067

Browse files
arndbKAGA-KOKO
authored andcommitted
pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday()
__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 panic() kmsg_dump() pstore_dump() pstore_record_init() __getnstimeofday() - The calling conventions are different from any other timekeeping functions, to deal with returning an error code during suspended timekeeping. Address 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. As Thomas Gleixner explained, this is safe, as ktime_get_real_fast_ns() does not call into the clocksource driver that might be suspended. The result can easily be transformed into a timespec structure. Since ktime_get_real_fast_ns() was not exported to modules, add the export. The pstore behavior for the suspended case changes slightly, as it now stores the timestamp at which timekeeping was suspended instead of storing a zero timestamp. This change is not addressing y2038-safety, that's subject to a more complex follow up patch. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Kees Cook <keescook@chromium.org> Cc: Tony Luck <tony.luck@intel.com> Cc: Anton Vorontsov <anton@enomsg.org> Cc: Stephen Boyd <sboyd@codeaurora.org> Cc: John Stultz <john.stultz@linaro.org> Cc: Colin Cross <ccross@android.com> Link: https://lkml.kernel.org/r/20171110152530.1926955-1-arnd@arndb.de
1 parent b3fe565 commit df27067

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

fs/pstore/platform.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,7 @@ void pstore_record_init(struct pstore_record *record,
482482
record->psi = psinfo;
483483

484484
/* Report zeroed timestamp if called before timekeeping has resumed. */
485-
if (__getnstimeofday(&record->time)) {
486-
record->time.tv_sec = 0;
487-
record->time.tv_nsec = 0;
488-
}
485+
record->time = ns_to_timespec(ktime_get_real_fast_ns());
489486
}
490487

491488
/*

kernel/time/timekeeping.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ u64 ktime_get_real_fast_ns(void)
528528
{
529529
return __ktime_get_real_fast_ns(&tk_fast_mono);
530530
}
531+
EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns);
531532

532533
/**
533534
* halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.

0 commit comments

Comments
 (0)