Skip to content

Commit

Permalink
pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday()
Browse files Browse the repository at this point in the history
__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 <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Colin Cross <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
arndb authored and KAGA-KOKO committed Nov 12, 2017
1 parent b3fe565 commit df27067
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 1 addition & 4 deletions fs/pstore/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/*
Expand Down
1 change: 1 addition & 0 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ u64 ktime_get_real_fast_ns(void)
{
return __ktime_get_real_fast_ns(&tk_fast_mono);
}
EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns);

/**
* halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.
Expand Down

0 comments on commit df27067

Please sign in to comment.