<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/kernel/time/time.c, branch v4.9.20</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.9.20</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.9.20'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2016-08-31T21:43:35Z</updated>
<entry>
<title>time: Avoid undefined behaviour in timespec64_add_safe()</title>
<updated>2016-08-31T21:43:35Z</updated>
<author>
<name>Vegard Nossum</name>
<email>vegard.nossum@oracle.com</email>
</author>
<published>2016-08-12T18:14:09Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=469e857f374640f6164913835ce30d0736b40a60'/>
<id>urn:sha1:469e857f374640f6164913835ce30d0736b40a60</id>
<content type='text'>
I ran into this:

    ================================================================================
    UBSAN: Undefined behaviour in kernel/time/time.c:783:2
    signed integer overflow:
    5273 + 9223372036854771711 cannot be represented in type 'long int'
    CPU: 0 PID: 17363 Comm: trinity-c0 Not tainted 4.8.0-rc1+ #88
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org
    04/01/2014
     0000000000000000 ffff88011457f8f0 ffffffff82344f50 0000000041b58ab3
     ffffffff84f98080 ffffffff82344ea4 ffff88011457f918 ffff88011457f8c8
     ffff88011457f8e0 7fffffffffffefff ffff88011457f6d8 dffffc0000000000
    Call Trace:
     [&lt;ffffffff82344f50&gt;] dump_stack+0xac/0xfc
     [&lt;ffffffff82344ea4&gt;] ? _atomic_dec_and_lock+0xc4/0xc4
     [&lt;ffffffff8242f4c8&gt;] ubsan_epilogue+0xd/0x8a
     [&lt;ffffffff8242fc04&gt;] handle_overflow+0x202/0x23d
     [&lt;ffffffff8242fa02&gt;] ? val_to_string.constprop.6+0x11e/0x11e
     [&lt;ffffffff823c7837&gt;] ? debug_smp_processor_id+0x17/0x20
     [&lt;ffffffff8131b581&gt;] ? __sigqueue_free.part.13+0x51/0x70
     [&lt;ffffffff8146d4e0&gt;] ? rcu_is_watching+0x110/0x110
     [&lt;ffffffff8242fc4d&gt;] __ubsan_handle_add_overflow+0xe/0x10
     [&lt;ffffffff81476ef8&gt;] timespec64_add_safe+0x298/0x340
     [&lt;ffffffff81476c60&gt;] ? timespec_add_safe+0x330/0x330
     [&lt;ffffffff812f7990&gt;] ? wait_noreap_copyout+0x1d0/0x1d0
     [&lt;ffffffff8184bf18&gt;] poll_select_set_timeout+0xf8/0x170
     [&lt;ffffffff8184be20&gt;] ? poll_schedule_timeout+0x2b0/0x2b0
     [&lt;ffffffff813aa9bb&gt;] ? __might_sleep+0x5b/0x260
     [&lt;ffffffff833c8a87&gt;] __sys_recvmmsg+0x107/0x790
     [&lt;ffffffff833c8980&gt;] ? SyS_recvmsg+0x20/0x20
     [&lt;ffffffff81486378&gt;] ? hrtimer_start_range_ns+0x3b8/0x1380
     [&lt;ffffffff845f8bfb&gt;] ? _raw_spin_unlock_irqrestore+0x3b/0x60
     [&lt;ffffffff8148bcea&gt;] ? do_setitimer+0x39a/0x8e0
     [&lt;ffffffff813aa9bb&gt;] ? __might_sleep+0x5b/0x260
     [&lt;ffffffff833c9110&gt;] ? __sys_recvmmsg+0x790/0x790
     [&lt;ffffffff833c91e9&gt;] SyS_recvmmsg+0xd9/0x160
     [&lt;ffffffff833c9110&gt;] ? __sys_recvmmsg+0x790/0x790
     [&lt;ffffffff823c7853&gt;] ? __this_cpu_preempt_check+0x13/0x20
     [&lt;ffffffff8162f680&gt;] ? __context_tracking_exit.part.3+0x30/0x1b0
     [&lt;ffffffff833c9110&gt;] ? __sys_recvmmsg+0x790/0x790
     [&lt;ffffffff81007bd3&gt;] do_syscall_64+0x1b3/0x4b0
     [&lt;ffffffff845f936a&gt;] entry_SYSCALL64_slow_path+0x25/0x25
    ================================================================================

Line 783 is this:

783         set_normalized_timespec64(&amp;res, lhs.tv_sec + rhs.tv_sec,
784                         lhs.tv_nsec + rhs.tv_nsec);

In other words, since lhs.tv_sec and rhs.tv_sec are both time64_t, this
is a signed addition which will cause undefined behaviour on overflow.

Note that this is not currently a huge concern since the kernel should be
built with -fno-strict-overflow by default, but could be a problem in the
future, a problem with older compilers, or other compilers than gcc.

The easiest way to avoid the overflow is to cast one of the arguments to
unsigned (so the addition will be done using unsigned arithmetic).

Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Richard Cochran &lt;richardcochran@gmail.com&gt;
Cc: Prarit Bhargava &lt;prarit@redhat.com&gt;
Signed-off-by: Vegard Nossum &lt;vegard.nossum@oracle.com&gt;
Signed-off-by: John Stultz &lt;john.stultz@linaro.org&gt;
</content>
</entry>
<entry>
<title>time: remove timespec_add_safe()</title>
<updated>2016-05-20T02:12:14Z</updated>
<author>
<name>Deepa Dinamani</name>
<email>deepa.kernel@gmail.com</email>
</author>
<published>2016-05-20T00:09:08Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8e4f70e21877297577dce13cca97599a5864a91f'/>
<id>urn:sha1:8e4f70e21877297577dce13cca97599a5864a91f</id>
<content type='text'>
All references to timespec_add_safe() now use timespec64_add_safe().

The plan is to replace struct timespec references with struct timespec64
throughout the kernel as timespec is not y2038 safe.

Drop timespec_add_safe() and use timespec64_add_safe() for all
architectures.

Link: http://lkml.kernel.org/r/1461947989-21926-4-git-send-email-deepa.kernel@gmail.com
Signed-off-by: Deepa Dinamani &lt;deepa.kernel@gmail.com&gt;
Acked-by: John Stultz &lt;john.stultz@linaro.org&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Arnd Bergmann &lt;arnd@arndb.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>time: add missing implementation for timespec64_add_safe()</title>
<updated>2016-05-20T02:12:14Z</updated>
<author>
<name>Deepa Dinamani</name>
<email>deepa.kernel@gmail.com</email>
</author>
<published>2016-05-20T00:09:02Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=bc2c53e5f1a2bae69ae50ce3a592633da7fcf6d9'/>
<id>urn:sha1:bc2c53e5f1a2bae69ae50ce3a592633da7fcf6d9</id>
<content type='text'>
timespec64_add_safe() has been defined in time64.h for 64 bit systems.
But, 32 bit systems only have an extern function prototype defined.
Provide a definition for the above function.

The function will be necessary as part of y2038 changes.  struct
timespec is not y2038 safe.  All references to timespec will be replaced
by struct timespec64.  The function is meant to be a replacement for
timespec_add_safe().

The implementation is similar to timespec_add_safe().

Link: http://lkml.kernel.org/r/1461947989-21926-2-git-send-email-deepa.kernel@gmail.com
Signed-off-by: Deepa Dinamani &lt;deepa.kernel@gmail.com&gt;
Acked-by: John Stultz &lt;john.stultz@linaro.org&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Arnd Bergmann &lt;arnd@arndb.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>time: Introduce do_sys_settimeofday64()</title>
<updated>2016-04-22T18:49:04Z</updated>
<author>
<name>Baolin Wang</name>
<email>baolin.wang@linaro.org</email>
</author>
<published>2016-04-08T06:02:12Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=86d3473224b004f920c107206d181d37db735145'/>
<id>urn:sha1:86d3473224b004f920c107206d181d37db735145</id>
<content type='text'>
The do_sys_settimeofday() function uses a timespec, which is not year
2038 safe on 32bit systems.

Thus this patch introduces do_sys_settimeofday64(), which allows us to
transition users of do_sys_settimeofday() to using 64bit time types.

Cc: Prarit Bhargava &lt;prarit@redhat.com&gt;
Cc: Richard Cochran &lt;richardcochran@gmail.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Signed-off-by: Baolin Wang &lt;baolin.wang@linaro.org&gt;
[jstultz: Include errno-base.h to avoid build issue on some arches]
Signed-off-by: John Stultz &lt;john.stultz@linaro.org&gt;
</content>
</entry>
<entry>
<title>Handle ISO 8601 leap seconds and encodings of midnight in mktime64()</title>
<updated>2016-02-29T14:29:40Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2016-02-24T14:37:53Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=ede5147d515694e012cd958ec874b9daf8a65fec'/>
<id>urn:sha1:ede5147d515694e012cd958ec874b9daf8a65fec</id>
<content type='text'>
Handle the following ISO 8601 features in mktime64():

 (1) Leap seconds.

     Leap seconds are indicated by the seconds parameter being the value
     60.  Handle this by treating it the same as 00 of the following
     minute.

     It has been pointed out that a minute may contain two leap seconds.
     However, pending discussion of what that looks like and how to handle
     it, I'm not going to concern myself with it.

 (2) Alternate encodings of midnight.

     Two different encodings of midnight are permitted - 00:00:00 and
     24:00:00 - the first is midnight today and the second is midnight
     tomorrow and is exactly equivalent to the first with tomorrow's date.

As it happens, we don't actually need to change mktime64() to handle either
of these - just comment them as valid parameters.

These facility will be used by the X.509 parser.  Doing it in mktime64()
makes the policy common to the whole kernel and easier to find.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Arnd Bergmann &lt;arnd@arndb.de&gt;
cc: John Stultz &lt;john.stultz@linaro.org&gt;
cc: Rudolf Polzer &lt;rpolzer@google.com&gt;
cc: One Thousand Gnomes &lt;gnomes@lxorguk.ukuu.org.uk&gt;
</content>
</entry>
<entry>
<title>Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip</title>
<updated>2015-09-01T21:04:50Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2015-09-01T21:04:50Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=5e359bf2219d8622eb0931701e45af55db323228'/>
<id>urn:sha1:5e359bf2219d8622eb0931701e45af55db323228</id>
<content type='text'>
Pull timer updates from Thomas Gleixner:
 "Rather large, but nothing exiting:

   - new range check for settimeofday() to prevent that boot time
     becomes negative.
   - fix for file time rounding
   - a few simplifications of the hrtimer code
   - fix for the proc/timerlist code so the output of clock realtime
     timers is accurate
   - more y2038 work
   - tree wide conversion of clockevent drivers to the new callbacks"

* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (88 commits)
  hrtimer: Handle failure of tick_init_highres() gracefully
  hrtimer: Unconfuse switch_hrtimer_base() a bit
  hrtimer: Simplify get_target_base() by returning current base
  hrtimer: Drop return code of hrtimer_switch_to_hres()
  time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()
  time: Introduce current_kernel_time64()
  time: Introduce struct itimerspec64
  time: Add the common weak version of update_persistent_clock()
  time: Always make sure wall_to_monotonic isn't positive
  time: Fix nanosecond file time rounding in timespec_trunc()
  timer_list: Add the base offset so remaining nsecs are accurate for non monotonic timers
  cris/time: Migrate to new 'set-state' interface
  kernel: broadcast-hrtimer: Migrate to new 'set-state' interface
  xtensa/time: Migrate to new 'set-state' interface
  unicore/time: Migrate to new 'set-state' interface
  um/time: Migrate to new 'set-state' interface
  sparc/time: Migrate to new 'set-state' interface
  sh/localtimer: Migrate to new 'set-state' interface
  score/time: Migrate to new 'set-state' interface
  s390/time: Migrate to new 'set-state' interface
  ...
</content>
</entry>
<entry>
<title>time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()</title>
<updated>2015-08-17T18:25:41Z</updated>
<author>
<name>Baolin Wang</name>
<email>baolin.wang@linaro.org</email>
</author>
<published>2015-07-29T12:18:31Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=9ca308506062fc4a4ee8ca7ad2f71033c831c2fb'/>
<id>urn:sha1:9ca308506062fc4a4ee8ca7ad2f71033c831c2fb</id>
<content type='text'>
The conversion between struct timespec and jiffies is not year 2038
safe on 32bit systems. Introduce timespec64_to_jiffies() and
jiffies_to_timespec64() functions which use struct timespec64 to
make it ready for 2038 issue.

Cc: Prarit Bhargava &lt;prarit@redhat.com&gt;
Cc: Richard Cochran &lt;richardcochran@gmail.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Baolin Wang &lt;baolin.wang@linaro.org&gt;
Signed-off-by: John Stultz &lt;john.stultz@linaro.org&gt;
</content>
</entry>
<entry>
<title>time: Fix nanosecond file time rounding in timespec_trunc()</title>
<updated>2015-08-17T18:23:46Z</updated>
<author>
<name>Karsten Blees</name>
<email>karsten.blees@gmail.com</email>
</author>
<published>2015-06-25T12:13:55Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=de4a95faf173be1e798c37ca486dfcb234a0941b'/>
<id>urn:sha1:de4a95faf173be1e798c37ca486dfcb234a0941b</id>
<content type='text'>
timespec_trunc() avoids rounding if granularity &lt;= nanoseconds-per-jiffie
(or TICK_NSEC). This optimization assumes that:

 1. current_kernel_time().tv_nsec is already rounded to TICK_NSEC (i.e.
    with HZ=1000 you'd get 1000000, 2000000, 3000000... but never 1000001).
    This is no longer true (probably since hrtimers introduced in 2.6.16).

 2. TICK_NSEC is evenly divisible by all possible granularities. This may
    be true for HZ=100, 250, 1000, but obviously not for HZ=300 /
    TICK_NSEC=3333333 (introduced in 2.6.20).

Thus, sub-second portions of in-core file times are not rounded to on-disk
granularity. I.e. file times may change when the inode is re-read from disk
or when the file system is remounted.

This affects all file systems with file time granularities &gt; 1 ns and &lt; 1s,
e.g. CEPH (1000 ns), UDF (1000 ns), CIFS (100 ns), NTFS (100 ns) and FUSE
(configurable from user mode via struct fuse_init_out.time_gran).

Steps to reproduce with e.g. UDF:

  $ dd if=/dev/zero of=udfdisk count=10000 &amp;&amp; mkudffs udfdisk
  $ mkdir udf &amp;&amp; mount udfdisk udf
  $ touch udf/test &amp;&amp; stat -c %y udf/test
  2015-06-09 10:22:56.130006767 +0200
  $ umount udf &amp;&amp; mount udfdisk udf
  $ stat -c %y udf/test
  2015-06-09 10:22:56.130006000 +0200

Remounting truncates the mtime to 1 µs.

Fix the rounding in timespec_trunc() and update the documentation.

timespec_trunc() is exclusively used to calculate inode's [acm]time (mostly
via current_fs_time()), and always with super_block.s_time_gran as second
argument. So this can safely be changed without side effects.

Note: This does _not_ fix the issue for FAT's 2 second mtime resolution,
as super_block.s_time_gran isn't prepared to handle different ctime /
mtime / atime resolutions nor resolutions &gt; 1 second.

Cc: Prarit Bhargava &lt;prarit@redhat.com&gt;
Cc: Richard Cochran &lt;richardcochran@gmail.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Karsten Blees &lt;blees@dcon.de&gt;
Signed-off-by: John Stultz &lt;john.stultz@linaro.org&gt;
</content>
</entry>
<entry>
<title>jiffies: Remove HZ &gt; USEC_PER_SEC special case</title>
<updated>2015-07-29T13:44:57Z</updated>
<author>
<name>Frederic Weisbecker</name>
<email>fweisbec@gmail.com</email>
</author>
<published>2014-10-10T00:44:01Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=e075867681ca9b8c0b8823e24d0fb4ce3b4f2655'/>
<id>urn:sha1:e075867681ca9b8c0b8823e24d0fb4ce3b4f2655</id>
<content type='text'>
HZ never goes much further 1000 and a bit. And if we ever reach one tick
per microsecond, we might be having a problem.

Lets stop maintaining this special case, just leave a paranoid check.

Reviewed-by: Rik van Riel &lt;riel@redhat.com&gt;
Cc: Christoph Lameter &lt;cl@linux.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc; John Stultz &lt;john.stultz@linaro.org&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Preeti U Murthy &lt;preeti@linux.vnet.ibm.com&gt;
Cc: Rik van Riel &lt;riel@redhat.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Signed-off-by: Frederic Weisbecker &lt;fweisbec@gmail.com&gt;
</content>
</entry>
<entry>
<title>time: Refactor usecs_to_jiffies</title>
<updated>2015-06-10T09:31:13Z</updated>
<author>
<name>Nicholas Mc Guire</name>
<email>hofrat@osadl.org</email>
</author>
<published>2015-05-28T17:09:55Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=ae60d6a0e3a9197d37f8c8c4584a8ecd18518cd6'/>
<id>urn:sha1:ae60d6a0e3a9197d37f8c8c4584a8ecd18518cd6</id>
<content type='text'>
Refactor the usecs_to_jiffies conditional code part in time.c and
jiffies.h putting it into conditional functions rather than #ifdefs
to improve readability. This is analogous to the msecs_to_jiffies()
cleanup in commit ca42aaf0c861 ("time: Refactor msecs_to_jiffies")

Signed-off-by: Nicholas Mc Guire &lt;hofrat@osadl.org&gt;
Cc: Masahiro Yamada &lt;yamada.m@jp.panasonic.com&gt;
Cc: Sam Ravnborg &lt;sam@ravnborg.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: John Stultz &lt;john.stultz@linaro.org&gt;
Cc: Andrew Hunter &lt;ahh@google.com&gt;
Cc: Paul Turner &lt;pjt@google.com&gt;
Cc: Michal Marek &lt;mmarek@suse.cz&gt;
Link: http://lkml.kernel.org/r/1432832996-12129-1-git-send-email-hofrat@osadl.org
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
</content>
</entry>
</feed>
