From patchwork Thu Oct 19 11:14:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116367 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp367775qgn; Thu, 19 Oct 2017 04:17:29 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SSk1Alx4hQYQMN8B/HE1MFlhtEkCJPLhGBb2/yCXcCSnSKABQBb4UV000uuSCFprpHh4av X-Received: by 10.101.70.15 with SMTP id v15mr1082398pgq.446.1508411849546; Thu, 19 Oct 2017 04:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411849; cv=none; d=google.com; s=arc-20160816; b=Dv8c8DQCQUx8rXSjOc0LUCxNGNb5TELPI2Ff2wfb4hENXJYfQsjRE2I6bh5+w6IQzl 70FbYvvB77KQicID+qYvos1vXKnw5Qdy0lMgpk0Pgw4IcbBLvDWcQkLFCgYgrR3k0XVY Hc89t7GY9GZFKbTS+Pe+28T+OQzv8u/UFyX60TYDMRC4yFMGkEf1uUd+4gIkFCqDOLqf AyRC22WV3U50DB2liTuMx21nE/ebgIOdVg9s/GszplNLZE1Hxi9y8HX43CBQlHJTOknk M3vX4DUig7+dqpzriI+c9EApbGviF/wQw7EVJK/IKZFNArEnzkiYJfsyI6gjMz5KxfLM XrOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=25onzy553y6NlG983n71p+yJTZdQigBBWtDVMPo06ZI=; b=VtC82ki6kG4TDdFTG4atLs/zvXGH5BKDNqlMlWHD0I4XMZMEQVdYBp+O94oNryW9sZ 5mcUlPtEj4DVFLmcjZVS3f7oHkH5KH5eH/zi6wKxnvzzFEWKxGiK0M/WeYcjHa5dKkhX Q+inF61dXAd81tW9CqEmfknmlARlSFvPmuBpAbn9NxJTK9M89ExggzPYwZG7boG9bdpa HgelvMcA1OFTrcDzDMMwQ+ONQNdboiJlpXVaPrmkEEtYb/AJdYEC1l5EFvN6Z6sSu5iF ZN7dQU54DcYlbm1hD3rnyEiEaTE1YtKeg4L4tgZDVMPaqBu8JSWhXBAXCv9nUqh5Rq4S d8Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8si6455089plm.56.2017.10.19.04.17.29; Thu, 19 Oct 2017 04:17:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752892AbdJSLR0 (ORCPT + 27 others); Thu, 19 Oct 2017 07:17:26 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:56510 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752665AbdJSLPP (ORCPT ); Thu, 19 Oct 2017 07:15:15 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0M6VWV-1dHJJr1WYd-00ySAw; Thu, 19 Oct 2017 13:15:04 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 2/7] timekeeping: use timespec64 in timekeeping_inject_offset Date: Thu, 19 Oct 2017 13:14:45 +0200 Message-Id: <20171019111450.3702205-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171019111450.3702205-1-arnd@arndb.de> References: <20171019111450.3702205-1-arnd@arndb.de> X-Provags-ID: V03:K0:etNaBGhm7jK0EbzSXBfBcWKIq2MuBMddr01Vp/kBb8qczcStqmF CLkASm8w5iR1MaHTeBNIti7YFJfUdniXmqND4RKsoGOnJmoRw+JUy4gov5BIk4yF4r6Gghe LKqIQhir60oA7eZB7lmj9NCDPONxV8OcqdC+hWgIOXrhnpTEOLAQbeAyfbA3H6LVsBTKVlp VZZKCqg15OKrFT9eekHhQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Cmoel+Y/j2A=:DS2kCNI/HjDl8To7mYpK/k X32Iuvf00y85sn+vTNSXte9TZT48sJLEVqvRBvJ1kQ0FowsBu9ni0kBhCRF315+psGHzRFQS1 h/nnNcPDQVdNhbdrrC1G/nC504mKRvUxgvVx7McNJUf0ypMmBsMvY8kdI6VCc5o+Una0Z+k/+ r1lcvYTPPbGhwwnWKM5fEussIS5VlFLNFL9l8knHqBktWJKoQm4vBTM/YO0/EzxDXaAsaPFB6 W0K07RuO9MQJr2mRM/JPEV9aTKy1o/POO1kmMvERRTPASzemakhTzDQpsBYj7wHNLdI8/xDre 5LbRprC3Ifejx0EWXC+G/Lo7O78msbh3A/qSpjH6sPWW5tH/CLnSJCuw1jN/JhYOXfUTIWCsX szTyJ25dJ/QWHHC4eiyODbi0yp70888H5vvUc97W0M3u6y9qdaKucN1MQUyA1D+JpOwvYDZzl dUU/9QoplXF5RTdLwpmsnf3JYwQTT9Gc3pGrLokwzeTRTWbTi0hdZuWQdus2NRlsU7wmQU0Sx 1wCCfYqFpoge16IJIxgkXronDq6y9CFhhBgH2pPUvey4aodYn2C/JZU+n1g9Mp8BodWolbu5a fdQ4uYpbtiRPMn7WSeVthtumQwbjRNLCYVP5BFOuApL0Lp0u4DwX2pq60nXRM3BbG8xQfNTUV vwizSC6QKOiY/9e5udtP5xYfKL0r6zhU87XkbiTD+bU7u59GExacj2OCGRwNpjplAJ1zY3KnP MrlwWfGt47knbemtYGHH70MzvCKAziE/VaLyiA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Arnd Bergmann --- kernel/time/timekeeping.c | 72 ++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) -- 2.9.0 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 679dbfbea419..66f6fe5ea97a 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1300,65 +1300,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); @@ -1397,7 +1369,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; @@ -2349,9 +2321,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 */ @@ -2379,16 +2351,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; } } @@ -2420,12 +2398,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))