[Y2038] [PATCH] fs: cifs: Replace CURRENT_TIME by get_seconds

2016-10-01 Thread Deepa Dinamani
This is in preparation for the change that transitions
filesystem timestamps to use 64 bit time and hence make
them y2038 safe.

CURRENT_TIME macro will be deleted before merging the
aforementioned patch.

Filesystems will use current_time() instead of
CURRENT_TIME.
Use ktime_get_real_seconds() here as this is not filesystem
time.
Only the seconds portion of the timestamp is necessary for
timezone calculation using server time.

Assume that the difference between server and client times
lie in the range INT_MIN..INT_MAX. This is valid because
this is the difference between current times between server
and client, and the largest timezone difference is in the
range of one day.

All cifs timestamps currently use timespec internally.
This timestamp can also be transitioned into using
timespec64 when all other timestamps for cifs is transitioned
to use timespec64.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
Cc: Steve French <sfre...@samba.org>
---
 fs/cifs/cifssmb.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index d47197e..6c666a3 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -478,14 +478,14 @@ decode_lanman_negprot_rsp(struct TCP_Server_Info *server, 
NEGOTIATE_RSP *pSMBr)
 * this requirement.
 */
int val, seconds, remain, result;
-   struct timespec ts, utc;
-   utc = CURRENT_TIME;
+   struct timespec ts;
+   unsigned long utc = ktime_get_real_seconds();
ts = cnvrtDosUnixTm(rsp->SrvTime.Date,
rsp->SrvTime.Time, 0);
cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n",
-(int)ts.tv_sec, (int)utc.tv_sec,
-(int)(utc.tv_sec - ts.tv_sec));
-   val = (int)(utc.tv_sec - ts.tv_sec);
+(int)ts.tv_sec, (int)utc,
+(int)(utc - ts.tv_sec));
+   val = (int)(utc - ts.tv_sec);
seconds = abs(val);
result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ;
remain = seconds % MIN_TZ_ADJ;
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] fs: ufs: Use ktime_get_real_ts64() for birthtime

2016-10-01 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
Replace it with ktime_get_real_ts64().
Inode time formats are already 64 bit long and
accommodates time64_t.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: Evgeniy Dushistov <dushis...@mail.ru>
---
 fs/ufs/ialloc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index fd0203c..876a478 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -176,6 +176,7 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
struct ufs_cg_private_info * ucpi;
struct ufs_cylinder_group * ucg;
struct inode * inode;
+   struct timespec64 ts;
unsigned cg, bit, i, j, start;
struct ufs_inode_info *ufsi;
int err = -ENOSPC;
@@ -323,8 +324,9 @@ cg_found:
lock_buffer(bh);
ufs2_inode = (struct ufs2_inode *)bh->b_data;
ufs2_inode += ufs_inotofsbo(inode->i_ino);
-   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, CURRENT_TIME.tv_sec);
-   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, 
CURRENT_TIME.tv_nsec);
+   ktime_get_real_ts64();
+   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, ts.tv_sec);
+   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, ts.tv_nsec);
mark_buffer_dirty(bh);
unlock_buffer(bh);
if (sb->s_flags & MS_SYNCHRONOUS)
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] fs: ocfs2: Replace CURRENT_TIME macro

2016-10-01 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.

Use y2038 safe ktime_get_real_seconds() here for timestamps.
struct heartbeat_block's hb_seq and deletetion time are already
64 bits wide and accommodate times beyond y2038.

Also use y2038 safe ktime_get_real_ts64() for on disk inode
timestamps.
These are also wide enough to accommodate time64_t.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
Cc: Joel Becker <jl...@evilplan.org>
Cc: ocfs2-de...@oss.oracle.com
---
 fs/ocfs2/cluster/heartbeat.c | 2 +-
 fs/ocfs2/inode.c | 2 +-
 fs/ocfs2/namei.c | 6 --
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 636abcb..9158c98 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -741,7 +741,7 @@ static inline void o2hb_prepare_block(struct o2hb_region 
*reg,
hb_block = (struct o2hb_disk_heartbeat_block *)slot->ds_raw_block;
memset(hb_block, 0, reg->hr_block_bytes);
/* TODO: time stuff */
-   cputime = CURRENT_TIME.tv_sec;
+   cputime = ktime_get_real_seconds();
if (!cputime)
cputime = 1;
 
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index c56a767..382401d 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -703,7 +703,7 @@ static int ocfs2_remove_inode(struct inode *inode,
goto bail_commit;
}
 
-   di->i_dtime = cpu_to_le64(CURRENT_TIME.tv_sec);
+   di->i_dtime = cpu_to_le64(ktime_get_real_seconds());
di->i_flags &= cpu_to_le32(~(OCFS2_VALID_FL | OCFS2_ORPHANED_FL));
ocfs2_journal_dirty(handle, di_bh);
 
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index a8f1225..e96ed24 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -516,6 +516,7 @@ static int __ocfs2_mknod_locked(struct inode *dir,
struct ocfs2_extent_list *fel;
u16 feat;
struct ocfs2_inode_info *oi = OCFS2_I(inode);
+   struct timespec64 ts;
 
*new_fe_bh = NULL;
 
@@ -564,10 +565,11 @@ static int __ocfs2_mknod_locked(struct inode *dir,
fe->i_last_eb_blk = 0;
strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
fe->i_flags |= cpu_to_le32(OCFS2_VALID_FL);
+   ktime_get_real_ts64();
fe->i_atime = fe->i_ctime = fe->i_mtime =
-   cpu_to_le64(CURRENT_TIME.tv_sec);
+   cpu_to_le64(ts.tv_sec);
fe->i_mtime_nsec = fe->i_ctime_nsec = fe->i_atime_nsec =
-   cpu_to_le32(CURRENT_TIME.tv_nsec);
+   cpu_to_le32(ts.tv_nsec);
fe->i_dtime = 0;
 
/*
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] audit: Use timespec64 to represent audit timestamps

2016-10-01 Thread Deepa Dinamani
struct timespec is not y2038 safe.
Audit timestamps are recorded in string format into
an audit buffer for a given context.
These mark the entry timestamps for the syscalls.
Use y2038 safe struct timespec64 to represent the times.
The log strings can handle this transition as strings can
hold upto 1024 characters.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Paul Moore <p...@paul-moore.com>
Acked-by: Richard Guy Briggs <r...@redhat.com>
Cc: Eric Paris <epa...@redhat.com>
Cc: Paul Moore <p...@paul-moore.com>
Cc: Richard Guy Briggs <r...@redhat.com>
Cc: linux-au...@redhat.com
---
 include/linux/audit.h |  4 ++--
 kernel/audit.c| 10 +-
 kernel/audit.h|  2 +-
 kernel/auditsc.c  |  6 +++---
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 9d4443f..e51782b 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -332,7 +332,7 @@ static inline void audit_ptrace(struct task_struct *t)
/* Private API (for audit.c only) */
 extern unsigned int audit_serial(void);
 extern int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial);
+ struct timespec64 *t, unsigned int *serial);
 extern int audit_set_loginuid(kuid_t loginuid);
 
 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
@@ -490,7 +490,7 @@ static inline void __audit_seccomp(unsigned long syscall, 
long signr, int code)
 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
 { }
 static inline int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial)
+ struct timespec64 *t, unsigned int *serial)
 {
return 0;
 }
diff --git a/kernel/audit.c b/kernel/audit.c
index a8a91bd..b03b6c7 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -1325,10 +1325,10 @@ unsigned int audit_serial(void)
 }
 
 static inline void audit_get_stamp(struct audit_context *ctx,
-  struct timespec *t, unsigned int *serial)
+  struct timespec64 *t, unsigned int *serial)
 {
if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
-   *t = CURRENT_TIME;
+   ktime_get_real_ts64(t);
*serial = audit_serial();
}
 }
@@ -1370,7 +1370,7 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
 int type)
 {
struct audit_buffer *ab = NULL;
-   struct timespec t;
+   struct timespec64   t;
unsigned intuninitialized_var(serial);
int reserve = 5; /* Allow atomic callers to go up to five
entries over the normal backlog limit */
@@ -1422,8 +1422,8 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
 
audit_get_stamp(ab->ctx, , );
 
-   audit_log_format(ab, "audit(%lu.%03lu:%u): ",
-t.tv_sec, t.tv_nsec/100, serial);
+   audit_log_format(ab, "audit(%llu.%03lu:%u): ",
+(unsigned long long)t.tv_sec, t.tv_nsec/100, 
serial);
return ab;
 }
 
diff --git a/kernel/audit.h b/kernel/audit.h
index 431444c..55d1ca2 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -112,7 +112,7 @@ struct audit_context {
enum audit_statestate, current_state;
unsigned intserial; /* serial number for record */
int major;  /* syscall number */
-   struct timespec ctime;  /* time of syscall entry */
+   struct timespec64   ctime;  /* time of syscall entry */
unsigned long   argv[4];/* syscall arguments */
longreturn_code;/* syscall return code */
u64 prio;
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 5abf1dc..8dc7fe9 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1522,7 +1522,7 @@ void __audit_syscall_entry(int major, unsigned long a1, 
unsigned long a2,
return;
 
context->serial = 0;
-   context->ctime  = CURRENT_TIME;
+   ktime_get_real_ts64(>ctime);
context->in_syscall = 1;
context->current_state  = state;
context->ppid   = 0;
@@ -1931,13 +1931,13 @@ EXPORT_SYMBOL_GPL(__audit_inode_child);
 /**
  * auditsc_get_stamp - get local copies of audit_context values
  * @ctx: audit_context for the task
- * @t: timespec to store time recorded in the audit_context
+ * @t: timespec64 to store time recorded in the audit_context
  * @serial: serial value that is recorded in the audit_context
  *
  * Also sets the context as auditable.
  */
 int 

Re: [Y2038] [PATCH v2 3/4] input: Deprecate real timestamps beyond year 2106

2016-10-27 Thread Deepa Dinamani
>> struct timeval is not y2038 safe.
>> All usage of timeval in the kernel will be replaced by
>> y2038 safe structures.
>>
>> struct input_event maintains time for each input event.
>> Real time timestamps are not ideal for input as this
>> time can go backwards as noted in the patch a80b83b7b8
>> by John Stultz. Hence, having the input_event.time fields
>> only big enough for monotonic and boot times are
>> sufficient.
>>
>> Leave the original input_event as is. This is to maintain
>> backward compatibility with existing userspace interfaces
>> that use input_event.
>> Introduce a new replacement struct raw_input_event.
>> This replaces timeval with struct input_timeval. This structure
>> maintains time in __kernel_ulong_t or compat_ulong_t to allow
>> for architectures to override types as in the case of x32.
>>
>> The change requires any userspace utilities reading or writing
>> from event nodes to update their reading format to match
>> raw_input_event. The changes to the popular libraries will be
>> posted along with the kernel changes.
>> The driver version is also updated to reflect the change in
>> event format.
>
> If users are forced to update to adapt to the new event format, should
> we consider more radical changes? For example, does it make sense to
> send timestamp on every event? Maybe we should only send it once per
> event packet (between EV_SYN/SYN_REPORT)? What granularity do we need?
> Is there anything else in current protocol that we'd like to change?

I did see the thread with Pingbo's patches where you had a similar comment.

I see my series as decoupling the kernel input event format from the
userspace format.
The formats also are really the same still.
Could this be considered the first step towards changing the protocol?

The protocol changes might need new interfaces to be defined between libraries.
And, could end up being a substantial change.
Would a step by step approach make sense?

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2 3/4] input: Deprecate real timestamps beyond year 2106

2016-10-27 Thread Deepa Dinamani
On Wed, Oct 26, 2016 at 7:56 PM, Peter Hutterer
<peter.hutte...@who-t.net> wrote:
> On Mon, Oct 17, 2016 at 08:27:32PM -0700, Deepa Dinamani wrote:
>> struct timeval is not y2038 safe.
>> All usage of timeval in the kernel will be replaced by
>> y2038 safe structures.
>>
>> struct input_event maintains time for each input event.
>> Real time timestamps are not ideal for input as this
>> time can go backwards as noted in the patch a80b83b7b8
>> by John Stultz. Hence, having the input_event.time fields
>> only big enough for monotonic and boot times are
>> sufficient.
>>
>> Leave the original input_event as is. This is to maintain
>> backward compatibility with existing userspace interfaces
>> that use input_event.
>> Introduce a new replacement struct raw_input_event.
>
> general comment here - please don't name it "raw_input_event".
> First, when you grep for input_event you want the new ones to show up too,
> so a struct input_event_raw would be better here. That also has better
> namespacing in general. Second though: the event isn't any more "raw" than
> the previous we had.
>
> I can't think of anything better than struct input_event_v2 though.

The general idea was to leave the original struct input_event as a
common interface for userspace (as it cannot be deleted).
So reading raw data unformatted by the userspace will have the new
struct raw_input_event format.
This was the reason for the "raw" in the name.

struct input_event_v2 is fine too, if this is more preferred.

>> This replaces timeval with struct input_timeval. This structure
>> maintains time in __kernel_ulong_t or compat_ulong_t to allow
>> for architectures to override types as in the case of x32.
>>
>> The change requires any userspace utilities reading or writing
>> from event nodes to update their reading format to match
>> raw_input_event. The changes to the popular libraries will be
>> posted along with the kernel changes.
>> The driver version is also updated to reflect the change in
>> event format.
>
> Doesn't this break *all* of userspace then? I don't see anything to
> negotiate the type of input event the kernel gives me. And nothing right now
> checks for EVDEV_VERSION, so they all just assume it's a struct
> input_event. Best case, if the available events aren't a multiple of
> sizeof(struct input_event) userspace will bomb out, but unless that happens,
> everyone will just happily read old-style events.
>
> So we need some negotiation what is acceptable. Which also needs to address
> the race conditions we're going to get when events start coming in before
> the client has announced that it supports the new-style events.

No, this does not break any userspace right now.
Both struct input_event and struct raw_input_event are exactly the same today.
This will be the case until a 2038-safe glibc is used with a 64 bit time_t flag.

So these are the scenarios:
1. old kernel driver + new userspace
  -- should still be ok until 2038. Version checks could help discover these
2. new kernel driver + old userspace (without recompiled with new 2038 gblic)
  -- works because the format is really the same.

The patch I posted to libevdev checks this driver version.
And, hence any library that results in a call to libevdev_set_fd()
will fail if it is not this updated driver.
We could just do a similar check in every library also.
I think the latter would be better.

So, the kernel patches can go in as a no-op right now and then I can
add version checks to respective user space libraries.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2 3/4] input: Deprecate real timestamps beyond year 2106

2016-10-28 Thread Deepa Dinamani
On Fri, Oct 28, 2016 at 5:43 AM, Arnd Bergmann <a...@arndb.de> wrote:
> On Monday, October 17, 2016 8:27:32 PM CEST Deepa Dinamani wrote:
>> @@ -55,24 +60,24 @@ struct ff_effect_compat {
>>
>>  static inline size_t input_event_size(void)
>>  {
>> -   return (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) ?
>> -   sizeof(struct input_event_compat) : sizeof(struct 
>> input_event);
>> +   return in_compat_syscall() ? sizeof(struct raw_input_event_compat) :
>> +sizeof(struct raw_input_event);
>>  }
>
> I think the COMPAT_USE_64BIT_TIME check has to stay here,
> it's needed for x32 mode on x86-64.

There is no time_t anymore in the raw_input_event structure.
The struct uses __kernel_ulong_t type.
This should take care of x32 support.

From this cover letter:
https://www.spinics.net/lists/linux-arch/msg16356.html

I see that that the __kernel types were introduced to address the ABI
issues for x32.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2 3/4] input: Deprecate real timestamps beyond year 2106

2016-10-29 Thread Deepa Dinamani
> btw, where did you post the libevdev patch? I haven't seen it anywhere I'm
> subscribed to.

The libevdev patch was posted to input-to...@lists.freedesktop.org :
https://www.mail-archive.com/y2038@lists.linaro.org/msg01824.html


-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2 3/4] input: Deprecate real timestamps beyond year 2106

2016-10-29 Thread Deepa Dinamani
> I think we should do those two things completely independently.
> We need to do something now to preserve the current interfaces
> for the glibc changes that are coming soon [1], and Deepa's
> patches do that (though I now realize the changelog doesn't
> mention the requirement).

I'll update the changelog in the next version of the series along with
the task check for x32 mode.

> An overhaul of the input_event handling with a new modern
> but incompatible format may or may not be a good idea, but
> this should be decided independently.

Just to clarify, we are going with the plan that Arnd suggested:
leaving the overhaul of the input event protocol alone and proceeding
with the series according to suggested changes.
Are we in agreement over this?

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [RFC 0/6] vfs: Add timestamp range check support

2016-11-06 Thread Deepa Dinamani
On Sun, Nov 6, 2016 at 12:28 PM, Arnd Bergmann <a...@arndb.de> wrote:
> On Sunday, November 6, 2016 9:44:33 AM CET Deepa Dinamani wrote:
>> I will post xfs tests that validate mount and range checking.
>> I will keep the policy same as what the RFC suggests for now.
>>
>> Clamping can be verified once vfs is transitioned to using time64_t.
>
> Won't it already work as expected on 64-bit architectures as they
> have a 64-bit time_t?

Yes, on 64 bit architectures, it should work fine.
32 bit machines will have wrong clamped timestamps though for some filesystems.

I can post a test for clamping that only works on 64 bit machines.

Thanks,
-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] Update libinput to support evdev driver v1.2

2016-10-19 Thread Deepa Dinamani
Update input event structures read from the kernel to match
the 1.2 version of the driver.

There are no changes to the exposed interfaces of libinput.

Note that the patch goes along with the changes to libevdev
and mtdev to support the updated kernel driver.

The associated kernel driver change is proposed at
https://lkml.org/lkml/2016/10/17/1146 .

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 include/linux/input.h | 49 +++--
 src/evdev.c   |  4 ++--
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/include/linux/input.h b/include/linux/input.h
index 4bf3d6d..202798a 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -13,10 +13,29 @@
 #include 
 #include 
 
-/*
- * The event structure itself
+/* The time structure for y2038 safe raw_input_event.
+ * The fields use unsigned types to extend times until
+ * year 2106 rather than 2038.
  */
+struct input_timeval {
+   __kernel_ulong_t tv_sec;
+   __kernel_ulong_t tv_usec;
+};
+
+struct raw_input_event {
+   struct input_timeval time;
+   __u16 type;
+   __u16 code;
+   __s32 value;
+};
+
+#ifndef __KERNEL__
 
+/* Userspace structure.
+ * Definition maintained here for userspace that is not yet updated to use
+ * struct raw_input_event.
+ * Not to be used anywhere within the kernel.
+ */
 struct input_event {
struct timeval time;
__u16 type;
@@ -24,11 +43,37 @@ struct input_event {
__s32 value;
 };
 
+
+static inline void
+raw_input_to_input_event(const struct raw_input_event *raw, struct input_event 
*ev)
+{
+   ev->time.tv_sec = raw->time.tv_sec;
+   ev->time.tv_usec = raw->time.tv_usec;
+   ev->type = raw->type;
+   ev->code = raw->code;
+   ev->value = raw->value;
+}
+
+static inline void
+input_to_raw_event(const struct input_event *ev, struct raw_input_event *raw)
+{
+   raw->time.tv_sec = ev->time.tv_sec;
+   raw->time.tv_usec = ev->time.tv_usec;
+   raw->type = ev->type;
+   raw->code = ev->code;
+   raw->value = ev->value;
+}
+
+#endif
+
+
 /*
  * Protocol version.
  */
 
 #define EV_VERSION 0x010001
+#define EV_VERSION_1_2 0x010002
+
 
 /*
  * IOCTLs (0x00 - 0x7f)
diff --git a/src/evdev.c b/src/evdev.c
index f7f7230..5d47119 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -256,7 +256,7 @@ evdev_device_led_update(struct evdev_device *device, enum 
libinput_led leds)
{ LIBINPUT_LED_CAPS_LOCK, LED_CAPSL },
{ LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL },
};
-   struct input_event ev[ARRAY_LENGTH(map) + 1];
+   struct raw_input_event ev[ARRAY_LENGTH(map) + 1];
unsigned int i;
 
if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
@@ -2665,7 +2665,7 @@ evdev_set_device_group(struct evdev_device *device,
 static inline void
 evdev_drain_fd(int fd)
 {
-   struct input_event ev[24];
+   struct raw_input_event ev[24];
size_t sz = sizeof ev;
 
while (read(fd, , sz) == (int)sz) {
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] Update libevdev to support evdev driver v1.2

2016-10-19 Thread Deepa Dinamani
Update input event structures read from the kernel to match
the 1.2 version of the driver.

Update the UAPI version of the header file input.h to use
__inline__ instead of inline to maintain compatibility with
the pedantic gcc flag used to test the headers.

There are no changes to the exposed interfaces of libevdev.

The associated kernel driver change is at
https://lkml.org/lkml/2016/10/17/1146 .

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 include/linux/input.h  | 47 ++
 include/linux/uinput.h |  3 +++
 libevdev/libevdev-int.h| 31 +++-
 libevdev/libevdev.c| 30 ++-
 test/test-libevdev-has-event.c |  2 +-
 5 files changed, 92 insertions(+), 21 deletions(-)

diff --git a/include/linux/input.h b/include/linux/input.h
index fbc968f..e253679 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -20,6 +20,29 @@
  * The event structure itself
  */
 
+/* The time structure for y2038 safe raw_input_event.
+ * The fields use unsigned types to extend times until
+ * year 2106 rather than 2038.
+ */
+struct input_timeval {
+   __kernel_ulong_t tv_sec;
+   __kernel_ulong_t tv_usec;
+};
+
+struct raw_input_event {
+   struct input_timeval time;
+   __u16 type;
+   __u16 code;
+   __s32 value;
+};
+
+#ifndef __KERNEL__
+
+/* Userspace structure.
+ * Definition maintained here for userspace that is not yet updated to use
+ * struct raw_input_event.
+ * Not to be used anywhere within the kernel.
+ */
 struct input_event {
struct timeval time;
__u16 type;
@@ -27,11 +50,35 @@ struct input_event {
__s32 value;
 };
 
+static __inline__ void
+raw_input_to_input_event(const struct raw_input_event *raw, struct input_event 
*ev)
+{
+   ev->time.tv_sec = raw->time.tv_sec;
+   ev->time.tv_usec = raw->time.tv_usec;
+   ev->type = raw->type;
+   ev->code = raw->code;
+   ev->value = raw->value;
+}
+
+static __inline__ void
+input_to_raw_event(const struct input_event *ev, struct raw_input_event *raw)
+{
+   raw->time.tv_sec = ev->time.tv_sec;
+   raw->time.tv_usec = ev->time.tv_usec;
+   raw->type = ev->type;
+   raw->code = ev->code;
+   raw->value = ev->value;
+}
+
+#endif
+
 /*
  * Protocol version.
  */
 
 #define EV_VERSION 0x010001
+#define EV_VERSION_1_2 0x010002
+
 
 /*
  * IOCTLs (0x00 - 0x7f)
diff --git a/include/linux/uinput.h b/include/linux/uinput.h
index 434f02d..c7b7054 100644
--- a/include/linux/uinput.h
+++ b/include/linux/uinput.h
@@ -133,6 +133,9 @@ struct uinput_abs_setup {
  */
 #define UI_ABS_SETUP _IOW(UINPUT_IOCTL_BASE, 4, struct uinput_abs_setup)
 
+/* Set clockid to be used for timestamps */
+#define UI_SET_CLOCKID _IOW(UINPUT_IOCTL_BASE, 5, int)
+
 #define UI_SET_EVBIT   _IOW(UINPUT_IOCTL_BASE, 100, int)
 #define UI_SET_KEYBIT  _IOW(UINPUT_IOCTL_BASE, 101, int)
 #define UI_SET_RELBIT  _IOW(UINPUT_IOCTL_BASE, 102, int)
diff --git a/libevdev/libevdev-int.h b/libevdev/libevdev-int.h
index e1c7ec5..8539987 100644
--- a/libevdev/libevdev-int.h
+++ b/libevdev/libevdev-int.h
@@ -105,7 +105,7 @@ struct libevdev {
enum SyncState sync_state;
enum libevdev_grab_mode grabbed;
 
-   struct input_event *queue;
+   struct raw_input_event *queue;
size_t queue_size; /**< size of queue in elements */
size_t queue_next; /**< next event index */
size_t queue_nsync; /**< number of sync events */
@@ -147,7 +147,7 @@ _libevdev_log_priority(const struct libevdev *dev);
  * @return a pointer to the next element in the queue, or NULL if the queue
  * is full.
  */
-static inline struct input_event*
+static inline struct raw_input_event*
 queue_push(struct libevdev *dev)
 {
if (dev->queue_next >= dev->queue_size)
@@ -167,8 +167,8 @@ queue_pop(struct libevdev *dev, struct input_event *ev)
if (dev->queue_next == 0)
return 1;
 
-   *ev = dev->queue[--dev->queue_next];
-
+   raw_input_to_input_event(>queue[dev->queue_next-1], ev);
+   --dev->queue_next;
return 0;
 }
 
@@ -177,7 +177,8 @@ queue_peek(struct libevdev *dev, size_t idx, struct 
input_event *ev)
 {
if (dev->queue_next == 0 || idx > dev->queue_next)
return 1;
-   *ev = dev->queue[idx];
+   raw_input_to_input_event(>queue[idx], ev);
+
return 0;
 }
 
@@ -192,7 +193,9 @@ queue_peek(struct libevdev *dev, size_t idx, struct 
input_event *ev)
 static inline int
 queue_shift_multiple(struct libevdev *dev, size_t n, struct input_event *ev)
 {
-   size_t remaining;
+   struct raw_input_event *raw_event;
+   struct input_event *event;
+   size_t i, remaining;
 
if (dev->queue_next == 0)
return 0;
@@ -201

[Y2038] [PATCH] Update mtdev to support evdev driver v1.2

2016-10-19 Thread Deepa Dinamani
Update input event structures read from the kernel to match
the 1.2 version of the driver.

There are no changes to the exposed interfaces of the mtdev.

The associated kernel driver change is proposed at
https://lkml.org/lkml/2016/10/17/1146 .

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 src/evbuf.h | 10 ++
 src/iobuf.c |  8 
 src/iobuf.h |  4 +++-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/evbuf.h b/src/evbuf.h
index 17ea4e7..9ec2da6 100644
--- a/src/evbuf.h
+++ b/src/evbuf.h
@@ -34,7 +34,7 @@
 struct mtdev_evbuf {
int head;
int tail;
-   struct input_event buffer[DIM_EVENTS];
+   struct raw_input_event buffer[DIM_EVENTS];
 };
 
 static inline int evbuf_empty(const struct mtdev_evbuf *evbuf)
@@ -43,16 +43,18 @@ static inline int evbuf_empty(const struct mtdev_evbuf 
*evbuf)
 }
 
 static inline void evbuf_put(struct mtdev_evbuf *evbuf,
-const struct input_event *ev)
+struct input_event *ev)
 {
-   evbuf->buffer[evbuf->head++] = *ev;
+   input_to_raw_event(ev, >buffer[evbuf->head]);
+   evbuf->head++;
evbuf->head &= DIM_EVENTS - 1;
 }
 
 static inline void evbuf_get(struct mtdev_evbuf *evbuf,
 struct input_event *ev)
 {
-   *ev = evbuf->buffer[evbuf->tail++];
+   raw_input_to_input_event(>buffer[evbuf->tail], ev);
+   evbuf->tail++;
evbuf->tail &= DIM_EVENTS - 1;
 }
 
diff --git a/src/iobuf.c b/src/iobuf.c
index 61ec9c1..6f7c923 100644
--- a/src/iobuf.c
+++ b/src/iobuf.c
@@ -42,7 +42,7 @@ int mtdev_fetch_event(struct mtdev *dev, int fd, struct 
input_event *ev)
 {
struct mtdev_iobuf *buf = >state->iobuf;
int n = buf->head - buf->tail;
-   if (n < EVENT_SIZE) {
+   if (n < RAW_EVENT_SIZE) {
if (buf->tail && n > 0)
memmove(buf->data, buf->data + buf->tail, n);
buf->head = n;
@@ -53,10 +53,10 @@ int mtdev_fetch_event(struct mtdev *dev, int fd, struct 
input_event *ev)
return n;
buf->head += n;
}
-   if (buf->head - buf->tail < EVENT_SIZE)
+   if (buf->head - buf->tail < RAW_EVENT_SIZE)
return 0;
-   memcpy(ev, buf->data + buf->tail, EVENT_SIZE);
-   buf->tail += EVENT_SIZE;
+   raw_input_to_input_event(buf->data + buf->tail, ev);
+   buf->tail += RAW_EVENT_SIZE;
return 1;
 }
 
diff --git a/src/iobuf.h b/src/iobuf.h
index 09c26c4..7450b01 100644
--- a/src/iobuf.h
+++ b/src/iobuf.h
@@ -32,7 +32,9 @@
 #include "common.h"
 
 #define EVENT_SIZE sizeof(struct input_event)
-#define DIM_BUFFER (DIM_EVENTS * EVENT_SIZE)
+#define RAW_EVENT_SIZE sizeof(struct input_event)
+
+#define DIM_BUFFER (DIM_EVENTS * RAW_EVENT_SIZE)
 
 struct mtdev_iobuf {
int head, tail;
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2 3/4] input: Deprecate real timestamps beyond year 2106

2016-10-17 Thread Deepa Dinamani
struct timeval is not y2038 safe.
All usage of timeval in the kernel will be replaced by
y2038 safe structures.

struct input_event maintains time for each input event.
Real time timestamps are not ideal for input as this
time can go backwards as noted in the patch a80b83b7b8
by John Stultz. Hence, having the input_event.time fields
only big enough for monotonic and boot times are
sufficient.

Leave the original input_event as is. This is to maintain
backward compatibility with existing userspace interfaces
that use input_event.
Introduce a new replacement struct raw_input_event.
This replaces timeval with struct input_timeval. This structure
maintains time in __kernel_ulong_t or compat_ulong_t to allow
for architectures to override types as in the case of x32.

The change requires any userspace utilities reading or writing
from event nodes to update their reading format to match
raw_input_event. The changes to the popular libraries will be
posted along with the kernel changes.
The driver version is also updated to reflect the change in
event format.

Suggested-by: Arnd Bergmann <a...@arndb.de>
Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 drivers/input/evdev.c| 20 +--
 drivers/input/input-compat.c | 29 ++-
 drivers/input/input-compat.h | 19 +++---
 drivers/input/misc/uinput.c  |  6 +++---
 include/linux/uinput.h   |  2 +-
 include/uapi/linux/input.h   | 47 
 6 files changed, 88 insertions(+), 35 deletions(-)

diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index b4e3171..459e3ba 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -60,7 +60,7 @@ struct evdev_client {
bool revoked;
unsigned long *evmasks[EV_CNT];
unsigned int bufsize;
-   struct input_event buffer[];
+   struct raw_input_event buffer[];
 };
 
 static size_t evdev_get_mask_cnt(unsigned int type)
@@ -113,7 +113,7 @@ static void __evdev_flush_queue(struct evdev_client 
*client, unsigned int type)
unsigned int i, head, num;
unsigned int mask = client->bufsize - 1;
bool is_report;
-   struct input_event *ev;
+   struct raw_input_event *ev;
 
BUG_ON(type == EV_SYN);
 
@@ -155,7 +155,7 @@ static void __evdev_flush_queue(struct evdev_client 
*client, unsigned int type)
 
 static void __evdev_queue_syn_dropped(struct evdev_client *client)
 {
-   struct input_event ev;
+   struct raw_input_event ev;
struct timespec64 ts;
 
switch (client->clk_type) {
@@ -236,7 +236,7 @@ static int evdev_set_clk_type(struct evdev_client *client, 
unsigned int clkid)
 }
 
 static void __pass_event(struct evdev_client *client,
-const struct input_event *event)
+const struct raw_input_event *event)
 {
client->buffer[client->head++] = *event;
client->head &= client->bufsize - 1;
@@ -268,7 +268,7 @@ static void evdev_pass_values(struct evdev_client *client,
 {
struct evdev *evdev = client->evdev;
const struct input_value *v;
-   struct input_event event;
+   struct raw_input_event event;
struct timespec64 ts;
bool wakeup = false;
 
@@ -507,7 +507,7 @@ static int evdev_open(struct inode *inode, struct file 
*file)
struct evdev *evdev = container_of(inode->i_cdev, struct evdev, cdev);
unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev);
unsigned int size = sizeof(struct evdev_client) +
-   bufsize * sizeof(struct input_event);
+   bufsize * sizeof(struct raw_input_event);
struct evdev_client *client;
int error;
 
@@ -542,7 +542,7 @@ static ssize_t evdev_write(struct file *file, const char 
__user *buffer,
 {
struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
-   struct input_event event;
+   struct raw_input_event event;
int retval = 0;
 
if (count != 0 && count < input_event_size())
@@ -575,7 +575,7 @@ static ssize_t evdev_write(struct file *file, const char 
__user *buffer,
 }
 
 static int evdev_fetch_next_event(struct evdev_client *client,
- struct input_event *event)
+ struct raw_input_event *event)
 {
int have_event;
 
@@ -597,7 +597,7 @@ static ssize_t evdev_read(struct file *file, char __user 
*buffer,
 {
struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
-   struct input_event event;
+   struct raw_input_event event;
size_t read = 0;
int error;
 
@@ -1083,7 +1083,7 @@ static long evdev_do_ioctl(struct file *file, unsigned 
int cmd,
switch (cmd) {
 
  

[Y2038] [PATCH v2 0/4] Make input drivers y2038 safe

2016-10-17 Thread Deepa Dinamani
Reposting the series as I did not hear comments from the
maintainers.

The series is aimed at making input events y2038 safe.
It extends the lifetime of the realtime timestamps in the
events to year 2106.
The plan is to deprecate realtime timestamps anyway as they
are not appropriate for these timestamps as noted in the patch
a80b83b7b8 by John Stultz.

The series is a result of many discussions with Arnd Bergmann.

The design updates the format of the input events read/ written
to the device nodes. This structure and the uapi/input.h
header file are copied across many userspace libraries.
These libraries not only use this struct input_event locally,
but also expose interfaces that contain input_event. To maintain
backward compatibility with all these interfaces, kernel
updates the format of the input events at the dev node to
struct raw_input_event. Kernel also maintains the old struct
input_event and provides apis to convert between the old and new
input event types.

The userspace library changes to libevdev, libuinput and mtdev
will be posted to the respective mailing groups for review.
Once there is a consensus on the design, all the changes dependent
on the kernel change will be merged at the same time.

Changes from v1:
* Updated changes according to review comments.
* Posted userspace library changes that go along with the series.

Deepa Dinamani (4):
  uinput: Add ioctl for using monotonic/ boot times
  input: evdev: Replace timeval with timespec64
  input: Deprecate real timestamps beyond year 2106
  input: serio: Replace timeval by timespec64

 drivers/input/evdev.c| 57 
 drivers/input/input-compat.c | 29 ++-
 drivers/input/input-compat.h | 19 +++-
 drivers/input/misc/uinput.c  | 62 +---
 drivers/input/serio/hil_mlc.c| 37 
 drivers/input/serio/hp_sdc.c | 17 +--
 drivers/input/serio/hp_sdc_mlc.c | 10 +++
 include/linux/hil_mlc.h  |  6 ++--
 include/linux/hp_sdc.h   |  6 ++--
 include/linux/uinput.h   |  3 +-
 include/uapi/linux/input.h   | 47 ++
 include/uapi/linux/uinput.h  |  3 ++
 12 files changed, 208 insertions(+), 88 deletions(-)

-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2 4/4] input: serio: Replace timeval by timespec64

2016-10-17 Thread Deepa Dinamani
struct timeval is not y2038 safe.
All references to timeval will be deleted from the
kernel to make it y2038 safe.
Replace its uses by y2038 safe struct timespec64.

The timestamps changed here only keep track of delta
times. These timestamps are also internal to kernel.
Hence, monotonic times are sufficient here.
The unit of the delta times is also changed in certain
cases to nanoseconds rather than microseconds. This is
in line with timespec64 which keeps time in nanoseconds.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 drivers/input/serio/hil_mlc.c| 37 ++---
 drivers/input/serio/hp_sdc.c | 17 +
 drivers/input/serio/hp_sdc_mlc.c | 10 +-
 include/linux/hil_mlc.h  |  6 +++---
 include/linux/hp_sdc.h   |  6 +++---
 5 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c
index 65605e4..7c59a79 100644
--- a/drivers/input/serio/hil_mlc.c
+++ b/drivers/input/serio/hil_mlc.c
@@ -274,14 +274,14 @@ static int hilse_match(hil_mlc *mlc, int unused)
 /* An LCV used to prevent runaway loops, forces 5 second sleep when reset. */
 static int hilse_init_lcv(hil_mlc *mlc, int unused)
 {
-   struct timeval tv;
+   time64_t time;
 
-   do_gettimeofday();
+   time = ktime_get_seconds();
 
-   if (mlc->lcv && (tv.tv_sec - mlc->lcv_tv.tv_sec) < 5)
+   if (mlc->lcv && (time - mlc->lcv_tv.tv_sec) < 5)
return -1;
 
-   mlc->lcv_tv = tv;
+   mlc->lcv_tv.tv_sec = time;
mlc->lcv = 0;
 
return 0;
@@ -466,7 +466,7 @@ static const struct hilse_node hil_mlc_se[HILSEN_END] = {
FUNC(hilse_init_lcv, 0, HILSEN_NEXT,HILSEN_SLEEP,   0)
 
/* 1  HILSEN_RESTART */
-   FUNC(hilse_inc_lcv, 10, HILSEN_NEXT,HILSEN_START,  0)
+   FUNC(hilse_inc_lcv, 1,  HILSEN_NEXT,HILSEN_START,  0)
OUT(HIL_CTRL_ONLY)  /* Disable APE */
CTS
 
@@ -485,7 +485,7 @@ static const struct hilse_node hil_mlc_se[HILSEN_END] = {
FUNC(hilse_init_lcv, 0, HILSEN_NEXT,HILSEN_SLEEP,   0)
 
/* 10 HILSEN_DHR2 */
-   FUNC(hilse_inc_lcv, 10, HILSEN_NEXT,HILSEN_START,   0)
+   FUNC(hilse_inc_lcv, 1,  HILSEN_NEXT,HILSEN_START,   0)
FUNC(hilse_set_ddi, -1, HILSEN_NEXT,0,  0)
OUT(HIL_PKT_CMD | HIL_CMD_DHR)
IN(30,  HILSEN_DHR2,HILSEN_DHR2,HILSEN_NEXT)
@@ -515,7 +515,7 @@ static const struct hilse_node hil_mlc_se[HILSEN_END] = {
FUNC(hilse_init_lcv, 0, HILSEN_NEXT,HILSEN_DOZE,0)
 
/* 22 HILSEN_ACF2 */
-   FUNC(hilse_inc_lcv, 10, HILSEN_NEXT,HILSEN_START,   0)
+   FUNC(hilse_inc_lcv, 1,  HILSEN_NEXT,HILSEN_START,   0)
OUT(HIL_PKT_CMD | HIL_CMD_ACF | 1)
IN(2,   HILSEN_NEXT,HILSEN_DSR, HILSEN_NEXT)
 
@@ -572,7 +572,7 @@ static const struct hilse_node hil_mlc_se[HILSEN_END] = {
OUT(HIL_PKT_CMD | HIL_CMD_RPL)
EXPECT(HIL_PKT_CMD | HIL_CMD_RPL | HIL_ERR_INT,
   2,   HILSEN_NEXT,HILSEN_DSR, HILSEN_NEXT)
-   FUNC(hilse_operate, 1,  HILSEN_OPERATE, HILSEN_IFC, HILSEN_PROBE)
+   FUNC(hilse_operate, 1000, HILSEN_OPERATE, HILSEN_IFC,   HILSEN_PROBE)
 
/* 58 HILSEN_IFCACF */
OUT(HIL_PKT_CMD | HIL_CMD_IFC)
@@ -584,7 +584,6 @@ static const struct hilse_node hil_mlc_se[HILSEN_END] = {
 
 static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node 
*node)
 {
-
switch (node->act) {
case HILSE_EXPECT_DISC:
mlc->imatch = node->object.packet;
@@ -605,7 +604,7 @@ static inline void hilse_setup_input(hil_mlc *mlc, const 
struct hilse_node *node
}
mlc->istarted = 1;
mlc->intimeout = node->arg;
-   do_gettimeofday(&(mlc->instart));
+   ktime_get_ts64(&(mlc->instart));
mlc->icount = 15;
memset(mlc->ipacket, 0, 16 * sizeof(hil_packet));
BUG_ON(down_trylock(>isem));
@@ -710,7 +709,7 @@ static int hilse_donode(hil_mlc *mlc)
break;
}
mlc->ostarted = 0;
-   do_gettimeofday(&(mlc->instart));
+   ktime_get_ts64(&(mlc->instart));
write_unlock_irqrestore(>lock, flags);
nextidx = HILSEN_NEXT;
break;
@@ -731,18 +730,18 @@ static int hilse_donode(hil_mlc *mlc)
 #endif
 
while (nextidx & HILSEN_SCHED) {
-   struct timeval tv;
+   struct timespec64 ts;
 
if (!sched_long)
goto sched;
 
-   do_gettimeofday();
-   tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instar

[Y2038] [RESEND PATCH] fs: ufs: Use ktime_get_real_ts64() for birthtime

2016-11-11 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
Replace it with ktime_get_real_ts64().
Inode time formats are already 64 bit long and
accommodates time64_t.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/ufs/ialloc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index 9774555..d1dd8cc 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -176,6 +176,7 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
struct ufs_cg_private_info * ucpi;
struct ufs_cylinder_group * ucg;
struct inode * inode;
+   struct timespec64 ts;
unsigned cg, bit, i, j, start;
struct ufs_inode_info *ufsi;
int err = -ENOSPC;
@@ -323,8 +324,9 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
lock_buffer(bh);
ufs2_inode = (struct ufs2_inode *)bh->b_data;
ufs2_inode += ufs_inotofsbo(inode->i_ino);
-   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, CURRENT_TIME.tv_sec);
-   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, 
CURRENT_TIME.tv_nsec);
+   ktime_get_real_ts64();
+   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, ts.tv_sec);
+   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, ts.tv_nsec);
mark_buffer_dirty(bh);
unlock_buffer(bh);
if (sb->s_flags & MS_SYNCHRONOUS)
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [RESEND PATCH] fs: jfs: Replace CURRENT_TIME_SEC by current_time()

2016-11-11 Thread Deepa Dinamani
On Fri, Nov 11, 2016 at 10:42 AM, Dave Kleikamp
<dave.kleik...@oracle.com> wrote:
> On 11/11/2016 12:00 PM, Deepa Dinamani wrote:
>> jfs uses nanosecond granularity for filesystem timestamps.
>> Only this assignment is not using nanosecond granularity.
>> Use current_time() to get the right granularity.
>
> I had thought these were being handled as a group. I'll push this one
> through the jfs tree.

Yes, that was the original plan.
Then, Greg suggested pushing only the big patches as a group and
sending individual filesystem patches separately.
Big patches introducing current_time() have been merged in 4.9 rc1.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH] fs: ext4: Use current_time() for inode timestamps

2016-11-11 Thread Deepa Dinamani
CURRENT_TIME_SEC and CURRENT_TIME are not y2038 safe.
current_time() will be transitioned to be y2038 safe
along with vfs.

current_time() returns timestamps according to the
granularities set in the super_block.
The granularity check in ext4_current_time() to call
current_time() or CURRENT_TIME_SEC is not required.
Use current_time() directly to obtain timestamps
unconditionally, and remove ext4_current_time().

Quota files are assumed to be on the same filesystem.
Hence, use current_time() for these files as well.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 fs/ext4/acl.c |  2 +-
 fs/ext4/ext4.h|  6 --
 fs/ext4/extents.c | 10 +-
 fs/ext4/ialloc.c  |  2 +-
 fs/ext4/inline.c  |  4 ++--
 fs/ext4/inode.c   |  6 +++---
 fs/ext4/ioctl.c   |  8 
 fs/ext4/namei.c   | 24 +---
 fs/ext4/super.c   |  2 +-
 fs/ext4/xattr.c   |  2 +-
 10 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
index dfa5199..fd38993 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -196,7 +196,7 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int 
type,
error = posix_acl_update_mode(inode, >i_mode, 
);
if (error)
return error;
-   inode->i_ctime = ext4_current_time(inode);
+   inode->i_ctime = current_time(inode);
ext4_mark_inode_dirty(handle, inode);
}
break;
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 282a51b..6789379 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1532,12 +1532,6 @@ static inline struct ext4_inode_info *EXT4_I(struct 
inode *inode)
return container_of(inode, struct ext4_inode_info, vfs_inode);
 }
 
-static inline struct timespec ext4_current_time(struct inode *inode)
-{
-   return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
-   current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
-}
-
 static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
 {
return ino == EXT4_ROOT_INO ||
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index c930a01..786be87 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4725,7 +4725,7 @@ static int ext4_alloc_file_blocks(struct file *file, 
ext4_lblk_t offset,
map.m_lblk += ret;
map.m_len = len = len - ret;
epos = (loff_t)map.m_lblk << inode->i_blkbits;
-   inode->i_ctime = ext4_current_time(inode);
+   inode->i_ctime = current_time(inode);
if (new_size) {
if (epos > new_size)
epos = new_size;
@@ -4853,7 +4853,7 @@ static long ext4_zero_range(struct file *file, loff_t 
offset,
}
/* Now release the pages and zero block aligned part of pages */
truncate_pagecache_range(inode, start, end - 1);
-   inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
 
ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size,
 flags, mode);
@@ -4878,7 +4878,7 @@ static long ext4_zero_range(struct file *file, loff_t 
offset,
goto out_dio;
}
 
-   inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
if (new_size) {
ext4_update_inode_size(inode, new_size);
} else {
@@ -5568,7 +5568,7 @@ int ext4_collapse_range(struct inode *inode, loff_t 
offset, loff_t len)
up_write(_I(inode)->i_data_sem);
if (IS_SYNC(inode))
ext4_handle_sync(handle);
-   inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
ext4_mark_inode_dirty(handle, inode);
 
 out_stop:
@@ -5678,7 +5678,7 @@ int ext4_insert_range(struct inode *inode, loff_t offset, 
loff_t len)
/* Expand file to avoid data loss if there is error while shifting */
inode->i_size += len;
EXT4_I(inode)->i_disksize += len;
-   inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
ret = ext4_mark_inode_dirty(handle, inode);
if (ret)
goto out_stop;
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 170421e..088afe0 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -1039,7 +1039,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct 
inode *dir,
/* This is the optimal IO size (for stat), not the fs block 

[Y2038] [RFC 1/6] vfs: Add file timestamp range support

2016-11-23 Thread Deepa Dinamani
Add fields to the superblock to track the min and max
timestamps supported by filesystems.

Initially, when a superblock is allocated, initialize
it to the max and min values the fields can hold.
Individual filesystems override these to match their
actual limits.

Pseudo filesystems are assumed to always support the
min and max allowable values for the fields.

Note that the time ranges are save in type time64_t
rather than time_t.
This is required because if we save ranges in time_t
then we would not be able to save timestamp ranges
for files that support timestamps beyond y2038.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/libfs.c | 4 
 fs/super.c | 2 ++
 include/linux/fs.h | 3 +++
 include/linux/time64.h | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/fs/libfs.c b/fs/libfs.c
index 48826d4..f03c904 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -256,6 +256,8 @@ struct dentry *mount_pseudo_xattr(struct file_system_type 
*fs_type, char *name,
s->s_op = ops ? ops : _super_operations;
s->s_xattr = xattr;
s->s_time_gran = 1;
+   s->s_time_min = TIME64_MIN;
+   s->s_time_max = TIME64_MAX;
root = new_inode(s);
if (!root)
goto Enomem;
@@ -515,6 +517,8 @@ int simple_fill_super(struct super_block *s, unsigned long 
magic,
s->s_magic = magic;
s->s_op = _super_operations;
s->s_time_gran = 1;
+   s->s_time_min = TIME64_MIN;
+   s->s_time_max = TIME64_MAX;
 
inode = new_inode(s);
if (!inode)
diff --git a/fs/super.c b/fs/super.c
index c183835..27c973e 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -248,6 +248,8 @@ static struct super_block *alloc_super(struct 
file_system_type *type, int flags,
s->s_maxbytes = MAX_NON_LFS;
s->s_op = _op;
s->s_time_gran = 10;
+   s->s_time_min = TIME64_MIN;
+   s->s_time_max = TIME64_MAX;
s->cleancache_poolid = CLEANCACHE_NO_POOL;
 
s->s_shrink.seeks = DEFAULT_SEEKS;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 03a5a39..8eba822 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1329,6 +1329,9 @@ struct super_block {
/* Granularity of c/m/atime in ns.
   Cannot be worse than a second */
u32s_time_gran;
+   /* Time limits for c/m/atime in seconds. */
+   time64_t   s_time_min;
+   time64_t   s_time_max;
 
/*
 * The next field is for VFS *only*. No filesystems have any business
diff --git a/include/linux/time64.h b/include/linux/time64.h
index 980c71b..25433b18 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -38,6 +38,8 @@ struct itimerspec64 {
 
 /* Located here for timespec[64]_valid_strict */
 #define TIME64_MAX ((s64)~((u64)1 << 63))
+#define TIME64_MIN (-TIME64_MAX - 1)
+
 #define KTIME_MAX  ((s64)~((u64)1 << 63))
 #define KTIME_SEC_MAX  (KTIME_MAX / NSEC_PER_SEC)
 
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 2/6] vfs: Add checks for filesystem timestamp limits

2016-11-23 Thread Deepa Dinamani
Allow read only mounts for filesystems that do not
have maximum timestamps beyond the y2038 expiry
timestamp.

Also, allow a sysctl override to all such filesystems
to be mounted with write permissions.

Alternatively, a mount option can be created to allow or
disallow range check based clamps and the least max
timestamp supported.

If we take the sysctl approach, then the plan is to also
add a boot param to support initial override of these
checks without recompilation.

Suggested-by: Arnd Bergmann <a...@arndb.de>
Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/inode.c  |  5 +
 fs/internal.h   |  2 ++
 fs/namespace.c  | 12 
 fs/super.c  |  7 +++
 include/linux/fs.h  |  1 +
 include/linux/time64.h  |  4 
 include/uapi/linux/fs.h |  6 +-
 kernel/sysctl.c |  7 +++
 8 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index 88110fd..7b2b78d 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -75,6 +75,11 @@ static DEFINE_PER_CPU(unsigned long, nr_unused);
 
 static struct kmem_cache *inode_cachep __read_mostly;
 
+struct vfs_max_timestamp_check timestamp_check = {
+   .timestamp_supported = Y2038_EXPIRY_TIMESTAMP,
+   .check_on = 1,
+};
+
 static long get_nr_inodes(void)
 {
int i;
diff --git a/fs/internal.h b/fs/internal.h
index f4da334..5a144a8 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -67,6 +67,8 @@ extern int finish_automount(struct vfsmount *, struct path *);
 
 extern int sb_prepare_remount_readonly(struct super_block *);
 
+extern bool sb_file_times_updatable(struct super_block *sb);
+
 extern void __init mnt_init(void);
 
 extern int __mnt_want_write(struct vfsmount *);
diff --git a/fs/namespace.c b/fs/namespace.c
index 5ef9618..27eab32 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -543,6 +543,18 @@ static void __mnt_unmake_readonly(struct mount *mnt)
unlock_mount_hash();
 }
 
+bool sb_file_times_updatable(struct super_block *sb)
+{
+
+   if (!timestamp_check.check_on)
+   return true;
+
+   if (sb->s_time_max > timestamp_check.timestamp_supported)
+   return true;
+
+   return false;
+}
+
 int sb_prepare_remount_readonly(struct super_block *sb)
 {
struct mount *mnt;
diff --git a/fs/super.c b/fs/super.c
index 27c973e..d21327f 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1199,6 +1199,13 @@ mount_fs(struct file_system_type *type, int flags, const 
char *name, void *data)
WARN((sb->s_maxbytes < 0), "%s set sb->s_maxbytes to "
"negative value (%lld)\n", type->name, sb->s_maxbytes);
 
+   if (!(sb->s_flags & MS_RDONLY) && !sb_file_times_updatable(sb)) {
+   WARN(1, "File times cannot be updated on the filesystem.\n");
+   WARN(1, "Retry mounting the filesystem readonly.\n");
+   error = -EROFS;
+   goto out_sb;
+   }
+
up_write(>s_umount);
free_secdata(secdata);
return root;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 8eba822..b80d1e2 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -68,6 +68,7 @@ extern struct inodes_stat_t inodes_stat;
 extern int leases_enable, lease_break_time;
 extern int sysctl_protected_symlinks;
 extern int sysctl_protected_hardlinks;
+extern struct vfs_max_timestamp_check timestamp_check;
 
 struct buffer_head;
 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
diff --git a/include/linux/time64.h b/include/linux/time64.h
index 25433b18..906e0b3 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -43,6 +43,10 @@ struct itimerspec64 {
 #define KTIME_MAX  ((s64)~((u64)1 << 63))
 #define KTIME_SEC_MAX  (KTIME_MAX / NSEC_PER_SEC)
 
+/* Timestamps on boundary */
+#define Y2038_EXPIRY_TIMESTAMP S32_MAX /* 2147483647 */
+#define Y2106_EXPIRY_TIMESTAMP U32_MAX /* 4294967295 */
+
 #if __BITS_PER_LONG == 64
 
 static inline struct timespec timespec64_to_timespec(const struct timespec64 
ts64)
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index c1d11df..07d225c 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -91,6 +91,11 @@ struct files_stat_struct {
unsigned long max_files;/* tunable */
 };
 
+struct vfs_max_timestamp_check {
+   time64_t timestamp_supported;
+   int check_on;
+};
+
 struct inodes_stat_t {
long nr_inodes;
long nr_unused;
@@ -100,7 +105,6 @@ struct inodes_stat_t {
 
 #define NR_FILE  8192  /* this can well be larger on a larger system */
 
-
 /*
  * These are the fs-independent mount-flags: up to 32 flags are supported
  */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 1475d25..b6030d5 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1667,6 +1667,13 @

[Y2038] [RFC 4/6] ext4: Initialize timestamps limits

2016-11-23 Thread Deepa Dinamani
ext4 has different overflow limits for max filesystem
timestamps based on the extra bytes available.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: "Theodore Ts'o" <ty...@mit.edu>
Cc: Andreas Dilger <adilger.ker...@dilger.ca>
Cc: linux-e...@vger.kernel.org
---
 fs/ext4/ext4.h  | 4 
 fs/ext4/super.c | 7 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index aff204f..e15c081 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1636,6 +1636,10 @@ static inline void ext4_clear_state_flags(struct 
ext4_inode_info *ei)
 
 #define EXT4_GOOD_OLD_INODE_SIZE 128
 
+#define EXT4_EXTRA_TIMESTAMP_MAX   (((s64)1 << 34) - 1  + S32_MIN)
+#define EXT4_NON_EXTRA_TIMESTAMP_MAX   Y2038_EXPIRY_TIMESTAMP
+#define EXT4_TIMESTAMP_MIN S32_MIN
+
 /*
  * Feature set definitions
  */
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 72b459d..0519c52 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3672,8 +3672,13 @@ static int ext4_fill_super(struct super_block *sb, void 
*data, int silent)
   sbi->s_inode_size);
goto failed_mount;
}
-   if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
+   if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
+   sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
+   } else
+   sb->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX;
+
+   sb->s_time_min = EXT4_TIMESTAMP_MIN;
}
 
sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 3/6] afs: Add time limits in the super block

2016-11-23 Thread Deepa Dinamani
Note that all the filesystems that have such simple limits
will be initialized in the same patch.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: linux-...@lists.infradead.org
---
 fs/afs/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/afs/super.c b/fs/afs/super.c
index fbdb022..ab00434 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -321,6 +321,8 @@ static int afs_fill_super(struct super_block *sb,
sb->s_op= _super_ops;
sb->s_bdi   = >volume->bdi;
strlcpy(sb->s_id, as->volume->vlocation->vldb.name, sizeof(sb->s_id));
+   sb->s_time_max = Y2106_EXPIRY_TIMESTAMP;
+   sb->s_time_min = 0;
 
/* allocate the root inode and dentry */
fid.vid = as->volume->vid;
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 6/6] utimes: Clamp the timestamps before update

2016-11-23 Thread Deepa Dinamani
POSIX.1 section for futimens, utimensat and utimes says:
The file's relevant timestamp shall be set to the
greatest value supported by the file system that is
not greater than the specified time.

Clamp the timestamps accordingly before assignment.

Note that clamp_t macro is used for clamping here as vfs
is not yet using struct timespec64 internally. This is
for compilation purposes only.
The actual patch can only be merged only after vfs is
transitioned to use timespec64 for correct operation of
clamp macro. At which point, clamp_t() will be replaced
by clamp().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/utimes.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/utimes.c b/fs/utimes.c
index 22307cd..4378378 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -53,6 +53,7 @@ static int utimes_common(struct path *path, struct timespec 
*times)
int error;
struct iattr newattrs;
struct inode *inode = path->dentry->d_inode;
+   struct super_block *sb = inode->i_sb;
struct inode *delegated_inode = NULL;
 
error = mnt_want_write(path->mnt);
@@ -68,16 +69,24 @@ static int utimes_common(struct path *path, struct timespec 
*times)
if (times[0].tv_nsec == UTIME_OMIT)
newattrs.ia_valid &= ~ATTR_ATIME;
else if (times[0].tv_nsec != UTIME_NOW) {
-   newattrs.ia_atime.tv_sec = times[0].tv_sec;
-   newattrs.ia_atime.tv_nsec = times[0].tv_nsec;
+   newattrs.ia_atime.tv_sec =
+   clamp_t(time64_t, times[0].tv_sec, 
sb->s_time_min, sb->s_time_max);
+   if (times[0].tv_sec >= sb->s_time_max)
+   newattrs.ia_atime.tv_nsec = 0;
+   else
+   newattrs.ia_atime.tv_nsec = times[0].tv_nsec;
newattrs.ia_valid |= ATTR_ATIME_SET;
}
 
if (times[1].tv_nsec == UTIME_OMIT)
newattrs.ia_valid &= ~ATTR_MTIME;
else if (times[1].tv_nsec != UTIME_NOW) {
-   newattrs.ia_mtime.tv_sec = times[1].tv_sec;
-   newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
+   newattrs.ia_mtime.tv_sec =
+   clamp_t(time64_t, times[1].tv_sec, 
sb->s_time_min, sb->s_time_max);
+   if (times[1].tv_sec >= sb->s_time_max)
+   newattrs.ia_mtime.tv_nsec = 0;
+   else
+   newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
newattrs.ia_valid |= ATTR_MTIME_SET;
}
/*
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 5/6] vfs: Add timestamp_truncate() api

2016-11-23 Thread Deepa Dinamani
timespec_trunc() function is used to truncate a
filesystem timestamp to the right granularity.
But, the function does not clamp tv_sec part of the
timestamps according to the filesystem timestamp limits.

Also, timespec_trunc() is exclusively used for filesystem
timestamps. Move the api to be part of vfs.

The replacement api: timestamp_truncate() also alters the
signature of the function to accommodate filesystem
timestamp clamping according to flesystem limits.

Note that clamp_t macro is used for clamping here as vfs
is not yet using struct timespec64 internally. This is
only for compilation purposes.
The actual patch can only be merged after the vfs is
transitioned to use timespec64 for correct operation of
clamp macro. At which point, clamp_t() will be replaced
by clamp().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/inode.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index 7b2b78d..f9285f2 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2106,6 +2106,36 @@ void inode_nohighmem(struct inode *inode)
 EXPORT_SYMBOL(inode_nohighmem);
 
 /**
+ * fs_timespec_trunc - Truncate timespec to a granularity
+ * @t: Timespec
+ * @gran: Granularity in ns.
+ *
+ * Truncate a timespec to a granularity. Always rounds down. gran must
+ * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns).
+ */
+struct timespec timestamp_truncate(struct timespec t, struct inode *inode)
+{
+   struct super_block *sb = inode->i_sb;
+   unsigned int gran = sb->s_time_gran;
+
+   t.tv_sec = clamp_t(time64_t, t.tv_sec, sb->s_time_min, sb->s_time_max);
+
+   /* Avoid division in the common cases 1 ns and 1 s. */
+   if (gran == 1) {
+   /* nothing */
+   } else if (gran == NSEC_PER_SEC) {
+   t.tv_nsec = 0;
+   } else if (gran > 1 && gran < NSEC_PER_SEC) {
+   t.tv_nsec -= t.tv_nsec % gran;
+   } else {
+   WARN(1, "illegal file time granularity: %u", gran);
+   }
+   return t;
+}
+EXPORT_SYMBOL(timestamp_truncate);
+
+
+/**
  * current_time - Return FS time
  * @inode: inode.
  *
@@ -2124,6 +2154,6 @@ struct timespec current_time(struct inode *inode)
return now;
}
 
-   return timespec_trunc(now, inode->i_sb->s_time_gran);
+   return timestamp_truncate(now, inode);
 }
 EXPORT_SYMBOL(current_time);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] generic/390: Add tests for inode timestamp policy

2016-11-23 Thread Deepa Dinamani
The test helps to validate clamping and mount behaviors
according to supported file system timestamp ranges.

Note that the test can fail on 32-bit systems for a
few file systems. This will be corrected when vfs is
transitioned to use 64-bit timestamps.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 common/attr   |  27 ++
 src/Makefile  |   2 +-
 src/y2038_futimens.c  |  61 +
 tests/generic/390 | 238 ++
 tests/generic/390.out |   2 +
 tests/generic/group   |   1 +
 6 files changed, 330 insertions(+), 1 deletion(-)
 create mode 100644 src/y2038_futimens.c
 create mode 100755 tests/generic/390
 create mode 100644 tests/generic/390.out

diff --git a/common/attr b/common/attr
index ce2d76a..579dc9b 100644
--- a/common/attr
+++ b/common/attr
@@ -56,6 +56,33 @@ _acl_get_max()
esac
 }
 
+_filesystem_timestamp_range()
+{
+   device=${1:-$TEST_DEV}
+   case $FSTYP in
+   ext4)   #dumpe2fs
+   if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | 
cut -d: -f2) -gt 128 ]; then
+   echo "-2147483648 15032385535"
+   else
+   echo "-2147483648 2147483647"
+   fi
+   ;;
+
+   xfs)
+   echo "-2147483648 2147483647"
+   ;;
+   jfs)
+   echo "0 4294967295"
+   ;;
+   f2fs)
+   echo "-2147483648 2147483647"
+   ;;
+   *)
+   echo "-1 -1"
+   ;;
+   esac
+}
+
 _require_acl_get_max()
 {
if [ $(_acl_get_max) -eq 0 ]; then
diff --git a/src/Makefile b/src/Makefile
index dd51216..0b99ae4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize 
preallo_rw_pattern_reader \
stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
renameat2 t_getcwd e4compact test-nextquota punch-alternating \
-   attr-list-by-handle-cursor-test listxattr
+   attr-list-by-handle-cursor-test listxattr y2038_futimens
 
 SUBDIRS =
 
diff --git a/src/y2038_futimens.c b/src/y2038_futimens.c
new file mode 100644
index 000..291e4fa
--- /dev/null
+++ b/src/y2038_futimens.c
@@ -0,0 +1,61 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int
+do_utime(int fd, long long time)
+{
+   struct timespec t[2];
+
+   /*
+* Convert long long to timespec format.
+* Seconds precision is assumed here.
+*/
+   t[0].tv_sec = time;
+   t[0].tv_nsec = 0;
+   t[1].tv_sec = time;
+   t[1].tv_nsec = 0;
+
+   /* Call utimens to update time. */
+   if (futimens(fd, t)) {
+   perror("futimens");
+   return 1;
+   }
+
+   return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+   int fd;
+   long long time;
+
+   if(argc < 3) {
+   fprintf(stderr, "Usage: %s filename timestamp\n"
+   "Filename: file to be created or opened 
in current directory\n"
+   "Timestamp: is seconds since 1970-01-01 
00:00:00 UTC\n", argv[0]);
+   exit(1);
+   }
+
+   /* Create the file */
+   fd = creat(argv[1], 0666);
+   if(fd < 0) {
+   perror("creat");
+   exit(1);
+   }
+
+   /* Get the timestamp */
+   time = strtoull(argv[2], NULL, 0);
+   if (errno) {
+   perror("strtoull");
+   exit(1);
+   }
+
+   if (do_utime(fd, time))
+   return 1;
+
+   return 0;
+}
diff --git a/tests/generic/390 b/tests/generic/390
new file mode 100755
index 000..f069988
--- /dev/null
+++ b/tests/generic/390
@@ -0,0 +1,238 @@
+#! /bin/bash
+# FS QA Test No. generic/390
+#
+# Tests to verify policy for filesystem timestamps for
+# supported ranges:
+# 1. Verify filesystem rw mount according to sysctl
+# timestamp_supported.
+# 2. Verify timestamp clamping for timestamps beyond max
+# timestamp supported.
+#
+# Exit status 1: either or both tests above fail.
+# Exit status 0: both the above tests pass.
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+#echo "output in $seqres.full"
+here=`pwd`
+
+# Get standard environment, filters and checks.
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+SRC_GROUPS=`find tests -not -path tests -type d -printf "%f "`
+
+# Prerequisites for the test run.
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+
+Y2038_PROG=$here/src/y2038_futimens
+
+#initialize exit status
+status=0
+
+# Generic test cleanup function.
+_cleanup()
+{
+# Remov

[Y2038] [RESEND PATCH] fs: jfs: Replace CURRENT_TIME_SEC by current_time()

2016-11-11 Thread Deepa Dinamani
jfs uses nanosecond granularity for filesystem timestamps.
Only this assignment is not using nanosecond granularity.
Use current_time() to get the right granularity.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Acked-by: Dave Kleikamp <dave.kleik...@oracle.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 fs/jfs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/jfs/ioctl.c b/fs/jfs/ioctl.c
index 8653cac..b6fd1ff 100644
--- a/fs/jfs/ioctl.c
+++ b/fs/jfs/ioctl.c
@@ -121,7 +121,7 @@ long jfs_ioctl(struct file *filp, unsigned int cmd, 
unsigned long arg)
 
jfs_set_inode_flags(inode);
inode_unlock(inode);
-   inode->i_ctime = CURRENT_TIME_SEC;
+   inode->i_ctime = current_time(inode);
mark_inode_dirty(inode);
 setflags_out:
mnt_drop_write_file(filp);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 2/6] vfs: Add checks for filesystem timestamp limits

2016-11-02 Thread Deepa Dinamani
Allow read only mounts for filesystems that do not
have maximum timestamps beyond the y2038 expiry
timestamp.

Also, allow a sysctl override to all such filesystems
to be mounted with write permissions.

Alternatively, a mount option can be created to allow or
disallow range check based clamps and the least max
timestamp supported.

If we take the sysctl approach, then the plan is to also
add a boot param to support initial override of these
checks without recompilation.

Suggested-by: Arnd Bergmann <a...@arndb.de>
Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/inode.c  |  5 +
 fs/internal.h   |  2 ++
 fs/namespace.c  | 12 
 fs/super.c  |  6 ++
 include/linux/fs.h  |  1 +
 include/linux/time64.h  |  4 
 include/uapi/linux/fs.h |  6 +-
 kernel/sysctl.c |  7 +++
 8 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index 88110fd..7b2b78d 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -75,6 +75,11 @@ static DEFINE_PER_CPU(unsigned long, nr_unused);
 
 static struct kmem_cache *inode_cachep __read_mostly;
 
+struct vfs_max_timestamp_check timestamp_check = {
+   .timestamp_supported = Y2038_EXPIRY_TIMESTAMP,
+   .check_on = 1,
+};
+
 static long get_nr_inodes(void)
 {
int i;
diff --git a/fs/internal.h b/fs/internal.h
index f4da334..5a144a8 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -67,6 +67,8 @@ extern int finish_automount(struct vfsmount *, struct path *);
 
 extern int sb_prepare_remount_readonly(struct super_block *);
 
+extern bool sb_file_times_updatable(struct super_block *sb);
+
 extern void __init mnt_init(void);
 
 extern int __mnt_want_write(struct vfsmount *);
diff --git a/fs/namespace.c b/fs/namespace.c
index e6c234b..b784b95 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -542,6 +542,18 @@ static void __mnt_unmake_readonly(struct mount *mnt)
unlock_mount_hash();
 }
 
+bool sb_file_times_updatable(struct super_block *sb)
+{
+
+   if (!timestamp_check.check_on)
+   return true;
+
+   else if (sb->s_time_max > timestamp_check.timestamp_supported)
+   return true;
+
+   return false;
+}
+
 int sb_prepare_remount_readonly(struct super_block *sb)
 {
struct mount *mnt;
diff --git a/fs/super.c b/fs/super.c
index 27c973e..5073d70 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1199,6 +1199,12 @@ mount_fs(struct file_system_type *type, int flags, const 
char *name, void *data)
WARN((sb->s_maxbytes < 0), "%s set sb->s_maxbytes to "
"negative value (%lld)\n", type->name, sb->s_maxbytes);
 
+   if (!(sb->s_flags & MS_RDONLY) && !sb_file_times_updatable(sb)) {
+   WARN(1, "File times cannot be updated on the filesystem.\n");
+   WARN(1, "Retry mounting the filesystem readonly.\n");
+   goto out_sb;
+   }
+
up_write(>s_umount);
free_secdata(secdata);
return root;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6d1346b..a079393 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -68,6 +68,7 @@ extern struct inodes_stat_t inodes_stat;
 extern int leases_enable, lease_break_time;
 extern int sysctl_protected_symlinks;
 extern int sysctl_protected_hardlinks;
+extern struct vfs_max_timestamp_check timestamp_check;
 
 struct buffer_head;
 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
diff --git a/include/linux/time64.h b/include/linux/time64.h
index 25433b18..906e0b3 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -43,6 +43,10 @@ struct itimerspec64 {
 #define KTIME_MAX  ((s64)~((u64)1 << 63))
 #define KTIME_SEC_MAX  (KTIME_MAX / NSEC_PER_SEC)
 
+/* Timestamps on boundary */
+#define Y2038_EXPIRY_TIMESTAMP S32_MAX /* 2147483647 */
+#define Y2106_EXPIRY_TIMESTAMP U32_MAX /* 4294967295 */
+
 #if __BITS_PER_LONG == 64
 
 static inline struct timespec timespec64_to_timespec(const struct timespec64 
ts64)
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index acb2b61..60482b1 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -91,6 +91,11 @@ struct files_stat_struct {
unsigned long max_files;/* tunable */
 };
 
+struct vfs_max_timestamp_check {
+   time64_t timestamp_supported;
+   int check_on;
+};
+
 struct inodes_stat_t {
long nr_inodes;
long nr_unused;
@@ -100,7 +105,6 @@ struct inodes_stat_t {
 
 #define NR_FILE  8192  /* this can well be larger on a larger system */
 
-
 /*
  * These are the fs-independent mount-flags: up to 32 flags are supported
  */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 706309f..e65e6b9 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1681,6 +1681,13 @@ static struct ctl_table fs_table[] = {
   

[Y2038] [RFC 6/6] utimes: Clamp the timestamps before update

2016-11-02 Thread Deepa Dinamani
POSIX.1 section for futimens, utimensat and utimes says:
The file's relevant timestamp shall be set to the
greatest value supported by the file system that is
not greater than the specified time.

Clamp the timestamps accordingly before assignment.

Note that clamp_t macro is used for clamping here as vfs
is not yet using struct timespec64 internally. This is
for compilation purposes only.
The actual patch can only be merged only after vfs is
transitioned to use timespec64 for correct operation of
clamp macro. At which point, clamp_t() will be replaced
by clamp().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/utimes.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/utimes.c b/fs/utimes.c
index 22307cd..186e12b 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -53,6 +53,7 @@ static int utimes_common(struct path *path, struct timespec 
*times)
int error;
struct iattr newattrs;
struct inode *inode = path->dentry->d_inode;
+   struct super_block *sb = inode->i_sb;
struct inode *delegated_inode = NULL;
 
error = mnt_want_write(path->mnt);
@@ -68,16 +69,24 @@ static int utimes_common(struct path *path, struct timespec 
*times)
if (times[0].tv_nsec == UTIME_OMIT)
newattrs.ia_valid &= ~ATTR_ATIME;
else if (times[0].tv_nsec != UTIME_NOW) {
-   newattrs.ia_atime.tv_sec = times[0].tv_sec;
-   newattrs.ia_atime.tv_nsec = times[0].tv_nsec;
+   newattrs.ia_atime.tv_sec =
+   clamp_t(time64_t, times[0].tv_sec, 
sb->s_time_min, sb->s_time_max);
+   if (times[0].tv_sec >= sb->s_time_max)
+   newattrs.ia_atime.tv_nsec = 0;
+   else
+   newattrs.ia_atime.tv_nsec = times[0].tv_nsec;
newattrs.ia_valid |= ATTR_ATIME_SET;
}
 
if (times[1].tv_nsec == UTIME_OMIT)
newattrs.ia_valid &= ~ATTR_MTIME;
else if (times[1].tv_nsec != UTIME_NOW) {
-   newattrs.ia_mtime.tv_sec = times[1].tv_sec;
-   newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
+   newattrs.ia_atime.tv_sec =
+   clamp_t(time64_t, times[0].tv_sec, 
sb->s_time_min, sb->s_time_max);
+   if (times[0].tv_sec >= sb->s_time_max)
+   newattrs.ia_atime.tv_nsec = 0;
+   else
+   newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
newattrs.ia_valid |= ATTR_MTIME_SET;
}
/*
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 4/6] ext4: Initialize timestamps limits

2016-11-02 Thread Deepa Dinamani
ext4 has different overflow limits for max filesystem
timestamps based on the extra bytes available.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: "Theodore Ts'o" <ty...@mit.edu>
Cc: Andreas Dilger <adilger.ker...@dilger.ca>
Cc: linux-e...@vger.kernel.org
---
 fs/ext4/ext4.h  | 4 
 fs/ext4/super.c | 7 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 6789379..fca339a 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1635,6 +1635,10 @@ static inline void ext4_clear_state_flags(struct 
ext4_inode_info *ei)
 
 #define EXT4_GOOD_OLD_INODE_SIZE 128
 
+#define EXT4_EXTRA_TIMESTAMP_MAX   (((s64)1 << 34) - 1  + S32_MIN)
+#define EXT4_NON_EXTRA_TIMESTAMP_MAX   Y2038_EXPIRY_TIMESTAMP
+#define EXT4_TIMESTAMP_MIN S32_MIN
+
 /*
  * Feature set definitions
  */
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index ab00bff..ebd039d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3633,8 +3633,13 @@ static int ext4_fill_super(struct super_block *sb, void 
*data, int silent)
   sbi->s_inode_size);
goto failed_mount;
}
-   if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
+   if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
+   sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
+   } else
+   sb->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX;
+
+   sb->s_time_min = EXT4_TIMESTAMP_MIN;
}
 
sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 5/6] vfs: Add timestamp_truncate() api

2016-11-02 Thread Deepa Dinamani
timespec_trunc() function is used to truncate a
filesystem timestamp to the right granularity.
But, the function does not clamp tv_sec part of the
timestamps according to the filesystem timestamp limits.

Also, timespec_trunc() is exclusively used for filesystem
timestamps. Move the api to be part of vfs.

The replacement api: timestamp_truncate() also alters the
signature of the function to accommodate filesystem
timestamp clamping according to flesystem limits.

Note that clamp_t macro is used for clamping here as vfs
is not yet using struct timespec64 internally. This is
only for compilation purposes.
The actual patch can only be merged after the vfs is
transitioned to use timespec64 for correct operation of
clamp macro. At which point, clamp_t() will be replaced
by clamp().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/inode.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index 7b2b78d..f9285f2 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2106,6 +2106,36 @@ void inode_nohighmem(struct inode *inode)
 EXPORT_SYMBOL(inode_nohighmem);
 
 /**
+ * fs_timespec_trunc - Truncate timespec to a granularity
+ * @t: Timespec
+ * @gran: Granularity in ns.
+ *
+ * Truncate a timespec to a granularity. Always rounds down. gran must
+ * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns).
+ */
+struct timespec timestamp_truncate(struct timespec t, struct inode *inode)
+{
+   struct super_block *sb = inode->i_sb;
+   unsigned int gran = sb->s_time_gran;
+
+   t.tv_sec = clamp_t(time64_t, t.tv_sec, sb->s_time_min, sb->s_time_max);
+
+   /* Avoid division in the common cases 1 ns and 1 s. */
+   if (gran == 1) {
+   /* nothing */
+   } else if (gran == NSEC_PER_SEC) {
+   t.tv_nsec = 0;
+   } else if (gran > 1 && gran < NSEC_PER_SEC) {
+   t.tv_nsec -= t.tv_nsec % gran;
+   } else {
+   WARN(1, "illegal file time granularity: %u", gran);
+   }
+   return t;
+}
+EXPORT_SYMBOL(timestamp_truncate);
+
+
+/**
  * current_time - Return FS time
  * @inode: inode.
  *
@@ -2124,6 +2154,6 @@ struct timespec current_time(struct inode *inode)
return now;
}
 
-   return timespec_trunc(now, inode->i_sb->s_time_gran);
+   return timestamp_truncate(now, inode);
 }
 EXPORT_SYMBOL(current_time);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RFC 0/6] vfs: Add timestamp range check support

2016-11-02 Thread Deepa Dinamani
The series is aimed at adding timestamp checking and policy
related to it to vfs.

The series was developed with discussions and guidance from
Arnd Bergmann.

The original idea for the series was the discussion:
https://lkml.org/lkml/2014/5/30/551

Patches 5 and 6 can be merged only after vfs is transitioned
to use 64 bit timestamps as noted in the respective commit
texts.

The series only includes adding range limits to filesystems:
ext4 and afs as examples to keep the series simple.
Every filesystem will be updated to add these limits.

There is an ext4 current_time() api replacement patch that the
series depends on:
https://lkml.org/lkml/2016/6/9/38 .
This needs reposting to the mailing list.

The branch for the tree along with dependency can be found at

https://github.com/deepa-hub/vfs.git refs/heads/vfs_timestamp_policy

Deepa Dinamani (6):
  vfs: Add file timestamp range support
  vfs: Add checks for filesystem timestamp limits
  afs: Add time limits in the super block
  ext4: Initialize timestamps limits
  vfs: Add timestamp_truncate() api
  utimes: Clamp the timestamps before update

 fs/afs/super.c  |  2 ++
 fs/ext4/ext4.h  |  4 
 fs/ext4/super.c |  7 ++-
 fs/inode.c  | 37 -
 fs/internal.h   |  2 ++
 fs/libfs.c  |  4 
 fs/namespace.c  | 12 
 fs/super.c  |  8 
 fs/utimes.c | 17 +
 include/linux/fs.h  |  4 
 include/linux/time64.h  |  6 ++
 include/uapi/linux/fs.h |  6 +-
 kernel/sysctl.c |  7 +++
 13 files changed, 109 insertions(+), 7 deletions(-)

-- 
2.7.4

Cc: linux-...@lists.infradead.org
Cc: "Theodore Ts'o" <ty...@mit.edu>
Cc: Andreas Dilger <adilger.ker...@dilger.ca>
Cc: linux-e...@vger.kernel.org


___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] xfs_io: implement 'utimes' command

2016-12-17 Thread Deepa Dinamani
Add the utimes command to provide a way to utilize
the futimens C library call. This is the
interface to the utimensat system call, which updates
the mtime and atime of a file.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 include/input.h   |  1 +
 io/Makefile   |  2 +-
 io/init.c |  1 +
 io/io.h   |  1 +
 io/utimes.c   | 84 +++
 libxcmd/input.c   | 22 +++
 man/man8/xfs_io.8 | 12 
 7 files changed, 122 insertions(+), 1 deletion(-)
 create mode 100644 io/utimes.c

diff --git a/include/input.h b/include/input.h
index d02170f..221678e 100644
--- a/include/input.h
+++ b/include/input.h
@@ -48,6 +48,7 @@ extern uid_t  uid_from_string(char *user);
 extern gid_t   gid_from_string(char *group);
 extern prid_t  prid_from_string(char *project);
 extern boolisdigits_only(const char *str);
+extern int timespec_from_string(const char *sec, const char *nsec, struct 
timespec *ts);
 
 #define HAVE_FTW_H 1   /* TODO: configure me */
 
diff --git a/io/Makefile b/io/Makefile
index 62bc03b..392e02a 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -11,7 +11,7 @@ HFILES = init.h io.h
 CFILES = init.c \
attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c link.c \
mmap.c open.c parent.c pread.c prealloc.c pwrite.c seek.c shutdown.c \
-   sync.c truncate.c reflink.c
+   sync.c truncate.c reflink.c utimes.c
 
 LLDLIBS = $(LIBXCMD) $(LIBHANDLE)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE)
diff --git a/io/init.c b/io/init.c
index efe7390..6319aeb 100644
--- a/io/init.c
+++ b/io/init.c
@@ -85,6 +85,7 @@ init_commands(void)
sync_range_init();
truncate_init();
reflink_init();
+   utimes_init();
 }
 
 static int
diff --git a/io/io.h b/io/io.h
index 2bc7ac4..fddd7a3 100644
--- a/io/io.h
+++ b/io/io.h
@@ -113,6 +113,7 @@ extern void seek_init(void);
 extern voidshutdown_init(void);
 extern voidsync_init(void);
 extern voidtruncate_init(void);
+extern voidutimes_init(void);
 
 #ifdef HAVE_FADVISE
 extern voidfadvise_init(void);
diff --git a/io/utimes.c b/io/utimes.c
new file mode 100644
index 000..1465762
--- /dev/null
+++ b/io/utimes.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2016 Deepa Dinamani
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t utimes_cmd;
+
+static void
+utimes_help(void)
+{
+   printf(_(
+"\n"
+" Update file atime and mtime of the current file with nansecond precision.\n"
+"\n"
+" Usage: utimes atime_sec atime_nsec mtime_sec mtime_nsec.\n"
+" *_sec: Seconds elapsed since 1970-01-01 00:00:00 UTC.\n"
+" *_nsec: Nanoseconds since the corresponding *_sec.\n"
+"\n"));
+}
+
+static int
+utimes_f(
+   int argc,
+   char**argv)
+{
+   struct timespec t[2];
+   int result;
+
+   if (argc != 5)
+   return command_usage(_cmd);
+
+   /* Get the timestamps */
+   result = timespec_from_string(argv[1], argv[2], [0]);
+   if (result) {
+   fprintf(stderr, "Bad value for atime\n");
+   return 1;
+   }
+   result = timespec_from_string(argv[3], argv[4], [1]);
+   if (result) {
+   fprintf(stderr, "Bad value for mtime\n");
+   return 1;
+   }
+
+   /* Call futimens to update time. */
+   if (futimens(file->fd, t)) {
+   perror("futimens");
+   return 1;
+   }
+
+   return 0;
+}
+
+void
+utimes_init(void)
+{
+   utimes_cmd.name = "utimes";
+   utimes_cmd.cfunc = utimes_f;
+   utimes_cmd.argmin = 4;
+   utimes_cmd.argmax = 4;
+   utimes_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+   utimes_cmd.args = _("atime_sec atime_nsec mtime_sec mtime_nsec");
+   utimes_cmd.oneline = _("Update file times of the current file");
+   utimes_cmd.help = utimes_help;
+
+   add_command(_cmd);
+}
diff --git a/libxcmd/input.c b/libxcmd/input.c
index 5a7dce3..2fdb3e8 100644
--- a/libxcmd/input.c
+++ b/libxcmd/

[Y2038] [LSF/MM TOPIC] Making VFS y2038 ready

2017-01-10 Thread Deepa Dinamani
I would like to discuss approaches to finish preparing the kernel to
be y2038 ready.

Arnd started the effort a few years ago and I'm working on a few parts
of the problem.

Background:

The y2038 problem arises because of time_t being defined as long,
which is different between 32-bit and 64-bit systems. This leaves
insufficient bits to represent time on a 32-bit system from the year
2038. time_t data type conversions can be broadly divided into the
following sub categories:

* Internal kernel usage of time_t

* UAPI interfaces with time_t and derived types

* Userspace applications using time_t

Discussion motivation:

The solution to use a larger data type to represent time is rather
straightforward and is agreed upon:
Replace all time_t occurrences by time64_t, which is always defined to be s64.

The tricky part is how to reach the goal of this transition without
breaking backward compatibility of interfaces internal and external to
the kernel. This can be done in more than one way. After long
discussions, we have managed to get some initial clean up patches
merged. These will help the VFS transition to using time64_t. It is
now a good time to look at the remaining problems in changing time_t.

Discussion topics:

The following are some key issues particularly needing discussion:

1. Time types we plan to retain within the kernel and in system APIs.
We posted multiple series, there have been a few changes since then.

https://lkml.org/lkml/2014/5/30/669

https://lkml.org/lkml/2016/1/7/20

2. Syscall transition: Arnd had posted a version of this. There are a
few updates here as well. I intend to post an update soon.

https://sourceware.org/ml/libc-alpha/2015-05/msg00070.html

3. Policy for filesystems that do not support a y2038 safe on-disk
representation: I posted a series and the initial xfstest patch.

https://lwn.net/Articles/705358/

https://www.spinics.net/lists/y2038/msg01945.html

4. VFS transition to using struct timespec64: I posted a few revisions
and our approach has changed for the cleanup patches. A discussion
would help pick an approach.

   https://lwn.net/Articles/675381/

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH] generic/390: Add tests for inode timestamp policy

2016-12-02 Thread Deepa Dinamani
> Need an entry in .gitignore file too.

Will add this.

>>  SUBDIRS =
>>
>> diff --git a/src/y2038_futimens.c b/src/y2038_futimens.c
>> new file mode 100644
>> index 000..291e4fa
>> --- /dev/null
>> +++ b/src/y2038_futimens.c
>> @@ -0,0 +1,61 @@
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +int
>> +do_utime(int fd, long long time)
>> +{
>> + struct timespec t[2];
>> +
>> + /*
>> +  * Convert long long to timespec format.
>> +  * Seconds precision is assumed here.
>> +  */
>> + t[0].tv_sec = time;
>> + t[0].tv_nsec = 0;
>> + t[1].tv_sec = time;
>> + t[1].tv_nsec = 0;
>> +
>> + /* Call utimens to update time. */
>> + if (futimens(fd, t)) {
>> + perror("futimens");
>> + return 1;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +int
>> +main(int argc, char **argv)
>> +{
>> + int fd;
>> + long long time;
>> +
>> + if(argc < 3) {
>> + fprintf(stderr, "Usage: %s filename timestamp\n"
>> + "Filename: file to be created or 
>> opened in current directory\n"
>> + "Timestamp: is seconds since 
>> 1970-01-01 00:00:00 UTC\n", argv[0]);
>> + exit(1);
>
> Seems there's no need for an extra level of indention :)

Ok, will fix this.

>> + }
>> +
>> + /* Create the file */
>> + fd = creat(argv[1], 0666);
>> + if(fd < 0) {
>> + perror("creat");
>> + exit(1);
>> + }
>> +
>> + /* Get the timestamp */
>> + time = strtoull(argv[2], NULL, 0);
>> + if (errno) {
>
> From errno(3), errno is never set to zero by any system call or library
> function, so errno isn't reset to zero on strtoull and this check always
> fails for me, with errno = ENOENT, because:
>
> ...
> access("/usr/share/dracut/modules.d/01fips", F_OK) = -1 ENOENT (No such file 
> or directory)
> ...
> write(4, "strtoull: No such file or direct"..., 36strtoull: No such file or 
> directory
>
> the errno was from access(2) call in my case.

Right. Man page for strtoull() says:

Since strtoul() can legitimately return 0 or ULONG_MAX (ULLONG_MAX for
strtoull()) on both success and failure, the calling program should
set errno to 0 before the call, and then determine if an error
occurred by checking whether errno has a nonzero value after the call.

I will set errno to 0 before strtoull().
Thanks.

>> diff --git a/tests/generic/390 b/tests/generic/390
>> new file mode 100755
>> index 000..f069988
>> --- /dev/null
>> +++ b/tests/generic/390
>> @@ -0,0 +1,238 @@
>> +#! /bin/bash
>> +# FS QA Test No. generic/390
>> +#
>> +# Tests to verify policy for filesystem timestamps for
>> +# supported ranges:
>> +# 1. Verify filesystem rw mount according to sysctl
>> +# timestamp_supported.
>> +# 2. Verify timestamp clamping for timestamps beyond max
>> +# timestamp supported.
>> +#
>> +# Exit status 1: either or both tests above fail.
>> +# Exit status 0: both the above tests pass.
>
> Please use "./new" script to generate template, which contains all
> necessary initial setups and the copyright info.

Thanks, will do.

>> +
>> +seq=`basename $0`
>> +seqres=$RESULT_DIR/$seq
>> +echo "QA output created by $seq"
>> +#echo "output in $seqres.full"
>> +here=`pwd`
>> +
>> +# Get standard environment, filters and checks.
>> +. ./common/rc
>> +. ./common/filter
>> +. ./common/attr
>> +
>> +SRC_GROUPS=`find tests -not -path tests -type d -printf "%f "`
>
> What's this for? Seems it's not used in the test.

Yes, this is not required. Leftovers from some previous version of the test.
Thanks.

>> +
>> +# Prerequisites for the test run.
>> +_supported_fs generic
>> +_supported_os Linux
>> +_require_scratch
>
> Need to check the existence of y2038_futimens program, to make sure it's
> really built, e.g.
>
> _require_test_program "y2038_futimens"

Will add this


>> +Y2038_PROG=$here/src/y2038_futimens
>> +
>> +#initialize exit status
>> +status=0
>
> We use 1 as the default value of status, so you can just "exit" on
> failure (because trap will catch the signal and exit with $status again)
> and only set status=0 and exit when test passes. "./new" already sets it
> up for you :)

Will take care of this.

>> +
>> +# Generic test cleanup function.
>> +_cleanup()
>> +{
>> +# Remove any leftover files from last run.
>> +rm -f ${SCRATCH_MNT}/test_?
>
> No need to cleanup files on SCRATCH_DEV, it's meant to be mkfs'ed every
> time before using it.

Ok, makes sense. I will remove this clean up.

>> +#unmount and mount  $SCRATCH_DEV.
>> +_umount_mount_scratch_dev()
>
> There's a helper to do this: _scratch_cycle_mount, only that it doesn't
> change PWD. And if you don't want to write $SCRATCH_MNT again, this is
> what we do usually in fstests:
>
> testfile=$SCRATCH_MNT/
> ...
> do_test $testfile

Thanks, will change it similar to what you suggest.

>> +{
>> +#change directory so that you are not using 

Re: [Y2038] [PATCH] generic/390: Add tests for inode timestamp policy

2016-12-02 Thread Deepa Dinamani
>> > +_filesystem_timestamp_range()
>> > +{
>> > +   device=${1:-$TEST_DEV}
>> > +   case $FSTYP in
>> > +   ext4)   #dumpe2fs
>> > +   if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | 
>> > cut -d: -f2) -gt 128 ]; then
>> > +   echo "-2147483648 15032385535"
>> > +   else
>> > +   echo "-2147483648 2147483647"
>> > +   fi
>>
>> Do ext3 and ext2 follow the same config as ext4?
>
> Those two only support the second case with 128 byte inodes, but the same
> check should work on all three.
>
> I have an overview of the limits on https://kernelnewbies.org/y2038/vfs,
> though I'd probably check all of them again, as some of them turned out
> to be wrong. In particular, identifying whether the on-disk timestamps
> are meant to be signed or unsigned can be a matter of interpretation
> and there may be a specification that disagrees with the implementation.

Right now I've only added tests for a few filesystems.
The plan is to add more filesystems later after we agree on the test.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [GIT PULL] [PATCH v4 00/26] Delete CURRENT_TIME and CURRENT_TIME_SEC macros

2017-01-01 Thread Deepa Dinamani
The series is aimed at getting rid of CURRENT_TIME and CURRENT_TIME_SEC macros.
The macros are not y2038 safe. There is no plan to transition them into being
y2038 safe.
ktime_get_* api's can be used in their place. And, these are y2038 safe.

Thanks to Arnd Bergmann for all the guidance and discussions.

Patches 2-4 were mostly generated using coccinelle scripts.

All filesystem timestamps use current_fs_time() for right granularity as
mentioned in the respective commit texts of patches. This has a changed
signature, renamed to current_time() and moved to the fs/inode.c.

This series also serves as a preparatory series to transition vfs to 64 bit
timestamps as outlined here: https://lkml.org/lkml/2016/2/12/104 .

As per Linus's suggestion in https://lkml.org/lkml/2016/5/24/663 , all the
inode timestamp changes have been squashed into a single patch. Also,
current_time() now is used as a single generic vfs filesystem timestamp api.
It also takes struct inode* as argument instead of struct super_block*.
Posting all patches together in a bigger series so that the big picture is
clear.

As per the suggestion in https://lwn.net/Articles/672598/, CURRENT_TIME macro
bug fixes are being handled in a series separate from transitioning vfs to
use 64 bit timestamps.

Changes from v3:
* Rebased to 4.8-rc1 to avoid merge conflicts.
* Added CURRENT_TIME deletion and fnic patches back as time64_to_tm() is merged.
* Rearranged a couple of instances of CURRENT_TIME.

Changes from v2:
* Fix buildbot error for uninitialized sb in inode.
* Minor fixes according to Arnd's comments.
* Leave out the fnic and deletion of CURRENT_TIME to be submitted after 4.8 rc1.

Changes from v1:
* Change current_fs_time(struct super_block *) to current_time(struct inode *)
* Note that change to add time64_to_tm() is already part of John's
  kernel tree: https://lkml.org/lkml/2016/6/17/875 .

---

The following changes since commit 09f0834105f7fe315ddaeb77fad15f00565c167e:

  Add linux-next specific files for 20160809 (2016-08-09 13:48:00 +1000)

are available in the git repository at:

  https://github.com/deepa-hub/vfs current_time-v4.8-rc1

for you to fetch changes up to 050e25f5112626e228b742ed219314abc409a70f:

  time: Delete CURRENT_TIME_SEC and CURRENT_TIME (2016-08-13 13:44:41 -0700)


Deepa Dinamani (26):
  vfs: Add current_time() api
  fs: proc: Delete inode time initializations in proc_alloc_inode()
  fs: Replace CURRENT_TIME with current_time() for inode timestamps
  fs: Replace CURRENT_TIME_SEC with current_time() for inode timestamps
  fs: Replace current_fs_time() with current_time()
  fs: ufs: Use ktime_get_real_ts64() for birthtime
  fs: jfs: Replace CURRENT_TIME_SEC by current_time()
  fs: ext4: Use current_time() for inode timestamps
  fs: ubifs: Replace CURRENT_TIME_SEC with current_time
  fs: btrfs: Use ktime_get_real_ts for root ctime
  fs: udf: Replace CURRENT_TIME with current_time()
  fs: cifs: Replace CURRENT_TIME by current_time()
  fs: cifs: Replace CURRENT_TIME with ktime_get_real_ts()
  fs: cifs: Replace CURRENT_TIME by get_seconds
  fs: f2fs: Use ktime_get_real_seconds for sit_info times
  drivers: staging: lustre: Replace CURRENT_TIME with current_time()
  fs: ocfs2: Use time64_t to represent orphan scan times
  fs: ocfs2: Replace CURRENT_TIME macro
  audit: Use timespec64 to represent audit timestamps
  fs: nfs: Make nfs boot time y2038 safe
  block: Replace CURRENT_TIME with ktime_get_real_ts
  libceph: Replace CURRENT_TIME with ktime_get_real_ts
  fs: ceph: Replace current_fs_time for request stamp
  fnic: Use time64_t to represent trace timestamps
  time: Delete current_fs_time() function
  time: Delete CURRENT_TIME_SEC and CURRENT_TIME

 arch/powerpc/platforms/cell/spufs/inode.c  |  2 +-
 arch/s390/hypfs/inode.c|  4 +--
 drivers/block/rbd.c|  2 +-
 drivers/char/sonypi.c  |  2 +-
 drivers/infiniband/hw/qib/qib_fs.c |  2 +-
 drivers/misc/ibmasm/ibmasmfs.c |  2 +-
 drivers/oprofile/oprofilefs.c  |  2 +-
 drivers/platform/x86/sony-laptop.c |  2 +-
 drivers/scsi/fnic/fnic_trace.c |  4 +--
 drivers/scsi/fnic/fnic_trace.h |  2 +-
 drivers/staging/lustre/lustre/llite/llite_lib.c| 16 ++--
 drivers/staging/lustre/lustre/llite/namei.c|  4 +--
 drivers/staging/lustre/lustre/mdc/mdc_reint.c  |  6 ++---
 .../lustre/lustre/obdclass/linux/linux-obdo.c  |  6 ++---
 drivers/staging/lustre/lustre/obdclass/obdo.c  |  6 ++---
 drivers/staging/lustre/lustre/osc/osc_io.c |  2 +-
 drivers/usb/core/devio.c   | 18 +++---
 drivers/usb/gadget/function/f_fs.c |  8 +++---
 drivers/usb/gadget/legacy/inode.c

Re: [Y2038] [GIT PULL] [PATCH v4 00/26] Delete CURRENT_TIME and CURRENT_TIME_SEC macros

2017-01-01 Thread Deepa Dinamani
Thank you for the suggestion.

> Who are you execting to pull this huge patch series?

The last pull request was addressed to Al as per Arnd's suggestion.
I'm not completely sure who should it be addressed to.

> Why not just introduce the new api call, wait for that to be merged, and
> then push the individual patches through the different subsystems?
> After half of those get ignored, then provide a single set of patches
> that can go through Andrew or my trees.

Arnd and I tried to do this a few ways.

We can try to introduce the api first like you suggest.

There are a few Acks already on the patches.
And, patches 2-5 also need to be merged through some common tree like
yours or Andrew's as you suggest.

So, if everyone is ok, I could do the following:

1. Post patches 1-5 for rc-2.
2. Post all other patches to respective maintainers after rc-2
3. Then after patches get ignored or merged, post remaining as a
series for you or Andrew to pick up.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2] generic/390: Add tests for inode timestamp policy

2016-12-30 Thread Deepa Dinamani
On Wed, Dec 28, 2016 at 3:05 AM, Eryu Guan <eg...@redhat.com> wrote:
> On Sat, Dec 24, 2016 at 07:38:13PM -0800, Deepa Dinamani wrote:
>> The test helps to validate clamping and mount behaviors
>> according to supported file system timestamp ranges.
>>
>> Note that the test can fail on 32-bit systems for a
>> few file systems. This will be corrected when vfs is
>> transitioned to use 64-bit timestamps.
>>
>> Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
>> ---
>> The branch of the kernel tree can be located at
>>
>> https://github.com/deepa-hub/vfs refs/heads/vfs_timestamp_policy
>>
>> The xfs_io patch to add utimes is at
>>
>> https://www.spinics.net/lists/linux-xfs/msg02952.html
>
> Thanks for this info! I built your test kernel and applied the xfs_io
> patch, and I got test failure on XFS, test passed on ext4 (256 inode
> size) without problems, is this expected?

Yes, this is expected.
Since kernel does not have actual limits for xfs filled in.
Although I need to fix the if condition(-gt needs to change to -ge) to
fail on mount here.

>> + f2fs)
>> + echo "-2147483648 2147483647"
>> + ;;
>> + *)
>> + echo "-1 -1"
>> + _notrun "filesystem $FSTYP timestamp bounds are unknown"
>
> This "_notrun" doesn't belong here. I think we can introduce a
> _require_y2038 rule. e.g.

Ok, I will merge this with require_y2038_sysfs() like what you suggest below.

> _require_y2038()
> {
> local device=${1:-$TEST_DEV}
> local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
> if [ ! -ne $sysfsdir ]; then
> _notrun "no kernel support for y2038 sysfs switch"
> fi
>
> local tsmin tsmax
> read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
> if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
> _notrun "filesystem $FSTYP timestamp bounds are unknown"
> fi
> }
>
> Then
>
> _scratch_mkfs
> _require_y2038 $SCRATCH_DEV
>
>> + ;;
>> + esac
>> +}
>> +
>>  # indicate whether YP/NIS is active or not
>>  #
>>  _yp_active()
>> @@ -2070,6 +2109,9 @@ _require_xfs_io_command()
>>   echo $testio | egrep -q "Inappropriate ioctl" && \
>>   _notrun "xfs_io $command support is missing"
>>   ;;
>> + "utimes" )
>> + testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
>> + ;;
>>   *)
>>   testio=`$XFS_IO_PROG -c "$command help" 2>&1`
>>   esac
>> diff --git a/tests/generic/390 b/tests/generic/390
>> new file mode 100755
>> index 000..8ccadad
>> + stat_timestamp=`stat -c"%X;%Y" $file`
>> +
>> + prev_timestamp="$timestamp;$timestamp"
>> + if [ $prev_timestamp != $stat_timestamp ]; then
>> + echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
>> + exit
>
> No need to exit here. We prefer continuing the test in fstests when such
> test failure happens, it enlarges the test coverage and exercises some
> error paths. One exception is that when continuing the test could result
> in blocking all subsequent tests, we should exit early, one example
> provided later.

Ok, will continue here.

>> +{
>> + file=$1
>> + timestamp=$2
>> + update_time=$3
>> +
>> + #check if the time needs update
>> + if [ $update_time -eq 1 ]; then
>> + echo "Updating file: $file to timestamp `date -d @$timestamp`" 
>>  >> $seqres.full
>> + $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
>> + if [ $? -ne 0 ]; then
>> + echo "Failed to update times on $file" | tee -a 
>> $seqres.full
>> + exit
>
> Same here.

Will do.

>> + #initialization iterator
>> + n=1
>> +
>> + for TIME in "${TIMESTAMPS[@]}"
>> + do
>> + #Run the test
>> + run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
>> +
>> + #update iterator
>> + ((n++))
>
> Seems the comments here are not necessary, initialize the iterator, run
> the test and update iterator are all obvious.

Will remove comments.

> And we prefer this code style in fstests:
> for

[Y2038] [PATCH v3] generic/390: Add tests for inode timestamp policy

2017-01-03 Thread Deepa Dinamani
The test helps to validate clamping and mount behaviors
according to supported file system timestamp ranges.

Note that the test can fail on 32-bit systems for a
few file systems. This will be corrected when vfs is
transitioned to use 64-bit timestamps.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
The branch of the kernel tree can be located at

https://github.com/deepa-hub/vfs refs/heads/vfs_timestamp_policy

The xfs_io patch to add utimes is at

https://www.spinics.net/lists/linux-xfs/msg02952.html

Changes since v2:
* Refactored notrun handling
* Updated comments

Changes since v1:
* Use xfs_io utimes command
* Updated error handling
* Reorganized code according to review comments

 common/rc |  48 +
 tests/generic/390 | 192 ++
 tests/generic/390.out |   2 +
 tests/generic/group   |   1 +
 4 files changed, 243 insertions(+)
 create mode 100755 tests/generic/390
 create mode 100644 tests/generic/390.out

diff --git a/common/rc b/common/rc
index e3b54ec..17f025e 100644
--- a/common/rc
+++ b/common/rc
@@ -1960,6 +1960,51 @@ _run_aiodio()
 return $status
 }
 
+# this test requires y2038 sysfs switch and filesystem
+# timestamp ranges support.
+_require_y2038()
+{
+   local device=${1:-$TEST_DEV}
+   local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
+
+   if [ ! -e $sysfsdir ]; then
+   _notrun "no kernel support for y2038 sysfs switch"
+   fi
+
+   local tsmin tsmax
+   read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
+   if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
+   _notrun "filesystem $FSTYP timestamp bounds are unknown"
+   fi
+}
+
+_filesystem_timestamp_range()
+{
+   device=${1:-$TEST_DEV}
+   case $FSTYP in
+   ext4)
+   if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | 
cut -d: -f2) -gt 128 ]; then
+   echo "-2147483648 15032385535"
+   else
+   echo "-2147483648 2147483647"
+   fi
+   ;;
+
+   xfs)
+   echo "-2147483648 2147483647"
+   ;;
+   jfs)
+   echo "0 4294967295"
+   ;;
+   f2fs)
+   echo "-2147483648 2147483647"
+   ;;
+   *)
+   echo "-1 -1"
+   ;;
+   esac
+}
+
 # indicate whether YP/NIS is active or not
 #
 _yp_active()
@@ -2070,6 +2115,9 @@ _require_xfs_io_command()
echo $testio | egrep -q "Inappropriate ioctl" && \
_notrun "xfs_io $command support is missing"
;;
+   "utimes" )
+   testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
+   ;;
*)
testio=`$XFS_IO_PROG -c "$command help" 2>&1`
esac
diff --git a/tests/generic/390 b/tests/generic/390
new file mode 100755
index 000..f68b931
--- /dev/null
+++ b/tests/generic/390
@@ -0,0 +1,192 @@
+#! /bin/bash
+# FS QA Test 390
+#
+# Tests to verify policy for filesystem timestamps for
+# supported ranges:
+# 1. Verify filesystem rw mount according to sysctl
+# timestamp_supported.
+# 2. Verify timestamp clamping for timestamps beyond max
+# timestamp supported.
+#
+# Exit status 1: either or both tests above fail.
+# Exit status 0: both the above tests pass.
+#
+#---
+# Copyright (c) 2016 Deepa Dinamani.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1   # failure is the default!
+trap "exit \$status" 0 1 2 3 15
+
+# Get standard environment, filters and checks.
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# Prerequisites for the test run.
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_xfs_io_command utimes
+
+# Compare file timestamps obtained from stat
+# wit

Re: [Y2038] [PATCH v2] xfs_io: implement 'utimes' command

2016-12-29 Thread Deepa Dinamani
>> Add the utimes command to provide a way to utilize
>> the futimens C library call. This is the
>> interface to the utimensat system call, which updates
>> the mtime and atime of a file.
>>
>> Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
>> ---
>> Changes since v1:
>> * changed error return values
>> * removed redundant roff formatting directive
>> * removed unneeded argument count check
>>
>>  include/input.h   |  1 +
>>  io/Makefile   |  2 +-
>>  io/init.c |  1 +
>>  io/io.h   |  1 +
>>  io/utimes.c   | 81 
>> +++
>>  libxcmd/input.c   | 22 +++
>>  man/man8/xfs_io.8 | 11 
>>  7 files changed, 118 insertions(+), 1 deletion(-)
>>  create mode 100755 io/utimes.c
>>  mode change 100644 => 100755 libxcmd/input.c
>
> Just one nit, I think c files should not have "x" in file modes.

Yes, my bad.
Will post an update with this fixed.

Thanks,
Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] xfs_io: implement 'utimes' command

2016-12-19 Thread Deepa Dinamani
Add the utimes command to provide a way to utilize
the futimens C library call. This is the
interface to the utimensat system call, which updates
the mtime and atime of a file.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
Changes since v1:
* changed error return values
* removed redundant roff formatting directive
* removed unneeded argument count check

 include/input.h   |  1 +
 io/Makefile   |  2 +-
 io/init.c |  1 +
 io/io.h   |  1 +
 io/utimes.c   | 81 +++
 libxcmd/input.c   | 22 +++
 man/man8/xfs_io.8 | 11 
 7 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100755 io/utimes.c
 mode change 100644 => 100755 libxcmd/input.c

diff --git a/include/input.h b/include/input.h
index d02170f..221678e 100644
--- a/include/input.h
+++ b/include/input.h
@@ -48,6 +48,7 @@ extern uid_t  uid_from_string(char *user);
 extern gid_t   gid_from_string(char *group);
 extern prid_t  prid_from_string(char *project);
 extern boolisdigits_only(const char *str);
+extern int timespec_from_string(const char *sec, const char *nsec, struct 
timespec *ts);
 
 #define HAVE_FTW_H 1   /* TODO: configure me */
 
diff --git a/io/Makefile b/io/Makefile
index 62bc03b..392e02a 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -11,7 +11,7 @@ HFILES = init.h io.h
 CFILES = init.c \
attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c link.c \
mmap.c open.c parent.c pread.c prealloc.c pwrite.c seek.c shutdown.c \
-   sync.c truncate.c reflink.c
+   sync.c truncate.c reflink.c utimes.c
 
 LLDLIBS = $(LIBXCMD) $(LIBHANDLE)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE)
diff --git a/io/init.c b/io/init.c
index efe7390..6319aeb 100644
--- a/io/init.c
+++ b/io/init.c
@@ -85,6 +85,7 @@ init_commands(void)
sync_range_init();
truncate_init();
reflink_init();
+   utimes_init();
 }
 
 static int
diff --git a/io/io.h b/io/io.h
index 2bc7ac4..fddd7a3 100644
--- a/io/io.h
+++ b/io/io.h
@@ -113,6 +113,7 @@ extern void seek_init(void);
 extern voidshutdown_init(void);
 extern voidsync_init(void);
 extern voidtruncate_init(void);
+extern voidutimes_init(void);
 
 #ifdef HAVE_FADVISE
 extern voidfadvise_init(void);
diff --git a/io/utimes.c b/io/utimes.c
new file mode 100755
index 000..faf9b8d
--- /dev/null
+++ b/io/utimes.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016 Deepa Dinamani
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t utimes_cmd;
+
+static void
+utimes_help(void)
+{
+   printf(_(
+"\n"
+" Update file atime and mtime of the current file with nansecond precision.\n"
+"\n"
+" Usage: utimes atime_sec atime_nsec mtime_sec mtime_nsec.\n"
+" *_sec: Seconds elapsed since 1970-01-01 00:00:00 UTC.\n"
+" *_nsec: Nanoseconds since the corresponding *_sec.\n"
+"\n"));
+}
+
+static int
+utimes_f(
+   int argc,
+   char**argv)
+{
+   struct timespec t[2];
+   int result;
+
+   /* Get the timestamps */
+   result = timespec_from_string(argv[1], argv[2], [0]);
+   if (result) {
+   fprintf(stderr, "Bad value for atime\n");
+   return 0;
+   }
+   result = timespec_from_string(argv[3], argv[4], [1]);
+   if (result) {
+   fprintf(stderr, "Bad value for mtime\n");
+   return 0;
+   }
+
+   /* Call futimens to update time. */
+   if (futimens(file->fd, t)) {
+   perror("futimens");
+   return 0;
+   }
+
+   return 0;
+}
+
+void
+utimes_init(void)
+{
+   utimes_cmd.name = "utimes";
+   utimes_cmd.cfunc = utimes_f;
+   utimes_cmd.argmin = 4;
+   utimes_cmd.argmax = 4;
+   utimes_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+   utimes_cmd.args = _("atime_sec atime_nsec mtime_sec mtime_nsec");
+   utimes_cmd.oneline = _("Update file times of the current file");
+   utimes_cmd.help = utimes_help;
+
+   add_command(_c

Re: [Y2038] [PATCH] xfs_io: implement 'utimes' command

2016-12-18 Thread Deepa Dinamani
>> + if (argc != 5)
>> + return command_usage(_cmd);
>
> Because you set argsmin & argsmax to 4, it should be impossible
> to get here with anything other than argc=5 - it's caught
> elsewhere:

Yes, you are right. This was something I was using to debug.
I will remove this. Thanks.

>> + /* Get the timestamps */
>> + result = timespec_from_string(argv[1], argv[2], [0]);
>> + if (result) {
>> + fprintf(stderr, "Bad value for atime\n");
>> + return 1;
>> + }
>> + result = timespec_from_string(argv[3], argv[4], [1]);
>> + if (result) {
>> + fprintf(stderr, "Bad value for mtime\n");
>> + return 1;
>> + }
>> +
>> + /* Call futimens to update time. */
>> + if (futimens(file->fd, t)) {
>> + perror("futimens");
>> + return 1;
>> + }
>
> Most xfs_io functions return 0 even on errors, possibly after
> setting exit_code = 1 to change the ultimate exit code;
> returning 1 will cause all processing to stop, and/or kick you
> out of the interactive shell:
>
> $ xfs_io file
> xfs_io> utimes a b c d
> Bad value for atime
> $
>
> This needs some attention across all of xfs_io, but you might want
> to return 0 for now for consistency with other commands.

Will change to return 0 always. Thanks.

>>  /*
>> + * Convert from a pair of arbitrary user strings into a timespec.
>> + */
>> +
>> +int
>> +timespec_from_string(
>> + const char  * secs,
>> + const char  * nsecs,
>> + struct timespec * ts)
>> +{
>> + char* p;
>> + if (!secs || !nsecs || !ts)
>> + return -1;
>> + ts->tv_sec = strtoull(secs, , 0);
>> + if (*p)
>> + return -1;
>> + ts->tv_nsec = strtoull(nsecs, , 0);
>> + if (*p)
>> + return -1;
>> + return 0;
>
> I'd return 1/0 not -1/0 - not that big a deal, but the reason
> the i.e. prid_from_string() functions return -1 on error
> is because they actually return an ID, which is >= 0, so
> it detects "== -1" as an error, and can't simply test
> 1/0.

Ok. Will change this to return 1/0.

>> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
>> index 2c56f09..3ffe439 100644
>> --- a/man/man8/xfs_io.8
>> +++ b/man/man8/xfs_io.8
>> @@ -589,6 +589,17 @@ Copy data into the open file beginning at
>>  Copy up to
>>  .I length
>>  bytes of data.
>> +.RE
>> +.PD
>> +.TP
>> +.TP
>
> don't need two .TPs, a patch to remove the others is pending.

Ok, will remove it.

I will wait for a couple of days to see if there are any more comments
before submitting a v2.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] generic/390: Add tests for inode timestamp policy

2016-12-24 Thread Deepa Dinamani
The test helps to validate clamping and mount behaviors
according to supported file system timestamp ranges.

Note that the test can fail on 32-bit systems for a
few file systems. This will be corrected when vfs is
transitioned to use 64-bit timestamps.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
The branch of the kernel tree can be located at

https://github.com/deepa-hub/vfs refs/heads/vfs_timestamp_policy

The xfs_io patch to add utimes is at

https://www.spinics.net/lists/linux-xfs/msg02952.html

Changes since v1:
* Use xfs_io utimes command
* Updated error handling
* Reorganized code according to review comments

 common/rc |  42 +++
 tests/generic/390 | 197 ++
 tests/generic/390.out |   2 +
 tests/generic/group   |   1 +
 4 files changed, 242 insertions(+)
 create mode 100755 tests/generic/390
 create mode 100644 tests/generic/390.out

diff --git a/common/rc b/common/rc
index e3b54ec..93c6e65 100644
--- a/common/rc
+++ b/common/rc
@@ -1960,6 +1960,45 @@ _run_aiodio()
 return $status
 }
 
+# this test requires y2038 sysfs switch support
+#
+_require_y2038_sysfs()
+{
+   sysfsdir=/proc/sys/fs/fs-timestamp-check-on
+
+   if [ ! -e $sysfsdir ]; then
+   _notrun "no kernel support for y2038 sysfs switch"
+   fi
+}
+
+_filesystem_timestamp_range()
+{
+   device=${1:-$TEST_DEV}
+   case $FSTYP in
+   ext4)
+   if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | 
cut -d: -f2) -gt 128 ]; then
+   echo "-2147483648 15032385535"
+   else
+   echo "-2147483648 2147483647"
+   fi
+   ;;
+
+   xfs)
+   echo "-2147483648 2147483647"
+   ;;
+   jfs)
+   echo "0 4294967295"
+   ;;
+   f2fs)
+   echo "-2147483648 2147483647"
+   ;;
+   *)
+   echo "-1 -1"
+   _notrun "filesystem $FSTYP timestamp bounds are unknown"
+   ;;
+   esac
+}
+
 # indicate whether YP/NIS is active or not
 #
 _yp_active()
@@ -2070,6 +2109,9 @@ _require_xfs_io_command()
echo $testio | egrep -q "Inappropriate ioctl" && \
_notrun "xfs_io $command support is missing"
;;
+   "utimes" )
+   testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
+   ;;
*)
testio=`$XFS_IO_PROG -c "$command help" 2>&1`
esac
diff --git a/tests/generic/390 b/tests/generic/390
new file mode 100755
index 000..8ccadad
--- /dev/null
+++ b/tests/generic/390
@@ -0,0 +1,197 @@
+#! /bin/bash
+# FS QA Test 390
+#
+# Tests to verify policy for filesystem timestamps for
+# supported ranges:
+# 1. Verify filesystem rw mount according to sysctl
+# timestamp_supported.
+# 2. Verify timestamp clamping for timestamps beyond max
+# timestamp supported.
+#
+# Exit status 1: either or both tests above fail.
+# Exit status 0: both the above tests pass.
+#
+#---
+# Copyright (c) 2016 Deepa Dinamani.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1   # failure is the default!
+trap "exit \$status" 0 1 2 3 15
+
+# Get standard environment, filters and checks.
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# Prerequisites for the test run.
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_xfs_io_command utimes
+_require_y2038_sysfs
+
+# Compare file timestamps obtained from stat
+# with a given timestamp.
+check_stat()
+{
+   file=$1
+   timestamp=$2
+
+   stat_timestamp=`stat -c"%X;%Y" $file`
+
+   prev_timestamp="$timestamp;$timestamp"
+   if [ $prev_timestamp != $stat_timestamp ]; then
+   echo "$prev_

Re: [Y2038] [PATCH 7/7] Change k_clock nsleep() to use timespec64

2017-03-21 Thread Deepa Dinamani
>> index f608941..97a883a 100644
>> --- a/include/linux/posix-timers.h
>> +++ b/include/linux/posix-timers.h
>> @@ -94,7 +94,7 @@ struct k_clock {
>> int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
>> int (*timer_create) (struct k_itimer *timer);
>> int (*nsleep) (const clockid_t which_clock, int flags,
>> -  struct timespec *, struct timespec __user *);
>> +  struct timespec64 *, struct timespec __user *);
>> long (*nsleep_restart) (struct restart_block *restart_block);
>
> You change one of the two arguments, but not the second one
> or the code in the restart handler that uses that __user pointer.
>
> Your patch is a good step in the right direction, and the second half
> of it is definitely complicated enough to be done in a separate
> patch, so I think it's good to keep them separate, just add
> explain why this is done one at a time.

Yes, this is intentional.
I was including the restart_block param in the syscall interfaces category.

I will make an explicit note in the commit text.

Thanks,
Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [RESEND PATCH 1/7] time: Delete do_sys_setimeofday()

2017-03-21 Thread Deepa Dinamani
>arch/alpha/kernel/osf_sys.c: In function 'SYSC_osf_settimeofday':
>>> arch/alpha/kernel/osf_sys.c:1032:9: error: implicit declaration of function 
>>> 'do_sys_settimeofday' [-Werror=implicit-function-declaration]
>  return do_sys_settimeofday(tv ?  : NULL, tz ?  : NULL);
> ^~~
>cc1: some warnings being treated as errors
>
> vim +/do_sys_settimeofday +1032 arch/alpha/kernel/osf_sys.c

I missed this do_sys_settimeofday() call.
I will fix this in v2.

Thanks,
Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] trace: Make trace_hwlat timestamp y2038 safe

2017-03-28 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines
and needs to be replaced by struct timespec64
in order to represent times beyond year 2038 on such
machines.

Fix all the timestamp representation in struct trace_hwlat
and all the corresponding implementations.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
-Changes from v1
* Added long long casts to fix kbuild warning

kernel/trace/trace_entries.h | 6 +++---
 kernel/trace/trace_hwlat.c   | 4 ++--
 kernel/trace/trace_output.c  | 9 -
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index c203ac4..adcdbbe 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -348,14 +348,14 @@ FTRACE_ENTRY(hwlat, hwlat_entry,
__field(u64,duration)
__field(u64,outer_duration  )
__field(u64,nmi_total_ts)
-   __field_struct( struct timespec,timestamp   )
-   __field_desc(   long,   timestamp,  tv_sec  )
+   __field_struct( struct timespec64,  timestamp   )
+   __field_desc(   s64,timestamp,  tv_sec  )
__field_desc(   long,   timestamp,  tv_nsec )
__field(unsigned int,   nmi_count   )
__field(unsigned int,   seqnum  )
),
 
-   
F_printk("cnt:%u\tts:%010lu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
+   
F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
 __entry->seqnum,
 __entry->tv_sec,
 __entry->tv_nsec,
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 21ea6ae..2257ff1 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -83,7 +83,7 @@ struct hwlat_sample {
u64 duration;   /* delta */
u64 outer_duration; /* delta (outer loop) */
u64 nmi_total_ts;   /* Total time spent in NMIs */
-   struct timespec timestamp;  /* wall time */
+   struct timespec64   timestamp;  /* wall time */
int nmi_count;  /* # NMIs during this sample */
 };
 
@@ -250,7 +250,7 @@ static int get_sample(void)
s.seqnum = hwlat_data.count;
s.duration = sample;
s.outer_duration = outer_sample;
-   s.timestamp = CURRENT_TIME;
+   ktime_get_real_ts64();
s.nmi_total_ts = nmi_total_ts;
s.nmi_count = nmi_count;
trace_hwlat_sample();
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 02a4aeb..08f9bab 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srost...@redhat.com>
  *
  */
-
 #include 
 #include 
 #include 
@@ -1161,11 +1160,11 @@ trace_hwlat_print(struct trace_iterator *iter, int 
flags,
 
trace_assign_type(field, entry);
 
-   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
+   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
 field->seqnum,
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec);
 
if (field->nmi_count) {
@@ -1195,10 +1194,10 @@ trace_hwlat_raw(struct trace_iterator *iter, int flags,
 
trace_assign_type(field, iter->ent);
 
-   trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
+   trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec,
 field->seqnum);
 
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v3] trace: Make trace_hwlat timestamp y2038 safe

2017-03-28 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines
and needs to be replaced by struct timespec64
in order to represent times beyond year 2038 on such
machines.

Fix all the timestamp representation in struct trace_hwlat
and all the corresponding implementations.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
-Changes from v1
 * Added long long casts to fix kbuild warning
-Changes from v2
 * Fixed style for struct hwlat_sample

kernel/trace/trace_entries.h |  6 +++---
 kernel/trace/trace_hwlat.c   | 14 +++---
 kernel/trace/trace_output.c  |  9 -
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index c203ac4..adcdbbe 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -348,14 +348,14 @@ FTRACE_ENTRY(hwlat, hwlat_entry,
__field(u64,duration)
__field(u64,outer_duration  )
__field(u64,nmi_total_ts)
-   __field_struct( struct timespec,timestamp   )
-   __field_desc(   long,   timestamp,  tv_sec  )
+   __field_struct( struct timespec64,  timestamp   )
+   __field_desc(   s64,timestamp,  tv_sec  )
__field_desc(   long,   timestamp,  tv_nsec )
__field(unsigned int,   nmi_count   )
__field(unsigned int,   seqnum  )
),
 
-   
F_printk("cnt:%u\tts:%010lu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
+   
F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
 __entry->seqnum,
 __entry->tv_sec,
 __entry->tv_nsec,
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 21ea6ae..d7c8e4e 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -79,12 +79,12 @@ static u64 last_tracing_thresh = DEFAULT_LAT_THRESHOLD * 
NSEC_PER_USEC;
 
 /* Individual latency samples are stored here when detected. */
 struct hwlat_sample {
-   u64 seqnum; /* unique sequence */
-   u64 duration;   /* delta */
-   u64 outer_duration; /* delta (outer loop) */
-   u64 nmi_total_ts;   /* Total time spent in NMIs */
-   struct timespec timestamp;  /* wall time */
-   int nmi_count;  /* # NMIs during this sample */
+   u64 seqnum; /* unique sequence */
+   u64 duration;   /* delta */
+   u64 outer_duration; /* delta (outer loop) */
+   u64 nmi_total_ts;   /* Total time spent in NMIs */
+   struct timespec64   timestamp;  /* wall time */
+   int nmi_count;  /* # NMIs during this sample */
 };
 
 /* keep the global state somewhere. */
@@ -250,7 +250,7 @@ static int get_sample(void)
s.seqnum = hwlat_data.count;
s.duration = sample;
s.outer_duration = outer_sample;
-   s.timestamp = CURRENT_TIME;
+   ktime_get_real_ts64();
s.nmi_total_ts = nmi_total_ts;
s.nmi_count = nmi_count;
trace_hwlat_sample();
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 02a4aeb..08f9bab 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srost...@redhat.com>
  *
  */
-
 #include 
 #include 
 #include 
@@ -1161,11 +1160,11 @@ trace_hwlat_print(struct trace_iterator *iter, int 
flags,
 
trace_assign_type(field, entry);
 
-   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
+   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
 field->seqnum,
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec);
 
if (field->nmi_count) {
@@ -1195,10 +1194,10 @@ trace_hwlat_raw(struct trace_iterator *iter, int flags,
 
trace_assign_type(field, iter->ent);
 
-   trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
+   trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->time

[Y2038] [PATCH v2 2/7] time: Change posix clocks ops interfaces to use timespec64

2017-03-26 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines.

The posix clocks apis use struct timespec directly and
through struct itimerspec.

Replace the posix clock interfaces to use
struct timespec64 and struct itimerspec64 instead.
Also fix up their implementations accordingly.

Note that the clock_getres() interface has also been changed
to use timespec64 even though this particular interface is
not affected by the y2038 problem. This helps verification for
internal kernel code for y2038 readiness by getting rid of
time_t/ timeval/ timespec.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: net...@vger.kernel.org
---
 drivers/ptp/ptp_clock.c | 18 +++---
 include/linux/posix-clock.h | 10 +-
 kernel/time/posix-clock.c   | 34 --
 3 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index e814280..b774357 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -97,30 +97,26 @@ static s32 scaled_ppm_to_ppb(long ppm)
 
 /* posix clock implementation */
 
-static int ptp_clock_getres(struct posix_clock *pc, struct timespec *tp)
+static int ptp_clock_getres(struct posix_clock *pc, struct timespec64 *tp)
 {
tp->tv_sec = 0;
tp->tv_nsec = 1;
return 0;
 }
 
-static int ptp_clock_settime(struct posix_clock *pc, const struct timespec *tp)
+static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 
*tp)
 {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
-   struct timespec64 ts = timespec_to_timespec64(*tp);
 
-   return  ptp->info->settime64(ptp->info, );
+   return  ptp->info->settime64(ptp->info, tp);
 }
 
-static int ptp_clock_gettime(struct posix_clock *pc, struct timespec *tp)
+static int ptp_clock_gettime(struct posix_clock *pc, struct timespec64 *tp)
 {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
-   struct timespec64 ts;
int err;
 
-   err = ptp->info->gettime64(ptp->info, );
-   if (!err)
-   *tp = timespec64_to_timespec(ts);
+   err = ptp->info->gettime64(ptp->info, tp);
return err;
 }
 
@@ -133,7 +129,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct 
timex *tx)
ops = ptp->info;
 
if (tx->modes & ADJ_SETOFFSET) {
-   struct timespec ts;
+   struct timespec64 ts;
ktime_t kt;
s64 delta;
 
@@ -146,7 +142,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct 
timex *tx)
if ((unsigned long) ts.tv_nsec >= NSEC_PER_SEC)
return -EINVAL;
 
-   kt = timespec_to_ktime(ts);
+   kt = timespec64_to_ktime(ts);
delta = ktime_to_ns(kt);
err = ops->adjtime(ops, delta);
} else if (tx->modes & ADJ_FREQUENCY) {
diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
index 34c4498..83b22ae 100644
--- a/include/linux/posix-clock.h
+++ b/include/linux/posix-clock.h
@@ -59,23 +59,23 @@ struct posix_clock_operations {
 
int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
 
-   int  (*clock_gettime)(struct posix_clock *pc, struct timespec *ts);
+   int  (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
 
-   int  (*clock_getres) (struct posix_clock *pc, struct timespec *ts);
+   int  (*clock_getres) (struct posix_clock *pc, struct timespec64 *ts);
 
int  (*clock_settime)(struct posix_clock *pc,
- const struct timespec *ts);
+ const struct timespec64 *ts);
 
int  (*timer_create) (struct posix_clock *pc, struct k_itimer *kit);
 
int  (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit);
 
void (*timer_gettime)(struct posix_clock *pc,
- struct k_itimer *kit, struct itimerspec *tsp);
+ struct k_itimer *kit, struct itimerspec64 *tsp);
 
int  (*timer_settime)(struct posix_clock *pc,
  struct k_itimer *kit, int flags,
- struct itimerspec *tsp, struct itimerspec *old);
+ struct itimerspec64 *tsp, struct itimerspec64 
*old);
/*
 * Optional character device methods:
 */
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 9cff0ab..e24008c 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -300,14 +300,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
 static int pc_clock_gettime(clockid_t id, struct timespec *ts)
 {
struct posix_clock_desc cd;
+   struct timespec64 ts64;
int err;
 
err = get_clock_

[Y2038] [PATCH v2 1/7] time: Delete do_sys_setimeofday()

2017-03-26 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines
and needs to be replaced with struct timespec64.

do_sys_timeofday() is just a wrapper function.
Replace all calls to this function with direct
calls to do_sys_timeofday64() instead and delete
do_sys_timeofday().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: linux-al...@vger.kernel.org
---
 arch/alpha/kernel/osf_sys.c |  4 +++-
 include/linux/timekeeping.h | 15 ---
 kernel/compat.c |  4 ++--
 kernel/time/posix-stubs.c   |  5 -
 kernel/time/posix-timers.c  |  5 -
 kernel/time/time.c  |  4 ++--
 6 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 0b96109..9de47a9 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1016,6 +1016,7 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user 
*, tv,
 SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
struct timezone __user *, tz)
 {
+   struct timespec64 kts64;
struct timespec kts;
struct timezone ktz;
 
@@ -1023,13 +1024,14 @@ SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 
__user *, tv,
if (get_tv32((struct timeval *), tv))
return -EFAULT;
kts.tv_nsec *= 1000;
+   kts64 = timespec_to_timespec64(kts);
}
if (tz) {
if (copy_from_user(, tz, sizeof(*tz)))
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ?  : NULL, tz ?  : NULL);
+   return do_sys_settimeofday64(tv ?  : NULL, tz ?  : NULL);
 }
 
 asmlinkage long sys_ni_posix_timers(void);
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index b598cbc..3617a78 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -19,21 +19,6 @@ extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday64(const struct timespec64 *ts);
 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 do_sys_settimeofday64(NULL, tz);
-
-   if (!timespec_valid(tv))
-   return -EINVAL;
-
-   ts64 = timespec_to_timespec64(*tv);
-   return do_sys_settimeofday64(, tz);
-}
-
 /*
  * Kernel time accessors
  */
diff --git a/kernel/compat.c b/kernel/compat.c
index 19aec5d..e29a01a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -109,7 +109,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
   struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -123,7 +123,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? _ts : NULL, tz ? _tz : NULL);
+   return do_sys_settimeofday64(tv ? _ts : NULL, tz ? _tz : NULL);
 }
 
 static int __compat_get_timeval(struct timeval *tv, const struct 
compat_timeval __user *ctv)
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
index cd6716e..95a1b1f 100644
--- a/kernel/time/posix-stubs.c
+++ b/kernel/time/posix-stubs.c
@@ -49,13 +49,16 @@ SYS_NI(alarm);
 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
const struct timespec __user *, tp)
 {
+   struct timespec64 new_tp64;
struct timespec new_tp;
 
if (which_clock != CLOCK_REALTIME)
return -EINVAL;
if (copy_from_user(_tp, tp, sizeof (*tp)))
return -EFAULT;
-   return do_sys_settimeofday(_tp, NULL);
+
+   new_tp64 = timespec_to_timespec64(new_tp);
+   return do_sys_settimeofday64(_tp64, NULL);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 50a6a47..f215ef7 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -214,7 +214,10 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec *tp)
 static int posix_clock_realtime_set(const clockid_t which_clock,
const struct timespec *tp)
 {
-   return do_sys_settimeofday(tp, NULL);
+   struct timespec64 tp64;
+
+   tp64 = timespec_to_timespec64(*tp);
+   return do_sys_settimeofday64(, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..6574bba 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -193,8 +193,8 @@ int do_sys_settimeofday64(const struct timespec64 *tv, 

[Y2038] [PATCH v2 0/7] Change k_clock interfaces to use timespec64

2017-03-26 Thread Deepa Dinamani
The series is aimed at replacing struct timespec which is not
y2038 safe with y2038 safe struct timespec64 for k_clock interfaces.
The series also replaces struct itimerspec which uses struct timespec
internally with struct itimerspec64 for the k_clock interfaces.

The series does not change the syscall interface.
This will be done in a follow up series.

A few existing checkpatch-noted style issues, such as the 80 line
character limit, have been left as-is to facilitate easier review.

Changes since v1:
* Address review comments for change logs and coding style.
* Fix kbuild test error for alpha.

Deepa Dinamani (7):
  time: Delete do_sys_setimeofday()
  time: Change posix clocks ops interfaces to use timespec64
  Change k_clock clock_get() to use timespec64
  Change k_clock clock_getres() to use timespec64
  Change k_clock clock_set() to use timespec64
  Change k_clock timer_set() and timer_get() to use timespec64
  Change k_clock nsleep() to use timespec64

 arch/alpha/kernel/osf_sys.c|  4 +-
 drivers/char/mmtimer.c | 28 ++---
 drivers/ptp/ptp_clock.c| 18 
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-clock.h| 10 ++---
 include/linux/posix-timers.h   | 20 -
 include/linux/timekeeping.h| 20 +++--
 kernel/compat.c| 10 +++--
 kernel/time/alarmtimer.c   | 24 +--
 kernel/time/hrtimer.c  | 10 +++--
 kernel/time/posix-clock.c  | 10 ++---
 kernel/time/posix-cpu-timers.c | 66 +++--
 kernel/time/posix-stubs.c  | 20 ++---
 kernel/time/posix-timers.c | 95 --
 kernel/time/time.c |  4 +-
 15 files changed, 179 insertions(+), 162 deletions(-)

-- 
2.7.4

Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: linux-al...@vger.kernel.org
Cc: net...@vger.kernel.org
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2 6/7] Change k_clock timer_set() and timer_get() to use timespec64

2017-03-26 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines.
Replace uses of struct timespec with struct timespec64
in the kernel.

struct itimerspec internally uses struct timespec.
Use struct itimerspec64 which uses struct timespec64.

The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c | 20 ++--
 include/linux/posix-timers.h   | 12 ++--
 kernel/time/alarmtimer.c   | 14 +++---
 kernel/time/posix-clock.c  | 21 +++--
 kernel/time/posix-cpu-timers.c | 28 
 kernel/time/posix-timers.c | 35 ---
 6 files changed, 66 insertions(+), 64 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ba1b892..0e7fcb0 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -657,7 +657,7 @@ static int sgi_timer_del(struct k_itimer *timr)
 }
 
 /* Assumption: it_lock is already held with irq's disabled */
-static void sgi_timer_get(struct k_itimer *timr, struct itimerspec 
*cur_setting)
+static void sgi_timer_get(struct k_itimer *timr, struct itimerspec64 
*cur_setting)
 {
 
if (timr->it.mmtimer.clock == TIMER_OFF) {
@@ -668,14 +668,14 @@ static void sgi_timer_get(struct k_itimer *timr, struct 
itimerspec *cur_setting)
return;
}
 
-   cur_setting->it_interval = ns_to_timespec(timr->it.mmtimer.incr * 
sgi_clock_period);
-   cur_setting->it_value = ns_to_timespec((timr->it.mmtimer.expires - 
rtc_time()) * sgi_clock_period);
+   cur_setting->it_interval = ns_to_timespec64(timr->it.mmtimer.incr * 
sgi_clock_period);
+   cur_setting->it_value = ns_to_timespec64((timr->it.mmtimer.expires - 
rtc_time()) * sgi_clock_period);
 }
 
 
 static int sgi_timer_set(struct k_itimer *timr, int flags,
-   struct itimerspec * new_setting,
-   struct itimerspec * old_setting)
+   struct itimerspec64 *new_setting,
+   struct itimerspec64 *old_setting)
 {
unsigned long when, period, irqflags;
int err = 0;
@@ -687,8 +687,8 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
sgi_timer_get(timr, old_setting);
 
sgi_timer_del(timr);
-   when = timespec_to_ns(_setting->it_value);
-   period = timespec_to_ns(_setting->it_interval);
+   when = timespec64_to_ns(_setting->it_value);
+   period = timespec64_to_ns(_setting->it_interval);
 
if (when == 0)
/* Clear timer */
@@ -699,11 +699,11 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return -ENOMEM;
 
if (flags & TIMER_ABSTIME) {
-   struct timespec n;
+   struct timespec64 n;
unsigned long now;
 
-   getnstimeofday();
-   now = timespec_to_ns();
+   getnstimeofday64();
+   now = timespec64_to_ns();
if (when > now)
when -= now;
else
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 7825e24..ebc4c494 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -96,13 +96,13 @@ struct k_clock {
int (*nsleep) (const clockid_t which_clock, int flags,
   struct timespec *, struct timespec __user *);
long (*nsleep_restart) (struct restart_block *restart_block);
-   int (*timer_set) (struct k_itimer * timr, int flags,
- struct itimerspec * new_setting,
- struct itimerspec * old_setting);
-   int (*timer_del) (struct k_itimer * timr);
+   int (*timer_set) (struct k_itimer *timr, int flags,
+ struct itimerspec64 *new_setting,
+ struct itimerspec64 *old_setting);
+   int (*timer_del) (struct k_itimer *timr);
 #define TIMER_RETRY 1
-   void (*timer_get) (struct k_itimer * timr,
-  struct itimerspec * cur_setting);
+   void (*timer_get) (struct k_itimer *timr,
+  struct itimerspec64 *cur_setting);
 };
 
 extern struct k_clock clock_posix_cpu;
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index e8a45e2..81db6df 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -598,19 +598,19 @@ static int alarm_timer_create(struct k_itimer *new_timer)
  * Copies out the current itimerspec data
  */
 static void alarm_timer_get(struct k_itimer *timr,
-   struct itimerspec *cur_setting)
+   struct itimerspec64 *cur_setting)
 {
ktime_t relative_expiry_time =
alarm_expires_remaining(&(timr->it.alarm.alarmtimer));
 
if (ktime_to_ns(relative_expiry_time) > 0) {
-   cur_setting->it_value = ktime_to_time

[Y2038] [PATCH v2 3/7] Change k_clock clock_get() to use timespec64

2017-03-26 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines.
Replace uses of struct timespec with struct timespec64
in the kernel.

The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  4 ++--
 include/linux/posix-timers.h   |  2 +-
 include/linux/timekeeping.h|  5 +
 kernel/time/alarmtimer.c   |  4 ++--
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c | 10 +-
 kernel/time/posix-stubs.c  |  9 ++---
 kernel/time/posix-timers.c | 32 +---
 8 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index b708c85..40d880b 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -478,13 +478,13 @@ static int sgi_clock_period;
 static struct timespec sgi_clock_offset;
 static int sgi_clock_period;
 
-static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
+static int sgi_clock_get(clockid_t clockid, struct timespec64 *tp)
 {
u64 nsec;
 
nsec = rtc_time() * sgi_clock_period
+ sgi_clock_offset.tv_nsec;
-   *tp = ns_to_timespec(nsec);
+   *tp = ns_to_timespec64(nsec);
tp->tv_sec += sgi_clock_offset.tv_sec;
return 0;
 };
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 64aa189..0688f39 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -90,7 +90,7 @@ struct k_clock {
int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
int (*clock_set) (const clockid_t which_clock,
  const struct timespec *tp);
-   int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
+   int (*clock_get) (const clockid_t which_clock, struct timespec64 *tp);
int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
int (*timer_create) (struct k_itimer *timer);
int (*nsleep) (const clockid_t which_clock, int flags,
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 3617a78..ddc229f 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -258,6 +258,11 @@ static inline void timekeeping_clocktai(struct timespec 
*ts)
*ts = ktime_to_timespec(ktime_get_clocktai());
 }
 
+static inline void timekeeping_clocktai64(struct timespec64 *ts)
+{
+   *ts = ktime_to_timespec64(ktime_get_clocktai());
+}
+
 /*
  * RTC specific
  */
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index ce3a31e..944ca6e 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -558,14 +558,14 @@ static int alarm_clock_getres(const clockid_t 
which_clock, struct timespec *tp)
  *
  * Provides the underlying alarm base time.
  */
-static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_get(clockid_t which_clock, struct timespec64 *tp)
 {
struct alarm_base *base = _bases[clock2alarm(which_clock)];
 
if (!alarmtimer_get_rtcdev())
return -EINVAL;
 
-   *tp = ktime_to_timespec(base->gettime());
+   *tp = ktime_to_timespec64(base->gettime());
return 0;
 }
 
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index e24008c..fab6bd3 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -297,20 +297,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
return err;
 }
 
-static int pc_clock_gettime(clockid_t id, struct timespec *ts)
+static int pc_clock_gettime(clockid_t id, struct timespec64 *ts)
 {
struct posix_clock_desc cd;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, );
if (err)
return err;
 
-   if (cd.clk->ops.clock_gettime) {
-   err = cd.clk->ops.clock_gettime(cd.clk, );
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_gettime)
+   err = cd.clk->ops.clock_gettime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 76bea3a..082231c 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -261,7 +261,7 @@ static int cpu_clock_sample_group(const clockid_t 
which_clock,
 
 static int posix_cpu_clock_get_task(struct task_struct *tsk,
const clockid_t which_clock,
-   struct timespec *tp)
+   struct timespec64 *tp)
 {
int err = -EINVAL;
u64 rtn;
@@ -275,13 +275,13 @@ static int posix_cpu_clock_get_task(struct task_struct 
*tsk,
}
 
if (!err)
-   *tp = ns_to_timespec(rtn);
+   *tp = ns_to_timespec64(rtn);
 
ret

[Y2038] [PATCH v2 4/7] Change k_clock clock_getres() to use timespec64

2017-03-26 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines.
Replace uses of struct timespec with struct timespec64
in the kernel.

The syscall interfaces themselves will be changed
in a separate series.

Note that the clock_getres() interface has also been changed
to use timespec64 even though this particular interface is
not affected by the y2038 problem. This helps verification for
internal kernel code for y2038 readiness by getting rid of
time_t/ timeval/ timespec.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/alarmtimer.c   |  2 +-
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c |  6 +++---
 kernel/time/posix-timers.c | 10 ++
 6 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 40d880b..79d8ada 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -765,7 +765,7 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return err;
 }
 
-static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int sgi_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
tp->tv_sec = 0;
tp->tv_nsec = sgi_clock_period;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 0688f39..dd05b49 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -87,7 +87,7 @@ struct k_itimer {
 };
 
 struct k_clock {
-   int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+   int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
  const struct timespec *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 *tp);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 944ca6e..e8a45e2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -541,7 +541,7 @@ static enum alarmtimer_restart alarm_handle_timer(struct 
alarm *alarm,
  *
  * Returns the granularity of underlying alarm base clock
  */
-static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 
*tp)
 {
if (!alarmtimer_get_rtcdev())
return -EINVAL;
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index fab6bd3..af91031 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -316,20 +316,17 @@ static int pc_clock_gettime(clockid_t id, struct 
timespec64 *ts)
return err;
 }
 
-static int pc_clock_getres(clockid_t id, struct timespec *ts)
+static int pc_clock_getres(clockid_t id, struct timespec64 *ts)
 {
struct posix_clock_desc cd;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, );
if (err)
return err;
 
-   if (cd.clk->ops.clock_getres) {
-   err = cd.clk->ops.clock_getres(cd.clk, );
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_getres)
+   err = cd.clk->ops.clock_getres(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 082231c..37ce9ed 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -116,7 +116,7 @@ static inline u64 virt_ticks(struct task_struct *p)
 }
 
 static int
-posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
int error = check_clock(which_clock);
if (!error) {
@@ -1369,7 +1369,7 @@ static long posix_cpu_nsleep_restart(struct restart_block 
*restart_block)
 #define THREAD_CLOCK   MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
 
 static int process_cpu_clock_getres(const clockid_t which_clock,
-   struct timespec *tp)
+   struct timespec64 *tp)
 {
return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
 }
@@ -1394,7 +1394,7 @@ static long process_cpu_nsleep_restart(struct 
restart_block *restart_block)
return -EINVAL;
 }
 static int thread_cpu_clock_getres(const clockid_t which_clock,
-  struct timespec *tp)
+  struct timespec64 *tp)
 {
return posix_cpu_clock_getres(THREAD_CLOCK, tp);
 }
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 6817064..f67dae9 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -258,9 +258,9 @@ static int posix_get_monotonic_coarse(clockid_t which_clock,
return 0;
 }
 
-static int posix_get_coarse_res(const clockid_t which_clock, struct timespec 
*tp)
+static 

[Y2038] [PATCH v2 5/7] Change k_clock clock_set() to use timespec64

2017-03-26 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines.
Replace uses of struct timespec with struct timespec64
in the kernel.

The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/posix-clock.c  |  5 ++---
 kernel/time/posix-cpu-timers.c |  2 +-
 kernel/time/posix-timers.c | 11 +--
 5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 79d8ada..ba1b892 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -489,7 +489,7 @@ static int sgi_clock_get(clockid_t clockid, struct 
timespec64 *tp)
return 0;
 };
 
-static int sgi_clock_set(const clockid_t clockid, const struct timespec *tp)
+static int sgi_clock_set(const clockid_t clockid, const struct timespec64 *tp)
 {
 
u64 nsec;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index dd05b49..7825e24 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -89,7 +89,7 @@ struct k_itimer {
 struct k_clock {
int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
- const struct timespec *tp);
+ const struct timespec64 *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 *tp);
int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
int (*timer_create) (struct k_itimer *timer);
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index af91031..3807a34 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -335,9 +335,8 @@ static int pc_clock_getres(clockid_t id, struct timespec64 
*ts)
return err;
 }
 
-static int pc_clock_settime(clockid_t id, const struct timespec *ts)
+static int pc_clock_settime(clockid_t id, const struct timespec64 *ts)
 {
-   struct timespec64 ts64 = timespec_to_timespec64(*ts);
struct posix_clock_desc cd;
int err;
 
@@ -351,7 +350,7 @@ static int pc_clock_settime(clockid_t id, const struct 
timespec *ts)
}
 
if (cd.clk->ops.clock_settime)
-   err = cd.clk->ops.clock_settime(cd.clk, );
+   err = cd.clk->ops.clock_settime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 out:
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 37ce9ed..2cd4428 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -135,7 +135,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct 
timespec64 *tp)
 }
 
 static int
-posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec64 *tp)
 {
/*
 * You can never reset a CPU clock, but we check for other errors
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index f67dae9..7742da8 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -212,12 +212,9 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec64 *tp
 
 /* Set clock_realtime */
 static int posix_clock_realtime_set(const clockid_t which_clock,
-   const struct timespec *tp)
+   const struct timespec64 *tp)
 {
-   struct timespec64 tp64;
-
-   tp64 = timespec_to_timespec64(*tp);
-   return do_sys_settimeofday64(, NULL);
+   return do_sys_settimeofday64(tp, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
@@ -1017,6 +1014,7 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, 
which_clock,
const struct timespec __user *, tp)
 {
struct k_clock *kc = clockid_to_kclock(which_clock);
+   struct timespec64 new_tp64;
struct timespec new_tp;
 
if (!kc || !kc->clock_set)
@@ -1024,8 +1022,9 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, 
which_clock,
 
if (copy_from_user(_tp, tp, sizeof (*tp)))
return -EFAULT;
+   new_tp64 = timespec_to_timespec64(new_tp);
 
-   return kc->clock_set(which_clock, _tp);
+   return kc->clock_set(which_clock, _tp64);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH 6/7] Change k_clock timer_set() and timer_get() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c | 20 ++--
 include/linux/posix-timers.h   |  6 +++---
 kernel/time/alarmtimer.c   | 14 +++---
 kernel/time/posix-clock.c  | 21 +++--
 kernel/time/posix-cpu-timers.c | 28 
 kernel/time/posix-timers.c | 33 +++--
 6 files changed, 62 insertions(+), 60 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ba1b892..863a111 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -657,7 +657,7 @@ static int sgi_timer_del(struct k_itimer *timr)
 }
 
 /* Assumption: it_lock is already held with irq's disabled */
-static void sgi_timer_get(struct k_itimer *timr, struct itimerspec 
*cur_setting)
+static void sgi_timer_get(struct k_itimer *timr, struct itimerspec64 
*cur_setting)
 {
 
if (timr->it.mmtimer.clock == TIMER_OFF) {
@@ -668,14 +668,14 @@ static void sgi_timer_get(struct k_itimer *timr, struct 
itimerspec *cur_setting)
return;
}
 
-   cur_setting->it_interval = ns_to_timespec(timr->it.mmtimer.incr * 
sgi_clock_period);
-   cur_setting->it_value = ns_to_timespec((timr->it.mmtimer.expires - 
rtc_time()) * sgi_clock_period);
+   cur_setting->it_interval = ns_to_timespec64(timr->it.mmtimer.incr * 
sgi_clock_period);
+   cur_setting->it_value = ns_to_timespec64((timr->it.mmtimer.expires - 
rtc_time()) * sgi_clock_period);
 }
 
 
 static int sgi_timer_set(struct k_itimer *timr, int flags,
-   struct itimerspec * new_setting,
-   struct itimerspec * old_setting)
+   struct itimerspec64 * new_setting,
+   struct itimerspec64 * old_setting)
 {
unsigned long when, period, irqflags;
int err = 0;
@@ -687,8 +687,8 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
sgi_timer_get(timr, old_setting);
 
sgi_timer_del(timr);
-   when = timespec_to_ns(_setting->it_value);
-   period = timespec_to_ns(_setting->it_interval);
+   when = timespec64_to_ns(_setting->it_value);
+   period = timespec64_to_ns(_setting->it_interval);
 
if (when == 0)
/* Clear timer */
@@ -699,11 +699,11 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return -ENOMEM;
 
if (flags & TIMER_ABSTIME) {
-   struct timespec n;
+   struct timespec64 n;
unsigned long now;
 
-   getnstimeofday();
-   now = timespec_to_ns();
+   getnstimeofday64();
+   now = timespec64_to_ns();
if (when > now)
when -= now;
else
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 249429c..f608941 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -97,12 +97,12 @@ struct k_clock {
   struct timespec *, struct timespec __user *);
long (*nsleep_restart) (struct restart_block *restart_block);
int (*timer_set) (struct k_itimer * timr, int flags,
- struct itimerspec * new_setting,
- struct itimerspec * old_setting);
+ struct itimerspec64 * new_setting,
+ struct itimerspec64 * old_setting);
int (*timer_del) (struct k_itimer * timr);
 #define TIMER_RETRY 1
void (*timer_get) (struct k_itimer * timr,
-  struct itimerspec * cur_setting);
+  struct itimerspec64 * cur_setting);
 };
 
 extern struct k_clock clock_posix_cpu;
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index e8a45e2..81db6df 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -598,19 +598,19 @@ static int alarm_timer_create(struct k_itimer *new_timer)
  * Copies out the current itimerspec data
  */
 static void alarm_timer_get(struct k_itimer *timr,
-   struct itimerspec *cur_setting)
+   struct itimerspec64 *cur_setting)
 {
ktime_t relative_expiry_time =
alarm_expires_remaining(&(timr->it.alarm.alarmtimer));
 
if (ktime_to_ns(relative_expiry_time) > 0) {
-   cur_setting->it_value = ktime_to_timespec(relative_expiry_time);
+   cur_setting->it_value = 
ktime_to_timespec64(relative_expiry_time);
} else {
cur_setting->it_value.tv_sec = 0;
cur_setting->it_value.tv_nsec = 0;
}
 
-   cur_setting->it_interval =

[Y2038] [RESEND PATCH 7/7] Change k_clock nsleep() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/compat.c|  6 --
 kernel/time/alarmtimer.c   |  4 ++--
 kernel/time/hrtimer.c  | 10 ++
 kernel/time/posix-cpu-timers.c | 36 ++--
 kernel/time/posix-stubs.c  |  6 --
 kernel/time/posix-timers.c | 10 ++
 8 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 249e579..7d019c0 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -456,7 +456,7 @@ static inline u64 hrtimer_forward_now(struct hrtimer *timer,
 }
 
 /* Precise sleep: */
-extern long hrtimer_nanosleep(struct timespec *rqtp,
+extern long hrtimer_nanosleep(struct timespec64 *rqtp,
  struct timespec __user *rmtp,
  const enum hrtimer_mode mode,
  const clockid_t clockid);
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index f608941..97a883a 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -94,7 +94,7 @@ struct k_clock {
int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
int (*timer_create) (struct k_itimer *timer);
int (*nsleep) (const clockid_t which_clock, int flags,
-  struct timespec *, struct timespec __user *);
+  struct timespec64 *, struct timespec __user *);
long (*nsleep_restart) (struct restart_block *restart_block);
int (*timer_set) (struct k_itimer * timr, int flags,
  struct itimerspec64 * new_setting,
diff --git a/kernel/compat.c b/kernel/compat.c
index e29a01a..8ec15d1 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -240,18 +240,20 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec 
__user *, rqtp,
   struct compat_timespec __user *, rmtp)
 {
struct timespec tu, rmt;
+   struct timespec64 tu64;
mm_segment_t oldfs;
long ret;
 
if (compat_get_timespec(, rqtp))
return -EFAULT;
 
-   if (!timespec_valid())
+   tu64 = timespec_to_timespec64(tu);
+   if (!timespec64_valid())
return -EINVAL;
 
oldfs = get_fs();
set_fs(KERNEL_DS);
-   ret = hrtimer_nanosleep(,
+   ret = hrtimer_nanosleep(,
rmtp ? (struct timespec __user *) : NULL,
HRTIMER_MODE_REL, CLOCK_MONOTONIC);
set_fs(oldfs);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 81db6df..cc20417 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -790,7 +790,7 @@ static long __sched alarm_timer_nsleep_restart(struct 
restart_block *restart)
  * Handles clock_nanosleep calls against _ALARM clockids
  */
 static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
-struct timespec *tsreq, struct timespec __user *rmtp)
+struct timespec64 *tsreq, struct timespec __user *rmtp)
 {
enum  alarmtimer_type type = clock2alarm(which_clock);
struct alarm alarm;
@@ -809,7 +809,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, 
int flags,
 
alarm_init(, type, alarmtimer_nsleep_wakeup);
 
-   exp = timespec_to_ktime(*tsreq);
+   exp = timespec64_to_ktime(*tsreq);
/* Convert (if necessary) to absolute time */
if (flags != TIMER_ABSTIME) {
ktime_t now = alarm_bases[type].gettime();
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index ec08f52..f530295 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1506,7 +1506,7 @@ long __sched hrtimer_nanosleep_restart(struct 
restart_block *restart)
return ret;
 }
 
-long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
+long hrtimer_nanosleep(struct timespec64 *rqtp, struct timespec __user *rmtp,
   const enum hrtimer_mode mode, const clockid_t clockid)
 {
struct restart_block *restart;
@@ -1519,7 +1519,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct 
timespec __user *rmtp,
slack = 0;
 
hrtimer_init_on_stack(, clockid, mode);
-   hrtimer_set_expires_range_ns(, timespec_to_ktime(*rqtp), slack);
+   hrtimer_set_expires_range_ns(, timespec64_to_ktime(*rqtp), 
slack);
if (do_nanosleep(, mode))
goto out;
 
@@ -1551,14 +1551,16 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, 
rqtp,
struct timespec __user *, rmtp)
 {
struct times

[Y2038] [PATCH 4/7] Change k_clock clock_getres() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/alarmtimer.c   |  2 +-
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c |  6 +++---
 kernel/time/posix-timers.c | 10 ++
 6 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 40d880b..79d8ada 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -765,7 +765,7 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return err;
 }
 
-static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int sgi_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
tp->tv_sec = 0;
tp->tv_nsec = sgi_clock_period;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index db54f1b..2555d1c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -87,7 +87,7 @@ struct k_itimer {
 };
 
 struct k_clock {
-   int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+   int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
  const struct timespec *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 * tp);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 944ca6e..e8a45e2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -541,7 +541,7 @@ static enum alarmtimer_restart alarm_handle_timer(struct 
alarm *alarm,
  *
  * Returns the granularity of underlying alarm base clock
  */
-static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 
*tp)
 {
if (!alarmtimer_get_rtcdev())
return -EINVAL;
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 0427c8c..d5a4bec 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -316,20 +316,17 @@ static int pc_clock_gettime(clockid_t id, struct 
timespec64 *ts)
return err;
 }
 
-static int pc_clock_getres(clockid_t id, struct timespec *ts)
+static int pc_clock_getres(clockid_t id, struct timespec64 *ts)
 {
struct posix_clock_desc cd;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, );
if (err)
return err;
 
-   if (cd.clk->ops.clock_getres) {
-   err = cd.clk->ops.clock_getres(cd.clk, );
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_getres)
+   err = cd.clk->ops.clock_getres(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 6c509ea..42ca205 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -116,7 +116,7 @@ static inline u64 virt_ticks(struct task_struct *p)
 }
 
 static int
-posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
int error = check_clock(which_clock);
if (!error) {
@@ -1364,7 +1364,7 @@ static long posix_cpu_nsleep_restart(struct restart_block 
*restart_block)
 #define THREAD_CLOCK   MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
 
 static int process_cpu_clock_getres(const clockid_t which_clock,
-   struct timespec *tp)
+   struct timespec64 *tp)
 {
return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
 }
@@ -1389,7 +1389,7 @@ static long process_cpu_nsleep_restart(struct 
restart_block *restart_block)
return -EINVAL;
 }
 static int thread_cpu_clock_getres(const clockid_t which_clock,
-  struct timespec *tp)
+  struct timespec64 *tp)
 {
return posix_cpu_clock_getres(THREAD_CLOCK, tp);
 }
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index ba0c472..a314a63 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -258,9 +258,9 @@ static int posix_get_monotonic_coarse(clockid_t which_clock,
return 0;
 }
 
-static int posix_get_coarse_res(const clockid_t which_clock, struct timespec 
*tp)
+static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 
*tp)
 {
-   *tp = ktime_to_timespec(KTIME_LOW_RES);
+   *tp = ktime_to_timespec64(KTIME_LOW_RES);
return 0;
 }
 
@@ -276,7 +276,7 @@ static int posix_get_t

[Y2038] [PATCH 6/7] Change k_clock timer_set() and timer_get() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c | 20 ++--
 include/linux/posix-timers.h   |  6 +++---
 kernel/time/alarmtimer.c   | 14 +++---
 kernel/time/posix-clock.c  | 21 +++--
 kernel/time/posix-cpu-timers.c | 28 
 kernel/time/posix-timers.c | 33 +++--
 6 files changed, 62 insertions(+), 60 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ba1b892..863a111 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -657,7 +657,7 @@ static int sgi_timer_del(struct k_itimer *timr)
 }
 
 /* Assumption: it_lock is already held with irq's disabled */
-static void sgi_timer_get(struct k_itimer *timr, struct itimerspec 
*cur_setting)
+static void sgi_timer_get(struct k_itimer *timr, struct itimerspec64 
*cur_setting)
 {
 
if (timr->it.mmtimer.clock == TIMER_OFF) {
@@ -668,14 +668,14 @@ static void sgi_timer_get(struct k_itimer *timr, struct 
itimerspec *cur_setting)
return;
}
 
-   cur_setting->it_interval = ns_to_timespec(timr->it.mmtimer.incr * 
sgi_clock_period);
-   cur_setting->it_value = ns_to_timespec((timr->it.mmtimer.expires - 
rtc_time()) * sgi_clock_period);
+   cur_setting->it_interval = ns_to_timespec64(timr->it.mmtimer.incr * 
sgi_clock_period);
+   cur_setting->it_value = ns_to_timespec64((timr->it.mmtimer.expires - 
rtc_time()) * sgi_clock_period);
 }
 
 
 static int sgi_timer_set(struct k_itimer *timr, int flags,
-   struct itimerspec * new_setting,
-   struct itimerspec * old_setting)
+   struct itimerspec64 * new_setting,
+   struct itimerspec64 * old_setting)
 {
unsigned long when, period, irqflags;
int err = 0;
@@ -687,8 +687,8 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
sgi_timer_get(timr, old_setting);
 
sgi_timer_del(timr);
-   when = timespec_to_ns(_setting->it_value);
-   period = timespec_to_ns(_setting->it_interval);
+   when = timespec64_to_ns(_setting->it_value);
+   period = timespec64_to_ns(_setting->it_interval);
 
if (when == 0)
/* Clear timer */
@@ -699,11 +699,11 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return -ENOMEM;
 
if (flags & TIMER_ABSTIME) {
-   struct timespec n;
+   struct timespec64 n;
unsigned long now;
 
-   getnstimeofday();
-   now = timespec_to_ns();
+   getnstimeofday64();
+   now = timespec64_to_ns();
if (when > now)
when -= now;
else
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 249429c..f608941 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -97,12 +97,12 @@ struct k_clock {
   struct timespec *, struct timespec __user *);
long (*nsleep_restart) (struct restart_block *restart_block);
int (*timer_set) (struct k_itimer * timr, int flags,
- struct itimerspec * new_setting,
- struct itimerspec * old_setting);
+ struct itimerspec64 * new_setting,
+ struct itimerspec64 * old_setting);
int (*timer_del) (struct k_itimer * timr);
 #define TIMER_RETRY 1
void (*timer_get) (struct k_itimer * timr,
-  struct itimerspec * cur_setting);
+  struct itimerspec64 * cur_setting);
 };
 
 extern struct k_clock clock_posix_cpu;
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index e8a45e2..81db6df 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -598,19 +598,19 @@ static int alarm_timer_create(struct k_itimer *new_timer)
  * Copies out the current itimerspec data
  */
 static void alarm_timer_get(struct k_itimer *timr,
-   struct itimerspec *cur_setting)
+   struct itimerspec64 *cur_setting)
 {
ktime_t relative_expiry_time =
alarm_expires_remaining(&(timr->it.alarm.alarmtimer));
 
if (ktime_to_ns(relative_expiry_time) > 0) {
-   cur_setting->it_value = ktime_to_timespec(relative_expiry_time);
+   cur_setting->it_value = 
ktime_to_timespec64(relative_expiry_time);
} else {
cur_setting->it_value.tv_sec = 0;
cur_setting->it_value.tv_nsec = 0;
}
 
-   cur_setting->it_interval =

[Y2038] [PATCH 5/7] Change k_clock clock_set() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/posix-clock.c  |  5 ++---
 kernel/time/posix-cpu-timers.c |  2 +-
 kernel/time/posix-timers.c | 11 +--
 5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 79d8ada..ba1b892 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -489,7 +489,7 @@ static int sgi_clock_get(clockid_t clockid, struct 
timespec64 *tp)
return 0;
 };
 
-static int sgi_clock_set(const clockid_t clockid, const struct timespec *tp)
+static int sgi_clock_set(const clockid_t clockid, const struct timespec64 *tp)
 {
 
u64 nsec;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 2555d1c..249429c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -89,7 +89,7 @@ struct k_itimer {
 struct k_clock {
int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
- const struct timespec *tp);
+ const struct timespec64 *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 * tp);
int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
int (*timer_create) (struct k_itimer *timer);
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index d5a4bec..6378fc6 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -335,10 +335,9 @@ static int pc_clock_getres(clockid_t id, struct timespec64 
*ts)
return err;
 }
 
-static int pc_clock_settime(clockid_t id, const struct timespec *ts)
+static int pc_clock_settime(clockid_t id, const struct timespec64 *ts)
 {
struct posix_clock_desc cd;
-   struct timespec64 ts64 = timespec_to_timespec64(*ts);
int err;
 
err = get_clock_desc(id, );
@@ -351,7 +350,7 @@ static int pc_clock_settime(clockid_t id, const struct 
timespec *ts)
}
 
if (cd.clk->ops.clock_settime)
-   err = cd.clk->ops.clock_settime(cd.clk, );
+   err = cd.clk->ops.clock_settime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 out:
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 42ca205..0db0e16 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -135,7 +135,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct 
timespec64 *tp)
 }
 
 static int
-posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec64 *tp)
 {
/*
 * You can never reset a CPU clock, but we check for other errors
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index a314a63..6c09f87 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -212,12 +212,9 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec64 *tp
 
 /* Set clock_realtime */
 static int posix_clock_realtime_set(const clockid_t which_clock,
-   const struct timespec *tp)
+   const struct timespec64 *tp)
 {
-   struct timespec64 tp64;
-
-   tp64 = timespec_to_timespec64(*tp);
-   return do_sys_settimeofday64(, NULL);
+   return do_sys_settimeofday64(tp, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
@@ -1018,14 +1015,16 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, 
which_clock,
 {
struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (!kc || !kc->clock_set)
return -EINVAL;
 
if (copy_from_user(_tp, tp, sizeof (*tp)))
return -EFAULT;
+   new_tp64 = timespec_to_timespec64(new_tp);
 
-   return kc->clock_set(which_clock, _tp);
+   return kc->clock_set(which_clock, _tp64);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 3/7] Change k_clock clock_get() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  4 ++--
 include/linux/posix-timers.h   |  2 +-
 include/linux/timekeeping.h|  5 +
 kernel/time/alarmtimer.c   |  4 ++--
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c | 10 +-
 kernel/time/posix-stubs.c  |  9 ++---
 kernel/time/posix-timers.c | 32 +---
 8 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index b708c85..40d880b 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -478,13 +478,13 @@ static int sgi_clock_period;
 static struct timespec sgi_clock_offset;
 static int sgi_clock_period;
 
-static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
+static int sgi_clock_get(clockid_t clockid, struct timespec64 *tp)
 {
u64 nsec;
 
nsec = rtc_time() * sgi_clock_period
+ sgi_clock_offset.tv_nsec;
-   *tp = ns_to_timespec(nsec);
+   *tp = ns_to_timespec64(nsec);
tp->tv_sec += sgi_clock_offset.tv_sec;
return 0;
 };
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 64aa189..db54f1b 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -90,7 +90,7 @@ struct k_clock {
int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
int (*clock_set) (const clockid_t which_clock,
  const struct timespec *tp);
-   int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
+   int (*clock_get) (const clockid_t which_clock, struct timespec64 * tp);
int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
int (*timer_create) (struct k_itimer *timer);
int (*nsleep) (const clockid_t which_clock, int flags,
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 3617a78..ddc229f 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -258,6 +258,11 @@ static inline void timekeeping_clocktai(struct timespec 
*ts)
*ts = ktime_to_timespec(ktime_get_clocktai());
 }
 
+static inline void timekeeping_clocktai64(struct timespec64 *ts)
+{
+   *ts = ktime_to_timespec64(ktime_get_clocktai());
+}
+
 /*
  * RTC specific
  */
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index ce3a31e..944ca6e 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -558,14 +558,14 @@ static int alarm_clock_getres(const clockid_t 
which_clock, struct timespec *tp)
  *
  * Provides the underlying alarm base time.
  */
-static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_get(clockid_t which_clock, struct timespec64 *tp)
 {
struct alarm_base *base = _bases[clock2alarm(which_clock)];
 
if (!alarmtimer_get_rtcdev())
return -EINVAL;
 
-   *tp = ktime_to_timespec(base->gettime());
+   *tp = ktime_to_timespec64(base->gettime());
return 0;
 }
 
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index f2af1b5..0427c8c 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -297,20 +297,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
return err;
 }
 
-static int pc_clock_gettime(clockid_t id, struct timespec *ts)
+static int pc_clock_gettime(clockid_t id, struct timespec64 *ts)
 {
struct posix_clock_desc cd;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, );
if (err)
return err;
 
-   if (cd.clk->ops.clock_gettime) {
-   err = cd.clk->ops.clock_gettime(cd.clk, );
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_gettime)
+   err = cd.clk->ops.clock_gettime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 4513ad1..6c509ea 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -261,7 +261,7 @@ static int cpu_clock_sample_group(const clockid_t 
which_clock,
 
 static int posix_cpu_clock_get_task(struct task_struct *tsk,
const clockid_t which_clock,
-   struct timespec *tp)
+   struct timespec64 *tp)
 {
int err = -EINVAL;
u64 rtn;
@@ -275,13 +275,13 @@ static int posix_cpu_clock_get_task(struct task_struct 
*tsk,
}
 
if (!err)
-   *tp = ns_to_timespec(rtn);
+   *tp = ns_to_timespec64

[Y2038] [PATCH 1/7] time: Delete do_sys_setimeofday()

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces will be changed in a separate
series.
Call to do_sys_setimeofday() is superfluous as all
the necessary checks and functions are done by the
underlying function do_sys_setimeofday64().
Replace do_sys_setimeofday64() directly instead of
do_sys_settimeofday(). The do_sys_setimeofday64()
calls timespec64_valid() internally, which is the
same as timespec_valid().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 include/linux/timekeeping.h | 15 ---
 kernel/compat.c |  4 ++--
 kernel/time/posix-stubs.c   |  5 -
 kernel/time/posix-timers.c  |  5 -
 kernel/time/time.c  |  4 ++--
 5 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index b598cbc..3617a78 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -19,21 +19,6 @@ extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday64(const struct timespec64 *ts);
 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 do_sys_settimeofday64(NULL, tz);
-
-   if (!timespec_valid(tv))
-   return -EINVAL;
-
-   ts64 = timespec_to_timespec64(*tv);
-   return do_sys_settimeofday64(, tz);
-}
-
 /*
  * Kernel time accessors
  */
diff --git a/kernel/compat.c b/kernel/compat.c
index 19aec5d..e29a01a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -109,7 +109,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
   struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -123,7 +123,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? _ts : NULL, tz ? _tz : NULL);
+   return do_sys_settimeofday64(tv ? _ts : NULL, tz ? _tz : NULL);
 }
 
 static int __compat_get_timeval(struct timeval *tv, const struct 
compat_timeval __user *ctv)
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
index cd6716e..df275db 100644
--- a/kernel/time/posix-stubs.c
+++ b/kernel/time/posix-stubs.c
@@ -50,12 +50,15 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
const struct timespec __user *, tp)
 {
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (which_clock != CLOCK_REALTIME)
return -EINVAL;
if (copy_from_user(_tp, tp, sizeof (*tp)))
return -EFAULT;
-   return do_sys_settimeofday(_tp, NULL);
+
+   new_tp64 = timespec_to_timespec64(new_tp);
+   return do_sys_settimeofday64(_tp64, NULL);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 50a6a47..f215ef7 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -214,7 +214,10 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec *tp)
 static int posix_clock_realtime_set(const clockid_t which_clock,
const struct timespec *tp)
 {
-   return do_sys_settimeofday(tp, NULL);
+   struct timespec64 tp64;
+
+   tp64 = timespec_to_timespec64(*tp);
+   return do_sys_settimeofday64(, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..450e8a1 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -194,7 +194,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -212,7 +212,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? _ts : NULL, tz ? _tz : NULL);
+   return do_sys_settimeofday64(tv ? _ts : NULL, tz ? _tz : NULL);
 }
 
 SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 2/7] time: Change posix clocks ops interfaces to use timespec64

2017-03-18 Thread Deepa Dinamani
 struct timespec is not y2038 safe.
 Replace the posix_clock ops interfaces to use
 struct timespec64.
 The patch also changes struct itimerspec interfaces to
 struct itimerspec64 as itimerspec internally uses timespec
 and itimerspec64 uses timespec64.
 PTP clocks is the only module that sets up these interfaces.
 All individual drivers rely on PTP class driver for exposure
 to userspace. Hence, the change also deals with fixing up these
 PTP interfaces.
 The patch also changes dynamic posix clock implementation to
 reflect the changes in the functional clock interface.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/ptp/ptp_clock.c | 18 +++---
 include/linux/posix-clock.h | 10 +-
 kernel/time/posix-clock.c   | 34 --
 3 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index e814280..b774357 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -97,30 +97,26 @@ static s32 scaled_ppm_to_ppb(long ppm)
 
 /* posix clock implementation */
 
-static int ptp_clock_getres(struct posix_clock *pc, struct timespec *tp)
+static int ptp_clock_getres(struct posix_clock *pc, struct timespec64 *tp)
 {
tp->tv_sec = 0;
tp->tv_nsec = 1;
return 0;
 }
 
-static int ptp_clock_settime(struct posix_clock *pc, const struct timespec *tp)
+static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 
*tp)
 {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
-   struct timespec64 ts = timespec_to_timespec64(*tp);
 
-   return  ptp->info->settime64(ptp->info, );
+   return  ptp->info->settime64(ptp->info, tp);
 }
 
-static int ptp_clock_gettime(struct posix_clock *pc, struct timespec *tp)
+static int ptp_clock_gettime(struct posix_clock *pc, struct timespec64 *tp)
 {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
-   struct timespec64 ts;
int err;
 
-   err = ptp->info->gettime64(ptp->info, );
-   if (!err)
-   *tp = timespec64_to_timespec(ts);
+   err = ptp->info->gettime64(ptp->info, tp);
return err;
 }
 
@@ -133,7 +129,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct 
timex *tx)
ops = ptp->info;
 
if (tx->modes & ADJ_SETOFFSET) {
-   struct timespec ts;
+   struct timespec64 ts;
ktime_t kt;
s64 delta;
 
@@ -146,7 +142,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct 
timex *tx)
if ((unsigned long) ts.tv_nsec >= NSEC_PER_SEC)
return -EINVAL;
 
-   kt = timespec_to_ktime(ts);
+   kt = timespec64_to_ktime(ts);
delta = ktime_to_ns(kt);
err = ops->adjtime(ops, delta);
} else if (tx->modes & ADJ_FREQUENCY) {
diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
index 34c4498..83b22ae 100644
--- a/include/linux/posix-clock.h
+++ b/include/linux/posix-clock.h
@@ -59,23 +59,23 @@ struct posix_clock_operations {
 
int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
 
-   int  (*clock_gettime)(struct posix_clock *pc, struct timespec *ts);
+   int  (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
 
-   int  (*clock_getres) (struct posix_clock *pc, struct timespec *ts);
+   int  (*clock_getres) (struct posix_clock *pc, struct timespec64 *ts);
 
int  (*clock_settime)(struct posix_clock *pc,
- const struct timespec *ts);
+ const struct timespec64 *ts);
 
int  (*timer_create) (struct posix_clock *pc, struct k_itimer *kit);
 
int  (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit);
 
void (*timer_gettime)(struct posix_clock *pc,
- struct k_itimer *kit, struct itimerspec *tsp);
+ struct k_itimer *kit, struct itimerspec64 *tsp);
 
int  (*timer_settime)(struct posix_clock *pc,
  struct k_itimer *kit, int flags,
- struct itimerspec *tsp, struct itimerspec *old);
+ struct itimerspec64 *tsp, struct itimerspec64 
*old);
/*
 * Optional character device methods:
 */
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 9cff0ab..f2af1b5 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -300,14 +300,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
 static int pc_clock_gettime(clockid_t id, struct timespec *ts)
 {
struct posix_clock_desc cd;
+   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, );
if (err)
return err

[Y2038] [PATCH 0/7] Change k_clock interfaces to use timespec64

2017-03-18 Thread Deepa Dinamani
The series is aimed at replacing struct timespec which is not
y2038 safe with y2038 safe struct timespec64 for k_clock interfaces.

The series does not change the syscall interface.
This will be done in a follow up series.

A few existing checkpatch-noted style issues, such as the 80 line
character limit, have been left as-is to facilitate easier review.

Deepa Dinamani (7):
  time: Delete do_sys_setimeofday()
  time: Change posix clocks ops interfaces to use timespec64
  Change k_clock clock_get() to use timespec64
  Change k_clock clock_getres() to use timespec64
  Change k_clock clock_set() to use timespec64
  Change k_clock timer_set() and timer_get() to use timespec64
  Change k_clock nsleep() to use timespec64

 drivers/char/mmtimer.c | 28 ++---
 drivers/ptp/ptp_clock.c| 18 
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-clock.h| 10 ++---
 include/linux/posix-timers.h   | 14 +++
 include/linux/timekeeping.h| 20 +++--
 kernel/compat.c| 10 +++--
 kernel/time/alarmtimer.c   | 24 +--
 kernel/time/hrtimer.c  | 10 +++--
 kernel/time/posix-clock.c  | 10 ++---
 kernel/time/posix-cpu-timers.c | 66 --
 kernel/time/posix-stubs.c  | 20 ++---
 kernel/time/posix-timers.c | 93 --
 kernel/time/time.c |  4 +-
 14 files changed, 172 insertions(+), 157 deletions(-)

-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH 0/7] Change k_clock interfaces to use timespec64

2017-03-18 Thread Deepa Dinamani
Resending to update author id in patch 7/7.

The series is aimed at replacing struct timespec which is not
y2038 safe with y2038 safe struct timespec64 for k_clock interfaces.

The series does not change the syscall interface.
This will be done in a follow up series.

A few existing checkpatch-noted style issues, such as the 80 line
character limit, have been left as-is to facilitate easier review.

Deepa Dinamani (7):
  time: Delete do_sys_setimeofday()
  time: Change posix clocks ops interfaces to use timespec64
  Change k_clock clock_get() to use timespec64
  Change k_clock clock_getres() to use timespec64
  Change k_clock clock_set() to use timespec64
  Change k_clock timer_set() and timer_get() to use timespec64
  Change k_clock nsleep() to use timespec64

 drivers/char/mmtimer.c | 28 ++---
 drivers/ptp/ptp_clock.c| 18 
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-clock.h| 10 ++---
 include/linux/posix-timers.h   | 14 +++
 include/linux/timekeeping.h| 20 +++--
 kernel/compat.c| 10 +++--
 kernel/time/alarmtimer.c   | 24 +--
 kernel/time/hrtimer.c  | 10 +++--
 kernel/time/posix-clock.c  | 10 ++---
 kernel/time/posix-cpu-timers.c | 66 --
 kernel/time/posix-stubs.c  | 20 ++---
 kernel/time/posix-timers.c | 93 --
 kernel/time/time.c |  4 +-
 14 files changed, 172 insertions(+), 157 deletions(-)

-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH 4/7] Change k_clock clock_getres() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/alarmtimer.c   |  2 +-
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c |  6 +++---
 kernel/time/posix-timers.c | 10 ++
 6 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 40d880b..79d8ada 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -765,7 +765,7 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return err;
 }
 
-static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int sgi_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
tp->tv_sec = 0;
tp->tv_nsec = sgi_clock_period;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index db54f1b..2555d1c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -87,7 +87,7 @@ struct k_itimer {
 };
 
 struct k_clock {
-   int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+   int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
  const struct timespec *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 * tp);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 944ca6e..e8a45e2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -541,7 +541,7 @@ static enum alarmtimer_restart alarm_handle_timer(struct 
alarm *alarm,
  *
  * Returns the granularity of underlying alarm base clock
  */
-static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 
*tp)
 {
if (!alarmtimer_get_rtcdev())
return -EINVAL;
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 0427c8c..d5a4bec 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -316,20 +316,17 @@ static int pc_clock_gettime(clockid_t id, struct 
timespec64 *ts)
return err;
 }
 
-static int pc_clock_getres(clockid_t id, struct timespec *ts)
+static int pc_clock_getres(clockid_t id, struct timespec64 *ts)
 {
struct posix_clock_desc cd;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, );
if (err)
return err;
 
-   if (cd.clk->ops.clock_getres) {
-   err = cd.clk->ops.clock_getres(cd.clk, );
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_getres)
+   err = cd.clk->ops.clock_getres(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 6c509ea..42ca205 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -116,7 +116,7 @@ static inline u64 virt_ticks(struct task_struct *p)
 }
 
 static int
-posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
int error = check_clock(which_clock);
if (!error) {
@@ -1364,7 +1364,7 @@ static long posix_cpu_nsleep_restart(struct restart_block 
*restart_block)
 #define THREAD_CLOCK   MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
 
 static int process_cpu_clock_getres(const clockid_t which_clock,
-   struct timespec *tp)
+   struct timespec64 *tp)
 {
return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
 }
@@ -1389,7 +1389,7 @@ static long process_cpu_nsleep_restart(struct 
restart_block *restart_block)
return -EINVAL;
 }
 static int thread_cpu_clock_getres(const clockid_t which_clock,
-  struct timespec *tp)
+  struct timespec64 *tp)
 {
return posix_cpu_clock_getres(THREAD_CLOCK, tp);
 }
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index ba0c472..a314a63 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -258,9 +258,9 @@ static int posix_get_monotonic_coarse(clockid_t which_clock,
return 0;
 }
 
-static int posix_get_coarse_res(const clockid_t which_clock, struct timespec 
*tp)
+static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 
*tp)
 {
-   *tp = ktime_to_timespec(KTIME_LOW_RES);
+   *tp = ktime_to_timespec64(KTIME_LOW_RES);
return 0;
 }
 
@@ -276,7 +276,7 @@ static int posix_get_t

[Y2038] [RESEND PATCH 1/7] time: Delete do_sys_setimeofday()

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces will be changed in a separate
series.
Call to do_sys_setimeofday() is superfluous as all
the necessary checks and functions are done by the
underlying function do_sys_setimeofday64().
Replace do_sys_setimeofday64() directly instead of
do_sys_settimeofday(). The do_sys_setimeofday64()
calls timespec64_valid() internally, which is the
same as timespec_valid().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 include/linux/timekeeping.h | 15 ---
 kernel/compat.c |  4 ++--
 kernel/time/posix-stubs.c   |  5 -
 kernel/time/posix-timers.c  |  5 -
 kernel/time/time.c  |  4 ++--
 5 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index b598cbc..3617a78 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -19,21 +19,6 @@ extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday64(const struct timespec64 *ts);
 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 do_sys_settimeofday64(NULL, tz);
-
-   if (!timespec_valid(tv))
-   return -EINVAL;
-
-   ts64 = timespec_to_timespec64(*tv);
-   return do_sys_settimeofday64(, tz);
-}
-
 /*
  * Kernel time accessors
  */
diff --git a/kernel/compat.c b/kernel/compat.c
index 19aec5d..e29a01a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -109,7 +109,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
   struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -123,7 +123,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? _ts : NULL, tz ? _tz : NULL);
+   return do_sys_settimeofday64(tv ? _ts : NULL, tz ? _tz : NULL);
 }
 
 static int __compat_get_timeval(struct timeval *tv, const struct 
compat_timeval __user *ctv)
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
index cd6716e..df275db 100644
--- a/kernel/time/posix-stubs.c
+++ b/kernel/time/posix-stubs.c
@@ -50,12 +50,15 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
const struct timespec __user *, tp)
 {
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (which_clock != CLOCK_REALTIME)
return -EINVAL;
if (copy_from_user(_tp, tp, sizeof (*tp)))
return -EFAULT;
-   return do_sys_settimeofday(_tp, NULL);
+
+   new_tp64 = timespec_to_timespec64(new_tp);
+   return do_sys_settimeofday64(_tp64, NULL);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 50a6a47..f215ef7 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -214,7 +214,10 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec *tp)
 static int posix_clock_realtime_set(const clockid_t which_clock,
const struct timespec *tp)
 {
-   return do_sys_settimeofday(tp, NULL);
+   struct timespec64 tp64;
+
+   tp64 = timespec_to_timespec64(*tp);
+   return do_sys_settimeofday64(, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..450e8a1 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -194,7 +194,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -212,7 +212,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? _ts : NULL, tz ? _tz : NULL);
+   return do_sys_settimeofday64(tv ? _ts : NULL, tz ? _tz : NULL);
 }
 
 SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH 5/7] Change k_clock clock_set() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/posix-clock.c  |  5 ++---
 kernel/time/posix-cpu-timers.c |  2 +-
 kernel/time/posix-timers.c | 11 +--
 5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 79d8ada..ba1b892 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -489,7 +489,7 @@ static int sgi_clock_get(clockid_t clockid, struct 
timespec64 *tp)
return 0;
 };
 
-static int sgi_clock_set(const clockid_t clockid, const struct timespec *tp)
+static int sgi_clock_set(const clockid_t clockid, const struct timespec64 *tp)
 {
 
u64 nsec;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 2555d1c..249429c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -89,7 +89,7 @@ struct k_itimer {
 struct k_clock {
int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
- const struct timespec *tp);
+ const struct timespec64 *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 * tp);
int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
int (*timer_create) (struct k_itimer *timer);
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index d5a4bec..6378fc6 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -335,10 +335,9 @@ static int pc_clock_getres(clockid_t id, struct timespec64 
*ts)
return err;
 }
 
-static int pc_clock_settime(clockid_t id, const struct timespec *ts)
+static int pc_clock_settime(clockid_t id, const struct timespec64 *ts)
 {
struct posix_clock_desc cd;
-   struct timespec64 ts64 = timespec_to_timespec64(*ts);
int err;
 
err = get_clock_desc(id, );
@@ -351,7 +350,7 @@ static int pc_clock_settime(clockid_t id, const struct 
timespec *ts)
}
 
if (cd.clk->ops.clock_settime)
-   err = cd.clk->ops.clock_settime(cd.clk, );
+   err = cd.clk->ops.clock_settime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 out:
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 42ca205..0db0e16 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -135,7 +135,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct 
timespec64 *tp)
 }
 
 static int
-posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec64 *tp)
 {
/*
 * You can never reset a CPU clock, but we check for other errors
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index a314a63..6c09f87 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -212,12 +212,9 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec64 *tp
 
 /* Set clock_realtime */
 static int posix_clock_realtime_set(const clockid_t which_clock,
-   const struct timespec *tp)
+   const struct timespec64 *tp)
 {
-   struct timespec64 tp64;
-
-   tp64 = timespec_to_timespec64(*tp);
-   return do_sys_settimeofday64(, NULL);
+   return do_sys_settimeofday64(tp, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
@@ -1018,14 +1015,16 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, 
which_clock,
 {
struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (!kc || !kc->clock_set)
return -EINVAL;
 
if (copy_from_user(_tp, tp, sizeof (*tp)))
return -EFAULT;
+   new_tp64 = timespec_to_timespec64(new_tp);
 
-   return kc->clock_set(which_clock, _tp);
+   return kc->clock_set(which_clock, _tp64);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [RESEND PATCH 2/7] time: Change posix clocks ops interfaces to use timespec64

2017-03-20 Thread Deepa Dinamani
> When changing the PTP code, please put the PTP maintainer onto CC.

Will do. Thanks for pointing out the omission.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [RESEND PATCH 2/7] time: Change posix clocks ops interfaces to use timespec64

2017-03-20 Thread Deepa Dinamani
> Please do not explain WHAT the patch is doing. We can see that from the
> diff itself. What's important is the WHY. A good changelog is structured in
> paragraphs, which explain the context, the problem and the solution. Please
> read Documentation/process/submitting-patches.rst. Let me give you an
> example.
>
>   struct timespec is not Y2038 safe on 32 bit machines and needs to be
>   replaced with struct timespec64.
>
>   The posix clock functions use struct timespec directly and through struct
>   itimerspec.
>
>   Change all function prototypes to use timespec64 and itimerspec64 and fix
>   up all implementations.
>
> That gives all the information a reviewer or someone who is looking at the
> commit later needs: context, problem scope and solution.
>
> Hmm?

Thanks for the guidance. Will fix the changelog along these lines.

>>  /* posix clock implementation */
>>
>> -static int ptp_clock_getres(struct posix_clock *pc, struct timespec *tp)
>> +static int ptp_clock_getres(struct posix_clock *pc, struct timespec64 *tp)
>
> That's a pretty pointless exercise. getres() returns the resolution of the
> clock which obviously can never be affected by Y2038.

True, tv_sec does not need to be more than 32 bits here.
We plan to limit the use of struct timespec to existing user interfaces only.
This is the reason for the change.

>>  static int pc_clock_settime(clockid_t id, const struct timespec *ts)
>>  {
>>   struct posix_clock_desc cd;
>> + struct timespec64 ts64 = timespec_to_timespec64(*ts);
>>   int err;
>
> Please order the variables as a reverse fir tree sorted by length.

Will take care of these orderings.

> struct timespec64 ts64 = timespec_to_timespec64(*ts);
> struct posix_clock_desc cd;
> int err;
>
> That's way simpler to parse than the above random length odering.
>
>> @@ -418,14 +427,19 @@ static int pc_timer_settime(struct k_itimer *kit, int 
>> flags,
>>  {
>>   clockid_t id = kit->it_clock;
>>   struct posix_clock_desc cd;
>> + struct itimerspec64 old64;
>> + struct itimerspec64 ts64 = itimerspec_to_itimerspec64(ts);

Thanks,
Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v5 4/5] vfs: Add timestamp_truncate() api

2017-04-08 Thread Deepa Dinamani
timespec_trunc() function is used to truncate a
filesystem timestamp to the right granularity.
But, the function does not clamp tv_sec part of the
timestamps according to the filesystem timestamp limits.

Also, timespec_trunc() is exclusively used for filesystem
timestamps. Move the api to be part of vfs.

The replacement api: timestamp_truncate() also alters the
signature of the function to accommodate filesystem
timestamp clamping according to flesystem limits.

Note that the clamp_t macro is used for clamping here as vfs
is not yet using struct timespec64 internally. This is
required for compilation purposes.
Also note that clamp won't do the right thing for timestamps
beyond 2038 on 32-bit machines until the vfs uses timespec64.
After the vfs is transitioned to use timespec64 for timestamps,
clamp_t() can be replaced by clamp().

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/inode.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index a0c1522..8ad5561 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2103,6 +2103,36 @@ void inode_nohighmem(struct inode *inode)
 EXPORT_SYMBOL(inode_nohighmem);
 
 /**
+ * timestamp_truncate - Truncate timespec to a granularity
+ * @t: Timespec
+ * @inode: inode being updated
+ *
+ * Truncate a timespec to the granularity supported by the fs
+ * containing the inode. Always rounds down. gran must
+ * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns).
+ */
+struct timespec timestamp_truncate(struct timespec t, struct inode *inode)
+{
+   struct super_block *sb = inode->i_sb;
+   unsigned int gran = sb->s_time_gran;
+
+   t.tv_sec = clamp_t(time64_t, t.tv_sec, sb->s_time_min, sb->s_time_max);
+
+   /* Avoid division in the common cases 1 ns and 1 s. */
+   if (gran == 1) {
+   /* nothing */
+   } else if (gran == NSEC_PER_SEC) {
+   t.tv_nsec = 0;
+   } else if (gran > 1 && gran < NSEC_PER_SEC) {
+   t.tv_nsec -= t.tv_nsec % gran;
+   } else {
+   WARN(1, "illegal file time granularity: %u", gran);
+   }
+   return t;
+}
+EXPORT_SYMBOL(timestamp_truncate);
+
+/**
  * current_time - Return FS time
  * @inode: inode.
  *
@@ -2121,6 +2151,6 @@ struct timespec current_time(struct inode *inode)
return now;
}
 
-   return timespec_trunc(now, inode->i_sb->s_time_gran);
+   return timestamp_truncate(now, inode);
 }
 EXPORT_SYMBOL(current_time);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v5 3/5] ext4: Initialize timestamps limits

2017-04-08 Thread Deepa Dinamani
ext4 has different overflow limits for max filesystem
timestamps based on the extra bytes available.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: "Theodore Ts'o" <ty...@mit.edu>
Cc: Andreas Dilger <adilger.ker...@dilger.ca>
Cc: linux-e...@vger.kernel.org
---
 fs/ext4/ext4.h  | 4 
 fs/ext4/super.c | 7 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index fb69ee2..3292d4e 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1640,6 +1640,10 @@ static inline void ext4_clear_state_flags(struct 
ext4_inode_info *ei)
 
 #define EXT4_GOOD_OLD_INODE_SIZE 128
 
+#define EXT4_EXTRA_TIMESTAMP_MAX   (((s64)1 << 34) - 1  + S32_MIN)
+#define EXT4_NON_EXTRA_TIMESTAMP_MAX   Y2038_EXPIRY_TIMESTAMP
+#define EXT4_TIMESTAMP_MIN S32_MIN
+
 /*
  * Feature set definitions
  */
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 73cae0c..0c1a864 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3687,8 +3687,13 @@ static int ext4_fill_super(struct super_block *sb, void 
*data, int silent)
   sbi->s_inode_size);
goto failed_mount;
}
-   if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
+   if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
+   sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
+   } else
+   sb->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX;
+
+   sb->s_time_min = EXT4_TIMESTAMP_MIN;
}
 
sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v5 2/5] vfs: Add checks for filesystem timestamp limits

2017-04-08 Thread Deepa Dinamani
Allow read only mounts for filesystems that do not
have maximum timestamps beyond the y2038 expiry
timestamp.

Also, allow a sysctl override to all such filesystems
to be mounted with write permissions.
A boot param supports initial override of these
checks from the early boot without recompilation.

Suggested-by: Arnd Bergmann <a...@arndb.de>
Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  8 
 fs/inode.c  | 15 +++
 fs/internal.h   |  2 ++
 fs/namespace.c  | 12 
 fs/super.c  |  7 +++
 include/linux/fs.h  |  1 +
 include/linux/time64.h  |  4 
 include/uapi/linux/fs.h |  6 +-
 kernel/sysctl.c |  7 +++
 9 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index c2f220d..57f4a50 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1193,6 +1193,14 @@
can be changed at run time by the max_graph_depth file
in the tracefs tracing directory. default: 0 (no limit)
 
+   fstimestampcheck
+   Enable checking of max filesystem time supported
+   at mount time. The value is checked against y2038
+   date: Mon Jan 18 19:14:07 PST 2038. The option
+   disables rw mount of filesystems that are not able
+   to represent times beyond y2038 time mentioned above.
+   This check is off by default.
+
gamecon.map[2|3]=
[HW,JOY] Multisystem joystick and NES/SNES/PSX pad
support via parallel port (up to 5 devices per port)
diff --git a/fs/inode.c b/fs/inode.c
index a9caf53..a0c1522 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -75,6 +75,21 @@ static DEFINE_PER_CPU(unsigned long, nr_unused);
 
 static struct kmem_cache *inode_cachep __read_mostly;
 
+struct vfs_max_timestamp_check timestamp_check = {
+   .timestamp_supported = Y2038_EXPIRY_TIMESTAMP,
+   .check_on = 0,
+};
+
+static int __init setup_timestamp_check(char *str)
+{
+   if (*str)
+   return 0;
+   timestamp_check.check_on = 1;
+   return 1;
+}
+
+__setup("fstimestampcheck", setup_timestamp_check);
+
 static long get_nr_inodes(void)
 {
int i;
diff --git a/fs/internal.h b/fs/internal.h
index cef253a..76fbcde 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -67,6 +67,8 @@ extern int finish_automount(struct vfsmount *, struct path *);
 
 extern int sb_prepare_remount_readonly(struct super_block *);
 
+extern bool sb_file_times_updatable(struct super_block *sb);
+
 extern void __init mnt_init(void);
 
 extern int __mnt_want_write(struct vfsmount *);
diff --git a/fs/namespace.c b/fs/namespace.c
index 6b81c20..fd6e479 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -538,6 +538,18 @@ static void __mnt_unmake_readonly(struct mount *mnt)
unlock_mount_hash();
 }
 
+bool sb_file_times_updatable(struct super_block *sb)
+{
+
+   if (!timestamp_check.check_on)
+   return true;
+
+   if (sb->s_time_max > timestamp_check.timestamp_supported)
+   return true;
+
+   return false;
+}
+
 int sb_prepare_remount_readonly(struct super_block *sb)
 {
struct mount *mnt;
diff --git a/fs/super.c b/fs/super.c
index f9c2241..4e7577b 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1245,6 +1245,13 @@ mount_fs(struct file_system_type *type, int flags, const 
char *name, void *data)
WARN((sb->s_maxbytes < 0), "%s set sb->s_maxbytes to "
"negative value (%lld)\n", type->name, sb->s_maxbytes);
 
+   if (!(sb->s_flags & MS_RDONLY) && !sb_file_times_updatable(sb)) {
+   WARN(1, "File times cannot be updated on the filesystem.\n");
+   WARN(1, "Retry mounting the filesystem readonly.\n");
+   error = -EROFS;
+   goto out_sb;
+   }
+
up_write(>s_umount);
free_secdata(secdata);
return root;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 63f83440..a39dc8e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -68,6 +68,7 @@ extern struct inodes_stat_t inodes_stat;
 extern int leases_enable, lease_break_time;
 extern int sysctl_protected_symlinks;
 extern int sysctl_protected_hardlinks;
+extern struct vfs_max_timestamp_check timestamp_check;
 
 struct buffer_head;
 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
diff --git a/include/linux/time64

[Y2038] [PATCH v5 1/5] vfs: Add file timestamp range support

2017-04-08 Thread Deepa Dinamani
Add fields to the superblock to track the min and max
timestamps supported by filesystems.

Initially, when a superblock is allocated, initialize
it to the max and min values the fields can hold.
Individual filesystems override these to match their
actual limits.

Pseudo filesystems are assumed to always support the
min and max allowable values for the fields.

Note that the time ranges are saved in type time64_t
rather than time_t.
This is required because if we save ranges in time_t
then we would not be able to save timestamp ranges
for files that support timestamps beyond y2038.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/super.c | 2 ++
 include/linux/fs.h | 3 +++
 include/linux/time64.h | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index b8b6a08..f9c2241 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -247,6 +247,8 @@ static struct super_block *alloc_super(struct 
file_system_type *type, int flags,
s->s_maxbytes = MAX_NON_LFS;
s->s_op = _op;
s->s_time_gran = 10;
+   s->s_time_min = TIME64_MIN;
+   s->s_time_max = TIME64_MAX;
s->cleancache_poolid = CLEANCACHE_NO_POOL;
 
s->s_shrink.seeks = DEFAULT_SEEKS;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3c18fa6..63f83440 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1337,6 +1337,9 @@ struct super_block {
/* Granularity of c/m/atime in ns.
   Cannot be worse than a second */
u32s_time_gran;
+   /* Time limits for c/m/atime in seconds. */
+   time64_t   s_time_min;
+   time64_t   s_time_max;
 
/*
 * The next field is for VFS *only*. No filesystems have any business
diff --git a/include/linux/time64.h b/include/linux/time64.h
index 980c71b..25433b18 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -38,6 +38,8 @@ struct itimerspec64 {
 
 /* Located here for timespec[64]_valid_strict */
 #define TIME64_MAX ((s64)~((u64)1 << 63))
+#define TIME64_MIN (-TIME64_MAX - 1)
+
 #define KTIME_MAX  ((s64)~((u64)1 << 63))
 #define KTIME_SEC_MAX  (KTIME_MAX / NSEC_PER_SEC)
 
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v5 0/5] vfs: Add timestamp range check support

2017-04-08 Thread Deepa Dinamani
The series is aimed at adding timestamp checking and policy
related to it to vfs.

The series was developed with discussions and guidance from
Arnd Bergmann.

The original thread is at https://lkml.org/lkml/2016/11/2/294

Associated test: xfstests generic/402
Note that the above test will be run and will fail all filesystems that
do not have correct limits specified in the xfstests or the kernel or
that don't support times beyond the test dates. I will be submitting a
follow up xfstest and kernel patches to update all filesystems.
Currently ext4 is the only filesystem that reflects correct limits.

The branch is available at
https://github.com/deepa-hub/vfs.git refs/heads/vfs_timestamp_policy

Changes since v4:
* Added documentation for boot param
Changes since v3:
* Remove redundant initializations in libfs.c
* Change early_param to __setup similar to other root mount options.
* Fix documentation warning
Changes since v2:
* Introduce early boot param override for checks.
* Drop afs patch for timestamp limits.
Changes since v1:
* return EROFS on mount errors
* fix mtime copy/paste error in utimes

Deepa Dinamani (5):
  vfs: Add file timestamp range support
  vfs: Add checks for filesystem timestamp limits
  ext4: Initialize timestamps limits
  vfs: Add timestamp_truncate() api
  utimes: Clamp the timestamps before update

 Documentation/admin-guide/kernel-parameters.txt |  8 +
 fs/ext4/ext4.h  |  4 +++
 fs/ext4/super.c |  7 +++-
 fs/inode.c  | 47 -
 fs/internal.h   |  2 ++
 fs/namespace.c  | 12 +++
 fs/super.c  |  9 +
 fs/utimes.c | 17 ++---
 include/linux/fs.h  |  4 +++
 include/linux/time64.h  |  6 
 include/uapi/linux/fs.h |  6 +++-
 kernel/sysctl.c |  7 
 12 files changed, 122 insertions(+), 7 deletions(-)

-- 
2.7.4
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v5 2/5] vfs: Add checks for filesystem timestamp limits

2017-04-08 Thread Deepa Dinamani
>> Allow read only mounts for filesystems that do not
>> have maximum timestamps beyond the y2038 expiry
>> timestamp.
>
> This option seems arbitrary and pointless.
>
> Nobody sane should ever enable it except for testing, but for testing
> it would be much better to simply specify what the limit should be:
> 2038 is not magical for all filesystems, because the base may be
> different.

Yes, the way the patch is right now, it is meant only for testing
y2038 readiness.
The feature is meant for system wide tests and not individual filesystem tests.

The original idea was to disallow writes on all filesystem mounts that
were not able to update times at the time of mount, meaning max time
supported by the filesystem should be greater than current system
time. But, then we end up with the problem of what to do about mounts
whose max time exceeds current time after mount. This can be handled
by some logic while updating inode times. But, maybe this level of
complexity is not required and we could just stick to the former use
case. And, just print a warning in the latter case. This is what
pushes the feature to be something more than y2038 readiness.

> And honestly, for testing, it would be much better to just make it a
> mount option rather than some crazy system-wide one.

The patch allows the y2038 number to be changed at compile time. I can
extend the sysctl and boot option to allow changing of this limit also
if that is preferred.

We also proposed the mount option route in the RFC. But, we received
no preferences/ comments. We proceeded with the sysctl option because
this allows us to extend this feature into disallowing writes on non
updatable time filesystems.

I could change this to providing a mount option instead if you think
that is better.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 10/12] apparmorfs: Replace CURRENT_TIME with current_time()

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time().

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. current_time() is also planned to be transitioned
to y2038 safe behavior along with this change.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 security/apparmor/apparmorfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index be0b498..4f6ac9d 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -1357,7 +1357,7 @@ static int aa_mk_null_file(struct dentry *parent)
 
inode->i_ino = get_next_ino();
inode->i_mode = S_IFCHR | S_IRUGO | S_IWUGO;
-   inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+   inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO,
   MKDEV(MEM_MAJOR, 3));
d_instantiate(dentry, inode);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 12/12] time: Delete current_fs_time() function

2017-04-07 Thread Deepa Dinamani
All uses of the current_fs_time() function have been
replaced by other time interfaces.

And, its use cases can be fulfilled by current_time()
or ktime_get_* variants.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 include/linux/fs.h |  1 -
 kernel/time/time.c | 14 --
 2 files changed, 15 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index f1d7347..cce6c57 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1430,7 +1430,6 @@ static inline void i_gid_write(struct inode *inode, gid_t 
gid)
inode->i_gid = make_kgid(inode->i_sb->s_user_ns, gid);
 }
 
-extern struct timespec current_fs_time(struct super_block *sb);
 extern struct timespec current_time(struct inode *inode);
 
 /*
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..cf69cca 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -230,20 +230,6 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
return copy_to_user(txc_p, , sizeof(struct timex)) ? -EFAULT : ret;
 }
 
-/**
- * current_fs_time - Return FS time
- * @sb: Superblock.
- *
- * Return the current time truncated to the time granularity supported by
- * the fs.
- */
-struct timespec current_fs_time(struct super_block *sb)
-{
-   struct timespec now = current_kernel_time();
-   return timespec_trunc(now, sb->s_time_gran);
-}
-EXPORT_SYMBOL(current_fs_time);
-
 /*
  * Convert jiffies to milliseconds and back.
  *
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Deepa Dinamani
>> - trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
>> + trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu 
>> ts:%lld.%09ld",
>>field->seqnum,
>>field->duration,
>>field->outer_duration,
>> -  field->timestamp.tv_sec,
>> +  (long long)field->timestamp.tv_sec,
>
> Refresh my memory. We need the cast because on 64 bit boxes
> timestamp.tv_sec is just a long?

This is only required until we change the definition of timespec64.
Right now it is defined as

#if __BITS_PER_LONG == 64
# define timespec64 timespec
#else
struct timespec64 {
time64_t tv_sec;
long tv_nsec;
};
#endif

And timespec.tv_sec is just long int on 64 bit machines.
This is why we need the cast now.

We will probably change this and only define __kernel_timespec instead
of timespec, leaving only one definition of timespec64.
At that time, we will not need this.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines
and needs to be replaced by struct timespec64
in order to represent times beyond year 2038 on such
machines.

Fix all the timestamp representation in struct trace_hwlat
and all the corresponding implementations.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 kernel/trace/trace_entries.h |  6 +++---
 kernel/trace/trace_hwlat.c   | 14 +++---
 kernel/trace/trace_output.c  |  9 -
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index c203ac4..adcdbbe 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -348,14 +348,14 @@ FTRACE_ENTRY(hwlat, hwlat_entry,
__field(u64,duration)
__field(u64,outer_duration  )
__field(u64,nmi_total_ts)
-   __field_struct( struct timespec,timestamp   )
-   __field_desc(   long,   timestamp,  tv_sec  )
+   __field_struct( struct timespec64,  timestamp   )
+   __field_desc(   s64,timestamp,  tv_sec  )
__field_desc(   long,   timestamp,  tv_nsec )
__field(unsigned int,   nmi_count   )
__field(unsigned int,   seqnum  )
),
 
-   
F_printk("cnt:%u\tts:%010lu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
+   
F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
 __entry->seqnum,
 __entry->tv_sec,
 __entry->tv_nsec,
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 21ea6ae..d7c8e4e 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -79,12 +79,12 @@ static u64 last_tracing_thresh = DEFAULT_LAT_THRESHOLD * 
NSEC_PER_USEC;
 
 /* Individual latency samples are stored here when detected. */
 struct hwlat_sample {
-   u64 seqnum; /* unique sequence */
-   u64 duration;   /* delta */
-   u64 outer_duration; /* delta (outer loop) */
-   u64 nmi_total_ts;   /* Total time spent in NMIs */
-   struct timespec timestamp;  /* wall time */
-   int nmi_count;  /* # NMIs during this sample */
+   u64 seqnum; /* unique sequence */
+   u64 duration;   /* delta */
+   u64 outer_duration; /* delta (outer loop) */
+   u64 nmi_total_ts;   /* Total time spent in NMIs */
+   struct timespec64   timestamp;  /* wall time */
+   int nmi_count;  /* # NMIs during this sample */
 };
 
 /* keep the global state somewhere. */
@@ -250,7 +250,7 @@ static int get_sample(void)
s.seqnum = hwlat_data.count;
s.duration = sample;
s.outer_duration = outer_sample;
-   s.timestamp = CURRENT_TIME;
+   ktime_get_real_ts64();
s.nmi_total_ts = nmi_total_ts;
s.nmi_count = nmi_count;
trace_hwlat_sample();
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 02a4aeb..08f9bab 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srost...@redhat.com>
  *
  */
-
 #include 
 #include 
 #include 
@@ -1161,11 +1160,11 @@ trace_hwlat_print(struct trace_iterator *iter, int 
flags,
 
trace_assign_type(field, entry);
 
-   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
+   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
 field->seqnum,
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec);
 
if (field->nmi_count) {
@@ -1195,10 +1194,10 @@ trace_hwlat_raw(struct trace_iterator *iter, int flags,
 
trace_assign_type(field, iter->ent);
 
-   trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
+   trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec,
 field->seqnum);
 
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 03/12] fs: cifs: Replace CURRENT_TIME by other appropriate apis

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time() for filesystem times, and ktime_get_*
functions for authentication timestamps and timezone
calculations.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

The inode timestamps read from the server are assumed
to have correct granularity and range.

The patch also assumes that the difference between server and
client times lie in the range INT_MIN..INT_MAX. This is valid
because this is the difference between current times between
server and client, and the largest timezone difference is in the
range of one day.

All cifs timestamps currently use timespec representation internally.
Authentication and timezone timestamps can also be transitioned into
using timespec64 when all other timestamps for cifs is transitioned
to use timespec64.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 fs/cifs/cifsencrypt.c |  4 +++-
 fs/cifs/cifssmb.c | 10 +-
 fs/cifs/inode.c   | 28 +++-
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 058ac9b..68abbb0 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -478,6 +478,7 @@ find_timestamp(struct cifs_ses *ses)
unsigned char *blobptr;
unsigned char *blobend;
struct ntlmssp2_name *attrptr;
+   struct timespec ts;
 
if (!ses->auth_key.len || !ses->auth_key.response)
return 0;
@@ -502,7 +503,8 @@ find_timestamp(struct cifs_ses *ses)
blobptr += attrsize; /* advance attr value */
}
 
-   return cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
+   ktime_get_real_ts();
+   return cpu_to_le64(cifs_UnixTimeToNT(ts));
 }
 
 static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 0669506..2f279b7 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -478,14 +478,14 @@ decode_lanman_negprot_rsp(struct TCP_Server_Info *server, 
NEGOTIATE_RSP *pSMBr)
 * this requirement.
 */
int val, seconds, remain, result;
-   struct timespec ts, utc;
-   utc = CURRENT_TIME;
+   struct timespec ts;
+   unsigned long utc = ktime_get_real_seconds();
ts = cnvrtDosUnixTm(rsp->SrvTime.Date,
rsp->SrvTime.Time, 0);
cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n",
-(int)ts.tv_sec, (int)utc.tv_sec,
-(int)(utc.tv_sec - ts.tv_sec));
-   val = (int)(utc.tv_sec - ts.tv_sec);
+(int)ts.tv_sec, (int)utc,
+(int)(utc - ts.tv_sec));
+   val = (int)(utc - ts.tv_sec);
seconds = abs(val);
result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ;
remain = seconds % MIN_TZ_ADJ;
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index b261db3..c3b2fa0 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -322,9 +322,9 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct 
super_block *sb)
fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU;
fattr->cf_uid = cifs_sb->mnt_uid;
fattr->cf_gid = cifs_sb->mnt_gid;
-   fattr->cf_atime = CURRENT_TIME;
-   fattr->cf_ctime = CURRENT_TIME;
-   fattr->cf_mtime = CURRENT_TIME;
+   ktime_get_real_ts(>cf_mtime);
+   fattr->cf_mtime = timespec_trunc(fattr->cf_mtime, sb->s_time_gran);
+   fattr->cf_atime = fattr->cf_ctime = fattr->cf_mtime;
fattr->cf_nlink = 2;
fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL;
 }
@@ -586,9 +586,10 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const 
unsigned char *path,
 /* Fill a cifs_fattr struct with info from FILE_ALL_INFO */
 static void
 cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
-  struct cifs_sb_info *cifs_sb, bool adjust_tz,
+  struct super_block *sb, bool adjust_tz,
   bool symlink)
 {
+   struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
 
memset(fattr, 0, sizeof(*fattr));
@@ -598,8 +599,10 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, 
FILE_ALL_INFO *info,
 
if (info->LastAccessTime)
fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
-   else
-   fattr->cf_atime = CURRENT_TIME;
+   else {
+   ktime_get_real_ts(>cf_atime);
+   fatt

[Y2038] [PATCH 08/12] fs: ubifs: Replace CURRENT_TIME_SEC with current_time

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME_SEC is not y2038 safe. current_time() will
be transitioned to use 64 bit time along with vfs in a
separate patch.
There is no plan to transition CURRENT_TIME_SEC to use
y2038 safe time interfaces.

current_time() returns timestamps according to the
granularities set in the inode's super_block.
The granularity check to call current_fs_time() or
CURRENT_TIME_SEC is not required.

Use current_time() directly to update inode timestamp.
Use timespec_trunc during file system creation, before
the first inode is created.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 fs/ubifs/dir.c   | 12 ++--
 fs/ubifs/file.c  | 12 ++--
 fs/ubifs/ioctl.c |  2 +-
 fs/ubifs/misc.h  | 10 --
 fs/ubifs/sb.c| 14 ++
 fs/ubifs/xattr.c |  6 +++---
 6 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 30825d88..8510d79 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -121,7 +121,7 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct 
inode *dir,
 
inode_init_owner(inode, dir, mode);
inode->i_mtime = inode->i_atime = inode->i_ctime =
-ubifs_current_time(inode);
+current_time(inode);
inode->i_mapping->nrpages = 0;
 
switch (mode & S_IFMT) {
@@ -750,7 +750,7 @@ static int ubifs_link(struct dentry *old_dentry, struct 
inode *dir,
lock_2_inodes(dir, inode);
inc_nlink(inode);
ihold(inode);
-   inode->i_ctime = ubifs_current_time(inode);
+   inode->i_ctime = current_time(inode);
dir->i_size += sz_change;
dir_ui->ui_size = dir->i_size;
dir->i_mtime = dir->i_ctime = inode->i_ctime;
@@ -823,7 +823,7 @@ static int ubifs_unlink(struct inode *dir, struct dentry 
*dentry)
}
 
lock_2_inodes(dir, inode);
-   inode->i_ctime = ubifs_current_time(dir);
+   inode->i_ctime = current_time(dir);
drop_nlink(inode);
dir->i_size -= sz_change;
dir_ui->ui_size = dir->i_size;
@@ -927,7 +927,7 @@ static int ubifs_rmdir(struct inode *dir, struct dentry 
*dentry)
}
 
lock_2_inodes(dir, inode);
-   inode->i_ctime = ubifs_current_time(dir);
+   inode->i_ctime = current_time(dir);
clear_nlink(inode);
drop_nlink(dir);
dir->i_size -= sz_change;
@@ -1405,7 +1405,7 @@ static int do_rename(struct inode *old_dir, struct dentry 
*old_dentry,
 * Like most other Unix systems, set the @i_ctime for inodes on a
 * rename.
 */
-   time = ubifs_current_time(old_dir);
+   time = current_time(old_dir);
old_inode->i_ctime = time;
 
/* We must adjust parent link count when renaming directories */
@@ -1578,7 +1578,7 @@ static int ubifs_xrename(struct inode *old_dir, struct 
dentry *old_dentry,
 
lock_4_inodes(old_dir, new_dir, NULL, NULL);
 
-   time = ubifs_current_time(old_dir);
+   time = current_time(old_dir);
fst_inode->i_ctime = time;
snd_inode->i_ctime = time;
old_dir->i_mtime = old_dir->i_ctime = time;
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index d9ae86f..2cda3d6 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1196,7 +1196,7 @@ static int do_truncation(struct ubifs_info *c, struct 
inode *inode,
mutex_lock(>ui_mutex);
ui->ui_size = inode->i_size;
/* Truncation changes inode [mc]time */
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
/* Other attributes may be changed at the same time as well */
do_attr_changes(inode, attr);
err = ubifs_jnl_truncate(c, inode, old_size, new_size);
@@ -1243,7 +1243,7 @@ static int do_setattr(struct ubifs_info *c, struct inode 
*inode,
mutex_lock(>ui_mutex);
if (attr->ia_valid & ATTR_SIZE) {
/* Truncation changes inode [mc]time */
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
/* 'truncate_setsize()' changed @i_size, update @ui_size */
ui->ui_size = inode->i_size;
}
@@ -1420,7 +1420,7 @@ int ubifs_update_time(struct inode *inode, struct 
timespec *time,
  */
 static int update_mctime(struct inode *inode)
 {
-   struct timespec now = ubifs_current_time(inode);
+   struct timespec now = current_time(inode);
struct ubifs_inode *ui = ubifs_inode(inode);
struct ubifs_info *c = inode->i_sb->s_fs_info;
 
@@ -1434,7 +1434,7 @@ static int update_mctime(struct inode *inode)
return err;
 
mutex_lock(>ui_mutex);
-   inode->i_mti

[Y2038] [PATCH 09/12] lustre: Replace CURRENT_TIME macro

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time() for filesystem times, and ktime_get_*
functions for others.

struct timespec is also not y2038 safe.
Retain timespec for timestamp representation here as lustre
uses it internally everywhere.
These references will be changed to use struct timespec64
in a separate patch.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. current_time() is also planned to be transitioned
to y2038 safe behavior along with this change.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 drivers/staging/lustre/lustre/llite/llite_lib.c | 6 +++---
 drivers/staging/lustre/lustre/osc/osc_io.c  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c 
b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 7b80040..2b4b6b9 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -1472,17 +1472,17 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr 
*attr, bool hsm_import)
 
/* We mark all of the fields "set" so MDS/OST does not re-set them */
if (attr->ia_valid & ATTR_CTIME) {
-   attr->ia_ctime = CURRENT_TIME;
+   attr->ia_ctime = current_time(inode);
attr->ia_valid |= ATTR_CTIME_SET;
}
if (!(attr->ia_valid & ATTR_ATIME_SET) &&
(attr->ia_valid & ATTR_ATIME)) {
-   attr->ia_atime = CURRENT_TIME;
+   attr->ia_atime = current_time(inode);
attr->ia_valid |= ATTR_ATIME_SET;
}
if (!(attr->ia_valid & ATTR_MTIME_SET) &&
(attr->ia_valid & ATTR_MTIME)) {
-   attr->ia_mtime = CURRENT_TIME;
+   attr->ia_mtime = current_time(inode);
attr->ia_valid |= ATTR_MTIME_SET;
}
 
diff --git a/drivers/staging/lustre/lustre/osc/osc_io.c 
b/drivers/staging/lustre/lustre/osc/osc_io.c
index f991bee..cbab800 100644
--- a/drivers/staging/lustre/lustre/osc/osc_io.c
+++ b/drivers/staging/lustre/lustre/osc/osc_io.c
@@ -216,7 +216,7 @@ static int osc_io_submit(const struct lu_env *env,
struct cl_object *obj = ios->cis_obj;
 
cl_object_attr_lock(obj);
-   attr->cat_mtime = LTIME_S(CURRENT_TIME);
+   attr->cat_mtime = ktime_get_real_seconds();
attr->cat_ctime = attr->cat_mtime;
cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
cl_object_attr_unlock(obj);
@@ -256,7 +256,7 @@ static void osc_page_touch_at(const struct lu_env *env,
   kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
   loi->loi_lvb.lvb_size);
 
-   attr->cat_ctime = LTIME_S(CURRENT_TIME);
+   attr->cat_ctime = ktime_get_real_seconds();
attr->cat_mtime = attr->cat_ctime;
valid = CAT_MTIME | CAT_CTIME;
if (kms > loi->loi_kms) {
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 05/12] fs: ufs: Use ktime_get_real_ts64() for birthtime

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
Replace it with ktime_get_real_ts64().
Inode time formats are already 64 bit long and
accommodates time64_t.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 fs/ufs/ialloc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index 9774555..d1dd8cc 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -176,6 +176,7 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
struct ufs_cg_private_info * ucpi;
struct ufs_cylinder_group * ucg;
struct inode * inode;
+   struct timespec64 ts;
unsigned cg, bit, i, j, start;
struct ufs_inode_info *ufsi;
int err = -ENOSPC;
@@ -323,8 +324,9 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
lock_buffer(bh);
ufs2_inode = (struct ufs2_inode *)bh->b_data;
ufs2_inode += ufs_inotofsbo(inode->i_ino);
-   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, CURRENT_TIME.tv_sec);
-   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, 
CURRENT_TIME.tv_nsec);
+   ktime_get_real_ts64();
+   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, ts.tv_sec);
+   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, ts.tv_nsec);
mark_buffer_dirty(bh);
unlock_buffer(bh);
if (sb->s_flags & MS_SYNCHRONOUS)
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 04/12] fs: ceph: CURRENT_TIME with ktime_get_real_ts()

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
The macro will be deleted and all the references to it
will be replaced by ktime_get_* apis.

struct timespec is also not y2038 safe.
Retain timespec for timestamp representation here as ceph
uses it internally everywhere.
These references will be changed to use struct timespec64
in a separate patch.

The current_fs_time() api is being changed to use vfs
struct inode* as an argument instead of struct super_block*.

Set the new mds client request r_stamp field using
ktime_get_real_ts() instead of using current_fs_time().

Also, since r_stamp is used as mtime on the server, use
timespec_trunc() to truncate the timestamp, using the right
granularity from the superblock.

This api will be transitioned to be y2038 safe along
with vfs.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 drivers/block/rbd.c   | 2 +-
 fs/ceph/mds_client.c  | 4 +++-
 net/ceph/messenger.c  | 6 --
 net/ceph/osd_client.c | 4 ++--
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 517838b..77204da 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1922,7 +1922,7 @@ static void rbd_osd_req_format_write(struct 
rbd_obj_request *obj_request)
 {
struct ceph_osd_request *osd_req = obj_request->osd_req;
 
-   osd_req->r_mtime = CURRENT_TIME;
+   ktime_get_real_ts(_req->r_mtime);
osd_req->r_data_offset = obj_request->offset;
 }
 
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index c681762..1d3fa90 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -1666,6 +1666,7 @@ struct ceph_mds_request *
 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode)
 {
struct ceph_mds_request *req = kzalloc(sizeof(*req), GFP_NOFS);
+   struct timespec ts;
 
if (!req)
return ERR_PTR(-ENOMEM);
@@ -1684,7 +1685,8 @@ ceph_mdsc_create_request(struct ceph_mds_client *mdsc, 
int op, int mode)
init_completion(>r_safe_completion);
INIT_LIST_HEAD(>r_unsafe_item);
 
-   req->r_stamp = current_fs_time(mdsc->fsc->sb);
+   ktime_get_real_ts();
+   req->r_stamp = timespec_trunc(ts, mdsc->fsc->sb->s_time_gran);
 
req->r_op = op;
req->r_direct_mode = mode;
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index f76bb33..5766a6c 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1386,8 +1386,9 @@ static void prepare_write_keepalive(struct 
ceph_connection *con)
dout("prepare_write_keepalive %p\n", con);
con_out_kvec_reset(con);
if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) {
-   struct timespec now = CURRENT_TIME;
+   struct timespec now;
 
+   ktime_get_real_ts();
con_out_kvec_add(con, sizeof(tag_keepalive2), _keepalive2);
ceph_encode_timespec(>out_temp_keepalive2, );
con_out_kvec_add(con, sizeof(con->out_temp_keepalive2),
@@ -3176,8 +3177,9 @@ bool ceph_con_keepalive_expired(struct ceph_connection 
*con,
 {
if (interval > 0 &&
(con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2)) {
-   struct timespec now = CURRENT_TIME;
+   struct timespec now;
struct timespec ts;
+   ktime_get_real_ts();
jiffies_to_timespec(interval, );
ts = timespec_add(con->last_keepalive_ack, ts);
return timespec_compare(, ) >= 0;
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index e15ea9e..242d7c0 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -3574,7 +3574,7 @@ ceph_osdc_watch(struct ceph_osd_client *osdc,
ceph_oid_copy(>t.base_oid, oid);
ceph_oloc_copy(>t.base_oloc, oloc);
lreq->t.flags = CEPH_OSD_FLAG_WRITE;
-   lreq->mtime = CURRENT_TIME;
+   ktime_get_real_ts(>mtime);
 
lreq->reg_req = alloc_linger_request(lreq);
if (!lreq->reg_req) {
@@ -3632,7 +3632,7 @@ int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
ceph_oid_copy(>r_base_oid, >t.base_oid);
ceph_oloc_copy(>r_base_oloc, >t.base_oloc);
req->r_flags = CEPH_OSD_FLAG_WRITE;
-   req->r_mtime = CURRENT_TIME;
+   ktime_get_real_ts(>r_mtime);
osd_req_op_watch_init(req, 0, lreq->linger_id,
  CEPH_OSD_WATCH_OP_UNWATCH);
 
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 07/12] fs: btrfs: Use ktime_get_real_ts for root ctime

2017-04-07 Thread Deepa Dinamani
btrfs_root_item maintains the ctime for root updates.
This is not part of vfs_inode.

Since current_time() uses struct inode* as an argument
as Linus suggested, this cannot be used to update root
times unless, we modify the signature to use inode.

Since btrfs uses nanosecond time granularity, it can also
use ktime_get_real_ts directly to obtain timestamp for
the root. It is necessary to use the timespec time api
here because the same btrfs_set_stack_timespec_*() apis
are used for vfs inode times as well. These can be
transitioned to using timespec64 when btrfs internally
changes to use timespec64 as well.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Acked-by: David Sterba <dste...@suse.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 fs/btrfs/root-tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index a08224e..7d6bc30 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -501,8 +501,9 @@ void btrfs_update_root_times(struct btrfs_trans_handle 
*trans,
 struct btrfs_root *root)
 {
struct btrfs_root_item *item = >root_item;
-   struct timespec ct = current_fs_time(root->fs_info->sb);
+   struct timespec ct;
 
+   ktime_get_real_ts();
spin_lock(>root_item_lock);
btrfs_set_root_ctransid(item, trans->transid);
btrfs_set_stack_timespec_sec(>ctime, ct.tv_sec);
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 06/12] audit: Use timespec64 to represent audit timestamps

2017-04-07 Thread Deepa Dinamani
struct timespec is not y2038 safe.
Audit timestamps are recorded in string format into
an audit buffer for a given context.
These mark the entry timestamps for the syscalls.
Use y2038 safe struct timespec64 to represent the times.
The log strings can handle this transition as strings can
hold upto 1024 characters.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Paul Moore <p...@paul-moore.com>
Acked-by: Richard Guy Briggs <r...@redhat.com>
---
 include/linux/audit.h |  4 ++--
 kernel/audit.c| 10 +-
 kernel/audit.h|  2 +-
 kernel/auditsc.c  |  6 +++---
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 6fdfefc..f830508 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -332,7 +332,7 @@ static inline void audit_ptrace(struct task_struct *t)
/* Private API (for audit.c only) */
 extern unsigned int audit_serial(void);
 extern int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial);
+ struct timespec64 *t, unsigned int *serial);
 extern int audit_set_loginuid(kuid_t loginuid);
 
 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
@@ -511,7 +511,7 @@ static inline void __audit_seccomp(unsigned long syscall, 
long signr, int code)
 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
 { }
 static inline int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial)
+ struct timespec64 *t, unsigned int *serial)
 {
return 0;
 }
diff --git a/kernel/audit.c b/kernel/audit.c
index 2f4964c..fcbf377 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -1625,10 +1625,10 @@ unsigned int audit_serial(void)
 }
 
 static inline void audit_get_stamp(struct audit_context *ctx,
-  struct timespec *t, unsigned int *serial)
+  struct timespec64 *t, unsigned int *serial)
 {
if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
-   *t = CURRENT_TIME;
+   ktime_get_real_ts64(t);
*serial = audit_serial();
}
 }
@@ -1652,7 +1652,7 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
 int type)
 {
struct audit_buffer *ab;
-   struct timespec t;
+   struct timespec64 t;
unsigned int uninitialized_var(serial);
 
if (audit_initialized != AUDIT_INITIALIZED)
@@ -1705,8 +1705,8 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
}
 
audit_get_stamp(ab->ctx, , );
-   audit_log_format(ab, "audit(%lu.%03lu:%u): ",
-t.tv_sec, t.tv_nsec/100, serial);
+   audit_log_format(ab, "audit(%llu.%03lu:%u): ",
+(unsigned long long)t.tv_sec, t.tv_nsec/100, 
serial);
 
return ab;
 }
diff --git a/kernel/audit.h b/kernel/audit.h
index 0f1cf6d..cdf96f4 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -112,7 +112,7 @@ struct audit_context {
enum audit_statestate, current_state;
unsigned intserial; /* serial number for record */
int major;  /* syscall number */
-   struct timespec ctime;  /* time of syscall entry */
+   struct timespec64   ctime;  /* time of syscall entry */
unsigned long   argv[4];/* syscall arguments */
longreturn_code;/* syscall return code */
u64 prio;
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index e59ffc7..a2d9217 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1532,7 +1532,7 @@ void __audit_syscall_entry(int major, unsigned long a1, 
unsigned long a2,
return;
 
context->serial = 0;
-   context->ctime  = CURRENT_TIME;
+   ktime_get_real_ts64(>ctime);
context->in_syscall = 1;
context->current_state  = state;
context->ppid   = 0;
@@ -1941,13 +1941,13 @@ EXPORT_SYMBOL_GPL(__audit_inode_child);
 /**
  * auditsc_get_stamp - get local copies of audit_context values
  * @ctx: audit_context for the task
- * @t: timespec to store time recorded in the audit_context
+ * @t: timespec64 to store time recorded in the audit_context
  * @serial: serial value that is recorded in the audit_context
  *
  * Also sets the context as auditable.
  */
 int auditsc_get_stamp(struct audit_context *ctx,
-  struct timespec *t, unsigned int *serial)
+  struct timespec64 *t, unsigned int *serial)
 {
if (!ctx->in_syscall)
return 0;
-- 
2.7.4

_

[Y2038] [PATCH 11/12] time: Delete CURRENT_TIME_SEC and CURRENT_TIME

2017-04-07 Thread Deepa Dinamani
All uses of CURRENT_TIME_SEC and CURRENT_TIME macros have
been replaced by other time functions. These macros are
also not y2038 safe.
And, all their use cases can be fulfilled by y2038 safe
ktime_get_* variants.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Acked-by: John Stultz <john.stu...@linaro.org>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 include/linux/time.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 23f0f5c..c0543f5 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -151,9 +151,6 @@ static inline bool timespec_inject_offset_valid(const 
struct timespec *ts)
return true;
 }
 
-#define CURRENT_TIME   (current_kernel_time())
-#define CURRENT_TIME_SEC   ((struct timespec) { get_seconds(), 0 })
-
 /* Some architectures do not supply their own clocksource.
  * This is mainly the case in architectures that get their
  * inter-tick times by reading the counter on their interval
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 01/12] fs: f2fs: Use ktime_get_real_seconds for sit_info times

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME_SEC is not y2038 safe.

Replace use of CURRENT_TIME_SEC with ktime_get_real_seconds
in segment timestamps used by GC algorithm including the
segment mtime timestamps.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 fs/f2fs/segment.c | 2 +-
 fs/f2fs/segment.h | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 010324c..0531500 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2678,7 +2678,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
sit_i->dirty_sentries = 0;
sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK;
sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time);
-   sit_i->mounted_time = CURRENT_TIME_SEC.tv_sec;
+   sit_i->mounted_time = ktime_get_real_seconds();
mutex_init(_i->sentry_lock);
return 0;
 }
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 57e36c1..156afc3 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -692,8 +692,9 @@ static inline void set_to_next_sit(struct sit_info *sit_i, 
unsigned int start)
 static inline unsigned long long get_mtime(struct f2fs_sb_info *sbi)
 {
struct sit_info *sit_i = SIT_I(sbi);
-   return sit_i->elapsed_time + CURRENT_TIME_SEC.tv_sec -
-   sit_i->mounted_time;
+   time64_t now = ktime_get_real_seconds();
+
+   return sit_i->elapsed_time + now - sit_i->mounted_time;
 }
 
 static inline void set_summary(struct f2fs_summary *sum, nid_t nid,
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 00/12] Delete CURRENT_TIME, CURRENT_TIME_SEC and current_fs_time

2017-04-07 Thread Deepa Dinamani
The series contains the last unmerged uses of CURRENT_TIME,
CURRENT_TIME_SEC, and current_fs_time().
The series also deletes these apis.

All the patches except [PATCH 9/12] and [PATCH 10/12] are resend patches.
These patches fix new instances of CURRENT_TIME.
cifs and ceph patches have been squashed so that we have one patch per
filesystem.

We want to get these merged onto 4.12 release so that I can post the series
that changes vfs timestamps to use 64 bits for 4.13 release.

I'm proposing these to be merged through Andrew's tree.

Filesystem maintainers, please let Andrew know if you will be picking up
the patch in your trees.

Let me know if anybody has other preferences for merging.

Deepa Dinamani (12):
  fs: f2fs: Use ktime_get_real_seconds for sit_info times
  trace: Make trace_hwlat timestamp y2038 safe
  fs: cifs: Replace CURRENT_TIME by other appropriate apis
  fs: ceph: CURRENT_TIME with ktime_get_real_ts()
  fs: ufs: Use ktime_get_real_ts64() for birthtime
  audit: Use timespec64 to represent audit timestamps
  fs: btrfs: Use ktime_get_real_ts for root ctime
  fs: ubifs: Replace CURRENT_TIME_SEC with current_time
  lustre: Replace CURRENT_TIME macro
  apparmorfs: Replace CURRENT_TIME with current_time()
  time: Delete CURRENT_TIME_SEC and CURRENT_TIME
  time: Delete current_fs_time() function

 drivers/block/rbd.c |  2 +-
 drivers/staging/lustre/lustre/llite/llite_lib.c |  6 +++---
 drivers/staging/lustre/lustre/osc/osc_io.c  |  4 ++--
 fs/btrfs/root-tree.c|  3 ++-
 fs/ceph/mds_client.c|  4 +++-
 fs/cifs/cifsencrypt.c   |  4 +++-
 fs/cifs/cifssmb.c   | 10 -
 fs/cifs/inode.c | 28 +
 fs/f2fs/segment.c   |  2 +-
 fs/f2fs/segment.h   |  5 +++--
 fs/ubifs/dir.c  | 12 +--
 fs/ubifs/file.c | 12 +--
 fs/ubifs/ioctl.c|  2 +-
 fs/ubifs/misc.h | 10 -
 fs/ubifs/sb.c   | 14 +
 fs/ubifs/xattr.c|  6 +++---
 fs/ufs/ialloc.c |  6 --
 include/linux/audit.h   |  4 ++--
 include/linux/fs.h  |  1 -
 include/linux/time.h|  3 ---
 kernel/audit.c  | 10 -
 kernel/audit.h  |  2 +-
 kernel/auditsc.c|  6 +++---
 kernel/time/time.c  | 14 -
 kernel/trace/trace_entries.h|  6 +++---
 kernel/trace/trace_hwlat.c  | 14 ++---
 kernel/trace/trace_output.c |  9 
 net/ceph/messenger.c|  6 --
 net/ceph/osd_client.c   |  4 ++--
 security/apparmor/apparmorfs.c  |  2 +-
 30 files changed, 100 insertions(+), 111 deletions(-)

-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH 06/12] audit: Use timespec64 to represent audit timestamps

2017-04-08 Thread Deepa Dinamani
> I have no problem merging this patch into audit/next for v4.12, would
> you prefer me to do that so at least this patch is merged?

This would be fine.
But, I think whoever takes the last 2 deletion patches should also take them.
I'm not sure how that part works out.

> It would probably make life a small bit easier for us in the audit
> world too as it would reduce the potential merge conflict.  However,
> that's a relatively small thing to worry about.

-Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v3 4/6] ipc: sem: Make sem_array timestamps y2038 safe

2017-08-02 Thread Deepa Dinamani
time_t is not y2038 safe. Replace all uses of
time_t by y2038 safe time64_t.

Similarly, replace the calls to get_seconds() with
y2038 safe ktime_get_real_seconds().
Note that this preserves fast access on 64 bit systems,
but 32 bit systems need sequence counters.

The syscall interface themselves are not changed as part of
the patch. They will be part of a different series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 include/linux/sem.h |  3 ++-
 ipc/sem.c   | 18 +-
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/linux/sem.h b/include/linux/sem.h
index 9edec926e9d9..8012ce99f72f 100644
--- a/include/linux/sem.h
+++ b/include/linux/sem.h
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 struct task_struct;
@@ -11,7 +12,7 @@ struct task_struct;
 /* One sem_array data structure for each set of semaphores in the system. */
 struct sem_array {
struct kern_ipc_permsem_perm;   /* permissions .. see ipc.h */
-   time_t  sem_ctime;  /* last change time */
+   time64_tsem_ctime;  /* last change time */
struct sem  *sem_base;  /* ptr to first semaphore in 
array */
struct list_headpending_alter;  /* pending operations */
/* that alter the array */
diff --git a/ipc/sem.c b/ipc/sem.c
index b41cd00d104c..48e7babdb869 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -518,7 +518,7 @@ static int newary(struct ipc_namespace *ns, struct 
ipc_params *params)
INIT_LIST_HEAD(>pending_const);
INIT_LIST_HEAD(>list_id);
sma->sem_nsems = nsems;
-   sma->sem_ctime = get_seconds();
+   sma->sem_ctime = ktime_get_real_seconds();
 
id = ipc_addid(_ids(ns), >sem_perm, ns->sc_semmni);
if (id < 0) {
@@ -1169,14 +1169,14 @@ static unsigned long copy_semid_to_user(void __user 
*buf, struct semid64_ds *in,
}
 }
 
-static time_t get_semotime(struct sem_array *sma)
+static time64_t get_semotime(struct sem_array *sma)
 {
int i;
-   time_t res;
+   time64_t res;
 
res = sma->sem_base[0].sem_otime;
for (i = 1; i < sma->sem_nsems; i++) {
-   time_t to = sma->sem_base[i].sem_otime;
+   time64_t to = sma->sem_base[i].sem_otime;
 
if (to > res)
res = to;
@@ -1316,7 +1316,7 @@ static int semctl_setval(struct ipc_namespace *ns, int 
semid, int semnum,
 
curr->semval = val;
curr->sempid = task_tgid_vnr(current);
-   sma->sem_ctime = get_seconds();
+   sma->sem_ctime = ktime_get_real_seconds();
/* maybe some queued-up processes were waiting for this */
do_smart_update(sma, NULL, 0, 0, _q);
sem_unlock(sma, -1);
@@ -1442,7 +1442,7 @@ static int semctl_main(struct ipc_namespace *ns, int 
semid, int semnum,
for (i = 0; i < nsems; i++)
un->semadj[i] = 0;
}
-   sma->sem_ctime = get_seconds();
+   sma->sem_ctime = ktime_get_real_seconds();
/* maybe some queued-up processes were waiting for this */
do_smart_update(sma, NULL, 0, 0, _q);
err = 0;
@@ -1552,7 +1552,7 @@ static int semctl_down(struct ipc_namespace *ns, int 
semid,
err = ipc_update_perm(>sem_perm, ipcp);
if (err)
goto out_unlock0;
-   sma->sem_ctime = get_seconds();
+   sma->sem_ctime = ktime_get_real_seconds();
break;
default:
err = -EINVAL;
@@ -2297,7 +2297,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void 
*it)
 {
struct user_namespace *user_ns = seq_user_ns(s);
struct sem_array *sma = it;
-   time_t sem_otime;
+   time64_t sem_otime;
 
/*
 * The proc interface isn't aware of sem_lock(), it calls
@@ -2310,7 +2310,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void 
*it)
sem_otime = get_semotime(sma);
 
seq_printf(s,
-  "%10d %10d  %4o %10u %5u %5u %5u %5u %10lu %10lu\n",
+  "%10d %10d  %4o %10u %5u %5u %5u %5u %10llu %10llu\n",
   sma->sem_perm.key,
   sma->sem_perm.id,
   sma->sem_perm.mode,
-- 
2.11.0

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v3 2/6] ipc: mqueue: Replace timespec with timespec64

2017-08-02 Thread Deepa Dinamani
struct timespec is not y2038 safe. Replace
all uses of timespec by y2038 safe struct timespec64.

Even though timespec is used here to represent timeouts,
replace these with timespec64 so that it facilitates
in verification by creating a y2038 safe kernel image
that is free of timespec.

The syscall interfaces themselves are not changed as part
of the patch. They will be part of a different series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: Paul Moore <p...@paul-moore.com>
Cc: Richard Guy Briggs <r...@redhat.com>
Reviewed-by: Richard Guy Briggs <r...@redhat.com>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Paul Moore <p...@paul-moore.com>
---
 include/linux/audit.h |  6 +++---
 ipc/mqueue.c  | 28 ++--
 kernel/audit.h|  2 +-
 kernel/auditsc.c  | 12 ++--
 4 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 2150bdccfbab..74d4d4e8e3db 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -351,7 +351,7 @@ extern int __audit_socketcall(int nargs, unsigned long 
*args);
 extern int __audit_sockaddr(int len, void *addr);
 extern void __audit_fd_pair(int fd1, int fd2);
 extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
-extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec *abs_timeout);
+extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec64 *abs_timeout);
 extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent 
*notification);
 extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
 extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
@@ -412,7 +412,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, 
struct mq_attr *attr)
if (unlikely(!audit_dummy_context()))
__audit_mq_open(oflag, mode, attr);
 }
-static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec *abs_timeout)
+static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec64 *abs_timeout)
 {
if (unlikely(!audit_dummy_context()))
__audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
@@ -549,7 +549,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, 
struct mq_attr *attr)
 { }
 static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
 unsigned int msg_prio,
-const struct timespec *abs_timeout)
+const struct timespec64 *abs_timeout)
 { }
 static inline void audit_mq_notify(mqd_t mqdes,
   const struct sigevent *notification)
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index c9ff943f19ab..5be1346a9167 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -668,11 +668,11 @@ static void __do_notify(struct mqueue_inode_info *info)
 }
 
 static int prepare_timeout(const struct timespec __user *u_abs_timeout,
-  struct timespec *ts)
+  struct timespec64 *ts)
 {
-   if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
+   if (get_timespec64(ts, u_abs_timeout))
return -EFAULT;
-   if (!timespec_valid(ts))
+   if (!timespec64_valid(ts))
return -EINVAL;
return 0;
 }
@@ -962,7 +962,7 @@ static inline void pipelined_receive(struct wake_q_head 
*wake_q,
 
 static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
size_t msg_len, unsigned int msg_prio,
-   struct timespec *ts)
+   struct timespec64 *ts)
 {
struct fd f;
struct inode *inode;
@@ -979,7 +979,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user 
*u_msg_ptr,
return -EINVAL;
 
if (ts) {
-   expires = timespec_to_ktime(*ts);
+   expires = timespec64_to_ktime(*ts);
timeout = 
}
 
@@ -1080,7 +1080,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user 
*u_msg_ptr,
 
 static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
size_t msg_len, unsigned int __user *u_msg_prio,
-   struct timespec *ts)
+   struct timespec64 *ts)
 {
ssize_t ret;
struct msg_msg *msg_ptr;
@@ -1092,7 +1092,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user 
*u_msg_ptr,
struct posix_msg_tree_node *new_leaf = NULL;
 
if (ts) {
-   expires = timespec_to_ktime(*ts);
+   expires = timespec64_to_ktime(*ts);
timeout = 
}
 
@@ -1184,7 +1184,7 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char 
__user *, u_msg_ptr,
size_t, msg_len, unsigned int, msg_prio,
 

[Y2038] [PATCH v3 0/6] Make ipc y2038 safe

2017-08-02 Thread Deepa Dinamani
The series aims to transition internal workings of ipc subsystem
to use y2038-safe types and apis.

The series is based on Al Viro's #work.ipc branch.

Changes since v2:
* Removed extra typecasts
Changes since v1:
* Addressed audit review comments

Deepa Dinamani (6):
  ipc: Make sys_semtimedop() y2038 safe
  ipc: mqueue: Replace timespec with timespec64
  ipc: msg: Make msg_queue timestamps y2038 safe
  ipc: sem: Make sem_array timestamps y2038 safe
  ipc: shm: Make shmid_kernel timestamps y2038 safe
  utimes: Make utimes y2038 safe

 fs/utimes.c   | 23 ---
 include/linux/audit.h |  6 +++---
 include/linux/msg.h   |  7 ---
 include/linux/sem.h   |  3 ++-
 include/linux/shm.h   |  6 +++---
 include/linux/time.h  |  2 +-
 init/initramfs.c  |  2 +-
 ipc/mqueue.c  | 28 ++--
 ipc/msg.c |  6 +++---
 ipc/sem.c | 30 +++---
 ipc/shm.c | 10 +-
 kernel/audit.h|  2 +-
 kernel/auditsc.c  | 12 ++--
 13 files changed, 70 insertions(+), 67 deletions(-)

-- 
2.11.0

Cc: Paul Moore <p...@paul-moore.com>
Cc: Richard Guy Briggs <r...@redhat.com>
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2 4/6] ipc: sem: Make sem_array timestamps y2038 safe

2017-08-01 Thread Deepa Dinamani
> Unless I'm missing something here, you can drop the cast to
> unsigned long long: time64_t is always 'long long' and won't
> cause a warning here.
>
> We only need a cast like this when printing the members of 'struct
>  timespec64', since that can be either 'long long' or 'long', when
> it is defined as an alias for timespec.

You are right.
I think I had timespec64 on my mind when I added this cast.
I will update the series with the casts removed.

Thanks,
Deepa
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 2/2] io_getevents: Use timespec64 to represent timeouts

2017-08-04 Thread Deepa Dinamani
struct timespec is not y2038 safe. Use y2038 safe
struct timespec64 to represent timeouts.
The system call interface itself will be changed as
part of different series.

Timeouts will not really need more than 32 bits.
But, replacing these with timespec64 helps verification
of a y2038 safe kernel by getting rid of timespec
internally.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: linux-...@kvack.org
---
 fs/aio.c | 55 ++-
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 8f0127526299..7ca6b7a00368 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1289,20 +1289,10 @@ static bool aio_read_events(struct kioctx *ctx, long 
min_nr, long nr,
 
 static long read_events(struct kioctx *ctx, long min_nr, long nr,
struct io_event __user *event,
-   struct timespec __user *timeout)
+   ktime_t until)
 {
-   ktime_t until = KTIME_MAX;
long ret = 0;
 
-   if (timeout) {
-   struct timespec ts;
-
-   if (unlikely(copy_from_user(, timeout, sizeof(ts
-   return -EFAULT;
-
-   until = timespec_to_ktime(ts);
-   }
-
/*
 * Note that aio_read_events() is being called as the conditional - i.e.
 * we're calling it after prepare_to_wait() has set task state to
@@ -1824,6 +1814,25 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct 
iocb __user *, iocb,
return ret;
 }
 
+static long do_io_getevents(aio_context_t ctx_id,
+   long min_nr,
+   long nr,
+   struct io_event __user *events,
+   struct timespec64 *ts)
+{
+   ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
+   struct kioctx *ioctx = lookup_ioctx(ctx_id);
+   long ret = -EINVAL;
+
+   if (likely(ioctx)) {
+   if (likely(min_nr <= nr && min_nr >= 0))
+   ret = read_events(ioctx, min_nr, nr, events, until);
+   percpu_ref_put(>users);
+   }
+
+   return ret;
+}
+
 /* io_getevents:
  * Attempts to read at least min_nr events and up to nr events from
  * the completion queue for the aio_context specified by ctx_id. If
@@ -1842,15 +1851,14 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
struct io_event __user *, events,
struct timespec __user *, timeout)
 {
-   struct kioctx *ioctx = lookup_ioctx(ctx_id);
-   long ret = -EINVAL;
+   struct timespec64   ts;
 
-   if (likely(ioctx)) {
-   if (likely(min_nr <= nr && min_nr >= 0))
-   ret = read_events(ioctx, min_nr, nr, events, timeout);
-   percpu_ref_put(>users);
+   if (timeout) {
+   if (unlikely(get_timespec64(, timeout)))
+   return -EFAULT;
}
-   return ret;
+
+   return do_io_getevents(ctx_id, min_nr, nr, events, timeout ?  : 
NULL);
 }
 
 #ifdef CONFIG_COMPAT
@@ -1860,17 +1868,14 @@ COMPAT_SYSCALL_DEFINE5(io_getevents, 
compat_aio_context_t, ctx_id,
   struct io_event __user *, events,
   struct compat_timespec __user *, timeout)
 {
-   struct timespec t;
-   struct timespec __user *ut = NULL;
+   struct timespec64 t;
 
if (timeout) {
-   if (compat_get_timespec(, timeout))
+   if (compat_get_timespec64(, timeout))
return -EFAULT;
 
-   ut = compat_alloc_user_space(sizeof(*ut));
-   if (copy_to_user(ut, , sizeof(t)))
-   return -EFAULT;
}
-   return sys_io_getevents(ctx_id, min_nr, nr, events, ut);
+
+   return do_io_getevents(ctx_id, min_nr, nr, events, timeout ?  : NULL);
 }
 #endif
-- 
2.11.0

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2 0/6] Make ipc y2038 safe

2017-07-30 Thread Deepa Dinamani
The series aims to transition internal workings of ipc subsystem
to use y2038-safe types and apis.

The series is based on Al Viro's #work.ipc branch.

Changes since v1:
* Addressed audit review comments

Deepa Dinamani (6):
  ipc: Make sys_semtimedop() y2038 safe
  ipc: mqueue: Replace timespec with timespec64
  ipc: msg: Make msg_queue timestamps y2038 safe
  ipc: sem: Make sem_array timestamps y2038 safe
  ipc: shm: Make shmid_kernel timestamps y2038 safe
  utimes: Make utimes y2038 safe

 fs/utimes.c   | 23 ---
 include/linux/audit.h |  6 +++---
 include/linux/msg.h   |  7 ---
 include/linux/sem.h   |  3 ++-
 include/linux/shm.h   |  6 +++---
 include/linux/time.h  |  2 +-
 init/initramfs.c  |  2 +-
 ipc/mqueue.c  | 28 ++--
 ipc/msg.c | 12 ++--
 ipc/sem.c | 34 +-
 ipc/shm.c | 16 
 kernel/audit.h|  2 +-
 kernel/auditsc.c  | 12 ++--
 13 files changed, 78 insertions(+), 75 deletions(-)

-- 
2.11.0

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2 1/6] ipc: Make sys_semtimedop() y2038 safe

2017-07-30 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines.
Replace timespec with y2038 safe struct timespec64.

Note that the patch only changes the internals without
modifying the syscall interface. This will be part
of a separate series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 ipc/sem.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ipc/sem.c b/ipc/sem.c
index 8b3b40c54a58..b41cd00d104c 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1861,7 +1861,7 @@ static struct sem_undo *find_alloc_undo(struct 
ipc_namespace *ns, int semid)
 }
 
 static long do_semtimedop(int semid, struct sembuf __user *tsops,
-   unsigned nsops, const struct timespec *timeout)
+   unsigned nsops, const struct timespec64 *timeout)
 {
int error = -EINVAL;
struct sem_array *sma;
@@ -1897,7 +1897,7 @@ static long do_semtimedop(int semid, struct sembuf __user 
*tsops,
error = -EINVAL;
goto out_free;
}
-   jiffies_left = timespec_to_jiffies(timeout);
+   jiffies_left = timespec64_to_jiffies(timeout);
}
 
max = 0;
@@ -2116,8 +2116,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf 
__user *, tsops,
unsigned, nsops, const struct timespec __user *, timeout)
 {
if (timeout) {
-   struct timespec ts;
-   if (copy_from_user(, timeout, sizeof(*timeout)))
+   struct timespec64 ts;
+   if (get_timespec64(, timeout))
return -EFAULT;
return do_semtimedop(semid, tsops, nsops, );
}
@@ -2130,8 +2130,8 @@ COMPAT_SYSCALL_DEFINE4(semtimedop, int, semid, struct 
sembuf __user *, tsems,
   const struct compat_timespec __user *, timeout)
 {
if (timeout) {
-   struct timespec ts;
-   if (compat_get_timespec(, timeout))
+   struct timespec64 ts;
+   if (compat_get_timespec64(, timeout))
return -EFAULT;
return do_semtimedop(semid, tsems, nsops, );
}
-- 
2.11.0

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2 3/6] ipc: msg: Make msg_queue timestamps y2038 safe

2017-07-30 Thread Deepa Dinamani
time_t is not y2038 safe. Replace all uses of
time_t by y2038 safe time64_t.

Similarly, replace the calls to get_seconds() with
y2038 safe ktime_get_real_seconds().
Note that this preserves fast access on 64 bit systems,
but 32 bit systems need sequence counters.

The syscall interfaces themselves are not changed as part of
the patch. They will be part of a different series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
---
 include/linux/msg.h |  7 ---
 ipc/msg.c   | 12 ++--
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/include/linux/msg.h b/include/linux/msg.h
index 4e5ec3cbf464..05115342daa3 100644
--- a/include/linux/msg.h
+++ b/include/linux/msg.h
@@ -2,6 +2,7 @@
 #define _LINUX_MSG_H
 
 #include 
+#include 
 #include 
 
 /* one msg_msg structure for each message */
@@ -17,9 +18,9 @@ struct msg_msg {
 /* one msq_queue structure for each present queue on the system */
 struct msg_queue {
struct kern_ipc_perm q_perm;
-   time_t q_stime; /* last msgsnd time */
-   time_t q_rtime; /* last msgrcv time */
-   time_t q_ctime; /* last change time */
+   time64_t q_stime;   /* last msgsnd time */
+   time64_t q_rtime;   /* last msgrcv time */
+   time64_t q_ctime;   /* last change time */
unsigned long q_cbytes; /* current number of bytes on queue */
unsigned long q_qnum;   /* number of messages in queue */
unsigned long q_qbytes; /* max number of bytes on queue */
diff --git a/ipc/msg.c b/ipc/msg.c
index 14369ad6c5ca..e967f0e3fe69 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -133,7 +133,7 @@ static int newque(struct ipc_namespace *ns, struct 
ipc_params *params)
}
 
msq->q_stime = msq->q_rtime = 0;
-   msq->q_ctime = get_seconds();
+   msq->q_ctime = ktime_get_real_seconds();
msq->q_cbytes = msq->q_qnum = 0;
msq->q_qbytes = ns->msg_ctlmnb;
msq->q_lspid = msq->q_lrpid = 0;
@@ -406,7 +406,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, 
int cmd,
 
msq->q_qbytes = msqid64->msg_qbytes;
 
-   msq->q_ctime = get_seconds();
+   msq->q_ctime = ktime_get_real_seconds();
/*
 * Sleeping receivers might be excluded by
 * stricter permissions.
@@ -1181,7 +1181,7 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void 
*it)
struct msg_queue *msq = it;
 
seq_printf(s,
-  "%10d %10d  %4o  %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu 
%10lu %10lu\n",
+  "%10d %10d  %4o  %10lu %10lu %5u %5u %5u %5u %5u %5u %10llu 
%10llu %10llu\n",
   msq->q_perm.key,
   msq->q_perm.id,
   msq->q_perm.mode,
@@ -1193,9 +1193,9 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void 
*it)
   from_kgid_munged(user_ns, msq->q_perm.gid),
   from_kuid_munged(user_ns, msq->q_perm.cuid),
   from_kgid_munged(user_ns, msq->q_perm.cgid),
-  msq->q_stime,
-  msq->q_rtime,
-  msq->q_ctime);
+  (unsigned long long) msq->q_stime,
+  (unsigned long long) msq->q_rtime,
+  (unsigned long long) msq->q_ctime);
 
return 0;
 }
-- 
2.11.0

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2 2/6] ipc: mqueue: Replace timespec with timespec64

2017-07-30 Thread Deepa Dinamani
struct timespec is not y2038 safe. Replace
all uses of timespec by y2038 safe struct timespec64.

Even though timespec is used here to represent timeouts,
replace these with timespec64 so that it facilitates
in verification by creating a y2038 safe kernel image
that is free of timespec.

The syscall interfaces themselves are not changed as part
of the patch. They will be part of a different series.

Signed-off-by: Deepa Dinamani <deepa.ker...@gmail.com>
Cc: Paul Moore <p...@paul-moore.com>
Cc: Richard Guy Briggs <r...@redhat.com>
Reviewed-by: Richard Guy Briggs <r...@redhat.com>
---
 include/linux/audit.h |  6 +++---
 ipc/mqueue.c  | 28 ++--
 kernel/audit.h|  2 +-
 kernel/auditsc.c  | 12 ++--
 4 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 2150bdccfbab..74d4d4e8e3db 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -351,7 +351,7 @@ extern int __audit_socketcall(int nargs, unsigned long 
*args);
 extern int __audit_sockaddr(int len, void *addr);
 extern void __audit_fd_pair(int fd1, int fd2);
 extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
-extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec *abs_timeout);
+extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec64 *abs_timeout);
 extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent 
*notification);
 extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
 extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
@@ -412,7 +412,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, 
struct mq_attr *attr)
if (unlikely(!audit_dummy_context()))
__audit_mq_open(oflag, mode, attr);
 }
-static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec *abs_timeout)
+static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int 
msg_prio, const struct timespec64 *abs_timeout)
 {
if (unlikely(!audit_dummy_context()))
__audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
@@ -549,7 +549,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, 
struct mq_attr *attr)
 { }
 static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
 unsigned int msg_prio,
-const struct timespec *abs_timeout)
+const struct timespec64 *abs_timeout)
 { }
 static inline void audit_mq_notify(mqd_t mqdes,
   const struct sigevent *notification)
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index c9ff943f19ab..5be1346a9167 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -668,11 +668,11 @@ static void __do_notify(struct mqueue_inode_info *info)
 }
 
 static int prepare_timeout(const struct timespec __user *u_abs_timeout,
-  struct timespec *ts)
+  struct timespec64 *ts)
 {
-   if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
+   if (get_timespec64(ts, u_abs_timeout))
return -EFAULT;
-   if (!timespec_valid(ts))
+   if (!timespec64_valid(ts))
return -EINVAL;
return 0;
 }
@@ -962,7 +962,7 @@ static inline void pipelined_receive(struct wake_q_head 
*wake_q,
 
 static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
size_t msg_len, unsigned int msg_prio,
-   struct timespec *ts)
+   struct timespec64 *ts)
 {
struct fd f;
struct inode *inode;
@@ -979,7 +979,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user 
*u_msg_ptr,
return -EINVAL;
 
if (ts) {
-   expires = timespec_to_ktime(*ts);
+   expires = timespec64_to_ktime(*ts);
timeout = 
}
 
@@ -1080,7 +1080,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user 
*u_msg_ptr,
 
 static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
size_t msg_len, unsigned int __user *u_msg_prio,
-   struct timespec *ts)
+   struct timespec64 *ts)
 {
ssize_t ret;
struct msg_msg *msg_ptr;
@@ -1092,7 +1092,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user 
*u_msg_ptr,
struct posix_msg_tree_node *new_leaf = NULL;
 
if (ts) {
-   expires = timespec_to_ktime(*ts);
+   expires = timespec64_to_ktime(*ts);
timeout = 
}
 
@@ -1184,7 +1184,7 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char 
__user *, u_msg_ptr,
size_t, msg_len, unsigned int, msg_prio,
const struct timespec __user *, u_abs_timeout)
 {
-   struct timespec ts, *

<    1   2   3   4   5   6   7   >