From patchwork Fri Jun 12 07:48:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 49797 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CCB60228DB for ; Fri, 12 Jun 2015 07:51:23 +0000 (UTC) Received: by lbcak1 with SMTP id ak1sf7650194lbc.2 for ; Fri, 12 Jun 2015 00:51:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=ZmFs6Eax3fl8ClXVSPA/ujW/hXAWE+piSBlDgkT+MII=; b=Ld66uNlAeWrYUvz69M79j/sqT8+sUNgSR9UE2ChbSvVkyPsEJz266tJDmm28ybsYap zYGYTBnhAaC4X2B3ayJUuA4JcZ7C0XbjLJZuE7RlNwEg+Et2W/0Km1GJKgW7Zv8ClW5r UKhpNDwJaqBOZGb/fRfz+ZuafnU7MwSKbHtd60ovZU6mwwbGCFR35gU/rjHWVwgsrn4/ 746kVl9p78uNdXxtDJrBehRBaCFmwJ3suwGaIZhORt7/uz9g9mTqocJZOlnXkJcblHLA MYEggDhVHabFjeGKdFhAgeyZtgwyUi8/A5CFv6lcRl08amRI5XeXHHZLqQKdAVtH0Q5T Usyw== X-Gm-Message-State: ALoCoQnzyHXeyA847XW8/cztq5ol1Arr0NYfkQrAAP1DJSi/lDby09ecyJKt+jaDD2W4f1XmHTdn X-Received: by 10.152.5.2 with SMTP id o2mr13024704lao.0.1434095482810; Fri, 12 Jun 2015 00:51:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.200 with SMTP id c8ls557327lab.81.gmail; Fri, 12 Jun 2015 00:51:22 -0700 (PDT) X-Received: by 10.152.3.97 with SMTP id b1mr14034720lab.54.1434095482641; Fri, 12 Jun 2015 00:51:22 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id a9si2700620laf.173.2015.06.12.00.51.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 00:51:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbcue7 with SMTP id ue7so15435718lbc.0 for ; Fri, 12 Jun 2015 00:51:22 -0700 (PDT) X-Received: by 10.152.206.75 with SMTP id lm11mr13561297lac.41.1434095482511; Fri, 12 Jun 2015 00:51:22 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp356558lbb; Fri, 12 Jun 2015 00:51:21 -0700 (PDT) X-Received: by 10.68.98.65 with SMTP id eg1mr21075565pbb.72.1434095480693; Fri, 12 Jun 2015 00:51:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si4243386pdq.207.2015.06.12.00.51.19; Fri, 12 Jun 2015 00:51:20 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754807AbbFLHvP (ORCPT + 29 others); Fri, 12 Jun 2015 03:51:15 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:35138 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754689AbbFLHun (ORCPT ); Fri, 12 Jun 2015 03:50:43 -0400 Received: by pdbnf5 with SMTP id nf5so19697896pdb.2 for ; Fri, 12 Jun 2015 00:50:43 -0700 (PDT) X-Received: by 10.67.11.98 with SMTP id eh2mr20876452pad.21.1434095443200; Fri, 12 Jun 2015 00:50:43 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by mx.google.com with ESMTPSA id yv6sm2734372pac.29.2015.06.12.00.50.41 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 00:50:42 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, y2038@lists.linaro.org Subject: [PATCH v5 15/24] posix-timers: Implement y2038 safe clock_getres64() callback Date: Fri, 12 Jun 2015 15:48:30 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <647dcc7ede88d9d95a6f9a2878487d46c233fb2a.1434079262.git.baolin.wang@linaro.org> References: <647dcc7ede88d9d95a6f9a2878487d46c233fb2a.1434079262.git.baolin.wang@linaro.org> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: baolin.wang@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The clock_getres() callback in struct k_clock is not year 2038 safe on 32bit systems. To address this implement a new callback clock_getres64() which uses struct timespec64 along with a default implementation which is a wrapper for the existing clock_getres() callback. The default callback is installed at registration time for all posix clocks which are not yet converted to clock_getres64() and will be removed once this is completed. Use the new callback in __clock_getres(). Signed-off-by: Baolin Wang --- include/linux/posix-timers.h | 1 + kernel/time/posix-timers.c | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index be2123d..35786c5 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -98,6 +98,7 @@ struct k_itimer { struct k_clock { int (*clock_getres) (const clockid_t which_clock, struct timespec *tp); + int (*clock_getres64) (const clockid_t which_clock, struct timespec64 *tp); int (*clock_set) (const clockid_t which_clock, const struct timespec *tp); int (*clock_set64) (const clockid_t which_clock, diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index a5207f0..0b0663a 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -603,6 +603,20 @@ static int default_clock_get64(const clockid_t which_clock, return ret; } +static int default_clock_getres64(const clockid_t which_clock, + struct timespec64 *tp64) +{ + struct k_clock *kc = clockid_to_kclock(which_clock); + struct timespec tp; + int ret; + + ret = kc->clock_getres(which_clock, &tp); + if (!ret) + *tp64 = timespec_to_timespec64(tp); + + return 0; +} + void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock) { @@ -617,8 +631,8 @@ void posix_timers_register_clock(const clockid_t clock_id, clock_id); return; } - if (!new_clock->clock_getres) { - printk(KERN_WARNING "POSIX clock id %d lacks clock_getres()\n", + if (!new_clock->clock_getres && !new_clock->clock_getres64) { + printk(KERN_WARNING "POSIX clock id %d lacks clock_getres() and clock_getres64()\n", clock_id); return; } @@ -631,6 +645,8 @@ void posix_timers_register_clock(const clockid_t clock_id, new_clock->clock_set64 = default_clock_set64; if (new_clock->clock_get && !new_clock->clock_get64) new_clock->clock_get64 = default_clock_get64; + if (new_clock->clock_getres && !new_clock->clock_getres64) + new_clock->clock_getres64 = default_clock_getres64; posix_clocks[clock_id] = *new_clock; } @@ -678,7 +694,8 @@ static struct k_clock *clockid_to_kclock(const clockid_t id) return (id & CLOCKFD_MASK) == CLOCKFD ? &clock_posix_dynamic : &clock_posix_cpu; - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres) + if (id >= MAX_CLOCKS || (!posix_clocks[id].clock_getres + && !posix_clocks[id].clock_getres64)) return NULL; return &posix_clocks[id]; } @@ -1187,25 +1204,25 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, return err; } -static int __clock_getres(clockid_t which_clock, struct timespec *ts) +static int __clock_getres(clockid_t which_clock, struct timespec64 *ts) { struct k_clock *kc = clockid_to_kclock(which_clock); if (!kc) return -EINVAL; - return kc->clock_getres(which_clock, ts); + return kc->clock_getres64(which_clock, ts); } SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp) { - struct timespec rtn_tp; + struct timespec64 rtn_tp; int error; error = __clock_getres(which_clock, &rtn_tp); - if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) + if (!error && tp && put_timespec(&rtn_tp, tp)) error = -EFAULT; return error;