Merge tag 'locks-v4.14-1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 6 Sep 2017 20:43:26 +0000 (13:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 6 Sep 2017 20:43:26 +0000 (13:43 -0700)
Pull file locking updates from Jeff Layton:
 "This pile just has a few file locking fixes from Ben Coddington. There
  are a couple of cleanup patches + an attempt to bring sanity to the
  l_pid value that is reported back to userland on an F_GETLK request.

  After a few gyrations, he came up with a way for filesystems to
  communicate to the VFS layer code whether the pid should be translated
  according to the namespace or presented as-is to userland"

* tag 'locks-v4.14-1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux:
  locks: restore a warn for leaked locks on close
  fs/locks: Remove fl_nspid and use fs-specific l_pid for remote locks
  fs/locks: Use allocation rather than the stack in fcntl_getlk()

1  2 
drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
fs/fuse/file.c
include/linux/fs.h

  
  #define DEBUG_SUBSYSTEM S_LDLM
  
 -#include "../include/lustre_dlm.h"
 -#include "../include/obd_support.h"
 -#include "../include/obd_class.h"
 -#include "../include/lustre_lib.h"
 +#include <lustre_dlm.h>
 +#include <obd_support.h>
 +#include <obd_class.h>
 +#include <lustre_lib.h>
  #include <linux/list.h>
  #include "ldlm_internal.h"
  
@@@ -90,8 -90,8 +90,8 @@@ ldlm_flocks_overlap(struct ldlm_lock *l
  static inline void
  ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags)
  {
 -      LDLM_DEBUG(lock, "ldlm_flock_destroy(mode: %d, flags: 0x%llx)",
 -                 mode, flags);
 +      LDLM_DEBUG(lock, "%s(mode: %d, flags: 0x%llx)",
 +                 __func__, mode, flags);
  
        /* Safe to not lock here, since it should be empty anyway */
        LASSERT(hlist_unhashed(&lock->l_exp_flock_hash));
@@@ -596,7 -596,7 +596,7 @@@ granted
                default:
                        getlk->fl_type = F_UNLCK;
                }
-               getlk->fl_pid = (pid_t)lock->l_policy_data.l_flock.pid;
+               getlk->fl_pid = -(pid_t)lock->l_policy_data.l_flock.pid;
                getlk->fl_start = (loff_t)lock->l_policy_data.l_flock.start;
                getlk->fl_end = (loff_t)lock->l_policy_data.l_flock.end;
        } else {
diff --combined fs/fuse/file.c
@@@ -46,7 -46,7 +46,7 @@@ struct fuse_file *fuse_file_alloc(struc
  {
        struct fuse_file *ff;
  
 -      ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
 +      ff = kzalloc(sizeof(struct fuse_file), GFP_KERNEL);
        if (unlikely(!ff))
                return NULL;
  
@@@ -609,7 -609,7 +609,7 @@@ static void fuse_aio_complete_req(struc
        struct fuse_io_priv *io = req->io;
        ssize_t pos = -1;
  
 -      fuse_release_user_pages(req, !io->write);
 +      fuse_release_user_pages(req, io->should_dirty);
  
        if (io->write) {
                if (req->misc.write.in.size != req->misc.write.out.size)
@@@ -1316,6 -1316,7 +1316,6 @@@ ssize_t fuse_direct_io(struct fuse_io_p
                       loff_t *ppos, int flags)
  {
        int write = flags & FUSE_DIO_WRITE;
 -      bool should_dirty = !write && iter_is_iovec(iter);
        int cuse = flags & FUSE_DIO_CUSE;
        struct file *file = io->file;
        struct inode *inode = file->f_mapping->host;
                        inode_unlock(inode);
        }
  
 +      io->should_dirty = !write && iter_is_iovec(iter);
        while (count) {
                size_t nres;
                fl_owner_t owner = current->files;
                        nres = fuse_send_read(req, io, pos, nbytes, owner);
  
                if (!io->async)
 -                      fuse_release_user_pages(req, should_dirty);
 +                      fuse_release_user_pages(req, io->should_dirty);
                if (req->out.h.error) {
                        err = req->out.h.error;
                        break;
@@@ -1669,7 -1669,6 +1669,7 @@@ err_nofile
  err_free:
        fuse_request_free(req);
  err:
 +      mapping_set_error(page->mapping, error);
        end_page_writeback(page);
        return error;
  }
@@@ -2102,11 -2101,11 +2102,11 @@@ static int convert_fuse_file_lock(struc
                fl->fl_end = ffl->end;
  
                /*
-                * Convert pid into the caller's pid namespace. If the pid
-                * does not map into the namespace fl_pid will get set to 0.
+                * Convert pid into init's pid namespace.  The locks API will
+                * translate it into the caller's pid namespace.
                 */
                rcu_read_lock();
-               fl->fl_pid = pid_vnr(find_pid_ns(ffl->pid, fc->pid_ns));
+               fl->fl_pid = pid_nr_ns(find_pid_ns(ffl->pid, fc->pid_ns), &init_pid_ns);
                rcu_read_unlock();
                break;
  
diff --combined include/linux/fs.h
@@@ -72,8 -72,6 +72,8 @@@ extern int leases_enable, lease_break_t
  extern int sysctl_protected_symlinks;
  extern int sysctl_protected_hardlinks;
  
 +typedef __kernel_rwf_t rwf_t;
 +
  struct buffer_head;
  typedef int (get_block_t)(struct inode *inode, sector_t iblock,
                        struct buffer_head *bh_result, int create);
@@@ -298,7 -296,7 +298,7 @@@ struct kiocb 
        void                    *private;
        int                     ki_flags;
        enum rw_hint            ki_hint;
 -};
 +} __randomize_layout;
  
  static inline bool is_sync_kiocb(struct kiocb *kiocb)
  {
@@@ -406,7 -404,7 +406,7 @@@ struct address_space 
        struct list_head        private_list;   /* ditto */
        void                    *private_data;  /* ditto */
        errseq_t                wb_err;
 -} __attribute__((aligned(sizeof(long))));
 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
        /*
         * On most architectures that alignment is already the case; but
         * must be enforced here for CRIS, to let the least significant bit
@@@ -449,7 -447,7 +449,7 @@@ struct block_device 
        int                     bd_fsfreeze_count;
        /* Mutex for freeze */
        struct mutex            bd_fsfreeze_mutex;
 -};
 +} __randomize_layout;
  
  /*
   * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
@@@ -668,7 -666,7 +668,7 @@@ struct inode 
  #endif
  
        void                    *i_private; /* fs or device private pointer */
 -};
 +} __randomize_layout;
  
  static inline unsigned int i_blocksize(const struct inode *node)
  {
@@@ -885,8 -883,7 +885,8 @@@ struct file 
  #endif /* #ifdef CONFIG_EPOLL */
        struct address_space    *f_mapping;
        errseq_t                f_wb_err;
 -} __attribute__((aligned(4)));        /* lest something weird decides that 2 is OK */
 +} __randomize_layout
 +  __attribute__((aligned(4)));        /* lest something weird decides that 2 is OK */
  
  struct file_handle {
        __u32 handle_bytes;
@@@ -909,9 -906,9 +909,9 @@@ static inline struct file *get_file(str
  /* Page cache limit. The filesystems should put that into their s_maxbytes 
     limits, otherwise bad things can happen in VM. */ 
  #if BITS_PER_LONG==32
 -#define MAX_LFS_FILESIZE      (((loff_t)PAGE_SIZE << (BITS_PER_LONG-1))-1)
 +#define MAX_LFS_FILESIZE      ((loff_t)ULONG_MAX << PAGE_SHIFT)
  #elif BITS_PER_LONG==64
 -#define MAX_LFS_FILESIZE      ((loff_t)0x7fffffffffffffffLL)
 +#define MAX_LFS_FILESIZE      ((loff_t)LLONG_MAX)
  #endif
  
  #define FL_POSIX      1
@@@ -1002,7 -999,6 +1002,6 @@@ struct file_lock 
        unsigned char fl_type;
        unsigned int fl_pid;
        int fl_link_cpu;                /* what cpu's list is this on? */
-       struct pid *fl_nspid;
        wait_queue_head_t fl_wait;
        struct file *fl_file;
        loff_t fl_start;
                        int state;              /* state of grant or error if -ve */
                } afs;
        } fl_u;
 -};
 +} __randomize_layout;
  
  struct file_lock_context {
        spinlock_t              flc_lock;
@@@ -1415,7 -1411,7 +1414,7 @@@ struct super_block 
  
        spinlock_t              s_inode_wblist_lock;
        struct list_head        s_inodes_wb;    /* writeback inodes */
 -};
 +} __randomize_layout;
  
  /* Helper functions so that in most cases filesystems will
   * not need to deal directly with kuid_t and kgid_t and can
@@@ -1701,7 -1697,7 +1700,7 @@@ struct file_operations 
                        u64);
        ssize_t (*dedupe_file_range)(struct file *, u64, u64, struct file *,
                        u64);
 -};
 +} __randomize_layout;
  
  struct inode_operations {
        struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
@@@ -1760,9 -1756,9 +1759,9 @@@ extern ssize_t __vfs_write(struct file 
  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
  extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
 -              unsigned long, loff_t *, int);
 +              unsigned long, loff_t *, rwf_t);
  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
 -              unsigned long, loff_t *, int);
 +              unsigned long, loff_t *, rwf_t);
  extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *,
                                   loff_t, size_t, unsigned int);
  extern int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
@@@ -2473,13 -2469,9 +2472,13 @@@ static inline void bd_unlink_disk_holde
  #endif
  
  /* fs/char_dev.c */
 -#define CHRDEV_MAJOR_HASH_SIZE        255
 +#define CHRDEV_MAJOR_MAX 512
  /* Marks the bottom of the first segment of free char majors */
  #define CHRDEV_MAJOR_DYN_END 234
 +/* Marks the top and bottom of the second segment of free char majors */
 +#define CHRDEV_MAJOR_DYN_EXT_START 511
 +#define CHRDEV_MAJOR_DYN_EXT_END 384
 +
  extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
  extern int register_chrdev_region(dev_t, unsigned, const char *);
  extern int __register_chrdev(unsigned int major, unsigned int baseminor,
@@@ -2506,14 -2498,14 +2505,14 @@@ static inline void unregister_chrdev(un
  #define BDEVT_SIZE    10      /* Largest string for MAJ:MIN for blkdev */
  
  #ifdef CONFIG_BLOCK
 -#define BLKDEV_MAJOR_HASH_SIZE        255
 +#define BLKDEV_MAJOR_MAX      512
  extern const char *__bdevname(dev_t, char *buffer);
  extern const char *bdevname(struct block_device *bdev, char *buffer);
  extern struct block_device *lookup_bdev(const char *);
  extern void blkdev_show(struct seq_file *,off_t);
  
  #else
 -#define BLKDEV_MAJOR_HASH_SIZE        0
 +#define BLKDEV_MAJOR_MAX      0
  #endif
  
  extern void init_special_inode(struct inode *, umode_t, dev_t);
@@@ -2837,7 -2829,6 +2836,7 @@@ static inline void lockdep_annotate_ino
  #endif
  extern void unlock_new_inode(struct inode *);
  extern unsigned int get_next_ino(void);
 +extern void evict_inodes(struct super_block *sb);
  
  extern void __iget(struct inode * inode);
  extern void iget_failed(struct inode *);
@@@ -2881,9 -2872,9 +2880,9 @@@ extern ssize_t generic_file_direct_writ
  extern ssize_t generic_perform_write(struct file *, struct iov_iter *, loff_t);
  
  ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos,
 -              int flags);
 +              rwf_t flags);
  ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos,
 -              int flags);
 +              rwf_t flags);
  
  /* fs/block_dev.c */
  extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to);
@@@ -3150,7 -3141,7 +3149,7 @@@ static inline int iocb_flags(struct fil
        return res;
  }
  
 -static inline int kiocb_set_rw_flags(struct kiocb *ki, int flags)
 +static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags)
  {
        if (unlikely(flags & ~RWF_SUPPORTED))
                return -EOPNOTSUPP;