From: Arnd Bergmann <arnd@arndb.de>
To: y2038@lists.linaro.org
Cc: libc-alpha@sourceware.org, Arnd Bergmann <arnd@arndb.de>,
baolin.wang@linaro.org, linux-api@vger.kernel.org,
ruchandani.tina@gmail.com, linux-kernel@vger.kernel.org,
albert.aribaud@3adev.fr, john.stultz@linaro.org,
tglx@linutronix.de, bamvor.zhangjian@linaro.org
Subject: [PATCH 08/19] y2038: introduce struct __kernel_timespec
Date: Wed, 6 May 2015 18:30:15 +0200 [thread overview]
Message-ID: <1430929826-318934-9-git-send-email-arnd@arndb.de> (raw)
In-Reply-To: <1430929826-318934-1-git-send-email-arnd@arndb.de>
A lot of system calls pass a 'struct timespec' from or to user space,
and we want to change that type to be based on a 64-bit time_t by
default.
This introduces a new type struct __kernel_timespec, which has the
format we want to use eventually, but also has an override so all
architectures that do not define CONFIG_COMPAT_TIME yet still get the
old behavior.
Once all architectures set this, we can remove that override.
This also introduces a get_timespec64/put_timespec64 set of functions
that convert between a __kernel_timespec in user space and a timespec64
in kernel space.
The current behavior of get_timespec64 explicitly zeroes the upper half
of the tv_nsec member, to allow user space to define its own 'struct
timespec' with some padding in it. Whether this is a good or bad idea
is open for discussion.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
include/linux/time64.h | 17 +++++++++++------
include/uapi/linux/time.h | 17 +++++++++++++++++
kernel/time/time.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/include/linux/time64.h b/include/linux/time64.h
index a3831478d9cf..880ebe4b4ba4 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -1,14 +1,12 @@
#ifndef _LINUX_TIME64_H
#define _LINUX_TIME64_H
-#include <uapi/linux/time.h>
-
typedef __s64 time64_t;
-/*
- * This wants to go into uapi/linux/time.h once we agreed about the
- * userspace interfaces.
- */
+#ifndef CONFIG_COMPAT_TIME
+# define __kernel_timespec timespec
+#endif
+
#if __BITS_PER_LONG == 64
# define timespec64 timespec
#else
@@ -18,6 +16,8 @@ struct timespec64 {
};
#endif
+#include <uapi/linux/time.h>
+
/* Parameters used to convert the timespec values: */
#define MSEC_PER_SEC 1000L
#define USEC_PER_MSEC 1000L
@@ -187,4 +187,9 @@ static __always_inline void timespec64_add_ns(struct timespec64 *a, u64 ns)
#endif
+extern int get_timespec64(struct timespec64 *ts,
+ const struct __kernel_timespec __user *uts);
+extern int put_timespec64(const struct timespec64 *ts,
+ struct __kernel_timespec __user *uts);
+
#endif /* _LINUX_TIME64_H */
diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h
index e75e1b6ff27f..72d894df3013 100644
--- a/include/uapi/linux/time.h
+++ b/include/uapi/linux/time.h
@@ -66,4 +66,21 @@ struct itimerval {
*/
#define TIMER_ABSTIME 0x01
+/* types based on 64-bit time_t */
+#ifndef __kernel_timespec
+typedef __s64 __kernel_time64_t;
+
+struct __kernel_timespec {
+ __kernel_time64_t tv_sec;
+ __s64 tv_nsec;
+};
+#endif
+
+#ifndef __kernel_itimerspec
+struct __kernel_itimerspec {
+ struct __kernel_timespec it_interval;
+ struct __kernel_timespec it_value;
+};
+#endif
+
#endif /* _UAPI_LINUX_TIME_H */
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 2c85b7724af4..845af1db66fa 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -30,6 +30,7 @@
#include <linux/export.h>
#include <linux/timex.h>
#include <linux/capability.h>
+#include <linux/compat.h>
#include <linux/timekeeper_internal.h>
#include <linux/errno.h>
#include <linux/syscalls.h>
@@ -37,6 +38,7 @@
#include <linux/fs.h>
#include <linux/math64.h>
#include <linux/ptrace.h>
+#include <linux/time64.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
@@ -783,3 +785,33 @@ struct timespec timespec_add_safe(const struct timespec lhs,
return res;
}
+
+int get_timespec64(struct timespec64 *ts,
+ const struct __kernel_timespec __user *uts)
+{
+ struct __kernel_timespec kts;
+ int ret;
+
+ ret = copy_from_user(&kts, uts, sizeof(kts));
+ if (ret)
+ return -EFAULT;
+
+ ts->tv_sec = kts.tv_sec;
+ if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task())
+ kts.tv_nsec &= 0xfffffffful;
+ ts->tv_nsec = kts.tv_nsec;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(get_timespec64);
+
+int put_timespec64(const struct timespec64 *ts,
+ struct __kernel_timespec __user *uts)
+{
+ struct __kernel_timespec kts = {
+ .tv_sec = ts->tv_sec,
+ .tv_nsec = ts->tv_nsec
+ };
+ return copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0;
+}
+EXPORT_SYMBOL_GPL(put_timespec64);
--
2.1.0.rc2
_______________________________________________
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038
next prev parent reply other threads:[~2015-05-06 16:30 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 16:30 [PATCH 00/19] converting system calls to 64-bit time_t, part 1 Arnd Bergmann
2015-05-06 16:30 ` [PATCH 01/19] compat: remove compat_printk Arnd Bergmann
2015-05-06 16:30 ` [PATCH 02/19] initramfs: use vfs_stat/lstat directly Arnd Bergmann
2015-05-06 16:30 ` [PATCH 03/19] y2038: introduce linux/compat_time.h header Arnd Bergmann
2015-05-06 16:30 ` [PATCH 04/19] y2038: introduce CONFIG_COMPAT_TIME Arnd Bergmann
2015-05-06 16:30 ` [PATCH 05/19] y2038: make linux/compat_time.h usable on 32-bit Arnd Bergmann
2015-05-06 16:30 ` [PATCH 07/19] y2038: add compat_sys_rt_sigtimedwait variants Arnd Bergmann
2015-05-06 16:30 ` Arnd Bergmann [this message]
[not found] ` <1430929826-318934-1-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
2015-05-06 16:30 ` [PATCH 06/19] y2038: compile compat time code even when CONFIG_COMPAT is not set Arnd Bergmann
2015-05-06 16:30 ` [PATCH 09/19] y2038: introduce struct __kernel_stat Arnd Bergmann
2015-05-06 16:30 ` [PATCH 11/19] y2038: introduce and use struct __kernel_rusage Arnd Bergmann
2015-05-07 7:27 ` [PATCH 00/19] converting system calls to 64-bit time_t, part 1 Paul Bolle
2015-05-07 7:39 ` Paul Bolle
2015-05-07 8:52 ` Arnd Bergmann
2015-05-07 9:24 ` Paul Bolle
2015-05-06 16:30 ` [PATCH 10/19] y2038: use __kernel_stat for sys_newstat syscalls Arnd Bergmann
2015-05-06 16:30 ` [PATCH 12/19] y2038: add compat_{get,put}_timespec64 Arnd Bergmann
2015-05-06 16:30 ` [PATCH 13/19] y2038: add compat handling for sys_semtimedop Arnd Bergmann
[not found] ` <1430929826-318934-14-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
2015-05-15 22:46 ` Thomas Gleixner
2015-05-16 7:28 ` Arnd Bergmann
2015-05-16 19:54 ` Arnd Bergmann
2015-05-19 9:19 ` Thomas Gleixner
2015-05-06 16:30 ` [PATCH 14/19] y2038: use __kernel_timespec for sys_mq_timed{send,receive} Arnd Bergmann
2015-05-06 16:30 ` [PATCH 15/19] y2038: introduce timespec64_to_jiffies Arnd Bergmann
2015-05-19 9:28 ` Thomas Gleixner
2015-05-06 16:30 ` [PATCH 16/19] y2038: use __kernel_timespec in sys_rt_sigtimedwait Arnd Bergmann
2015-05-19 9:28 ` Thomas Gleixner
2015-05-06 16:30 ` [PATCH 17/19] y2038: use __kernel_timespec in sys_futex Arnd Bergmann
2015-05-15 22:53 ` Thomas Gleixner
2015-05-16 7:21 ` Thomas Gleixner
[not found] ` <1430929826-318934-18-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
2015-05-19 9:24 ` Thomas Gleixner
2015-05-06 16:30 ` [PATCH 18/19] y2038: introduce jiffies_to_timespec64 Arnd Bergmann
[not found] ` <1430929826-318934-19-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
2015-05-19 9:25 ` Thomas Gleixner
2015-05-06 16:30 ` [PATCH 19/19] y2038: use __kernel_timespec in sys_sched_rr_get_interval Arnd Bergmann
2015-05-19 9:27 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430929826-318934-9-git-send-email-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=albert.aribaud@3adev.fr \
--cc=bamvor.zhangjian@linaro.org \
--cc=baolin.wang@linaro.org \
--cc=john.stultz@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ruchandani.tina@gmail.com \
--cc=tglx@linutronix.de \
--cc=y2038@lists.linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).