From: Arnd Bergmann <arnd@arndb.de>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Kees Cook <keescook@chromium.org>,
Anton Vorontsov <anton@enomsg.org>,
Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
John Stultz <john.stultz@linaro.org>,
Stephen Boyd <sboyd@codeaurora.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] pstore: use ktime_get_real_fast_ns() instead of __getnstimeofday()
Date: Fri, 10 Nov 2017 00:43:55 +0100 [thread overview]
Message-ID: <CAK8P3a1TWCSMoApGqEdmkLHVLgFdG0Zj2cg3B2hFLX-x5_5ueA@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1711092338470.2690@nanos>
On Fri, Nov 10, 2017 at 12:00 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
> On Thu, 9 Nov 2017, Arnd Bergmann wrote:
>> On Thu, Nov 9, 2017 at 1:55 AM, Kees Cook <keescook@chromium.org> wrote:
>> > On Wed, Nov 8, 2017 at 8:00 AM, Arnd Bergmann <arnd@arndb.de> wrote:
>> >> 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
>
> Hmm, no. None of the regular accessor functions can be called from NMI
> context safely.
Right, that's what I mean: it must not get called from NMI context, but it
currently is, at least for this case:
NMI handler:
something bad
panic()
kmsg_dump()
pstore_dump()
pstore_record_init()
__getnstimeofday()
I should probably add that to the changelog text ;-)
>> >> - The calling conventions are different from any other timekeeping functions
>
> Yes, that was done back then to actually return the value (which is
> possible with TSC) and indicate at the same time that timekeeping is
> suspended.
>
>> >> - The naming doesn't fit into the 'ktime_get_*()' scheme
>
> Right, because it's not in the ktime_get_() family of functions.
For the background on how I got here: I'm currently trying to go through
all functions in include/linux/timekeeping32.h with the intention of
replacing them with appropriate ktime_get_*() interfaces that don't have
the y2038 overflow problem. I considered just using
the existing __getnstimeofday64() here, which would be a trivial
change, but then I noticed the NMI problem.
Also, I have a related patch series that renames getrawmonotonic64(),
current_kernel_time64() and get_monotonic_coarse64() to
ktime_get_raw_ts64(), ktime_get_coarse_real_ts64() and
ktime_get_coarse_ts64(), for consistency, but then I couldn't
come up with a good name for __getnstimeofday64(), as the
__ktime_get_*() naming is already used for a number of other
things and I did not want to overload that more. Completely
removing __getnstimeofday64() would be handier here.
>> > As long as this is sane to call when timekeeping is not running, I'm
>> > happy to take the patch.
>>
>> Maybe John or Thomas can comment on this, I'm not totally sure how
>> reliable it is. My best guess is that it will still produce correct time stamps
>> a lot of the time, but it depends a bit on the clocksource hardware and
>> how long the timekeeping has been suspended. As far as I can tell,
>>
>> - if the clocksource register contents wrap around, the reported time
>> might appear to go back to the time of the last timer interrupt. The
>> shortest time I could find for an overflow is a 16-bit timer running at
>> 32khz on i.MX1, overflowing every two seconds.
>> - if reading a suspended clocksource returns zero (or another incorrect
>> value) the time might be in the far future
>> - if reading a suspended clocksource causes a hang or crash, you
>> lose.
>
> None of those problems exist for the fast NMI safe accessors. In
> timekeeping_suspend() we store the current time and any access to the fast
> timekeeper returns exactly the time at suspend up to the point where
> timekeeping is resumed. See halt_fast_timekeeper().
>
> So all you get between timekeeping_suspend() and timekeeping_resume() is
> a stale timestamp. No backwards, no crash and burn.
Ah, perfect, then my patch should be fine.
I think I had read that part of the code before, but then forgotten about it.
> The normal timekeeping accessor functions cannot be called between
> timekeeping_suspend() and timekeeping_resume() at all. They will emit a
> warning and can indeed crash and burn in one of the ways you described
> above. This does not happen on x86 because the TSC will just work on
> systems with pstore.
Sure, except for __getnstimeofday64(), which will intentionally not warn but
could crash in the clocksource driver (on non-x86). We do ignore the result
from __getnstimeofday64() when timekeeping is suspended, but only after
we call into the clocksource driver.
Arnd
next prev parent reply other threads:[~2017-11-09 23:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-08 16:00 Arnd Bergmann
2017-11-09 0:55 ` Kees Cook
2017-11-09 12:54 ` Arnd Bergmann
2017-11-09 23:00 ` Thomas Gleixner
2017-11-09 23:43 ` Arnd Bergmann [this message]
2017-11-10 0:46 ` Thomas Gleixner
2017-11-10 1:04 ` Kees Cook
2017-11-10 7:04 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAK8P3a1TWCSMoApGqEdmkLHVLgFdG0Zj2cg3B2hFLX-x5_5ueA@mail.gmail.com \
--to=arnd@arndb.de \
--cc=anton@enomsg.org \
--cc=ccross@android.com \
--cc=john.stultz@linaro.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=sboyd@codeaurora.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®