2015-07-15 05:49:18

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 0/6] Introduce 64bit accessors and structures required to address y2038 issues in the posix_clock subsystem

This patch series change the 32-bit time types (timespec/itimerspec) to
the 64-bit types (timespec64/itimerspec64), and add new 64bit accessor
functions, which are required in order to avoid y2038 issues in the
posix_clock subsystem.

In order to avoid spamming people too much, I'm only sending the first
few patches of the patch series, and left the other patches for later.

And if you are interested in the whole patch series, see:
https://git.linaro.org/people/baolin.wang/upstream_0627.git

Thoughts and feedback would be appreciated.

Baolin Wang (6):
time: Introduce struct itimerspec64
timekeeping: Introduce current_kernel_time64()
security: Introduce security_settime64()
time: Introduce do_sys_settimeofday64()
time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()
cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

arch/powerpc/include/asm/cputime.h | 6 +++---
arch/s390/include/asm/cputime.h | 8 ++++----
include/asm-generic/cputime_jiffies.h | 10 +++++-----
include/asm-generic/cputime_nsecs.h | 6 +++---
include/linux/cputime.h | 16 +++++++++++++++
include/linux/jiffies.h | 22 ++++++++++++++++++---
include/linux/lsm_hooks.h | 5 +++--
include/linux/security.h | 20 ++++++++++++++++---
include/linux/time64.h | 35 +++++++++++++++++++++++++++++++++
include/linux/timekeeping.h | 24 +++++++++++++++++++---
kernel/time/time.c | 28 +++++++++++++++-----------
kernel/time/timekeeping.c | 6 +++---
security/commoncap.c | 2 +-
security/security.c | 2 +-
14 files changed, 148 insertions(+), 42 deletions(-)

--
1.7.9.5


2015-07-15 05:53:06

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 1/6] time: Introduce struct itimerspec64

The struct itimerspec is not year 2038 safe on 32bit systems due to
the limitation of the struct timespec members. Introduce itimerspec64
which uses struct timespec64 instead and provide conversion functions.

Signed-off-by: Baolin Wang <[email protected]>
---
include/linux/time64.h | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)

diff --git a/include/linux/time64.h b/include/linux/time64.h
index 77b5df2..367d5af 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -12,11 +12,18 @@ typedef __s64 time64_t;
*/
#if __BITS_PER_LONG == 64
# define timespec64 timespec
+#define itimerspec64 itimerspec
#else
struct timespec64 {
time64_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
+
+struct itimerspec64 {
+ struct timespec64 it_interval;
+ struct timespec64 it_value;
+};
+
#endif

/* Parameters used to convert the timespec values: */
@@ -45,6 +52,16 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
return ts;
}

+static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64)
+{
+ return *its64;
+}
+
+static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its)
+{
+ return *its;
+}
+
# define timespec64_equal timespec_equal
# define timespec64_compare timespec_compare
# define set_normalized_timespec64 set_normalized_timespec
@@ -77,6 +94,24 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
return ret;
}

+static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64)
+{
+ struct itimerspec ret;
+
+ ret.it_interval = timespec64_to_timespec(its64->it_interval);
+ ret.it_value = timespec64_to_timespec(its64->it_value);
+ return ret;
+}
+
+static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its)
+{
+ struct itimerspec64 ret;
+
+ ret.it_interval = timespec_to_timespec64(its->it_interval);
+ ret.it_value = timespec_to_timespec64(its->it_value);
+ return ret;
+}
+
static inline int timespec64_equal(const struct timespec64 *a,
const struct timespec64 *b)
{
--
1.7.9.5

2015-07-15 05:55:21

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 2/6] timekeeping: Introduce current_kernel_time64()

The current_kernel_time() is not year 2038 safe on 32bit systems
since it returns a timespec value. Introduce current_kernel_time64()
which returns a timespec64 value.

Signed-off-by: Baolin Wang <[email protected]>
---
include/linux/timekeeping.h | 9 ++++++++-
kernel/time/timekeeping.c | 6 +++---
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 3aa72e6..657ea03 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -18,10 +18,17 @@ extern int do_sys_settimeofday(const struct timespec *tv,
* Kernel time accessors
*/
unsigned long get_seconds(void);
-struct timespec current_kernel_time(void);
+struct timespec64 current_kernel_time64(void);
/* does not take xtime_lock */
struct timespec __current_kernel_time(void);

+static inline struct timespec current_kernel_time(void)
+{
+ struct timespec64 now = current_kernel_time64();
+
+ return timespec64_to_timespec(now);
+}
+
/*
* timespec based interfaces
*/
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index bca3667..2d58742 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1874,7 +1874,7 @@ struct timespec __current_kernel_time(void)
return timespec64_to_timespec(tk_xtime(tk));
}

-struct timespec current_kernel_time(void)
+struct timespec64 current_kernel_time64(void)
{
struct timekeeper *tk = &tk_core.timekeeper;
struct timespec64 now;
@@ -1886,9 +1886,9 @@ struct timespec current_kernel_time(void)
now = tk_xtime(tk);
} while (read_seqcount_retry(&tk_core.seq, seq));

- return timespec64_to_timespec(now);
+ return now;
}
-EXPORT_SYMBOL(current_kernel_time);
+EXPORT_SYMBOL(current_kernel_time64);

struct timespec64 get_monotonic_coarse64(void)
{
--
1.7.9.5

2015-07-15 05:58:56

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 3/6] security: Introduce security_settime64()

security_settime() returns a timespec, which is not year 2038 safe
on 32bit systems. Thus this patch introduces the security_settime64()
function with timespec64 type.

We also convert the cap_settime() helper function to use the 64bit types.

Signed-off-by: Baolin Wang <[email protected]>
---
include/linux/lsm_hooks.h | 5 +++--
include/linux/security.h | 20 +++++++++++++++++---
security/commoncap.c | 2 +-
security/security.c | 2 +-
4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 9429f05..d791f35 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -1191,7 +1191,8 @@
* Return 0 if permission is granted.
* @settime:
* Check permission to change the system time.
- * struct timespec and timezone are defined in include/linux/time.h
+ * struct timespec64 is defined in include/linux/time64.h and timezone
+ * is defined in include/linux/time.h
* @ts contains new time
* @tz contains new timezone
* Return 0 if permission is granted.
@@ -1324,7 +1325,7 @@ union security_list_options {
int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
int (*quota_on)(struct dentry *dentry);
int (*syslog)(int type);
- int (*settime)(const struct timespec *ts, const struct timezone *tz);
+ int (*settime)(const struct timespec64 *ts, const struct timezone *tz);
int (*vm_enough_memory)(struct mm_struct *mm, long pages);

int (*bprm_set_creds)(struct linux_binprm *bprm);
diff --git a/include/linux/security.h b/include/linux/security.h
index 79d85dd..105fc27 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -69,7 +69,7 @@ struct timezone;
/* These functions are in security/commoncap.c */
extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
int cap, int audit);
-extern int cap_settime(const struct timespec *ts, const struct timezone *tz);
+extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz);
extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
extern int cap_ptrace_traceme(struct task_struct *parent);
extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
@@ -206,7 +206,13 @@ int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
int security_quotactl(int cmds, int type, int id, struct super_block *sb);
int security_quota_on(struct dentry *dentry);
int security_syslog(int type);
-int security_settime(const struct timespec *ts, const struct timezone *tz);
+int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
+static inline int security_settime(const struct timespec *ts, const struct timezone *tz)
+{
+ struct timespec64 ts64 = timespec_to_timespec64(*ts);
+
+ return security_settime64(&ts64, tz);
+}
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
int security_bprm_set_creds(struct linux_binprm *bprm);
int security_bprm_check(struct linux_binprm *bprm);
@@ -457,10 +463,18 @@ static inline int security_syslog(int type)
return 0;
}

+static inline int security_settime64(const struct timespec64 *ts,
+ const struct timezone *tz)
+{
+ return cap_settime(ts, tz);
+}
+
static inline int security_settime(const struct timespec *ts,
const struct timezone *tz)
{
- return cap_settime(ts, tz);
+ struct timespec64 ts64 = timespec_to_timespec64(*ts);
+
+ return cap_settime(&ts64, tz);
}

static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
diff --git a/security/commoncap.c b/security/commoncap.c
index d103f5a4..17b1f79 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -111,7 +111,7 @@ int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
* Determine whether the current process may set the system clock and timezone
* information, returning 0 if permission granted, -ve if denied.
*/
-int cap_settime(const struct timespec *ts, const struct timezone *tz)
+int cap_settime(const struct timespec64 *ts, const struct timezone *tz)
{
if (!capable(CAP_SYS_TIME))
return -EPERM;
diff --git a/security/security.c b/security/security.c
index 595fffa..8d0dbd6 100644
--- a/security/security.c
+++ b/security/security.c
@@ -213,7 +213,7 @@ int security_syslog(int type)
return call_int_hook(syslog, 0, type);
}

-int security_settime(const struct timespec *ts, const struct timezone *tz)
+int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
{
return call_int_hook(settime, 0, ts, tz);
}
--
1.7.9.5

2015-07-15 06:02:20

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 4/6] time: Introduce do_sys_settimeofday64()

The do_sys_settimeofday() function uses a timespec, which is not year
2038 safe on 32bit systems.

Thus this patch introduces do_sys_settimeofday64(), which allows us to
transition users of do_sys_settimeofday() to using 64bit time types.

Signed-off-by: Baolin Wang <[email protected]>
---
include/linux/timekeeping.h | 15 +++++++++++++--
kernel/time/time.c | 8 ++++----
2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 657ea03..dc60400 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -11,8 +11,19 @@ extern int timekeeping_suspended;
*/
extern void do_gettimeofday(struct timeval *tv);
extern int do_settimeofday64(const struct timespec64 *ts);
-extern int do_sys_settimeofday(const struct timespec *tv,
- const struct timezone *tz);
+extern int do_sys_settimeofday64(const struct timespec64 *tv,
+ const struct timezone *tz);
+static inline int do_sys_settimeofday(const struct timespec *tv,
+ const struct timezone *tz)
+{
+ struct timespec64 ts64;
+
+ if (!tv)
+ return -EINVAL;
+
+ ts64 = timespec_to_timespec64(*tv);
+ return do_sys_settimeofday64(&ts64, tz);
+}

/*
* Kernel time accessors
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 85d5bb1..5d00da4 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -160,15 +160,15 @@ static inline void warp_clock(void)
* various programs will get confused when the clock gets warped.
*/

-int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
+int do_sys_settimeofday64(const struct timespec64 *tv, const struct timezone *tz)
{
static int firsttime = 1;
int error = 0;

- if (tv && !timespec_valid(tv))
+ if (tv && !timespec64_valid(tv))
return -EINVAL;

- error = security_settime(tv, tz);
+ error = security_settime64(tv, tz);
if (error)
return error;

@@ -186,7 +186,7 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
}
}
if (tv)
- return do_settimeofday(tv);
+ return do_settimeofday64(tv);
return 0;
}

--
1.7.9.5

2015-07-15 06:05:23

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 5/6] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()

The conversion between struct timespec and jiffies is not year 2038
safe on 32bit systems. Introduce timespec64_to_jiffies() and
jiffies_to_timespec64() functions which use struct timespec64 to
make it ready for 2038 issue.

Signed-off-by: Baolin Wang <[email protected]>
---
include/linux/jiffies.h | 22 +++++++++++++++++++---
kernel/time/time.c | 20 +++++++++++++-------
2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 535fd3b..bf96d9f 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -416,9 +416,25 @@ static inline unsigned long usecs_to_jiffies(const unsigned int u)
}
}

-extern unsigned long timespec_to_jiffies(const struct timespec *value);
-extern void jiffies_to_timespec(const unsigned long jiffies,
- struct timespec *value);
+extern unsigned long timespec64_to_jiffies(const struct timespec64 *value);
+extern void jiffies_to_timespec64(const unsigned long jiffies,
+ struct timespec64 *value);
+static inline unsigned long timespec_to_jiffies(const struct timespec *value)
+{
+ struct timespec64 ts = timespec_to_timespec64(*value);
+
+ return timespec64_to_jiffies(&ts);
+}
+
+static inline void jiffies_to_timespec(const unsigned long jiffies,
+ struct timespec *value)
+{
+ struct timespec64 ts;
+
+ jiffies_to_timespec64(jiffies, &ts);
+ *value = timespec64_to_timespec(ts);
+}
+
extern unsigned long timeval_to_jiffies(const struct timeval *value);
extern void jiffies_to_timeval(const unsigned long jiffies,
struct timeval *value);
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 5d00da4..6692f5a 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -546,7 +546,7 @@ EXPORT_SYMBOL(__usecs_to_jiffies);
* value to a scaled second value.
*/
static unsigned long
-__timespec_to_jiffies(unsigned long sec, long nsec)
+__timespec64_to_jiffies(u64 sec, long nsec)
{
nsec = nsec + TICK_NSEC - 1;

@@ -554,22 +554,28 @@ __timespec_to_jiffies(unsigned long sec, long nsec)
sec = MAX_SEC_IN_JIFFIES;
nsec = 0;
}
- return (((u64)sec * SEC_CONVERSION) +
+ return ((sec * SEC_CONVERSION) +
(((u64)nsec * NSEC_CONVERSION) >>
(NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;

}

+static unsigned long
+__timespec_to_jiffies(unsigned long sec, long nsec)
+{
+ return __timespec64_to_jiffies((u64)sec, nsec);
+}
+
unsigned long
-timespec_to_jiffies(const struct timespec *value)
+timespec64_to_jiffies(const struct timespec64 *value)
{
- return __timespec_to_jiffies(value->tv_sec, value->tv_nsec);
+ return __timespec64_to_jiffies(value->tv_sec, value->tv_nsec);
}

-EXPORT_SYMBOL(timespec_to_jiffies);
+EXPORT_SYMBOL(timespec64_to_jiffies);

void
-jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
+jiffies_to_timespec64(const unsigned long jiffies, struct timespec64 *value)
{
/*
* Convert jiffies to nanoseconds and separate with
@@ -580,7 +586,7 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
NSEC_PER_SEC, &rem);
value->tv_nsec = rem;
}
-EXPORT_SYMBOL(jiffies_to_timespec);
+EXPORT_SYMBOL(jiffies_to_timespec64);

/*
* We could use a similar algorithm to timespec_to_jiffies (with a
--
1.7.9.5

2015-07-15 06:08:40

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

The cputime_to_timespec() and timespec_to_cputime() functions are
not year 2038 safe on 32bit systems due to that the struct timepsec
will overflow in 2038 year. This patch introduces cputime_to_timespec64()
and timespec64_to_cputime() functions which use struct timespec64.
And converts arch specific implementations in arch/s390 and arch/powerpc.

Signed-off-by: Baolin Wang <[email protected]>
---
arch/powerpc/include/asm/cputime.h | 6 +++---
arch/s390/include/asm/cputime.h | 8 ++++----
include/asm-generic/cputime_jiffies.h | 10 +++++-----
include/asm-generic/cputime_nsecs.h | 6 +++---
include/linux/cputime.h | 16 ++++++++++++++++
5 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index e245255..5dda5c0 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -154,9 +154,9 @@ static inline cputime_t secs_to_cputime(const unsigned long sec)
}

/*
- * Convert cputime <-> timespec
+ * Convert cputime <-> timespec64
*/
-static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
+static inline void cputime_to_timespec64(const cputime_t ct, struct timespec64 *p)
{
u64 x = (__force u64) ct;
unsigned int frac;
@@ -168,7 +168,7 @@ static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
p->tv_nsec = x;
}

-static inline cputime_t timespec_to_cputime(const struct timespec *p)
+static inline cputime_t timespec64_to_cputime(const struct timespec64 *p)
{
u64 ct;

diff --git a/arch/s390/include/asm/cputime.h b/arch/s390/include/asm/cputime.h
index 221b454..3319b51 100644
--- a/arch/s390/include/asm/cputime.h
+++ b/arch/s390/include/asm/cputime.h
@@ -81,16 +81,16 @@ static inline cputime_t secs_to_cputime(const unsigned int s)
}

/*
- * Convert cputime to timespec and back.
+ * Convert cputime to timespec64 and back.
*/
-static inline cputime_t timespec_to_cputime(const struct timespec *value)
+static inline cputime_t timespec64_to_cputime(const struct timespec64 *value)
{
unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
return (__force cputime_t)(ret + __div(value->tv_nsec * CPUTIME_PER_USEC, NSEC_PER_USEC));
}

-static inline void cputime_to_timespec(const cputime_t cputime,
- struct timespec *value)
+static inline void cputime_to_timespec64(const cputime_t cputime,
+ struct timespec64 *value)
{
unsigned long long __cputime = (__force unsigned long long) cputime;
value->tv_nsec = (__cputime % CPUTIME_PER_SEC) * NSEC_PER_USEC / CPUTIME_PER_USEC;
diff --git a/include/asm-generic/cputime_jiffies.h b/include/asm-generic/cputime_jiffies.h
index fe386fc..54e034c 100644
--- a/include/asm-generic/cputime_jiffies.h
+++ b/include/asm-generic/cputime_jiffies.h
@@ -44,12 +44,12 @@ typedef u64 __nocast cputime64_t;
#define secs_to_cputime(sec) jiffies_to_cputime((sec) * HZ)

/*
- * Convert cputime to timespec and back.
+ * Convert cputime to timespec64 and back.
*/
-#define timespec_to_cputime(__val) \
- jiffies_to_cputime(timespec_to_jiffies(__val))
-#define cputime_to_timespec(__ct,__val) \
- jiffies_to_timespec(cputime_to_jiffies(__ct),__val)
+#define timespec64_to_cputime(__val) \
+ jiffies_to_cputime(timespec64_to_jiffies(__val))
+#define cputime_to_timespec64(__ct,__val) \
+ jiffies_to_timespec64(cputime_to_jiffies(__ct),__val)

/*
* Convert cputime to timeval and back.
diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
index 0419485..c0cafc0 100644
--- a/include/asm-generic/cputime_nsecs.h
+++ b/include/asm-generic/cputime_nsecs.h
@@ -71,14 +71,14 @@ typedef u64 __nocast cputime64_t;
(__force cputime_t)((__secs) * NSEC_PER_SEC)

/*
- * Convert cputime <-> timespec (nsec)
+ * Convert cputime <-> timespec64 (nsec)
*/
-static inline cputime_t timespec_to_cputime(const struct timespec *val)
+static inline cputime_t timespec64_to_cputime(const struct timespec64 *val)
{
u64 ret = val->tv_sec * NSEC_PER_SEC + val->tv_nsec;
return (__force cputime_t) ret;
}
-static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val)
+static inline void cputime_to_timespec64(const cputime_t ct, struct timespec64 *val)
{
u32 rem;

diff --git a/include/linux/cputime.h b/include/linux/cputime.h
index f2eb2ee..cd638a0 100644
--- a/include/linux/cputime.h
+++ b/include/linux/cputime.h
@@ -13,4 +13,20 @@
usecs_to_cputime((__nsecs) / NSEC_PER_USEC)
#endif

+static inline cputime_t timespec_to_cputime(const struct timespec *ts)
+{
+ struct timespec64 ts64 = timespec_to_timespec64(*ts);
+
+ return timespec64_to_cputime(&ts64);
+}
+
+static inline void cputime_to_timespec(const cputime_t cputime,
+ struct timespec *value)
+{
+ struct timespec64 ts64;
+
+ cputime_to_timespec64(cputime, &ts64);
+ *value = timespec64_to_timespec(ts64);
+}
+
#endif /* __LINUX_CPUTIME_H */
--
1.7.9.5

2015-07-15 10:24:34

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 3/6] security: Introduce security_settime64()

On Wed, 15 Jul 2015, Baolin Wang wrote:

> security_settime() returns a timespec, which is not year 2038 safe

It returns int, which is year 2038 safe on all systems. Copy and paste
is great, right?

> -int security_settime(const struct timespec *ts, const struct timezone *tz);
> +int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
> +static inline int security_settime(const struct timespec *ts, const struct timezone *tz)
> +{
> + struct timespec64 ts64 = timespec_to_timespec64(*ts);
> +
> + return security_settime64(&ts64, tz);
> +}

What's the point of this inline? Explanation is missing in
changelog.

Also this wants follow up patches which fix the call sites and remove
that inline helper again.

> -int cap_settime(const struct timespec *ts, const struct timezone *tz)
> +int cap_settime(const struct timespec64 *ts, const struct timezone *tz)

Changelog is missing that none of the existing hooks is using the ts
argument and therefor the patch is not doing any functional changes.

Thanks,

tglx

2015-07-15 10:32:07

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

On Wed, 15 Jul 2015, Baolin Wang wrote:

> The cputime_to_timespec() and timespec_to_cputime() functions are
> not year 2038 safe on 32bit systems due to that the struct timepsec
> will overflow in 2038 year.

And how is this relevant? cputime is not based on wall clock time at
all. So what has 2038 to do with cputime?

We want proper explanations WHY we need such a change.

Thanks,

tglx

2015-07-15 11:34:48

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH 3/6] security: Introduce security_settime64()

On 15 July 2015 at 18:24, Thomas Gleixner <[email protected]> wrote:
> On Wed, 15 Jul 2015, Baolin Wang wrote:
>
>> security_settime() returns a timespec, which is not year 2038 safe
>
> It returns int, which is year 2038 safe on all systems. Copy and paste
> is great, right?
>

Sorry, will fix that.

>> -int security_settime(const struct timespec *ts, const struct timezone *tz);
>> +int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
>> +static inline int security_settime(const struct timespec *ts, const struct timezone *tz)
>> +{
>> + struct timespec64 ts64 = timespec_to_timespec64(*ts);
>> +
>> + return security_settime64(&ts64, tz);
>> +}
>
> What's the point of this inline? Explanation is missing in
> changelog.
>
> Also this wants follow up patches which fix the call sites and remove
> that inline helper again.
>

Yes, I'll add this explanation in changelog.

>> -int cap_settime(const struct timespec *ts, const struct timezone *tz)
>> +int cap_settime(const struct timespec64 *ts, const struct timezone *tz)
>
> Changelog is missing that none of the existing hooks is using the ts
> argument and therefor the patch is not doing any functional changes.
>

OK, will add these explanation. Thanks for your comments.

> Thanks,
>
> tglx



--
Baolin.wang
Best Regards

2015-07-15 11:42:28

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

On 15 July 2015 at 18:31, Thomas Gleixner <[email protected]> wrote:
> On Wed, 15 Jul 2015, Baolin Wang wrote:
>
>> The cputime_to_timespec() and timespec_to_cputime() functions are
>> not year 2038 safe on 32bit systems due to that the struct timepsec
>> will overflow in 2038 year.
>
> And how is this relevant? cputime is not based on wall clock time at
> all. So what has 2038 to do with cputime?
>
> We want proper explanations WHY we need such a change.

When converting the posix-cpu-timers, it call the
cputime_to_timespec() function. Thus it need a conversion for this
function.
You can see that conversion in patch "posix-cpu-timers: Convert to
y2038 safe callbacks" from
https://git.linaro.org/people/baolin.wang/upstream_0627.git.
And I also will explain this in the changelog. Thanks for your comments.

>
> Thanks,
>
> tglx
>
>


--
Baolin.wang
Best Regards

2015-07-15 11:56:33

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

On Wed, 15 Jul 2015, Baolin Wang wrote:

> On 15 July 2015 at 18:31, Thomas Gleixner <[email protected]> wrote:
> > On Wed, 15 Jul 2015, Baolin Wang wrote:
> >
> >> The cputime_to_timespec() and timespec_to_cputime() functions are
> >> not year 2038 safe on 32bit systems due to that the struct timepsec
> >> will overflow in 2038 year.
> >
> > And how is this relevant? cputime is not based on wall clock time at
> > all. So what has 2038 to do with cputime?
> >
> > We want proper explanations WHY we need such a change.
>
> When converting the posix-cpu-timers, it call the
> cputime_to_timespec() function. Thus it need a conversion for this
> function.

There is no requirement to convert posix-cpu-timers on their own. We
need to adopt the posix cpu timers code because it shares syscalls
with the other posix timers, but that still does not explain why we
need these functions.

> You can see that conversion in patch "posix-cpu-timers: Convert to
> y2038 safe callbacks" from
> https://git.linaro.org/people/baolin.wang/upstream_0627.git.

I do not care about your random git tree. I care about proper
changelogs. Your changelogs are just a copied boilerplate full of
errors.

Thanks,

tglx

2015-07-16 02:22:48

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

On 15 July 2015 at 19:55, Thomas Gleixner <[email protected]> wrote:
> On Wed, 15 Jul 2015, Baolin Wang wrote:
>
>> On 15 July 2015 at 18:31, Thomas Gleixner <[email protected]> wrote:
>> > On Wed, 15 Jul 2015, Baolin Wang wrote:
>> >
>> >> The cputime_to_timespec() and timespec_to_cputime() functions are
>> >> not year 2038 safe on 32bit systems due to that the struct timepsec
>> >> will overflow in 2038 year.
>> >
>> > And how is this relevant? cputime is not based on wall clock time at
>> > all. So what has 2038 to do with cputime?
>> >
>> > We want proper explanations WHY we need such a change.
>>
>> When converting the posix-cpu-timers, it call the
>> cputime_to_timespec() function. Thus it need a conversion for this
>> function.
>
> There is no requirement to convert posix-cpu-timers on their own. We
> need to adopt the posix cpu timers code because it shares syscalls
> with the other posix timers, but that still does not explain why we
> need these functions.
>

In posix-cpu-timers, it also defined some 'k_clock struct' variables,
and we need to convert the callbacks of the 'k_clock struct' which are
not year 2038 safe on 32bit systems. Some callbacks which need to
convert call the cputime_to_timespec() function, thus we also want to
convert the cputime_to_timespec() function to a year 2038 safe
function to make all them ready for the year 2038 issue.

>> You can see that conversion in patch "posix-cpu-timers: Convert to
>> y2038 safe callbacks" from
>> https://git.linaro.org/people/baolin.wang/upstream_0627.git.
>
> I do not care about your random git tree. I care about proper
> changelogs. Your changelogs are just a copied boilerplate full of
> errors.
>
> Thanks,
>
> tglx



--
Baolin.wang
Best Regards

2015-07-16 10:45:04

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

On Thu, 16 Jul 2015, Baolin Wang wrote:
> On 15 July 2015 at 19:55, Thomas Gleixner <[email protected]> wrote:
> > On Wed, 15 Jul 2015, Baolin Wang wrote:
> >
> >> On 15 July 2015 at 18:31, Thomas Gleixner <[email protected]> wrote:
> >> > On Wed, 15 Jul 2015, Baolin Wang wrote:
> >> >
> >> >> The cputime_to_timespec() and timespec_to_cputime() functions are
> >> >> not year 2038 safe on 32bit systems due to that the struct timepsec
> >> >> will overflow in 2038 year.
> >> >
> >> > And how is this relevant? cputime is not based on wall clock time at
> >> > all. So what has 2038 to do with cputime?
> >> >
> >> > We want proper explanations WHY we need such a change.
> >>
> >> When converting the posix-cpu-timers, it call the
> >> cputime_to_timespec() function. Thus it need a conversion for this
> >> function.
> >
> > There is no requirement to convert posix-cpu-timers on their own. We
> > need to adopt the posix cpu timers code because it shares syscalls
> > with the other posix timers, but that still does not explain why we
> > need these functions.
> >
>
> In posix-cpu-timers, it also defined some 'k_clock struct' variables,
> and we need to convert the callbacks of the 'k_clock struct' which are
> not year 2038 safe on 32bit systems. Some callbacks which need to
> convert call the cputime_to_timespec() function, thus we also want to
> convert the cputime_to_timespec() function to a year 2038 safe
> function to make all them ready for the year 2038 issue.

You are not getting it at all.

1) We need to change k_clock callbacks due to 2038 issues

2) posix cpu timers implement affected callbacks

3) posix cpu timers themself and cputime are NOT affected by 2038

So we have 2 options to change the code in posix cpu timers:

A) Do the timespec/timespec64 conversion in the posix cpu timer
callbacks and leave the cputime functions untouched.

B) Implement cputime/timespec64 functions to avoid #A

If you go for #B, you need to provide a reasonable explanation why
it is better than #A. And that explanation has absolutely nothing
to do with 2038 safety.

Not everything is a 2038 issue, just because the only tool you have is
a timespec64.

Thanks,

tglx


2015-07-17 08:39:38

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()

On 16 July 2015 at 18:43, Thomas Gleixner <[email protected]> wrote:
> On Thu, 16 Jul 2015, Baolin Wang wrote:
>> On 15 July 2015 at 19:55, Thomas Gleixner <[email protected]> wrote:
>> > On Wed, 15 Jul 2015, Baolin Wang wrote:
>> >
>> >> On 15 July 2015 at 18:31, Thomas Gleixner <[email protected]> wrote:
>> >> > On Wed, 15 Jul 2015, Baolin Wang wrote:
>> >> >
>> >> >> The cputime_to_timespec() and timespec_to_cputime() functions are
>> >> >> not year 2038 safe on 32bit systems due to that the struct timepsec
>> >> >> will overflow in 2038 year.
>> >> >
>> >> > And how is this relevant? cputime is not based on wall clock time at
>> >> > all. So what has 2038 to do with cputime?
>> >> >
>> >> > We want proper explanations WHY we need such a change.
>> >>
>> >> When converting the posix-cpu-timers, it call the
>> >> cputime_to_timespec() function. Thus it need a conversion for this
>> >> function.
>> >
>> > There is no requirement to convert posix-cpu-timers on their own. We
>> > need to adopt the posix cpu timers code because it shares syscalls
>> > with the other posix timers, but that still does not explain why we
>> > need these functions.
>> >
>>
>> In posix-cpu-timers, it also defined some 'k_clock struct' variables,
>> and we need to convert the callbacks of the 'k_clock struct' which are
>> not year 2038 safe on 32bit systems. Some callbacks which need to
>> convert call the cputime_to_timespec() function, thus we also want to
>> convert the cputime_to_timespec() function to a year 2038 safe
>> function to make all them ready for the year 2038 issue.
>
> You are not getting it at all.
>
> 1) We need to change k_clock callbacks due to 2038 issues
>
> 2) posix cpu timers implement affected callbacks
>
> 3) posix cpu timers themself and cputime are NOT affected by 2038
>
> So we have 2 options to change the code in posix cpu timers:
>
> A) Do the timespec/timespec64 conversion in the posix cpu timer
> callbacks and leave the cputime functions untouched.
>
> B) Implement cputime/timespec64 functions to avoid #A
>
> If you go for #B, you need to provide a reasonable explanation why
> it is better than #A. And that explanation has absolutely nothing
> to do with 2038 safety.

Very thanks for your explanation, and I'll think about that.

>
> Not everything is a 2038 issue, just because the only tool you have is
> a timespec64.
>
> Thanks,
>
> tglx
>
>
>



--
Baolin.wang
Best Regards