From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753234AbdKJP0A (ORCPT ); Fri, 10 Nov 2017 10:26:00 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:56420 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753181AbdKJPZ7 (ORCPT ); Fri, 10 Nov 2017 10:25:59 -0500 From: Arnd Bergmann To: Kees Cook , Thomas Gleixner Cc: Arnd Bergmann , Anton Vorontsov , Colin Cross , Tony Luck , John Stultz , Stephen Boyd , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH] [v2] pstore: use ktime_get_real_fast_ns() instead of __getnstimeofday() Date: Fri, 10 Nov 2017 16:25:04 +0100 Message-Id: <20171110152530.1926955-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:IAnkjk9d74kF6RoHFQrfAwmCWewTGeu7OYeLh891Xv7ohhteEFv BlLMgfofOeW5nJXwOsVJvaS/+9vhjGEUhcW0UOK9OYfVVOZqXArCCPqQRb6/JIvoHsohGaz mVOMPCTWBkciNmXwxDOknsaZtaXEvMVhqBWwUX97w5Y2UAgFxjVTxXD4uiVAgeov3ry6wIg CPGANyNV70TVGoVFEohQg== X-UI-Out-Filterresults: notjunk:1;V01:K0:gXEANVamGkw=:ns6cdm0qdbEAuxMH0NuOQa oMWJ59E5cN16zBOLb9doE/Jz7A4G4Fr0EV4XCtlGdvsoOxzZxK/v1+bEL0owErUHgUoqiJMPj YN4avpEERFa7yY11nKCAmjccnXM3Lhn2/By/kfpIVEwHZc3eYRdYQpXe7uGIKex61T3Jf7FnB NIEr/h2Uhb1UyuJRjsTT5yeY4xbcQzemBaVjZvT5dXJhW767JCkAChvDt0fLtm17LLIosSTIj RcC4PvPy2i1ygPo/lFuP3z1j3b5JguHiTCC8ou/pSbWNjN83kza2pKQG4OIi+D009LvMQsKOh oaUdqxExkYhGXPWXkNCq7D4CioM6AM8uVOxQcvJ0RjU45Bdj/rwjq71+swwgEau5lCLt1WpEU ilLPP/LVgpaNLORk3y9kNFS0ULu9Adah6NNVPUkjZNzvm3Ah0qCo/soEFzwE/iv55URV94JbB sONAwpAa2NfE6jvxZLHCr5bMc9DKDtrL+oeqtakRwsKo/4I25oKE5j4zJznTBeN8VXB/Tn9x/ qDs5GJ3t+3xGNuDMC5w9eKuDLqproaZsyZC3a5TbT8jby5s//+JubOheCX0IcirkgQSXFg5th 6mRycS/MffOfUXqQZxcOInE76Cfo+qk6OsaTF4yP/ExzSwwjDxDUWHJETW9gWt6Xf0TKtWnpB GUcZc8xPVtAFu101zk2l9rcqSbidp6n6YbFnJsVHFkLkrOVtb87c9fmXH57h5S869VqVMTAuV 2RHG/Vq06q/orTy70fw6BTPhn3YmvmSjSjZp2g== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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); } +EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns); /** * halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource. -- 2.9.0