Re: [Y2038] [PATCH 1/2] mips: remove nargs from __SYSCALL

2019-07-31 Thread Paul Burton
Hello,

Firoz Khan wrote:
> The __SYSCALL macro's arguments are system call number,
> system call entry name and number of arguments for the
> system call.
> 
> Argument- nargs in __SYSCALL(nr, entry, nargs) is neither
> calculated nor used anywhere. So it would be better to
> keep the implementaion as  __SYSCALL(nr, entry). This will
> unifies the implementation with some other architetures
> too.
> 
> Signed-off-by: Firoz Khan 

Applied to mips-next.

Thanks,
Paul

[ This message was auto-generated; if you believe anything is incorrect
  then please email paul.bur...@mips.com to report it. ]
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH 05/20] utimes: Clamp the timestamps before update

2019-07-31 Thread Deepa Dinamani
On Wed, Jul 31, 2019 at 8:15 AM Darrick J. Wong  wrote:
>
> On Mon, Jul 29, 2019 at 06:49:09PM -0700, Deepa Dinamani wrote:
> > POSIX is ambiguous on the behavior of timestamps for
> > futimens, utimensat and utimes. Whether to return an
> > error or silently clamp a timestamp beyond the range
> > supported by the underlying filesystems is not clear.
> >
> > POSIX.1 section for futimens, utimensat and utimes says:
> > (http://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html)
> >
> > 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.
> >
> > If the tv_nsec field of a timespec structure has the special
> > value UTIME_NOW, the file's relevant timestamp shall be set
> > to the greatest value supported by the file system that is
> > not greater than the current time.
> >
> > [EINVAL]
> > A new file timestamp would be a value whose tv_sec
> > component is not a value supported by the file system.
> >
> > The patch chooses to clamp the timestamps according to the
> > filesystem timestamp ranges and does not return an error.
> > This is in line with the behavior of utime syscall also
> > since the POSIX 
> > page(http://pubs.opengroup.org/onlinepubs/009695399/functions/utime.html)
> > for utime does not mention returning an error or clamping like above.
> >
> > Same for utimes 
> > http://pubs.opengroup.org/onlinepubs/009695399/functions/utimes.html
> >
> > Signed-off-by: Deepa Dinamani 
> > ---
> >  fs/utimes.c | 17 +
> >  1 file changed, 13 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/utimes.c b/fs/utimes.c
> > index 350c9c16ace1..4c1a2ce90bbc 100644
> > --- a/fs/utimes.c
> > +++ b/fs/utimes.c
> > @@ -21,6 +21,7 @@ static int utimes_common(const struct path *path, struct 
> > timespec64 *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);
> > @@ -36,16 +37,24 @@ static int utimes_common(const struct path *path, 
> > struct timespec64 *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(times[0].tv_sec, sb->s_time_min, 
> > sb->s_time_max);
> > + if (times[0].tv_sec == sb->s_time_max || 
> > times[0].tv_sec == sb->s_time_min)
> > + 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(times[1].tv_sec, sb->s_time_min, 
> > sb->s_time_max);
> > + if (times[1].tv_sec >= sb->s_time_max || 
> > times[1].tv_sec == sb->s_time_min)
>
> Line length.
>
> Also, didn't you just introduce a function to clamp tv_sec and fix
> granularity?  Why not just use it here?  I think this is the third time
> I've seen this open-coded logic.

Yes, we can use that now. Earlier we were not setting the tv_nsec to 0
in timestamp_truncate() which is why this was opencoded here.
I will make the change to include this.

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


Re: [Y2038] [PATCH 06/20] fs: Fill in max and min timestamps in superblock

2019-07-31 Thread Darrick J. Wong
On Mon, Jul 29, 2019 at 06:49:10PM -0700, Deepa Dinamani wrote:
> Fill in the appropriate limits to avoid inconsistencies
> in the vfs cached inode times when timestamps are
> outside the permitted range.
> 
> Even though some filesystems are read-only, fill in the
> timestamps to reflect the on-disk representation.
> 
> Signed-off-by: Deepa Dinamani 
> Cc: aivazian.tig...@gmail.com
> Cc: a...@alarsen.net
> Cc: c...@cs.cmu.edu
> Cc: darrick.w...@oracle.com
> Cc: dushis...@mail.ru
> Cc: dw...@infradead.org
> Cc: h...@infradead.org
> Cc: j...@suse.com
> Cc: jahar...@cs.cmu.edu
> Cc: lui...@kernel.org
> Cc: n...@fluxnic.net
> Cc: phil...@squashfs.org.uk
> Cc: rich...@nod.at
> Cc: salah.tr...@gmail.com
> Cc: sha...@kernel.org
> Cc: linux-...@vger.kernel.org
> Cc: codal...@coda.cs.cmu.edu
> Cc: linux-e...@vger.kernel.org
> Cc: linux-...@lists.infradead.org
> Cc: jfs-discuss...@lists.sourceforge.net
> Cc: reiserfs-de...@vger.kernel.org
> ---
>  fs/befs/linuxvfs.c   | 2 ++
>  fs/bfs/inode.c   | 2 ++
>  fs/coda/inode.c  | 3 +++
>  fs/cramfs/inode.c| 2 ++
>  fs/efs/super.c   | 2 ++
>  fs/ext2/super.c  | 2 ++
>  fs/freevxfs/vxfs_super.c | 2 ++
>  fs/jffs2/fs.c| 3 +++
>  fs/jfs/super.c   | 2 ++
>  fs/minix/inode.c | 2 ++
>  fs/qnx4/inode.c  | 2 ++
>  fs/qnx6/inode.c  | 2 ++
>  fs/reiserfs/super.c  | 3 +++
>  fs/romfs/super.c | 2 ++
>  fs/squashfs/super.c  | 2 ++
>  fs/ufs/super.c   | 7 +++
>  fs/xfs/xfs_super.c   | 2 ++
>  17 files changed, 42 insertions(+)
> 
> diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
> index 462d096ff3e9..64cdf4d8e424 100644
> --- a/fs/befs/linuxvfs.c
> +++ b/fs/befs/linuxvfs.c
> @@ -893,6 +893,8 @@ befs_fill_super(struct super_block *sb, void *data, int 
> silent)
>   sb_set_blocksize(sb, (ulong) befs_sb->block_size);
>   sb->s_op = _sops;
>   sb->s_export_op = _export_operations;
> + sb->s_time_min = 0;
> + sb->s_time_max = 0xll;
>   root = befs_iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)));
>   if (IS_ERR(root)) {
>   ret = PTR_ERR(root);
> diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c
> index 5e97bed073d7..f8ce1368218b 100644
> --- a/fs/bfs/inode.c
> +++ b/fs/bfs/inode.c
> @@ -324,6 +324,8 @@ static int bfs_fill_super(struct super_block *s, void 
> *data, int silent)
>   return -ENOMEM;
>   mutex_init(>bfs_lock);
>   s->s_fs_info = info;
> + s->s_time_min = 0;
> + s->s_time_max = U32_MAX;
>  
>   sb_set_blocksize(s, BFS_BSIZE);
>  
> diff --git a/fs/coda/inode.c b/fs/coda/inode.c
> index 321f56e487cb..b1c70e2b9b1e 100644
> --- a/fs/coda/inode.c
> +++ b/fs/coda/inode.c
> @@ -188,6 +188,9 @@ static int coda_fill_super(struct super_block *sb, void 
> *data, int silent)
>   sb->s_magic = CODA_SUPER_MAGIC;
>   sb->s_op = _super_operations;
>   sb->s_d_op = _dentry_operations;
> + sb->s_time_gran = 1;
> + sb->s_time_min = S64_MIN;
> + sb->s_time_max = S64_MAX;
>  
>   error = super_setup_bdi(sb);
>   if (error)
> diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
> index 9352487bd0fc..4d1d8b7761ed 100644
> --- a/fs/cramfs/inode.c
> +++ b/fs/cramfs/inode.c
> @@ -597,6 +597,8 @@ static int cramfs_finalize_super(struct super_block *sb,
>  
>   /* Set it all up.. */
>   sb->s_flags |= SB_RDONLY;
> + sb->s_time_min = 0;
> + sb->s_time_max = 0;
>   sb->s_op = _ops;
>   root = get_cramfs_inode(sb, cramfs_root, 0);
>   if (IS_ERR(root))
> diff --git a/fs/efs/super.c b/fs/efs/super.c
> index 867fc24dee20..4a6ebff2af76 100644
> --- a/fs/efs/super.c
> +++ b/fs/efs/super.c
> @@ -257,6 +257,8 @@ static int efs_fill_super(struct super_block *s, void *d, 
> int silent)
>   if (!sb)
>   return -ENOMEM;
>   s->s_fs_info = sb;
> + s->s_time_min = 0;
> + s->s_time_max = U32_MAX;
>   
>   s->s_magic  = EFS_SUPER_MAGIC;
>   if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) {
> diff --git a/fs/ext2/super.c b/fs/ext2/super.c
> index 44eb6e7eb492..baa36c6fb71e 100644
> --- a/fs/ext2/super.c
> +++ b/fs/ext2/super.c
> @@ -1002,6 +1002,8 @@ static int ext2_fill_super(struct super_block *sb, void 
> *data, int silent)
>  
>   sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits);
>   sb->s_max_links = EXT2_LINK_MAX;
> + sb->s_time_min = S32_MIN;
> + sb->s_time_max = S32_MAX;
>  
>   if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
>   sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
> diff --git a/fs/freevxfs/vxfs_super.c b/fs/freevxfs/vxfs_super.c
> index a89f68c3cbed..578a5062706e 100644
> --- a/fs/freevxfs/vxfs_super.c
> +++ b/fs/freevxfs/vxfs_super.c
> @@ -229,6 +229,8 @@ static int vxfs_fill_super(struct super_block *sbp, void 
> *dp, int silent)
>  
>   sbp->s_op = _super_ops;
>   sbp->s_fs_info = infp;
> + sbp->s_time_min = 0;
> + sbp->s_time_max = U32_MAX;

Re: [Y2038] [PATCH 09/20] ext4: Initialize timestamps limits

2019-07-31 Thread Darrick J. Wong
On Mon, Jul 29, 2019 at 06:49:13PM -0700, Deepa Dinamani wrote:
> ext4 has different overflow limits for max filesystem
> timestamps based on the extra bytes available.
> 
> The timestamp limits are calculated according to the
> encoding table in
> a4dad1ae24f85i(ext4: Fix handling of extended tv_sec):
> 
> * extra  msb of adjust for signed
> * epoch  32-bit 32-bit tv_sec to
> * bits   timedecoded 64-bit tv_sec  64-bit tv_sec  valid time range
> * 0 01-0x8000..-0x0001  0x0   1901-12-13..1969-12-31
> * 0 000x0..0x07fff  0x0   1970-01-01..2038-01-19
> * 0 110x08000..0x0  0x1   2038-01-19..2106-02-07
> * 0 100x1..0x17fff  0x1   2106-02-07..2174-02-25
> * 1 010x18000..0x1  0x2   2174-02-25..2242-03-16
> * 1 000x2..0x27fff  0x2   2242-03-16..2310-04-04
> * 1 110x28000..0x2  0x3   2310-04-04..2378-04-22
> * 1 100x3..0x37fff  0x3   2378-04-22..2446-05-10

My recollection of ext4 has gotten rusty, so this could be a bogus
question:

Say you have a filesystem with s_inode_size > 128 where not all of the
ondisk inodes have been upgraded to i_extra_isize > 0 and therefore
don't support nanoseconds or times beyond 2038.  I think this happens on
ext3 filesystems that reserved extra space for inode attrs that are
subsequently converted to ext4?

In any case, that means that you have some inodes that support 34-bit
tv_sec and some inodes that only support 32-bit tv_sec.  For the inodes
with 32-bit tv_sec, I think all that happens is that a large timestamp
will be truncated further, right?

And no mount time warning because at least /some/ of the inodes are
ready to go for the next 30 years?

--D

> Note that the time limits are not correct for deletion times.
> 
> Signed-off-by: Deepa Dinamani 
> Reviewed-by: Andreas Dilger 
> Cc: ty...@mit.edu
> Cc: adilger.ker...@dilger.ca
> Cc: linux-e...@vger.kernel.org
> ---
>  fs/ext4/ext4.h  |  4 
>  fs/ext4/super.c | 17 +++--
>  2 files changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 1cb67859e051..3f13cf12ae7f 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -1631,6 +1631,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 S32_MAX
> +#define EXT4_TIMESTAMP_MIN   S32_MIN
> +
>  /*
>   * Feature set definitions
>   */
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 4079605d437a..3ea2d60f33aa 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4035,8 +4035,21 @@ 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)
> - sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
> + /*
> +  * i_atime_extra is the last extra field available for 
> [acm]times in
> +  * struct ext4_inode. Checking for that field should suffice to 
> ensure
> +  * we have extra space for all three.
> +  */
> + if (sbi->s_inode_size >= offsetof(struct ext4_inode, 
> i_atime_extra) +
> + sizeof(((struct ext4_inode *)0)->i_atime_extra)) {
> + sb->s_time_gran = 1;
> + sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
> + } else {
> + sb->s_time_gran = NSEC_PER_SEC;
> + 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.17.1
> 
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH 05/20] utimes: Clamp the timestamps before update

2019-07-31 Thread Darrick J. Wong
On Mon, Jul 29, 2019 at 06:49:09PM -0700, Deepa Dinamani wrote:
> POSIX is ambiguous on the behavior of timestamps for
> futimens, utimensat and utimes. Whether to return an
> error or silently clamp a timestamp beyond the range
> supported by the underlying filesystems is not clear.
> 
> POSIX.1 section for futimens, utimensat and utimes says:
> (http://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html)
> 
> 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.
> 
> If the tv_nsec field of a timespec structure has the special
> value UTIME_NOW, the file's relevant timestamp shall be set
> to the greatest value supported by the file system that is
> not greater than the current time.
> 
> [EINVAL]
> A new file timestamp would be a value whose tv_sec
> component is not a value supported by the file system.
> 
> The patch chooses to clamp the timestamps according to the
> filesystem timestamp ranges and does not return an error.
> This is in line with the behavior of utime syscall also
> since the POSIX 
> page(http://pubs.opengroup.org/onlinepubs/009695399/functions/utime.html)
> for utime does not mention returning an error or clamping like above.
> 
> Same for utimes 
> http://pubs.opengroup.org/onlinepubs/009695399/functions/utimes.html
> 
> Signed-off-by: Deepa Dinamani 
> ---
>  fs/utimes.c | 17 +
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/utimes.c b/fs/utimes.c
> index 350c9c16ace1..4c1a2ce90bbc 100644
> --- a/fs/utimes.c
> +++ b/fs/utimes.c
> @@ -21,6 +21,7 @@ static int utimes_common(const struct path *path, struct 
> timespec64 *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);
> @@ -36,16 +37,24 @@ static int utimes_common(const struct path *path, struct 
> timespec64 *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(times[0].tv_sec, sb->s_time_min, 
> sb->s_time_max);
> + if (times[0].tv_sec == sb->s_time_max || 
> times[0].tv_sec == sb->s_time_min)
> + 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(times[1].tv_sec, sb->s_time_min, 
> sb->s_time_max);
> + if (times[1].tv_sec >= sb->s_time_max || 
> times[1].tv_sec == sb->s_time_min)

Line length.

Also, didn't you just introduce a function to clamp tv_sec and fix
granularity?  Why not just use it here?  I think this is the third time
I've seen this open-coded logic.

--D

> + newattrs.ia_mtime.tv_nsec = 0;
> + else
> + newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
>   newattrs.ia_valid |= ATTR_MTIME_SET;
>   }
>   /*
> -- 
> 2.17.1
> 
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038