* [PATCH v3] timekeeping: always make sure wall_to_monotonic isn't positive
@ 2015-06-23 10:38 Wang YanQing
2015-07-01 18:22 ` John Stultz
0 siblings, 1 reply; 2+ messages in thread
From: Wang YanQing @ 2015-06-23 10:38 UTC (permalink / raw)
To: john.stultz; +Cc: tglx, linux-kernel
I meet two issues on an IMX6 development board without enable
RTC device(so timekeeping_init will initialize the boot time
and monotonic to 0).
Issue 1:exportfs -a generate:
"exportfs: /opt/nfs/arm does not support NFS export"
Issue 2:cat /proc/stat:
"btime 4294967236"
Exact reproduction of the same issues on x86 after run below
code:
" int main(void)
{
struct timeval val;
int ret;
val.tv_sec = 0;
val.tv_usec = 0;
ret = settimeofday(&val, NULL);
return 0;
}
"
Two issues are different symptoms of same problem:
The reason is positive wall_to_monotonic push boot time back to the time
before Epoch, getboottime will return negative value.
In symptom 1:
negative boot time cause get_expiry overflow time_t when input expire
time is 2147483647, then cache_flush always clear entries just added
in ip_map_parse.
In symptom 2:
show_stat use "unsigned long" to print
negative value return by getboottime.
This patch fix the problem.
Impact:
You can't set the CLOCK_REALTIME time prior to (1970 + system uptime).
Signed-off-by: Wang YanQing <udknight@gmail.com>
---
Changes
v1-v2:
1: fix subject, use "isn't positive" instead of "is negative".
2: rewrite changelog.
3: simplify code as suggested by John Stultz.
v2-v3:
1: reword changelog, no change of source code.
kernel/time/timekeeping.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index bca3667..4cdb771 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -911,6 +911,7 @@ int do_settimeofday64(const struct timespec64 *ts)
struct timekeeper *tk = &tk_core.timekeeper;
struct timespec64 ts_delta, xt;
unsigned long flags;
+ int ret = 0;
if (!timespec64_valid_strict(ts))
return -EINVAL;
@@ -924,10 +925,15 @@ int do_settimeofday64(const struct timespec64 *ts)
ts_delta.tv_sec = ts->tv_sec - xt.tv_sec;
ts_delta.tv_nsec = ts->tv_nsec - xt.tv_nsec;
+ if (timespec64_compare(&tk->wall_to_monotonic, &ts_delta) > 0) {
+ ret = -EINVAL;
+ goto out;
+ }
+
tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts_delta));
tk_set_xtime(tk, ts);
-
+out:
timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET);
write_seqcount_end(&tk_core.seq);
@@ -936,7 +942,7 @@ int do_settimeofday64(const struct timespec64 *ts)
/* signal hrtimers about time change */
clock_was_set();
- return 0;
+ return ret;
}
EXPORT_SYMBOL(do_settimeofday64);
@@ -965,7 +971,8 @@ int timekeeping_inject_offset(struct timespec *ts)
/* Make sure the proposed value is valid */
tmp = timespec64_add(tk_xtime(tk), ts64);
- if (!timespec64_valid_strict(&tmp)) {
+ if (timespec64_compare(&tk->wall_to_monotonic, &ts64) > 0 ||
+ !timespec64_valid_strict(&tmp)) {
ret = -EINVAL;
goto error;
}
--
1.8.5.6.2.g3d8a54e.dirty
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v3] timekeeping: always make sure wall_to_monotonic isn't positive
2015-06-23 10:38 [PATCH v3] timekeeping: always make sure wall_to_monotonic isn't positive Wang YanQing
@ 2015-07-01 18:22 ` John Stultz
0 siblings, 0 replies; 2+ messages in thread
From: John Stultz @ 2015-07-01 18:22 UTC (permalink / raw)
To: Wang YanQing, John Stultz, Thomas Gleixner, lkml
On Tue, Jun 23, 2015 at 3:38 AM, Wang YanQing <udknight@gmail.com> wrote:
> I meet two issues on an IMX6 development board without enable
> RTC device(so timekeeping_init will initialize the boot time
> and monotonic to 0).
>
> Issue 1:exportfs -a generate:
> "exportfs: /opt/nfs/arm does not support NFS export"
> Issue 2:cat /proc/stat:
> "btime 4294967236"
>
> Exact reproduction of the same issues on x86 after run below
> code:
> " int main(void)
> {
> struct timeval val;
> int ret;
>
> val.tv_sec = 0;
> val.tv_usec = 0;
> ret = settimeofday(&val, NULL);
> return 0;
> }
> "
> Two issues are different symptoms of same problem:
> The reason is positive wall_to_monotonic push boot time back to the time
> before Epoch, getboottime will return negative value.
>
> In symptom 1:
> negative boot time cause get_expiry overflow time_t when input expire
> time is 2147483647, then cache_flush always clear entries just added
> in ip_map_parse.
> In symptom 2:
> show_stat use "unsigned long" to print
> negative value return by getboottime.
>
> This patch fix the problem.
>
> Impact:
> You can't set the CLOCK_REALTIME time prior to (1970 + system uptime).
>
> Signed-off-by: Wang YanQing <udknight@gmail.com>
Ok, the patch looks alright. The commit message is still not super
readable, but I went ahead and re-worded much of it. I've got it
queued for 4.3, and will be doing some testing. When I sent my stack
out to Thomas/Ingo for -tip, please review the rewording to make sure
you agree with the changes.
thanks
-john
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-01 18:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-23 10:38 [PATCH v3] timekeeping: always make sure wall_to_monotonic isn't positive Wang YanQing
2015-07-01 18:22 ` John Stultz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®