From: Mateusz Guzik <mguzik@redhat.com>
To: Eric Dumazet <edumazet@google.com>, Al Viro <viro@zeniv.linux.org.uk>
Cc: mszeredi@redhat.com, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] vfs: grab the lock instead of blocking in __fd_install during resizing
Date: Tue, 3 Oct 2017 12:58:15 +0200 [thread overview]
Message-ID: <1507028295-9353-3-git-send-email-mguzik@redhat.com> (raw)
In-Reply-To: <1507028295-9353-1-git-send-email-mguzik@redhat.com>
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>
---
Documentation/filesystems/porting | 4 ----
fs/file.c | 11 +++++++----
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/Documentation/filesystems/porting b/Documentation/filesystems/porting
index 93e0a24..17bb4dc 100644
--- a/Documentation/filesystems/porting
+++ b/Documentation/filesystems/porting
@@ -502,10 +502,6 @@ in your dentry operations instead.
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
its pagecache. No highmem pages should end up in the pagecache of such
diff --git a/fs/file.c b/fs/file.c
index 9d047bd..4115503 100644
--- 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();
--
1.8.3.1
next prev parent reply other threads:[~2017-10-03 10:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 10:58 [PATCH 0/2] minor fd cleanup Mateusz Guzik
2017-10-03 10:58 ` [PATCH 1/2] vfs: stop clearing close on exec when closing a fd Mateusz Guzik
2017-10-03 14:39 ` Eric Dumazet
2017-10-03 10:58 ` Mateusz Guzik [this message]
2017-10-03 14:41 ` [PATCH 2/2] vfs: grab the lock instead of blocking in __fd_install during resizing Eric Dumazet
2017-10-04 13:55 ` Matthew Wilcox
2017-10-04 14:00 ` Eric Dumazet
2017-10-04 14:58 ` Matthew Wilcox
2017-10-04 15:04 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1507028295-9353-3-git-send-email-mguzik@redhat.com \
--to=mguzik@redhat.com \
--cc=edumazet@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).