12 Nov, 2019

1 commit

  • A cast to 'time_t' was accidentally left in place during the
    conversion of __do_adjtimex() to 64-bit timestamps, so the
    resulting value is incorrectly truncated.

    Remove the cast so the 64-bit time gets propagated correctly.

    Fixes: ead25417f82e ("timex: use __kernel_timex internally")
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Thomas Gleixner
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20191108203435.112759-2-arnd@arndb.de

    Arnd Bergmann
     

22 Jun, 2019

1 commit

  • Don't allow the TAI-UTC offset of the system clock to be set by adjtimex()
    to a value larger than 100000 seconds.

    This prevents an overflow in the conversion to int, prevents the CLOCK_TAI
    clock from getting too far ahead of the CLOCK_REALTIME clock, and it is
    still large enough to allow leap seconds to be inserted at the maximum rate
    currently supported by the kernel (once per day) for the next ~270 years,
    however unlikely it is that someone can survive a catastrophic event which
    slowed down the rotation of the Earth so much.

    Reported-by: Weikang shi
    Signed-off-by: Miroslav Lichvar
    Signed-off-by: Thomas Gleixner
    Cc: John Stultz
    Cc: Prarit Bhargava
    Cc: Richard Cochran
    Cc: Stephen Boyd
    Link: https://lkml.kernel.org/r/20190618154713.20929-1-mlichvar@redhat.com

    Miroslav Lichvar
     

17 May, 2019

1 commit


09 May, 2019

1 commit

  • The ADJ_TAI adjtimex mode sets the TAI-UTC offset of the system clock.
    It is typically set by NTP/PTP implementations and it is automatically
    updated by the kernel on leap seconds. The initial value is zero (which
    applications may interpret as unknown), but this value cannot be set by
    adjtimex. This limitation seems to go back to the original "nanokernel"
    implementation by David Mills.

    Change the ADJ_TAI check to accept zero as a valid TAI-UTC offset in
    order to allow setting it back to the initial value.

    Fixes: 153b5d054ac2 ("ntp: support for TAI")
    Suggested-by: Ondrej Mosnacek
    Signed-off-by: Miroslav Lichvar
    Signed-off-by: Thomas Gleixner
    Cc: John Stultz
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Link: https://lkml.kernel.org/r/20190417084833.7401-1-mlichvar@redhat.com

    Miroslav Lichvar
     

16 Apr, 2019

1 commit

  • Emit an audit record every time selected NTP parameters are modified
    from userspace (via adjtimex(2) or clock_adjtime(2)). These parameters
    may be used to indirectly change system clock, and thus their
    modifications should be audited.

    Such events will now generate records of type AUDIT_TIME_ADJNTPVAL
    containing the following fields:
    - op -- which value was adjusted:
    - offset -- corresponding to the time_offset variable
    - freq -- corresponding to the time_freq variable
    - status -- corresponding to the time_status variable
    - adjust -- corresponding to the time_adjust variable
    - tick -- corresponding to the tick_usec variable
    - tai -- corresponding to the timekeeping's TAI offset
    - old -- the old value
    - new -- the new value

    Example records:

    type=TIME_ADJNTPVAL msg=audit(1530616044.507:7): op=status old=64 new=8256
    type=TIME_ADJNTPVAL msg=audit(1530616044.511:11): op=freq old=0 new=49180377088000

    The records of this type will be associated with the corresponding
    syscall records.

    An overview of parameter changes that can be done via do_adjtimex()
    (based on information from Miroslav Lichvar) and whether they are
    audited:
    __timekeeping_set_tai_offset() -- sets the offset from the
    International Atomic Time
    (AUDITED)
    NTP variables:
    time_offset -- can adjust the clock by up to 0.5 seconds per call
    and also speed it up or slow down by up to about
    0.05% (43 seconds per day) (AUDITED)
    time_freq -- can speed up or slow down by up to about 0.05%
    (AUDITED)
    time_status -- can insert/delete leap seconds and it also enables/
    disables synchronization of the hardware real-time
    clock (AUDITED)
    time_maxerror, time_esterror -- change error estimates used to
    inform userspace applications
    (NOT AUDITED)
    time_constant -- controls the speed of the clock adjustments that
    are made when time_offset is set (NOT AUDITED)
    time_adjust -- can temporarily speed up or slow down the clock by up
    to 0.05% (AUDITED)
    tick_usec -- a more extreme version of time_freq; can speed up or
    slow down the clock by up to 10% (AUDITED)

    Signed-off-by: Ondrej Mosnacek
    Reviewed-by: Richard Guy Briggs
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Paul Moore

    Ondrej Mosnacek
     

07 Feb, 2019

1 commit

  • struct timex is not y2038 safe.
    Replace all uses of timex with y2038 safe __kernel_timex.

    Note that struct __kernel_timex is an ABI interface definition.
    We could define a new structure based on __kernel_timex that
    is only available internally instead. Right now, there isn't
    a strong motivation for this as the structure is isolated to
    a few defined struct timex interfaces and such a structure would
    be exactly the same as struct timex.

    The patch was generated by the following coccinelle script:

    virtual patch

    @depends on patch forall@
    identifier ts;
    expression e;
    @@
    (
    - struct timex ts;
    + struct __kernel_timex ts;
    |
    - struct timex ts = {};
    + struct __kernel_timex ts = {};
    |
    - struct timex ts = e;
    + struct __kernel_timex ts = e;
    |
    - struct timex *ts;
    + struct __kernel_timex *ts;
    |
    (memset \| copy_from_user \| copy_to_user \)(...,
    - sizeof(struct timex))
    + sizeof(struct __kernel_timex))
    )

    @depends on patch forall@
    identifier ts;
    identifier fn;
    @@
    fn(...,
    - struct timex *ts,
    + struct __kernel_timex *ts,
    ...) {
    ...
    }

    @depends on patch forall@
    identifier ts;
    identifier fn;
    @@
    fn(...,
    - struct timex *ts) {
    + struct __kernel_timex *ts) {
    ...
    }

    Signed-off-by: Deepa Dinamani
    Cc: linux-alpha@vger.kernel.org
    Cc: netdev@vger.kernel.org
    Signed-off-by: Arnd Bergmann

    Deepa Dinamani
     

29 Dec, 2018

1 commit

  • Pull y2038 updates from Arnd Bergmann:
    "More syscalls and cleanups

    This concludes the main part of the system call rework for 64-bit
    time_t, which has spread over most of year 2018, the last six system
    calls being

    - ppoll
    - pselect6
    - io_pgetevents
    - recvmmsg
    - futex
    - rt_sigtimedwait

    As before, nothing changes for 64-bit architectures, while 32-bit
    architectures gain another entry point that differs only in the layout
    of the timespec structure. Hopefully in the next release we can wire
    up all 22 of those system calls on all 32-bit architectures, which
    gives us a baseline version for glibc to start using them.

    This does not include the clock_adjtime, getrusage/waitid, and
    getitimer/setitimer system calls. I still plan to have new versions of
    those as well, but they are not required for correct operation of the
    C library since they can be emulated using the old 32-bit time_t based
    system calls.

    Aside from the system calls, there are also a few cleanups here,
    removing old kernel internal interfaces that have become unused after
    all references got removed. The arch/sh cleanups are part of this,
    there were posted several times over the past year without a reaction
    from the maintainers, while the corresponding changes made it into all
    other architectures"

    * tag 'y2038-for-4.21' of ssh://gitolite.kernel.org:/pub/scm/linux/kernel/git/arnd/playground:
    timekeeping: remove obsolete time accessors
    vfs: replace current_kernel_time64 with ktime equivalent
    timekeeping: remove timespec_add/timespec_del
    timekeeping: remove unused {read,update}_persistent_clock
    sh: remove board_time_init() callback
    sh: remove unused rtc_sh_get/set_time infrastructure
    sh: sh03: rtc: push down rtc class ops into driver
    sh: dreamcast: rtc: push down rtc class ops into driver
    y2038: signal: Add compat_sys_rt_sigtimedwait_time64
    y2038: signal: Add sys_rt_sigtimedwait_time32
    y2038: socket: Add compat_sys_recvmmsg_time64
    y2038: futex: Add support for __kernel_timespec
    y2038: futex: Move compat implementation into futex.c
    io_pgetevents: use __kernel_timespec
    pselect6: use __kernel_timespec
    ppoll: use __kernel_timespec
    signal: Add restore_user_sigmask()
    signal: Add set_user_sigmask()

    Linus Torvalds
     

18 Dec, 2018

2 commits


20 Jul, 2018

3 commits

  • Add 'const' to some function arguments and variables to make it easier
    to read the code.

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Miroslav Lichvar
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Cc: Stephen Boyd
    Signed-off-by: Ondrej Mosnacek
    [jstultz: Also fixup pre-existing checkpatch warnings for
    prototype arguments with no variable name]
    Signed-off-by: John Stultz

    Ondrej Mosnacek
     
  • ...instead of kstrtol with a dirty cast.

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Miroslav Lichvar
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Cc: Stephen Boyd
    Signed-off-by: Ondrej Mosnacek
    Signed-off-by: John Stultz

    Ondrej Mosnacek
     
  • The 'ts' argument of process_adj_status() and process_adjtimex_modes()
    is unused and can be safely removed.

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Miroslav Lichvar
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Cc: Stephen Boyd
    Signed-off-by: Ondrej Mosnacek
    Signed-off-by: John Stultz

    Ondrej Mosnacek
     

19 Jun, 2018

1 commit


06 Apr, 2018

1 commit


14 Nov, 2017

1 commit

  • Pull timer updates from Thomas Gleixner:
    "Yet another big pile of changes:

    - More year 2038 work from Arnd slowly reaching the point where we
    need to think about the syscalls themself.

    - A new timer function which allows to conditionally (re)arm a timer
    only when it's either not running or the new expiry time is sooner
    than the armed expiry time. This allows to use a single timer for
    multiple timeout requirements w/o caring about the first expiry
    time at the call site.

    - A new NMI safe accessor to clock real time for the printk timestamp
    work. Can be used by tracing, perf as well if required.

    - A large number of timer setup conversions from Kees which got
    collected here because either maintainers requested so or they
    simply got ignored. As Kees pointed out already there are a few
    trivial merge conflicts and some redundant commits which was
    unavoidable due to the size of this conversion effort.

    - Avoid a redundant iteration in the timer wheel softirq processing.

    - Provide a mechanism to treat RTC implementations depending on their
    hardware properties, i.e. don't inflict the write at the 0.5
    seconds boundary which originates from the PC CMOS RTC to all RTCs.
    No functional change as drivers need to be updated separately.

    - The usual small updates to core code clocksource drivers. Nothing
    really exciting"

    * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (111 commits)
    timers: Add a function to start/reduce a timer
    pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday()
    timer: Prepare to change all DEFINE_TIMER() callbacks
    netfilter: ipvs: Convert timers to use timer_setup()
    scsi: qla2xxx: Convert timers to use timer_setup()
    block/aoe: discover_timer: Convert timers to use timer_setup()
    ide: Convert timers to use timer_setup()
    drbd: Convert timers to use timer_setup()
    mailbox: Convert timers to use timer_setup()
    crypto: Convert timers to use timer_setup()
    drivers/pcmcia: omap1: Fix error in automated timer conversion
    ARM: footbridge: Fix typo in timer conversion
    drivers/sgi-xp: Convert timers to use timer_setup()
    drivers/pcmcia: Convert timers to use timer_setup()
    drivers/memstick: Convert timers to use timer_setup()
    drivers/macintosh: Convert timers to use timer_setup()
    hwrng/xgene-rng: Convert timers to use timer_setup()
    auxdisplay: Convert timers to use timer_setup()
    sparc/led: Convert timers to use timer_setup()
    mips: ip22/32: Convert timers to use timer_setup()
    ...

    Linus Torvalds
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

31 Oct, 2017

2 commits

  • The code to check the adjtimex() or clock_adjtime() arguments is spread
    out across multiple files for presumably only historic reasons. As a
    preparatation for a rework to get rid of the use of 'struct timeval'
    and 'struct timespec' in there, this moves all the portions into
    kernel/time/timekeeping.c and marks them as 'static'.

    The warp_clock() function here is not as closely related as the others,
    but I feel it still makes sense to move it here in order to consolidate
    all callers of timekeeping_inject_offset().

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Miroslav Lichvar
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Cc: Stephen Boyd
    Signed-off-by: Arnd Bergmann
    [jstultz: Whitespace fixup]
    Signed-off-by: John Stultz

    Arnd Bergmann
     
  • ntp is currently hardwired to try and call the rtc set when wall clock
    tv_nsec is 0.5 seconds. This historical behaviour works well with certain
    PC RTCs, but is not universal to all rtc hardware.

    Change how this works by introducing the driver specific concept of
    set_offset_nsec, the delay between current wall clock time and the target
    time to set (with a 0 tv_nsecs).

    For x86-style CMOS set_offset_nsec should be -0.5 s which causes the last
    second to be written 0.5 s after it has started.

    For compat with the old rtc_set_ntp_time, the value is defaulted to
    + 0.5 s, which causes the next second to be written 0.5s before it starts,
    as things were before this patch.

    Testing shows many non-x86 RTCs would like set_offset_nsec ~= 0,
    so ultimately each RTC driver should set the set_offset_nsec according
    to its needs, and non x86 architectures should stop using
    update_persistent_clock64 in order to access this feature.
    Future patches will revise the drivers as needed.

    Since CMOS and RTC now have very different handling they are split
    into two dedicated code paths, sharing the support code, and ifdefs
    are replaced with IS_ENABLED.

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Miroslav Lichvar
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Cc: Stephen Boyd
    Signed-off-by: Jason Gunthorpe
    Signed-off-by: John Stultz

    Jason Gunthorpe
     

26 Dec, 2016

1 commit

  • ktime is a union because the initial implementation stored the time in
    scalar nanoseconds on 64 bit machine and in a endianess optimized timespec
    variant for 32bit machines. The Y2038 cleanup removed the timespec variant
    and switched everything to scalar nanoseconds. The union remained, but
    become completely pointless.

    Get rid of the union and just keep ktime_t as simple typedef of type s64.

    The conversion was done with coccinelle and some manual mopping up.

    Signed-off-by: Thomas Gleixner
    Cc: Peter Zijlstra

    Thomas Gleixner
     

22 Jan, 2016

1 commit

  • Recently, in commit 37cf4dc3370f I forgot to check if the timeval being passed
    was actually a timespec (as is signaled with ADJ_NANO).

    This resulted in that patch breaking ADJ_SETOFFSET users who set
    ADJ_NANO, by rejecting valid timespecs that were compared with
    valid timeval ranges.

    This patch addresses this by checking for the ADJ_NANO flag and
    using the timepsec check instead in that case.

    Reported-by: Harald Hoyer
    Reported-by: Kay Sievers
    Fixes: 37cf4dc3370f "time: Verify time values in adjtimex ADJ_SETOFFSET to avoid overflow"
    Signed-off-by: John Stultz
    Cc: Sasha Levin
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Cc: David Herrmann
    Link: http://lkml.kernel.org/r/1453417415-19110-2-git-send-email-john.stultz@linaro.org
    Signed-off-by: Thomas Gleixner

    John Stultz
     

17 Dec, 2015

2 commits

  • The function "second_overflow" uses "unsign long"
    as its input parameter type which will overflow after
    year 2106 on 32bit systems.

    Thus this patch replaces it with time64_t type.

    While the 64-bit division is expensive, "next_ntp_leap_sec"
    has been calculated already, so we can just re-use it in the
    TIME_INS/DEL cases, allowing one expensive division per
    leapsecond instead of re-doing the divsion once a second after
    the leap flag has been set.

    Signed-off-by: DengChao
    [jstultz: Tweaked commit message]
    Signed-off-by: John Stultz

    DengChao
     
  • The type of static variant "time_reftime" and the call of
    get_seconds in ntp are both not y2038 safe.

    So change the type of time_reftime to time64_t and replace
    get_seconds with __ktime_get_real_seconds.

    The local variant "secs" in ntp_update_offset represents
    seconds between now and last ntp adjustment, it seems impossible
    that this time will last more than 68 years, so keep its type as
    "long".

    Reviewed-by: John Stultz
    Signed-off-by: DengChao
    [jstultz: Tweaked commit message]
    Signed-off-by: John Stultz

    DengChao
     

11 Dec, 2015

2 commits

  • For adjtimex()'s ADJ_SETOFFSET, make sure the tv_usec value is
    sane. We might multiply them later which can cause an overflow
    and undefined behavior.

    This patch introduces new helper functions to simplify the
    checking code and adds comments to clarify

    Orginally this patch was by Sasha Levin, but I've basically
    rewritten it, so he should get credit for finding the issue
    and I should get the blame for any mistakes made since.

    Also, credit to Richard Cochran for the phrasing used in the
    comment for what is considered valid here.

    Cc: Sasha Levin
    Cc: Richard Cochran
    Cc: Thomas Gleixner
    Reported-by: Sasha Levin
    Signed-off-by: John Stultz

    John Stultz
     
  • We need to make sure that the offset is valid before manipulating it,
    otherwise it might overflow on the multiplication.

    Cc: Sasha Levin
    Cc: Richard Cochran
    Cc: Thomas Gleixner
    Signed-off-by: Sasha Levin
    [jstultz: Reworked one of the checks so it makes more sense]
    Signed-off-by: John Stultz

    Sasha Levin
     

02 Oct, 2015

2 commits

  • The sync_cmos_clock has one use of struct timespec, which we want to
    eventually replace with timespec64 or similar in the kernel. There
    is no way this one can overflow, but the conversion to timespec64
    is trivial and has no other dependencies.

    Acked-by: Richard Cochran
    Acked-by: David S. Miller
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Arnd Bergmann
    Signed-off-by: John Stultz

    Arnd Bergmann
     
  • There is only one user of the hardpps function in the kernel, so
    it makes sense to atomically change it over to using 64-bit
    timestamps for y2038 safety. In the hardpps implementation,
    we also need to change the pps_normtime structure, which is
    similar to struct timespec and also requires a 64-bit
    seconds portion.

    This introduces two temporary variables in pps_kc_event() to
    do the conversion, they will be removed again in the next step,
    which seemed preferable to having a larger patch changing it
    all at the same time.

    Acked-by: Richard Cochran
    Acked-by: David S. Miller
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Arnd Bergmann
    Signed-off-by: John Stultz

    Arnd Bergmann
     

18 Aug, 2015

1 commit

  • The weak update_persistent_clock64() calls update_persistent_clock(),
    if the architecture defines an update_persistent_clock64() to replace
    and remove its update_persistent_clock() version, when building the
    kernel the linker will throw an undefined symbol error, that is, any
    arch that switches to update_persistent_clock64() will have this issue.

    To solve the issue, we add the common weak update_persistent_clock().

    Cc: Prarit Bhargava
    Cc: Richard Cochran
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: Arnd Bergmann
    Signed-off-by: Xunlei Pang
    Signed-off-by: John Stultz

    Xunlei Pang
     

12 Jun, 2015

3 commits

  • Since the leapsecond is applied at tick-time, this means there is a
    small window of time at the start of a leap-second where we cross into
    the next second before applying the leap.

    This patch modified adjtimex so that the leap-second is applied on the
    second edge. Providing more correct leapsecond behavior.

    This does make it so that adjtimex()'s returned time values can be
    inconsistent with time values read from gettimeofday() or
    clock_gettime(CLOCK_REALTIME,...) for a brief period of one tick at
    the leapsecond. However, those other interfaces do not provide the
    TIME_OOP time_state return that adjtimex() provides, which allows the
    leapsecond to be properly represented. They instead only see a time
    discontinuity, and cannot tell the first 23:59:59 from the repeated
    23:59:59 leap second.

    This seems like a reasonable tradeoff given clock_gettime() /
    gettimeofday() cannot properly represent a leapsecond, and users
    likely care more about performance, while folks who are using
    adjtimex() more likely care about leap-second correctness.

    Signed-off-by: John Stultz
    Cc: Prarit Bhargava
    Cc: Daniel Bristot de Oliveira
    Cc: Richard Cochran
    Cc: Jan Kara
    Cc: Jiri Bohac
    Cc: Ingo Molnar
    Link: http://lkml.kernel.org/r/1434063297-28657-5-git-send-email-john.stultz@linaro.org
    Signed-off-by: Thomas Gleixner

    John Stultz
     
  • Currently, leapsecond adjustments are done at tick time. As a result,
    the leapsecond was applied at the first timer tick *after* the
    leapsecond (~1-10ms late depending on HZ), rather then exactly on the
    second edge.

    This was in part historical from back when we were always tick based,
    but correcting this since has been avoided since it adds extra
    conditional checks in the gettime fastpath, which has performance
    overhead.

    However, it was recently pointed out that ABS_TIME CLOCK_REALTIME
    timers set for right after the leapsecond could fire a second early,
    since some timers may be expired before we trigger the timekeeping
    timer, which then applies the leapsecond.

    This isn't quite as bad as it sounds, since behaviorally it is similar
    to what is possible w/ ntpd made leapsecond adjustments done w/o using
    the kernel discipline. Where due to latencies, timers may fire just
    prior to the settimeofday call. (Also, one should note that all
    applications using CLOCK_REALTIME timers should always be careful,
    since they are prone to quirks from settimeofday() disturbances.)

    However, the purpose of having the kernel do the leap adjustment is to
    avoid such latencies, so I think this is worth fixing.

    So in order to properly keep those timers from firing a second early,
    this patch modifies the ntp and timekeeping logic so that we keep
    enough state so that the update_base_offsets_now accessor, which
    provides the hrtimer core the current time, can check and apply the
    leapsecond adjustment on the second edge. This prevents the hrtimer
    core from expiring timers too early.

    This patch does not modify any other time read path, so no additional
    overhead is incurred. However, this also means that the leap-second
    continues to be applied at tick time for all other read-paths.

    Apologies to Richard Cochran, who pushed for similar changes years
    ago, which I resisted due to the concerns about the performance
    overhead.

    While I suspect this isn't extremely critical, folks who care about
    strict leap-second correctness will likely want to watch
    this. Potentially a -stable candidate eventually.

    Originally-suggested-by: Richard Cochran
    Reported-by: Daniel Bristot de Oliveira
    Reported-by: Prarit Bhargava
    Signed-off-by: John Stultz
    Cc: Richard Cochran
    Cc: Jan Kara
    Cc: Jiri Bohac
    Cc: Shuah Khan
    Cc: Ingo Molnar
    Link: http://lkml.kernel.org/r/1434063297-28657-4-git-send-email-john.stultz@linaro.org
    Signed-off-by: Thomas Gleixner

    John Stultz
     
  • Currently the leapsecond logic uses what looks like magic values.

    Improve this by defining SECS_PER_DAY and using that macro
    to make the logic more clear.

    Signed-off-by: John Stultz
    Cc: Prarit Bhargava
    Cc: Daniel Bristot de Oliveira
    Cc: Richard Cochran
    Cc: Jan Kara
    Cc: Jiri Bohac
    Cc: Ingo Molnar
    Link: http://lkml.kernel.org/r/1434063297-28657-3-git-send-email-john.stultz@linaro.org
    Signed-off-by: Thomas Gleixner

    John Stultz
     

03 Apr, 2015

1 commit

  • As part of addressing in-kernel y2038 issues, this patch adds
    update_persistent_clock64() and replaces all the call sites of
    update_persistent_clock() with this function. This is a __weak
    implementation, which simply calls the existing y2038 unsafe
    update_persistent_clock().

    This allows architecture specific implementations to be
    converted independently, and eventually y2038-unsafe
    update_persistent_clock() can be removed after all its
    architecture specific implementations have been converted to
    update_persistent_clock64().

    Suggested-by: Arnd Bergmann
    Signed-off-by: Xunlei Pang
    Signed-off-by: John Stultz
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/1427945681-29972-4-git-send-email-john.stultz@linaro.org
    Signed-off-by: Ingo Molnar

    Xunlei Pang
     

01 Apr, 2015

1 commit


18 Feb, 2015

1 commit

  • Additional validation of adjtimex freq values to avoid
    potential multiplication overflows were added in commit
    5e5aeb4367b (time: adjtimex: Validate the ADJ_FREQUENCY values)

    Unfortunately the patch used LONG_MAX/MIN instead of
    LLONG_MAX/MIN, which was fine on 64-bit systems, but being
    much smaller on 32-bit systems caused false positives
    resulting in most direct frequency adjustments to fail w/
    EINVAL.

    ntpd only does direct frequency adjustments at startup, so
    the issue was not as easily observed there, but other time
    sync applications like ptpd and chrony were more effected by
    the bug.

    See bugs:

    https://bugzilla.kernel.org/show_bug.cgi?id=92481
    https://bugzilla.redhat.com/show_bug.cgi?id=1188074

    This patch changes the checks to use LLONG_MAX for
    clarity, and additionally the checks are disabled
    on 32-bit systems since LLONG_MAX/PPM_SCALE is always
    larger then the 32-bit long freq value, so multiplication
    overflows aren't possible there.

    Reported-by: Josh Boyer
    Reported-by: George Joseph
    Tested-by: George Joseph
    Signed-off-by: John Stultz
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: # v3.19+
    Cc: Linus Torvalds
    Cc: Sasha Levin
    Link: http://lkml.kernel.org/r/1423553436-29747-1-git-send-email-john.stultz@linaro.org
    [ Prettified the changelog and the comments a bit. ]
    Signed-off-by: Ingo Molnar

    John Stultz
     

10 Feb, 2015

1 commit

  • Pull timer updates from Ingo Molnar:
    "The main changes in this cycle were:

    - rework hrtimer expiry calculation in hrtimer_interrupt(): the
    previous code had a subtle bug where expiry caching would miss an
    expiry, resulting in occasional bogus (late) expiry of hrtimers.

    - continuing Y2038 fixes

    - ktime division optimization

    - misc smaller fixes and cleanups"

    * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
    hrtimer: Make __hrtimer_get_next_event() static
    rtc: Convert rtc_set_ntp_time() to use timespec64
    rtc: Remove redundant rtc_valid_tm() from rtc_hctosys()
    rtc: Modify rtc_hctosys() to address y2038 issues
    rtc: Update rtc-dev to use y2038-safe time interfaces
    rtc: Update interface.c to use y2038-safe time interfaces
    time: Expose get_monotonic_boottime64 for in-kernel use
    time: Expose getboottime64 for in-kernel uses
    ktime: Optimize ktime_divns for constant divisors
    hrtimer: Prevent stale expiry time in hrtimer_interrupt()
    ktime.h: Introduce ktime_ms_delta

    Linus Torvalds
     

24 Jan, 2015

1 commit

  • rtc_set_ntp_time() uses timespec which is y2038-unsafe,
    so modify to use timespec64 which is y2038-safe, then
    replace rtc_time_to_tm() with rtc_time64_to_tm().

    Also adjust all its call sites(only NTP uses it) accordingly.

    Cc: pang.xunlei
    Cc: Arnd Bergmann
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Xunlei Pang
    Signed-off-by: John Stultz

    Xunlei Pang
     

08 Jan, 2015

1 commit

  • Verify that the frequency value from userspace is valid and makes sense.

    Unverified values can cause overflows later on.

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: stable
    Signed-off-by: Sasha Levin
    [jstultz: Fix up bug for negative values and drop redunent cap check]
    Signed-off-by: John Stultz

    Sasha Levin
     

24 Jul, 2014

2 commits


05 Jun, 2014

2 commits

  • Merge misc updates from Andrew Morton:

    - a few fixes for 3.16. Cc'ed to stable so they'll get there somehow.

    - various misc fixes and cleanups

    - most of the ocfs2 queue. Review is slow...

    - most of MM. The MM queue is pretty huge this time, but not much in
    the way of feature work.

    - some tweaks under kernel/

    - printk maintenance work

    - updates to lib/

    - checkpatch updates

    - tweaks to init/

    * emailed patches from Andrew Morton : (276 commits)
    fs/autofs4/dev-ioctl.c: add __init to autofs_dev_ioctl_init
    fs/ncpfs/getopt.c: replace simple_strtoul by kstrtoul
    init/main.c: remove an ifdef
    kthreads: kill CLONE_KERNEL, change kernel_thread(kernel_init) to avoid CLONE_SIGHAND
    init/main.c: add initcall_blacklist kernel parameter
    init/main.c: don't use pr_debug()
    fs/binfmt_flat.c: make old_reloc() static
    fs/binfmt_elf.c: fix bool assignements
    fs/efs: convert printk(KERN_DEBUG to pr_debug
    fs/efs: add pr_fmt / use __func__
    fs/efs: convert printk to pr_foo()
    scripts/checkpatch.pl: device_initcall is not the only __initcall substitute
    checkpatch: check stable email address
    checkpatch: warn on unnecessary void function return statements
    checkpatch: prefer kstrto to sscanf(buf, "%", &bar);
    checkpatch: add warning for kmalloc/kzalloc with multiply
    checkpatch: warn on #defines ending in semicolon
    checkpatch: make --strict a default for files in drivers/net and net/
    checkpatch: always warn on missing blank line after variable declaration block
    checkpatch: fix wildcard DT compatible string checking
    ...

    Linus Torvalds
     
  • Jiri Bohac pointed out that there are rare but potential deadlock
    possibilities when calling printk while holding the timekeeping
    seqlock.

    This is due to printk() triggering console sem wakeup, which can
    cause scheduling code to trigger hrtimers which may try to read
    the time.

    Specifically, as Jiri pointed out, that path is:
    printk
    vprintk_emit
    console_unlock
    up(&console_sem)
    __up
    wake_up_process
    try_to_wake_up
    ttwu_do_activate
    ttwu_activate
    activate_task
    enqueue_task
    enqueue_task_fair
    hrtick_update
    hrtick_start_fair
    hrtick_start_fair
    get_time
    ktime_get
    --> endless loop on
    read_seqcount_retry(&timekeeper_seq, ...)

    This patch tries to avoid this issue by using printk_deferred (previously
    named printk_sched) which should defer printing via a irq_work_queue.

    Signed-off-by: John Stultz
    Reported-by: Jiri Bohac
    Reviewed-by: Steven Rostedt
    Cc: Jan Kara
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Steven Rostedt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    John Stultz