From patchwork Thu Mar 15 16:12:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 131812 Delivered-To: patch@linaro.org Received: by 10.80.210.197 with SMTP id q5csp1675010edg; Thu, 15 Mar 2018 09:17:56 -0700 (PDT) X-Google-Smtp-Source: AG47ELu16kh7B/wCey9YSme2f8x/UcaPZJesw4LWACslNmr7V3HglcVzzNzAbpOEzlg48zS7x1KA X-Received: by 2002:a17:902:52c7:: with SMTP id a65-v6mr387656pli.249.1521130676202; Thu, 15 Mar 2018 09:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521130676; cv=none; d=google.com; s=arc-20160816; b=txDqyUxJAWbPYJrocu7L6MNZqAR5PB7u7l1gvM1peNJexJ5CQ5ms8GYGxR8v4/x6/n XsxEHJ4Ip+QRk5egWfoCdnr2BOfJclDERDazjfwFjJfEhp2maXwMMOmqbEKqPEMTCDTj LTT5RFsY+CvWaZ3HcjbcqPoDxsvGSuuTUx7HrIPWHe2inDR41i/QPDSd3GZjdXMKBm6b PPO6hpEncpgohKQMTBvgLcwOQv523e5MA1HB7+32CpGd61Srt7ATVAqkB/5mYA7AwB5W Nng6OM/kVQBcqmYDeQf63yVY2cLTezDekHVkG6cERQ0I3LZlwCIh66mQ3k3dUJ2vLu/7 g33w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=k8qADZd858IjHtzQMSLIE5h9TCt/g4x3r6rfLd9JkjY=; b=XrotpMvlRB8S8LXxiouSqOAWUXX6DSRJuftpsF1ksmKAvuWiDrxGkbD9kpLhpAVPwM z7/FsP3QABadZyPoKHdb4kHeDCuG61TD2ACtVDsD8ficvHK+cFw7IW57PS5pjQppFBYk IzBn0Ikv5k0wpVoW3wvAbwN/YebKu4+6XXqKqbnA2qMMEZWBUNS4wI8yQPjeshb4qN1y wPwd7dwNCjJAZLqmCGoS9mVwWBzAtTkzYeuBxnxT9FJM4lIBAzhCRLaQC/YzO1oz/DEJ 08wXLdnNKqmq5eefV+Bf/xBrANusiVu3sAPD8trt6ZJBkorZqgdQvoltJrd43Myd7qmG HTpA== 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 e9-v6si4320427pln.492.2018.03.15.09.17.55; Thu, 15 Mar 2018 09:17:56 -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 S1751929AbeCOQRw (ORCPT + 28 others); Thu, 15 Mar 2018 12:17:52 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:41705 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751456AbeCOQRv (ORCPT ); Thu, 15 Mar 2018 12:17:51 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0LrKaC-1eUxj63G3A-0135PK; Thu, 15 Mar 2018 17:17:40 +0100 From: Arnd Bergmann To: Thomas Gleixner Cc: Arnd Bergmann , John Stultz , Stephen Boyd , Al Viro , linux-kernel@vger.kernel.org Subject: [PATCH] [v3] y2038: introduce struct __kernel_old_timeval Date: Thu, 15 Mar 2018 17:12:40 +0100 Message-Id: <20180315161739.576085-1-arnd@arndb.de> X-Mail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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 v3: update for Thomas' comment --- 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..94adfae599e0 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; + __kernel_long_t tv_usec; +}; + +/* * 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 *