]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
vfs: grab the lock instead of blocking in __fd_install during resizing
authorMateusz Guzik <mguzik@redhat.com>
Tue, 3 Oct 2017 10:58:15 +0000 (12:58 +0200)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 5 Nov 2017 23:58:07 +0000 (18:58 -0500)
Explicit locking in the fallback case provides a safe state of the
table. Getting rid of blocking semantics makes __fd_install usable
again in non-sleepable contexts, which easies backporting efforts.

There is a side effect of slightly nicer assembly for the common case
as might_sleep can now be removed.

Signed-off-by: Mateusz Guzik <mguzik@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Documentation/filesystems/porting
fs/file.c

index 93e0a24045322b3e2417e024821520c9996eb6fc..17bb4dc28fae03371c328cc2135b576c4235ab03 100644 (file)
@@ -501,10 +501,6 @@ in your dentry operations instead.
        is non-NULL.  Note that link body isn't available anymore, so if you need it,
        store it as cookie.
 --
-[mandatory]
-       __fd_install() & fd_install() can now sleep. Callers should not
-       hold a spinlock or other resources that do not allow a schedule.
---
 [mandatory]
        any symlink that might use page_follow_link_light/page_put_link() must
        have inode_nohighmem(inode) called before anything might start playing with
index 9d047bd046b03df5dc2e855adead48febb35c5e9..4115503bb575acbaed46e5e471a882560856ffd1 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -592,13 +592,16 @@ void __fd_install(struct files_struct *files, unsigned int fd,
 {
        struct fdtable *fdt;
 
-       might_sleep();
        rcu_read_lock_sched();
 
-       while (unlikely(files->resize_in_progress)) {
+       if (unlikely(files->resize_in_progress)) {
                rcu_read_unlock_sched();
-               wait_event(files->resize_wait, !files->resize_in_progress);
-               rcu_read_lock_sched();
+               spin_lock(&files->file_lock);
+               fdt = files_fdtable(files);
+               BUG_ON(fdt->fd[fd] != NULL);
+               rcu_assign_pointer(fdt->fd[fd], file);
+               spin_unlock(&files->file_lock);
+               return;
        }
        /* coupled with smp_wmb() in expand_fdtable() */
        smp_rmb();