From patchwork Wed Mar 14 22:04:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 131726 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp356697ljb; Wed, 14 Mar 2018 15:05:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELvXaals4Z9N3UDgnw/Ad23ap/T7XJ7nxAkObQuTqE8CiPUChnisAVsxAgPFKeZaAFNkFGXA X-Received: by 10.101.98.149 with SMTP id f21mr4829109pgv.7.1521065115604; Wed, 14 Mar 2018 15:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521065115; cv=none; d=google.com; s=arc-20160816; b=rE+CAbONHoGVCWWB2VfCjQTPtUfSWmJ34/b3kev6Gu4x3OadOwLfUlJFiySmEepd/N 90FK96sdROzL+d1ZJBUL5ZQV3kJDE4A0wxi35qyrcmmmL7yFgMW5ZOSahi4n42uLdpzN cnjY61wfA0nvqaBtIK+HGInPwc+9IboTNg1As1q9SQD3I5tEMr8M4CCQGX71KsQklU04 dtDP3a3XmqExxo8p1uNg2b+qiiHnptMwQ+GUiQcX10sHjAOn0Gyq9tyTEw8GVt3XYMlq fHkvnLTpIX/AypxrX6Yc8yDGqJyEVd6GdUslIgSPegwJcdHpICbqpECb/tsI81x6/its jVQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=BEEjuXVFGv2xYLwQvBiPh+3JYyQ6uSsPxYlpVbiO8Ug=; b=yegOajo/ger3JzL1ywqO3FYC23WznSov3PDaf9AHuFQFXy9ni8R8RxErJAo6P1KH7e 27efZMF1H/hjqLQIIEJ49Jrp7t7vkLNy5CPjQkrI2wH+KiziKWET7PtCOSkglL4InRcI T1ovmVYFLxdcGxs+JDyxAk6bU3Dh9eIFS0witkwsQer4UNJ7S9yMYi/01bdqjI/xPsWH iTUm+LbbP8yzFN9KoHMaQzC1gbo2p5AwSzUP0BqJEnlsJ/Iwdccz5s5qmGE61CCEXrL0 RcSjqBFwhRnunEpQZJMvOGnzZgbobFrtvfIB+k8bNiOzoC7X4+N3FuJ5fjbdcZqpMvvz /YTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o33-v6si2647777plb.412.2018.03.14.15.05.15; Wed, 14 Mar 2018 15:05:15 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752009AbeCNWFL (ORCPT + 28 others); Wed, 14 Mar 2018 18:05:11 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:60831 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751279AbeCNWFJ (ORCPT ); Wed, 14 Mar 2018 18:05:09 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lsupa-1eU8zM2gHq-012Zk2; Wed, 14 Mar 2018 23:04:54 +0100 From: Arnd Bergmann To: lkml Cc: Ingo Molnar , John Stultz , Thomas Gleixner , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Arnd Bergmann , Deepa Dinamani Subject: [PATCH] [v2] y2038: introduce struct __kernel_old_timeval Date: Wed, 14 Mar 2018 23:04:15 +0100 Message-Id: <20180314220452.3453973-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: References: X-Provags-ID: V03:K0:3r9r2Mvb3wmSwqgjnM6akqV4jZ1JR4UhvfovsrY+BXw+n0Gw+Lt kfoJwf5MYeASIegQg/nJMWy0e0G0wiVfIt4z6k8M2ynjtlbHOAkB4mxJ+BlgeV2GUUUqOJ7 2gYsEtV72//HBEm83CCxP0qmiLzuLl52BTdby9PdA76M3f+dsNq1Adh+co4NSahyRsDonCn ErWB7SgP8CLpYvLTLs6/A== X-UI-Out-Filterresults: notjunk:1; V01:K0:rmjoqT+W36Q=:ejQQQnEpO05apqcmqu8/MQ Z0H0/fCcI8I64wiu9SK+t4pDobbWEErrKevrY5DVf1x8oXxPi+FstDO+slXp1apcyxX/YMAYh S0PVOiYslHcxTeQUlEuZ6gudhdaB8i9xn0CKXkaWVWgw1LtkM+m24ncW2zQQSsmUcPhSr4dfu zfdVhNthgnKm2YMResSqzBazTBGmynE8EXMuVuZVhjmnVKUBCZPlB5MAelHa0sv17GON+xKfW VhRMInv01PkNTkeIPHSYtQUCYrJ3mw2a9mVEqKH+UslfWO3FslYhAd2lV4F884bJ5IcBJMwig l+k1iaieU2dWA61Ujo5gr8b+CXkwCggh7TicNYkk68AKJF5O8qgHjumA1W63Lewf/COsLDZme VXBPKyNWbUXeB3FBbv2wBQc9Kvh4mDfUlMSDa7Zd2cPnWpkodKSjuOSzdHxfbyVqYGtbnsu6y XZOQLu1aVdLGYPFzAOZjIuzu5umN0OKiC1N02GVFm2TiFsX25z9v8b2BabbSScyz2wX/AoQgV nckkUn9/TRN8l9ef63FrHvzpREfP0emmhtsze5Sc2HNZ3yVXLccWKPNa4qqMhD7kP0lxgIMHG dIj/tXuH6Xi2bVZW6bnXcZWeiCqkUNcz8/CijxZ+aQSnxmDheFAdzyGvPTCp1ln+bBWLqh7S5 2BYeBkH3T10ZUB67i/SG6Q0jlpnk+xxNzeZv7EmCed3jll8JEyMLOQfWuqus983vATodzDLKG u/TN7ejQ/CWnDqzBr6NKuGq2RxFizfSkLH7sNw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dealing with 'struct timeval' users in the y2038 series is a bit tricky: We have two definitions of timeval that are visible to user space, one comes from glibc (or some other C library), the other comes from linux/time.h. The kernel copy is what we want to be used for a number of structures defined by the kernel itself, e.g. elf_prstatus (used it core dumps), sysinfo and rusage (used in system calls). These generally tend to be used for passing time intervals rather than absolute (epoch-based) times, so they do not suffer from the y2038 overflow. Some of them could be changed to use 64-bit timestamps by creating new system calls, others like the core files cannot easily be changed. An application using these interfaces likely also uses gettimeofday() or other interfaces that use absolute times, and pass 'struct timeval' pointers directly into kernel interfaces, so glibc must redefine their timeval based on a 64-bit time_t when they introduce their y2038-safe interfaces. The only reasonable way forward I see is to remove the 'timeval' definion from the kernel's uapi headers, and change the interfaces that we do not want to (or cannot) duplicate for 64-bit times to use a new __kernel_old_timeval definition instead. This type should be avoided for all new interfaces (those can use 64-bit nanoseconds, or the 64-bit version of timespec instead), and should be used with great care when converting existing interfaces from timeval, to be sure they don't suffer from the y2038 overflow, and only with consensus for the particular user that using __kernel_old_timeval is better than moving to a 64-bit based interface. The structure name is intentionally chosen to not conflict with user space types, and to be ugly enough to discourage its use. Note that ioctl based interfaces that pass a bare 'timeval' pointer cannot change to '__kernel_old_timeval' because the user space source code refers to 'timeval' instead, and we don't want to modify the user space sources if possible. However, any application that relies on a structure to contain an embedded 'timeval' (e.g. by passing a pointer to the member into a function call that expects a timeval pointer) is broken when that structure gets converted to __kernel_old_timeval. I don't see any way around that, and we have to rely on the compiler to produce a warning or compile failure that will alert users when they recompile their sources against a new libc. Signed-off-by: Arnd Bergmann --- v2: update for Ingo's comments --- include/linux/time32.h | 1 + include/uapi/linux/time.h | 12 ++++++++++++ kernel/time/time.c | 12 ++++++++++++ 3 files changed, 25 insertions(+) -- 2.9.0 diff --git a/include/linux/time32.h b/include/linux/time32.h index 100411c979be..0b14f936100a 100644 --- a/include/linux/time32.h +++ b/include/linux/time32.h @@ -205,5 +205,6 @@ static inline s64 timeval_to_ns(const struct timeval *tv) * Returns the timeval representation of the nsec parameter. */ extern struct timeval ns_to_timeval(const s64 nsec); +extern struct __kernel_old_timeval ns_to_kernel_old_timeval(s64 nsec); #endif diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 4ed5bd3a3145..44c994c8755e 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -50,6 +50,18 @@ struct __kernel_timespec { #endif /* + * legacy timeval structure, only embedded in structures that + * traditionally used 'timeval' to pass time intervals (not absolute + * times). Do not add new users. If user space fails to compile + * here, this is probably because it is not y2038 safe and needs to + * be changed to use another interface. + */ +struct __kernel_old_timeval { + __kernel_long_t tv_sec; /* seconds */ + __kernel_long_t tv_usec; /* microseconds */ +}; + +/* * The IDs of the various system clocks (for POSIX.1b interval timers): */ #define CLOCK_REALTIME 0 diff --git a/kernel/time/time.c b/kernel/time/time.c index 5db8f15ec056..6fa99213fc72 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -486,6 +486,18 @@ struct timeval ns_to_timeval(const s64 nsec) } EXPORT_SYMBOL(ns_to_timeval); +struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec) +{ + struct timespec64 ts = ns_to_timespec64(nsec); + struct __kernel_old_timeval tv; + + tv.tv_sec = ts.tv_sec; + tv.tv_usec = (suseconds_t)ts.tv_nsec / 1000; + + return tv; +} +EXPORT_SYMBOL(ns_to_kernel_old_timeval); + /** * set_normalized_timespec - set timespec sec and nsec parts and normalize *