From patchwork Fri Nov 10 15:25:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 118573 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp2326725edl; Fri, 10 Nov 2017 07:26:03 -0800 (PST) X-Google-Smtp-Source: AGs4zMaktSl2DkVhGdcAc/g7nTaCbm/GxCymXNbShFlfGzX3zEjAG3a6Nrx7Jzi6iObVDASMwdXw X-Received: by 10.84.131.34 with SMTP id 31mr691080pld.449.1510327563071; Fri, 10 Nov 2017 07:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510327563; cv=none; d=google.com; s=arc-20160816; b=oSGbe8X3dE/lr4seFNvHIqdOmrPkSinfIW6J5MUuIHzEOcjZkLWeqiYhwl/VXmRl30 RdbJNNvN42vJ4EAVPg8ToqCsrAvn3e6cdit+kYRFeM/diKLiRSG+lolInb6dBISSNBQw 9PfRZyAKzDpGaHIoDC4YeW3WWROUzpwkONu+MMeQhH7SNFTxhshix8+PGI1CHrIG7jck 5FZl5Cjus0ygMqTpMR+1F+0XkiBhw0lw2kbMySz6wbXcqigt0wZaiqPDcxliFe+KaC3D /396ymY7zQTyYHnm5EaVSz7fCHlKqQIeOHSVAVVbBpKGqQxMqrLUWdBiRh3xutHeRfJ7 DZcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Jve9iTHdmOdmXmhYG3OWX+WnM5PDfjndFZ14lnaUtdo=; b=PMHW59mkQNQqkHFfjm+AoOjzDI3mlku9epMhTNRBS3896+O01TGoQ5JYEQYsLvFVxB RAn/ZRbQLDoy3LOJtipWVbdoZQgGPRNfSpdYzLET2UMbCnD/FCj+s1s4gwT7QlaoVWq/ iv4QY2WwhAs8SZ2/FpRJWfN1cJQeaacYqLkXz8IV4XWQLoN0ake0zMbeqWP5ScKdfn6p boHQjTlh6X/tPuwRCSR65oYsN+Pl0xj1j73fenP9zMxIaLZbjgSlQnfUlh6pGRUJ7k+8 1QI3Wgurx32g9fkbTyfmQSO2CVyiIJJHQZR80IGNOVNNy5sb6Ns+RR8L92G610ov8X5s EYQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9si8928646pgs.213.2017.11.10.07.26.02; Fri, 10 Nov 2017 07:26:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753235AbdKJP0A (ORCPT + 23 others); 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 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0MC5PI-1eM0sF0sHg-008vpd; Fri, 10 Nov 2017 16:25:39 +0100 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 Precedence: bulk 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(-) -- 2.9.0 Acked-by: Kees Cook 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.