From patchwork Mon Nov 27 17:00:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119758 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp539675qgn; Mon, 27 Nov 2017 09:01:52 -0800 (PST) X-Google-Smtp-Source: AGs4zMbyF+6IPvD0qw64QkK2BLVyRoxxoLXUmcbeoA+g09ZJ+m0VvSn1u+ZxSLdnTNAuyJL8r8Mz X-Received: by 10.98.29.83 with SMTP id d80mr37048408pfd.156.1511802112842; Mon, 27 Nov 2017 09:01:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511802112; cv=none; d=google.com; s=arc-20160816; b=NLXBhXPMCkISxAnlgcgxz1GBTS1sRItz4dESkEp1AePkCZi1vRuoXV94LD1n90c1fD rCwYipwVC1E59QFOmJpi1A7d29gUSJS0YWAso1R/TI8vVMENbLQ2AqNfvHkKedjafm75 JqSz3Ccl7cQ249CcU1XsX9ktuE0NLED7bqybswkUn8brwYTq+n5h+t7M43q8O3+r3Q+5 aySWXIhogf9FazYZm4koqrbgFahzNcfDI4iHW/rMcFU5SGcUkZG81aGdmzo3+zhjRVH5 ou79aGSwQEc3ooLJzb106TNYPW3EVCbrnHkELk1cEnFVSmuGS73VIubFY3PRQk6MQ6To h8pA== 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=e/YqFAm15TGszX/P31cH6DwYxzrDYM2vkcMOWx9A5Dw=; b=uFVGe29+P+7Y1DQFFplQN0ySoyny//OkAxz7uP1IIJuJERpzMda9zTUuxyPsey2oVu AOXg4fDuR5AdqinY2vyo7wMsDd4eiTYBlwAjMxH/fdMS+LBgg2DJ64CYG24DoJt5ipe+ y64xmzKWrmxv9UmXf6Ztt2t1cgJy9iVEXDCSGVYpoZ2NhSa+GngKRnPgiu5l1wFk5hVC MQF5ua8R8FsrCdRAA6XvwwSvq+ZR1YFenX7ZBugx9cLOP9+W0fgRJiGyGb/Ot12Uiu44 jTolKSYVQAuf3+dT9OTEcBVJy+cyy1TeVlOumUxgK44J7XpRF0z67dosikYdsviaGf0B 9D0Q== 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 l30si23494222plg.363.2017.11.27.09.01.52; Mon, 27 Nov 2017 09:01:52 -0800 (PST) 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 S932417AbdK0RBv (ORCPT + 28 others); Mon, 27 Nov 2017 12:01:51 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:53173 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932086AbdK0RBs (ORCPT ); Mon, 27 Nov 2017 12:01:48 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MSJh5-1eiMoJ2bG7-00TWqX; Mon, 27 Nov 2017 18:01:32 +0100 From: Arnd Bergmann To: John Stultz , Thomas Gleixner Cc: y2038@lists.linaro.org, libc-alpha@sourceware.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Albert ARIBAUD , Arnd Bergmann , Stephen Boyd , Al Viro , Deepa Dinamani , Ingo Molnar , Andreas Dilger Subject: [PATCH 1/3] y2038: introduce struct __kernel_old_timeval Date: Mon, 27 Nov 2017 18:00:45 +0100 Message-Id: <20171127170121.634826-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:IsWBwuBpWKh7GIHHNi1d8o90Zj1SmouhvF0Yn2AcjZP/aTMDoN/ ybnF25l/Hyvnwl4fdsQFH4QOG0P1BT7GeoRvkK2y4RwwcMfPi/H2z3NaMJ5cjP2x1v4EEzM mUejm/hvZG9xdqtIwSFsBKampxdZS1PP/R3oX8u6bbfpgOEvK52ebEx3U3cFgvAZ+RbuSkh LvuaAuiPkQL678fdIdXjA== X-UI-Out-Filterresults: notjunk:1; V01:K0:A/taIUiopR0=:SicKl16WFJbQeZNfzE+4YR L6BmqMp3AMtsUfXLXsinyREQAGvv2QMXwNdgQI7Fl1n4wprIwfZm9cOG50gtwJ/1bm9/1X1rg 6dRbr6H+QeTlUmobGeDI5b5IF9bQXv+SZhrzL4aJqtLJTRPJ7I5L04XAaqHxD8vBVBp3sZx5C mw5nfB2kM+PI1+QPEsvg7IuurLXGhU21mjxTxLpik1swkPYeu9yu0NeeO4gDa0skXJjvdFRgU S9Y2G0xExgee0z0WggQ2oBk9GgTU+hv6XH+H9dzXxrOGs7s4+1Qk+XDzh4BXFKZnSxWHjzMgw 7akwjoH7G+e5n8Q8VI08TkpkV0LeVnuHQ4vp7JkY6hIfC6gLXHa6mtRus/c0FctwGe9JajfsZ +NTCKCpEZ2ptbJ1/vpU4WH/Dwpb4Ehvu4IkcpZgNa82FdFee29SKp0lJGDP+srGjxI6WLyeIz 3n7I4P+4nzEbn0hm3MwLycsA1j6newK6/qNYfJpmiXnktTU9UbNjLWbhOdXTe3dvPf3l8I/XU T5orgeKygeJjOqrXemSPgg3azAy2r7jZr1spVIN0qMgp5lpcDaQadsB2zEvANG31lwqprxjTR JWNwoetlIAH0xGSU/BgTOghaFBjwzA0fpTs3FRjrCsSlUnLgF8AgJfuRvhvkSyJrJ/QpC1Hgj ilCs+Sb3SWntgjtQMZySRojZkcrDrRyB8fAVFGIBgOys3EHd9b6GhnqwakUlRjIZSWzs+9Xeu H/PKJxVwKz6AvT9kl+ZH01XtCBcMVyVMS4GG2w== 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 --- 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..378c75d9a83c 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(const s64 nsec); #endif diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 0ad4510884b0..30aa734135ad 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; /* seconds */ +}; + +/* * 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 518b56b17147..92002257f083 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 *