From patchwork Fri Jun 12 07:48:26 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: 49798 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C61BE228DB for ; Fri, 12 Jun 2015 07:51:52 +0000 (UTC) Received: by wgv5 with SMTP id 5sf7419303wgv.0 for ; Fri, 12 Jun 2015 00:51:52 -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=tH12vjbJAiB8ve+k+kayUnQ1jtjZKddAjmcBOSXuigY=; b=L8nZTWjS/hRaYuI3Cqw0yiR6zUTiF1vozWXIJI7FIcdO4/7qlMPJW3FV+07fXjC2XV +3aKnNOlRLX3xAkU+tmPj2EudtGrMYvLnEFlAkA0yE/OQw+1PH8UcifKmUmlYu93DjEn j/ufn0HWEct1/DzVdLhhWHkPT0UXJDhvQ9i/b8dAHapupF+5FeDa8FQ1ZRCI2zOKx7iV agyZMHqM8uYuK72FxGDovbSC1Ai1x8NXExmZlBw/Tjdwdea6OiyiZDwDjVKcs7kS3Wfy ThPHIX33/GFkzCK7xrWX33OJJF4d+XGSxhLy8/3h9cZhVKrZrWbcunCrAEyKbgMMAlpS aZdw== X-Gm-Message-State: ALoCoQnXs5QCntdL/+dTftLBpmj9tG9Bh+cf+SXGlMXKMgAKnwMQD73gQIjzF3bY3JBRHSJn9/Sh X-Received: by 10.112.138.2 with SMTP id qm2mr12768629lbb.19.1434095512019; Fri, 12 Jun 2015 00:51:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.121.98 with SMTP id lj2ls505685lab.94.gmail; Fri, 12 Jun 2015 00:51:51 -0700 (PDT) X-Received: by 10.152.45.9 with SMTP id i9mr13591654lam.87.1434095511847; Fri, 12 Jun 2015 00:51:51 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id u7si2752914lae.10.2015.06.12.00.51.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 00:51:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by laew7 with SMTP id w7so16729240lae.1 for ; Fri, 12 Jun 2015 00:51:51 -0700 (PDT) X-Received: by 10.152.4.137 with SMTP id k9mr13659922lak.29.1434095511736; Fri, 12 Jun 2015 00:51:51 -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 hn6csp356769lbb; Fri, 12 Jun 2015 00:51:50 -0700 (PDT) X-Received: by 10.70.93.69 with SMTP id cs5mr20974884pdb.165.1434095509972; Fri, 12 Jun 2015 00:51:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si4231321pdl.238.2015.06.12.00.51.49; Fri, 12 Jun 2015 00:51:49 -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 S1754861AbbFLHvp (ORCPT + 29 others); Fri, 12 Jun 2015 03:51:45 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:36863 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754372AbbFLHuX (ORCPT ); Fri, 12 Jun 2015 03:50:23 -0400 Received: by pabqy3 with SMTP id qy3so18125902pab.3 for ; Fri, 12 Jun 2015 00:50:22 -0700 (PDT) X-Received: by 10.70.103.230 with SMTP id fz6mr21403489pdb.1.1434095422149; Fri, 12 Jun 2015 00:50:22 -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.19 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 00:50:21 -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 11/24] posix-timers: Implement y2038 safe clock_set64() callback Date: Fri, 12 Jun 2015 15:48:26 +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.54 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_set() callback in struct k_clock is not year 2038 safe on 32bit systems. To address this implement a new callback clock_set64() which uses struct timespec64 along with a default implementation which is a wrapper for the existing clock_set() callback. The default callback is installed at registration time for all posix clocks which are not yet converted to clock_set64() and will be removed once this is completed. Use the new callback in __clock_settime(). Signed-off-by: Baolin Wang --- include/linux/posix-timers.h | 2 ++ kernel/time/posix-timers.c | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index 16c3364..2b19ec8 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -100,6 +100,8 @@ struct k_clock { int (*clock_getres) (const clockid_t which_clock, struct timespec *tp); int (*clock_set) (const clockid_t which_clock, const struct timespec *tp); + 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_adj) (const clockid_t which_clock, struct timex *tx); int (*timer_create) (struct k_itimer *timer); diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 65610ac..dcc632c 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -577,6 +577,18 @@ static int default_timer_set64(struct k_itimer *timr, int flags, return ret; } +static int default_clock_set64(const clockid_t which_clock, + const struct timespec64 *tp64) +{ + struct k_clock *kc = clockid_to_kclock(which_clock); + struct timespec tp; + int ret; + + tp = timespec64_to_timespec(*tp64); + ret = kc->clock_set(which_clock, &tp); + return ret; +} + void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock) { @@ -601,6 +613,8 @@ void posix_timers_register_clock(const clockid_t clock_id, new_clock->timer_get64 = default_timer_get64; if (new_clock->timer_set && !new_clock->timer_set64) new_clock->timer_set64 = default_timer_set64; + if (new_clock->clock_set && !new_clock->clock_set64) + new_clock->clock_set64 = default_clock_set64; posix_clocks[clock_id] = *new_clock; } @@ -1089,22 +1103,22 @@ void exit_itimers(struct signal_struct *sig) } } -static int __clock_settime(clockid_t which_clock, struct timespec *ts) +static int __clock_settime(clockid_t which_clock, struct timespec64 *ts) { struct k_clock *kc = clockid_to_kclock(which_clock); - if (!kc || !kc->clock_set) + if (!kc || !kc->clock_set64) return -EINVAL; - return kc->clock_set(which_clock, ts); + return kc->clock_set64(which_clock, ts); } SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, const struct timespec __user *, tp) { - struct timespec new_tp; + struct timespec64 new_tp; - if (copy_from_user(&new_tp, tp, sizeof (*tp))) + if (get_timespec(&new_tp, tp)) return -EFAULT; return __clock_settime(which_clock, &new_tp);