From patchwork Fri Jun 12 07:48:28 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: 49796 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E0F99228DB for ; Fri, 12 Jun 2015 07:50:55 +0000 (UTC) Received: by lagh7 with SMTP id h7sf8425558lag.2 for ; Fri, 12 Jun 2015 00:50:54 -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=XkVS9H8rWt/AyI35btD+/YPFtT74gfSUSPsC0JIahIg=; b=ZUHae1kNyaSl8DQvU3sjeq86XfDM7TRKdhXy382b0uaSnY5cb8b5XPL6IFJcFAaooO AVUkb36sk7rBrr+ypYAb49vu1qbQj82KTR4Zp7NFPC1mkawKrxAnJ2hqZfZzVQotM/eo 3lxUwUhB6tboI4OQTbxHGZv5DXMlTL8tPyb+Lh7Q3ckosUXSncy6AQYMCnLAHQySYZdA p4SYF45kN5SJGOyEd9ny9egcp4oZS0nffMqhl6TS+OXLJ3lO0E6RezQgk2weXyVx1mnL 57BKSPZnQ6eWoTXYJllbl6iQBc1xpJ5Br3yIKQIMLqFRzQXuemS2pzQB8OL1vRaWu3xO sd5Q== X-Gm-Message-State: ALoCoQnJ7MUtJJtp5YA4C2D7sEkkfbD3mYpvJCEmFDHFPCE/7ffScH1qC0WhKz5ZBdsNxszWWvC4 X-Received: by 10.180.221.203 with SMTP id qg11mr2706206wic.7.1434095454790; Fri, 12 Jun 2015 00:50:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.228 with SMTP id h4ls551997lam.23.gmail; Fri, 12 Jun 2015 00:50:54 -0700 (PDT) X-Received: by 10.112.148.166 with SMTP id tt6mr13537701lbb.11.1434095454592; Fri, 12 Jun 2015 00:50:54 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id wj6si2732685lbb.87.2015.06.12.00.50.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 00:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbbqq2 with SMTP id qq2so15353866lbb.3 for ; Fri, 12 Jun 2015 00:50:54 -0700 (PDT) X-Received: by 10.112.93.37 with SMTP id cr5mr13992949lbb.106.1434095454421; Fri, 12 Jun 2015 00:50:54 -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 hn6csp356284lbb; Fri, 12 Jun 2015 00:50:53 -0700 (PDT) X-Received: by 10.68.197.161 with SMTP id iv1mr21421068pbc.0.1434095452633; Fri, 12 Jun 2015 00:50:52 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vx6si1869987pab.220.2015.06.12.00.50.51; Fri, 12 Jun 2015 00:50:52 -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 S1754774AbbFLHus (ORCPT + 29 others); Fri, 12 Jun 2015 03:50:48 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:35013 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754652AbbFLHue (ORCPT ); Fri, 12 Jun 2015 03:50:34 -0400 Received: by pdbnf5 with SMTP id nf5so19695445pdb.2 for ; Fri, 12 Jun 2015 00:50:33 -0700 (PDT) X-Received: by 10.66.182.161 with SMTP id ef1mr21068023pac.119.1434095433586; Fri, 12 Jun 2015 00:50:33 -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.31 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 00:50:33 -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 13/24] posix-timers: Implement y2038 safe clock_get64() callback Date: Fri, 12 Jun 2015 15:48:28 +0800 Message-Id: <31f264e19c66a513889a1d3511da1db7e7592df2.1434079263.git.baolin.wang@linaro.org> 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.179 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_get() callback in struct k_clock is not year 2038 safe on 32bit systems. To address this implement a new callback clock_get64() which uses struct timespec64 along with a default implementation which is a wrapper for the existing clock_get() callback. The default callback is installed at registration time for all posix clocks which are not yet converted to clock_get64() and will be removed once this is completed. Use the new callback in __clock_gettime(). Signed-off-by: Baolin Wang --- include/linux/posix-timers.h | 1 + kernel/time/posix-timers.c | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index 2b19ec8..be2123d 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -103,6 +103,7 @@ struct k_clock { int (*clock_set64) (const clockid_t which_clock, const struct timespec64 *tp); int (*clock_get) (const clockid_t which_clock, struct timespec * tp); + int (*clock_get64) (const clockid_t which_clock, struct timespec64 *tp); int (*clock_adj) (const clockid_t which_clock, struct timex *tx); int (*timer_create) (struct k_itimer *timer); int (*nsleep) (const clockid_t which_clock, int flags, diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index ca63626..021cd8f 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -589,6 +589,20 @@ static int default_clock_set64(const clockid_t which_clock, return ret; } +static int default_clock_get64(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_get(which_clock, &tp); + if (!ret) + *tp64 = timespec_to_timespec64(tp); + + return ret; +} + void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock) { @@ -598,8 +612,8 @@ void posix_timers_register_clock(const clockid_t clock_id, return; } - if (!new_clock->clock_get) { - printk(KERN_WARNING "POSIX clock id %d lacks clock_get()\n", + if (!new_clock->clock_get && !new_clock->clock_get64) { + printk(KERN_WARNING "POSIX clock id %d lacks clock_get() and clock_get64()\n", clock_id); return; } @@ -615,6 +629,8 @@ void posix_timers_register_clock(const clockid_t clock_id, new_clock->timer_set64 = default_timer_set64; if (new_clock->clock_set && !new_clock->clock_set64) new_clock->clock_set64 = default_clock_set64; + if (new_clock->clock_get && !new_clock->clock_get64) + new_clock->clock_get64 = default_clock_get64; posix_clocks[clock_id] = *new_clock; } @@ -1124,25 +1140,25 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, return __clock_settime(which_clock, &new_tp); } -static int __clock_gettime(clockid_t which_clock, struct timespec *ts) +static int __clock_gettime(clockid_t which_clock, struct timespec64 *ts) { struct k_clock *kc = clockid_to_kclock(which_clock); if (!kc) return -EINVAL; - return kc->clock_get(which_clock, ts); + return kc->clock_get64(which_clock, ts); } SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, struct timespec __user *,tp) { - struct timespec kernel_tp; + struct timespec64 kernel_tp; int error; error = __clock_gettime(which_clock, &kernel_tp); - if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp))) + if (!error && put_timespec(&kernel_tp, tp)) error = -EFAULT; return error;