Skip to content

Commit

Permalink
timekeeping: Avoid taking lock in NMI path with CONFIG_DEBUG_TIMEKEEPING
Browse files Browse the repository at this point in the history
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.

Fixes: 4ca22c2 "timekeeping: Add warnings when overflows or underflows are observed"
Reported-by: Steven Rostedt <[email protected]>
Reported-by: Peter Zijlstra <[email protected]>
Signed-off-by: John Stultz <[email protected]>
Cc: stable <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>
  • Loading branch information
johnstultz-work authored and KAGA-KOKO committed Aug 24, 2016
1 parent fa8410b commit 27727df
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
} while (read_seqcount_retry(&tkf->seq, seq));

return now;
Expand Down

0 comments on commit 27727df

Please sign in to comment.