]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.53/time-make-sure-jiffies_to_msecs-preserves-non-zero-time-periods.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.14.53 / time-make-sure-jiffies_to_msecs-preserves-non-zero-time-periods.patch
1 From abcbcb80cd09cd40f2089d912764e315459b71f7 Mon Sep 17 00:00:00 2001
2 From: Geert Uytterhoeven <geert@linux-m68k.org>
3 Date: Fri, 22 Jun 2018 16:33:57 +0200
4 Subject: time: Make sure jiffies_to_msecs() preserves non-zero time periods
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 From: Geert Uytterhoeven <geert@linux-m68k.org>
10
11 commit abcbcb80cd09cd40f2089d912764e315459b71f7 upstream.
12
13 For the common cases where 1000 is a multiple of HZ, or HZ is a multiple of
14 1000, jiffies_to_msecs() never returns zero when passed a non-zero time
15 period.
16
17 However, if HZ > 1000 and not an integer multiple of 1000 (e.g. 1024 or
18 1200, as used on alpha and DECstation), jiffies_to_msecs() may return zero
19 for small non-zero time periods. This may break code that relies on
20 receiving back a non-zero value.
21
22 jiffies_to_usecs() does not need such a fix: one jiffy can only be less
23 than one µs if HZ > 1000000, and such large values of HZ are already
24 rejected at build time, twice:
25
26 - include/linux/jiffies.h does #error if HZ >= 12288,
27 - kernel/time/time.c has BUILD_BUG_ON(HZ > USEC_PER_SEC).
28
29 Broken since forever.
30
31 Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
32 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
33 Reviewed-by: Arnd Bergmann <arnd@arndb.de>
34 Cc: John Stultz <john.stultz@linaro.org>
35 Cc: Stephen Boyd <sboyd@kernel.org>
36 Cc: linux-alpha@vger.kernel.org
37 Cc: linux-mips@linux-mips.org
38 Cc: stable@vger.kernel.org
39 Link: https://lkml.kernel.org/r/20180622143357.7495-1-geert@linux-m68k.org
40 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
41
42 ---
43 kernel/time/time.c | 6 ++++--
44 1 file changed, 4 insertions(+), 2 deletions(-)
45
46 --- a/kernel/time/time.c
47 +++ b/kernel/time/time.c
48 @@ -28,6 +28,7 @@
49 */
50
51 #include <linux/export.h>
52 +#include <linux/kernel.h>
53 #include <linux/timex.h>
54 #include <linux/capability.h>
55 #include <linux/timekeeper_internal.h>
56 @@ -348,9 +349,10 @@ unsigned int jiffies_to_msecs(const unsi
57 return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
58 #else
59 # if BITS_PER_LONG == 32
60 - return (HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32;
61 + return (HZ_TO_MSEC_MUL32 * j + (1ULL << HZ_TO_MSEC_SHR32) - 1) >>
62 + HZ_TO_MSEC_SHR32;
63 # else
64 - return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN;
65 + return DIV_ROUND_UP(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN);
66 # endif
67 #endif
68 }