From patchwork Fri Jun 12 07:48:24 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: 49793 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 28F27228DB for ; Fri, 12 Jun 2015 07:50:29 +0000 (UTC) Received: by wibut5 with SMTP id ut5sf2697422wib.0 for ; Fri, 12 Jun 2015 00:50:28 -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=m0uXnckYRmXZN/oWBX42mRUQWZmLF6CEs7JOpH+wtyY=; b=lfgjuEWDG/m+pWgnSYHhbrKdoGHzGHEFndZmNheJBe4TMI23izFj5b01vHmPkMZrfR PWV15DRALc5PFT6utNwA7ILrprO7v9vVIP7ymeeiX7r8PnPEwb0Q0OAMY6T+a7bUmDKJ tGzPV669mSxQnTEeOIcLf2ipLa5rEU2s9DOup5q02VehPsbAjeR/8CkqDJNLKTCB7Qen 2v2Z+Tg8+MpC7f+q1UdZ/u29y/kvvBcH22cZW9MPsWaU6ImRGpLjRXaVwMSeYDYp1jWP 8Xg8vk0ef23IK51+S3GmczSXp5PIIl10nGvxeRqfmO/5+TUeudrcmtsBR53NIZsX/29k 0bfw== X-Gm-Message-State: ALoCoQnlx4t7ZHrdfmy4Be2q87GAUJYmbZJiwbR0/3C2PIs7nyaTulk2SNqGKvFfvDCAS6lFIcJc X-Received: by 10.152.19.161 with SMTP id g1mr13022371lae.8.1434095428403; Fri, 12 Jun 2015 00:50:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.178.195 with SMTP id da3ls539539lac.43.gmail; Fri, 12 Jun 2015 00:50:28 -0700 (PDT) X-Received: by 10.152.170.165 with SMTP id an5mr13995216lac.100.1434095428226; Fri, 12 Jun 2015 00:50:28 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id le1si2705370lac.158.2015.06.12.00.50.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 00:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by laew7 with SMTP id w7so16710472lae.1 for ; Fri, 12 Jun 2015 00:50:28 -0700 (PDT) X-Received: by 10.152.22.99 with SMTP id c3mr14156859laf.32.1434095427985; Fri, 12 Jun 2015 00:50:27 -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 hn6csp356080lbb; Fri, 12 Jun 2015 00:50:26 -0700 (PDT) X-Received: by 10.70.129.202 with SMTP id ny10mr21000263pdb.107.1434095426157; Fri, 12 Jun 2015 00:50:26 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ps1si4210241pbb.236.2015.06.12.00.50.25; Fri, 12 Jun 2015 00:50:26 -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 S1754335AbbFLHuS (ORCPT + 29 others); Fri, 12 Jun 2015 03:50:18 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36671 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753695AbbFLHuI (ORCPT ); Fri, 12 Jun 2015 03:50:08 -0400 Received: by pabqy3 with SMTP id qy3so18122018pab.3 for ; Fri, 12 Jun 2015 00:50:08 -0700 (PDT) X-Received: by 10.68.108.132 with SMTP id hk4mr21394380pbb.6.1434095408278; Fri, 12 Jun 2015 00:50:08 -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.06 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 00:50:07 -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 09/24] posix-timers: Implement y2038 safe timer_set64() callback Date: Fri, 12 Jun 2015 15:48:24 +0800 Message-Id: <3551d1848e35f659e3753073c7ef58938faad776.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.215.52 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_set() callback in struct k_clock is not year 2038 safe on 32bit systems. To address this implement a new callback timer_set64() which uses struct itimerspec64 along with a default implementation which is a wrapper for the existing timer_set() callback. The default callback is installed at registration time for all posix clocks which are not yet converted to timer_set64() and will be removed once this is completed. Use the new callback in __timer_settime(). Signed-off-by: Baolin Wang --- include/linux/posix-timers.h | 3 +++ kernel/time/posix-timers.c | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index e84436b..16c3364 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -109,6 +109,9 @@ struct k_clock { int (*timer_set) (struct k_itimer * timr, int flags, struct itimerspec * new_setting, struct itimerspec * old_setting); + int (*timer_set64) (struct k_itimer *timr, int flags, + struct itimerspec64 *new_setting, + struct itimerspec64 *old_setting); int (*timer_del) (struct k_itimer * timr); #define TIMER_RETRY 1 void (*timer_get) (struct k_itimer * timr, diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 2f1c26f..778610c 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -560,6 +560,23 @@ static void default_timer_get64(struct k_itimer *timr, *cur_setting64 = itimerspec_to_itimerspec64(&cur_setting); } +static int default_timer_set64(struct k_itimer *timr, int flags, + struct itimerspec64 *new_setting64, + struct itimerspec64 *old_setting64) +{ + struct k_clock *kc = clockid_to_kclock(timr->it_clock); + struct itimerspec new_setting, old_setting; + struct itimerspec *rtn = old_setting64 ? &old_setting : NULL; + int ret; + + new_setting = itimerspec64_to_itimerspec(new_setting64); + ret = kc->timer_set(timr, flags, &new_setting, rtn); + if (!ret && old_setting64) + *old_setting64 = itimerspec_to_itimerspec64(&old_setting); + + return ret; +} + void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock) { @@ -582,6 +599,8 @@ void posix_timers_register_clock(const clockid_t clock_id, if (new_clock->timer_get && !new_clock->timer_get64) new_clock->timer_get64 = default_timer_get64; + if (new_clock->timer_set && !new_clock->timer_set64) + new_clock->timer_set64 = default_timer_set64; posix_clocks[clock_id] = *new_clock; } @@ -927,16 +946,16 @@ common_timer_set(struct k_itimer *timr, int flags, return 0; } -static int __timer_settime(timer_t timer_id, int flags, struct itimerspec *new_spec, - struct itimerspec *old_spec) +static int __timer_settime(timer_t timer_id, int flags, struct itimerspec64 *new_spec, + struct itimerspec64 *old_spec) { struct k_itimer *timr; int error = 0; unsigned long flag; struct k_clock *kc; - if (!timespec_valid(&new_spec->it_interval) || - !timespec_valid(&new_spec->it_value)) + if (!timespec64_valid(&new_spec->it_interval) || + !timespec64_valid(&new_spec->it_value)) return -EINVAL; retry: @@ -945,10 +964,10 @@ retry: return -EINVAL; kc = clockid_to_kclock(timr->it_clock); - if (WARN_ON_ONCE(!kc || !kc->timer_set)) + if (WARN_ON_ONCE(!kc || !kc->timer_set64)) error = -EINVAL; else - error = kc->timer_set(timr, flags, new_spec, old_spec); + error = kc->timer_set64(timr, flags, new_spec, old_spec); unlock_timer(timr, flag); if (error == TIMER_RETRY) { @@ -964,20 +983,20 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, const struct itimerspec __user *, new_setting, struct itimerspec __user *, old_setting) { - struct itimerspec new_spec, old_spec; + struct itimerspec64 new_spec, old_spec; int error = 0; - struct itimerspec *rtn = old_setting ? &old_spec : NULL; + struct itimerspec64 *rtn = old_setting ? &old_spec : NULL; if (!new_setting) return -EINVAL; - if (copy_from_user(&new_spec, new_setting, sizeof (new_spec))) + if (get_itimerspec(&new_spec, new_setting)) return -EFAULT; error = __timer_settime(timer_id, flags, &new_spec, rtn); if (old_setting && !error && - copy_to_user(old_setting, &old_spec, sizeof (old_spec))) + put_itimerspec(&old_spec, old_setting)) error = -EFAULT; return error;