From patchwork Fri Jun 12 07:48:22 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: 49791 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 34013228DB for ; Fri, 12 Jun 2015 07:50:10 +0000 (UTC) Received: by wgv5 with SMTP id 5sf7409646wgv.0 for ; Fri, 12 Jun 2015 00:50:08 -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=ucKrZlThajIbJzp6JywMt5TKXuNwZFEmNGKt/iMOEYc=; b=A4tAkG9TvSnlCYkNZ6slhIWeaYCXn7g1h6IQinIrsNmxfSQEef9CALaBwFmTWbbh4i gHb7Z4jdKuiSlB6lH4MGfQlKgnqsprCVsj2QoHU4xSkEv38tfKDNOwEdK2vUpI1LdXHQ sEDwGVbP0nEqifO+RnvOGgqEdFuN9w4Xq131Zu8cDhbVWVUE8NyKP1mwUlOyOr5l5Yj9 jfsvk+IaB2C1GWFwMk/TidpkopwbfRUTQyuRpVuppdJV8Ah6gkhSvslHglvtwB0RtRQe a2tKH0JRCNEcgs3phK3IE80sUVRNaENL8wzFvhYjA0BQgm5/pX9pTXRcvkz4nVQhv/Z9 /F/A== X-Gm-Message-State: ALoCoQk9o3f2UeNKiMWwbk86Vo1/g0XfsEeDfPC0CN8iXgPJRyotTn9Wruer5HASSqnx0utf9Q1z X-Received: by 10.180.97.9 with SMTP id dw9mr2834867wib.2.1434095407930; Fri, 12 Jun 2015 00:50:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.169 with SMTP id l9ls549295lah.52.gmail; Fri, 12 Jun 2015 00:50:07 -0700 (PDT) X-Received: by 10.152.21.65 with SMTP id t1mr13467535lae.49.1434095407724; Fri, 12 Jun 2015 00:50:07 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id o1si2752643lbc.8.2015.06.12.00.50.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 00:50:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by laew7 with SMTP id w7so16705908lae.1 for ; Fri, 12 Jun 2015 00:50:07 -0700 (PDT) X-Received: by 10.112.97.194 with SMTP id ec2mr13829962lbb.88.1434095407540; Fri, 12 Jun 2015 00:50:07 -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 hn6csp355874lbb; Fri, 12 Jun 2015 00:50:06 -0700 (PDT) X-Received: by 10.70.135.106 with SMTP id pr10mr20865010pdb.156.1434095404888; Fri, 12 Jun 2015 00:50:04 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si4228324pap.184.2015.06.12.00.50.03; Fri, 12 Jun 2015 00:50:04 -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 S1753570AbbFLHt7 (ORCPT + 29 others); Fri, 12 Jun 2015 03:49:59 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:36478 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753513AbbFLHty (ORCPT ); Fri, 12 Jun 2015 03:49:54 -0400 Received: by pabqy3 with SMTP id qy3so18118092pab.3 for ; Fri, 12 Jun 2015 00:49:53 -0700 (PDT) X-Received: by 10.68.223.165 with SMTP id qv5mr21449917pbc.82.1434095393542; Fri, 12 Jun 2015 00:49:53 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by mx.google.com with ESMTPSA id yv6sm2734372pac.29.2015.06.12.00.49.51 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 00:49:53 -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 07/24] posix-timers: Implement y2038 safe timer_get64() callback Date: Fri, 12 Jun 2015 15:48:22 +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.215.46 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 timer_get() callback in struct k_clock is not year 2038 safe on 32bit systems. To address this implement a new callback timer_get64() which uses struct itimerspec64 along with a default implementation which is a wrapper for the existing timer_get() callback. The default callback is installed at registration time for all posix clocks which are not yet converted to timer_get64() and will be removed once this is completed. Use the new callback in __timer_gettime(). Signed-off-by: Baolin Wang --- include/linux/posix-timers.h | 2 ++ kernel/time/posix-timers.c | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index 907f3fd..e84436b 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -113,6 +113,8 @@ struct k_clock { #define TIMER_RETRY 1 void (*timer_get) (struct k_itimer * timr, struct itimerspec * cur_setting); + void (*timer_get64) (struct k_itimer *timr, + struct itimerspec64 *cur_setting); }; extern struct k_clock clock_posix_cpu; diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 7d1973a..70b5550 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -140,6 +140,7 @@ static int common_timer_del(struct k_itimer *timer); static enum hrtimer_restart posix_timer_fn(struct hrtimer *data); static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags); +static struct k_clock *clockid_to_kclock(const clockid_t id); #define lock_timer(tid, flags) \ ({ struct k_itimer *__timr; \ @@ -549,6 +550,16 @@ static struct pid *good_sigevent(sigevent_t * event) return task_pid(rtn); } +static void default_timer_get64(struct k_itimer *timr, + struct itimerspec64 *cur_setting64) +{ + struct itimerspec cur_setting; + struct k_clock *kc = clockid_to_kclock(timr->it_clock); + + kc->timer_get(timr, &cur_setting); + *cur_setting64 = itimerspec_to_itimerspec64(&cur_setting); +} + void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock) { @@ -569,6 +580,9 @@ void posix_timers_register_clock(const clockid_t clock_id, return; } + if (new_clock->timer_get && !new_clock->timer_get64) + new_clock->timer_get64 = default_timer_get64; + posix_clocks[clock_id] = *new_clock; } EXPORT_SYMBOL_GPL(posix_timers_register_clock); @@ -802,7 +816,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting) cur_setting->it_value = ktime_to_timespec(remaining); } -static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting) +static int __timer_gettime(timer_t timer_id, struct itimerspec64 *cur_setting) { struct k_itimer *timr; struct k_clock *kc; @@ -814,10 +828,10 @@ static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting) return -EINVAL; kc = clockid_to_kclock(timr->it_clock); - if (WARN_ON_ONCE(!kc || !kc->timer_get)) + if (WARN_ON_ONCE(!kc || !kc->timer_get64)) ret = -EINVAL; else - kc->timer_get(timr, cur_setting); + kc->timer_get64(timr, cur_setting); unlock_timer(timr, flags); return ret; @@ -827,10 +841,11 @@ static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting) SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, struct itimerspec __user *, setting) { - struct itimerspec cur_setting; + struct itimerspec64 cur_setting; + int ret = __timer_gettime(timer_id, &cur_setting); - if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting))) + if (!ret && put_itimerspec(&cur_setting, setting)) return -EFAULT; return ret;