pstore: use ktime_get_real_fast_ns() instead of __getnstimeofday()
PATCH v2 1/1 pstore: use ktime_get_real_fast_ns() instead of __getnstimeofday()
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
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.
- 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 export.
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.
---
v2: improved changelog
--- fs/pstore/platform.c | 5 +---- kernel/time/timekeeping.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-)
fs/pstore/platform.c +1 -4
@@ -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 ()); }/*
kernel/time/timekeeping.c +1 -0
@@ -536,6 +536,7 @@ u64 ktime_get_coarse_real_fast_ns(void) {return __ktime_get_real_fast_ns (&tk_fast_mono, true); } +EXPORT_SYMBOL_GPL (ktime_get_real_fast_ns);/** * halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.
Signature · 1 line
2.9.0
Quoted 64 lines · Arnd Bergmann
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 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.
- 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. Sincektime_get_real_fast_ns()was not exported to modules, I also add the export.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 <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>---
v2: improved changelog--- fs/pstore/platform.c | 5 +---- kernel/time/timekeeping.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-)fs/pstore/platform.c +1
-4@@ -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 ()); }/* kernel/time/timekeeping.c +0
-0
kernel/time/timekeeping.c u64 ktime_get_coarse_real_fast_ns(void) · line 539
Quoted 4 lines
kernel/time/timekeeping.c +1
-0@@ -536,6 +536,7 @@ u64 ktime_get_coarse_real_fast_ns(void) {return __ktime_get_real_fast_ns (&tk_fast_mono, true); } +EXPORT_SYMBOL_GPL (ktime_get_real_fast_ns);
I was going to add this to the pstore tree, but ktime_get_real_fast_ns() doesn't exist. In which tree is ktime_get_real_fast_ns() added? This should be carried there:
Thanks!
-Kees
Quoted 6 lines
kernel/time/timekeeping.c +0
-1/** * halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource. -- 2.9.0
Signature · 2 lines
Kees Cook Pixel Security
Quoted 7 lines · Kees Cook
Quoted 1 line
+EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns);
I was going to add this to the pstore tree, but
ktime_get_real_fast_ns()doesn't exist. In which tree isktime_get_real_fast_ns()added? This should be carried there:Acked-by Kees Cook <[email protected]>
it's in tip timers/core
I pick it up.
Thanks,
tglx
tip-bot for Arnd Bergmann
merge bot[tip:timers/core] pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday()
In reply to Arnd Bergmannpstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday()
Commit-ID: df27067e6040b51188184876253d93da002433aa Gitweb: https://git.kernel.org/tip/df27067e6040b51188184876253d93da002433aa Author: Arnd Bergmann <[email protected]> AuthorDate: Fri, 10 Nov 2017 16:25:04 +0100 Committer: Thomas Gleixner <[email protected]> CommitDate: Sun, 12 Nov 2017 15:05:52 +0100
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.
--- fs/pstore/platform.c | 5 +---- kernel/time/timekeeping.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-)
fs/pstore/platform.c +1 -4
@@ -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 ()); }/*
kernel/time/timekeeping.c +1 -0
@@ -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.