From patchwork Mon Oct 30 22:29:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 117507 Delivered-To: patches@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3120309qgn; Mon, 30 Oct 2017 15:29:28 -0700 (PDT) X-Received: by 10.99.114.29 with SMTP id n29mr9022741pgc.303.1509402568365; Mon, 30 Oct 2017 15:29:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509402568; cv=none; d=google.com; s=arc-20160816; b=PdZ1rBdXfY91DrnUT0FOPV3DR/NgTZr3a+jC736V+UFZajXSh+QMPh2wjPI5d2WUtO 4w2z6BiqYYBabWkQ6N8b7Gu3dIXI7ieBuQUeenHOrB6hiCR4jBhbBZP7Mc8iLfq+qVZZ tjVMhLyld7pwv07aa+u5C4spkhflzBxN+IcvVkRbCkRhhGUqoU0adRPvUupD9bj9bEMl AbjstkD4hA0wet10y2nv8RCL6ibVBomVjx8jrKtelVckQ1R6zOKXlItfaHMRnWatV6Iy 1f7nPbo7741Yc2nGK9y0y+uGC0wVbdcnbOo9UUkXq9Y+LzCttNIc2gYs4M+TuQUqefLk 2KgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=/9vApLuyGKDutzrnKpbJSXiNB8MqKyaDwfRZedUNVrI=; b=yNDG+PNaVBgJ/rKxRDhuy9jzDMeTsAatBtecixlLXpRxL+MJIwWZmIMXbb/0CJ9D+B QWzxUf8NdSWPF20ouFZ8wrdieKRpp+wr4p206k3bSnotM79dBc+aNkBO8SxFKxPv8/I3 ECsiQdeAjsKrKf4IYMUH4/TI90liF8ReC+6qjy0BwS9jbxb4oDzEqwGkw16h8YjOI28A wOhxmpDa98h8pcPKzJYMVe4PWxKYtYyrkqzwd0qIWh8gbtZppkyCg/mHPyo9jr2RzcPQ 5n+BqAbr8k6U0F06XIkysD7mONjwjGS//Mco1ycxmYVJb1IbfR1p2i8w//eDGJpo0U25 zyyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jczutyof; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v2sor3459050pgt.313.2017.10.30.15.29.28 for (Google Transport Security); Mon, 30 Oct 2017 15:29:28 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jczutyof; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/9vApLuyGKDutzrnKpbJSXiNB8MqKyaDwfRZedUNVrI=; b=jczutyofkEoqlketf+HTo1MEz258GWBU6KGKjCKYa3ciwX6YMg9kpvlt9hAtBmn0Fm +TjhV7j9qycfk5ov5sfx2c6YiE6i36Y8IBo7odn277swJQKCAU7X2IgjCTy38mFqtt9X VFV4aJ3C7VEXlmUO8cbhRmZQvRRCh111O/+NY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/9vApLuyGKDutzrnKpbJSXiNB8MqKyaDwfRZedUNVrI=; b=kVSOzGbTSLTrQdty5+gsAcpTfwytsWjpdLKxjycNAzdr6/Nlyxf7AgwtHFyGou4jcl Za7xEh90gApgqIoCLKBhSnkUj7a7kPiTODqnM8Pi2zf2o+kxtkiNIf6W/jrDVVbYuDQO mouLb+EH3gVLGIKwFxmcqMCf5UOgMaLybjEdGnJChyVotC+HHg/X5kq4LYOaJ8e+wlIa uHmWXyCvXcEQIV4U/jH8Wm5aW0fzpQF55Yrz80EhiJh9SW6l+K91A6KpZydMN4/oPI7W Qrbjt0qD6G0AjWVZddgsbs+epgXzO75V2IfaOqQ3FMWbqYUS2B46G6/AJU5gBJaZnSJg Ew4A== X-Gm-Message-State: AMCzsaXIk7sa2F9U128gdXSHAOZwhkquzGJh8uxNtKK7Xbul7o8Raetu KYNsvH0q8ngsVtTkfKT4bi3sioGW X-Google-Smtp-Source: ABhQp+QP2u0PkEywgLZo2HirFJZDGOZtOr91zr1D7/NFlZlbLoekUPDeUAiAKYTZ2oRkRtztPkfBCg== X-Received: by 10.98.222.2 with SMTP id h2mr10313937pfg.165.1509402567954; Mon, 30 Oct 2017 15:29:27 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id g13sm27479320pfm.130.2017.10.30.15.29.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Oct 2017 15:29:27 -0700 (PDT) From: John Stultz To: lkml Cc: Arnd Bergmann , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 3/7] timekeeping: Use timespec64 in timekeeping_inject_offset Date: Mon, 30 Oct 2017 15:29:10 -0700 Message-Id: <1509402554-18437-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509402554-18437-1-git-send-email-john.stultz@linaro.org> References: <1509402554-18437-1-git-send-email-john.stultz@linaro.org> From: Arnd Bergmann As part of changing all the timekeeping code to use 64-bit time_t consistently, this removes the uses of timeval and timespec as much as possible from do_adjtimex() and timekeeping_inject_offset(). The timeval_inject_offset_valid() and timespec_inject_offset_valid() just complicate this, so I'm folding them into the respective callers. This leaves the actual 'struct timex' definition, which is part of the user-space ABI and should be dealt with separately when we have agreed on the ABI change. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Signed-off-by: Arnd Bergmann Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 72 ++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) -- 2.7.4 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7d8e0e8..c6a35fb 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1258,65 +1258,37 @@ int do_settimeofday64(const struct timespec64 *ts) } EXPORT_SYMBOL(do_settimeofday64); -/* - * Validates if a timespec/timeval used to inject a time offset is valid. - * Offsets can be postive or negative. The value of the timeval/timespec - * is the sum of its fields, but *NOTE*: the field tv_usec/tv_nsec must - * always be non-negative. - */ -static inline bool timeval_inject_offset_valid(const struct timeval *tv) -{ - /* We don't check the tv_sec as it can be positive or negative */ - - /* Can't have more microseconds then a second */ - if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) - return false; - return true; -} - -static inline bool timespec_inject_offset_valid(const struct timespec *ts) -{ - /* We don't check the tv_sec as it can be positive or negative */ - - /* Can't have more nanoseconds then a second */ - if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) - return false; - return true; -} - /** * timekeeping_inject_offset - Adds or subtracts from the current time. * @tv: pointer to the timespec variable containing the offset * * Adds or subtracts an offset value from the current time. */ -static int timekeeping_inject_offset(struct timespec *ts) +static int timekeeping_inject_offset(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long flags; - struct timespec64 ts64, tmp; + struct timespec64 tmp; int ret = 0; - if (!timespec_inject_offset_valid(ts)) + if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) return -EINVAL; - ts64 = timespec_to_timespec64(*ts); - raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); timekeeping_forward_now(tk); /* Make sure the proposed value is valid */ - tmp = timespec64_add(tk_xtime(tk), ts64); - if (timespec64_compare(&tk->wall_to_monotonic, &ts64) > 0 || + tmp = timespec64_add(tk_xtime(tk), *ts); + if (timespec64_compare(&tk->wall_to_monotonic, ts) > 0 || !timespec64_valid_strict(&tmp)) { ret = -EINVAL; goto error; } - tk_xtime_add(tk, &ts64); - tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts64)); + tk_xtime_add(tk, ts); + tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, *ts)); error: /* even if we error out, we forwarded the time, so call update */ timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); @@ -1355,7 +1327,7 @@ int persistent_clock_is_local; void timekeeping_warp_clock(void) { if (sys_tz.tz_minuteswest != 0) { - struct timespec adjust; + struct timespec64 adjust; persistent_clock_is_local = 1; adjust.tv_sec = sys_tz.tz_minuteswest * 60; @@ -2307,9 +2279,9 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, } /** - * ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex + * timekeeping_validate_timex - Ensures the timex is ok for use in do_adjtimex */ -static int ntp_validate_timex(struct timex *txc) +static int timekeeping_validate_timex(struct timex *txc) { if (txc->modes & ADJ_ADJTIME) { /* singleshot must not be used with any other mode bits */ @@ -2337,16 +2309,22 @@ static int ntp_validate_timex(struct timex *txc) if (!capable(CAP_SYS_TIME)) return -EPERM; - if (txc->modes & ADJ_NANO) { - struct timespec ts; + /* + * Validate if a timespec/timeval used to inject a time + * offset is valid. Offsets can be postive or negative, so + * we don't check tv_sec. The value of the timeval/timespec + * is the sum of its fields,but *NOTE*: + * The field tv_usec/tv_nsec must always be non-negative and + * we can't have more nanoseconds/microseconds than a second. + */ + if (txc->time.tv_usec < 0) + return -EINVAL; - ts.tv_sec = txc->time.tv_sec; - ts.tv_nsec = txc->time.tv_usec; - if (!timespec_inject_offset_valid(&ts)) + if (txc->modes & ADJ_NANO) { + if (txc->time.tv_usec >= NSEC_PER_SEC) return -EINVAL; - } else { - if (!timeval_inject_offset_valid(&txc->time)) + if (txc->time.tv_usec >= USEC_PER_SEC) return -EINVAL; } } @@ -2378,12 +2356,12 @@ int do_adjtimex(struct timex *txc) int ret; /* Validate the data before disabling interrupts */ - ret = ntp_validate_timex(txc); + ret = timekeeping_validate_timex(txc); if (ret) return ret; if (txc->modes & ADJ_SETOFFSET) { - struct timespec delta; + struct timespec64 delta; delta.tv_sec = txc->time.tv_sec; delta.tv_nsec = txc->time.tv_usec; if (!(txc->modes & ADJ_NANO))