[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALAqxLUFFZqiFVr5-8WAFzJ=JENUj3Yz4W+3zCoJ22zStUO1aw@mail.gmail.com>
Date: Tue, 4 Oct 2016 17:50:39 -0700
From: John Stultz <john.stultz@...aro.org>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: lkml <linux-kernel@...r.kernel.org>,
Steven Rostedt <rostedt@...dmis.org>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
stable <stable@...r.kernel.org>,
Brendan Gregg <bgregg@...flix.com>
Subject: Re: [PATCH 1/2] timekeeping: Avoid taking lock in NMI path with CONFIG_DEBUG_TIMEKEEPING
On Tue, Oct 4, 2016 at 5:30 PM, Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
> On Tue, Aug 23, 2016 at 04:08:21PM -0700, John Stultz wrote:
>> When I added some extra sanity checking in timekeeping_get_ns() under
>> CONFIG_DEBUG_TIMEKEEPING, I missed that the NMI safe __ktime_get_fast_ns()
>> method was using timekeeping_get_ns().
>>
>> Thus the locking added to the debug checks broke the NMI-safety of
>> __ktime_get_fast_ns().
>>
>> This patch open-codes the timekeeping_get_ns() logic for
>> __ktime_get_fast_ns(), so can avoid any deadlocks in NMI.
>>
>> Cc: Steven Rostedt <rostedt@...dmis.org>
>> Cc: Peter Zijlstra <peterz@...radead.org>
>> Cc: Ingo Molnar <mingo@...nel.org>
>> Cc: Thomas Gleixner <tglx@...utronix.de>
>> Cc: stable <stable@...r.kernel.org> # 4.1+
>> Reported-by: Steven Rostedt <rostedt@...dmis.org>
>> Reported-by: Peter Zijlstra <peterz@...radead.org>
>> Signed-off-by: John Stultz <john.stultz@...aro.org>
>> ---
>> kernel/time/timekeeping.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
>> index 3b65746..e07fb09 100644
>> --- a/kernel/time/timekeeping.c
>> +++ b/kernel/time/timekeeping.c
>> @@ -401,7 +401,10 @@ static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf)
>> do {
>> seq = raw_read_seqcount_latch(&tkf->seq);
>> tkr = tkf->base + (seq & 0x01);
>> - now = ktime_to_ns(tkr->base) + timekeeping_get_ns(tkr);
>> + now = ktime_to_ns(tkr->base);
>> +
>> + now += clocksource_delta(tkr->read(tkr->clock),
>> + tkr->cycle_last, tkr->mask);
>
> we're seeing the time jumping backwards between __ktime_get_fast_ns calls.
> and looks like this patch broke it, since delta is being added to ns.
> It seems it should be:
> now += timekeeping_delta_to_ns(clocksource_delta(...));
> or better fix possible?
Gah! Yes. Quite right. I'm not sure how I missed that. Thanks for
catching it quickly and apologies!
I've got an initial fix but I'm sitting down for dinner so I'll send
it out a bit later after I can test it.
thanks
-john
Powered by blists - more mailing lists