* [PATCH] f2fs: call unlock_new_inode() before d_instantiate()
@ 2018-04-18 22:48 Eric Biggers
2018-04-23 3:25 ` Chao Yu
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2018-04-18 22:48 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu; +Cc: linux-fsdevel, Eric Biggers
From: Eric Biggers <ebiggers@google.com>
xfstest generic/429 sometimes hangs on f2fs, caused by a thread being
unable to take a directory's i_rwsem for write in vfs_rmdir(). In the
test, one thread repeatedly creates and removes a directory, and other
threads repeatedly look up a file in the directory. The bug is that
f2fs_mkdir() calls d_instantiate() before unlock_new_inode(), resulting
in the directory inode being exposed to lookups before it has been fully
initialized. And with CONFIG_DEBUG_LOCK_ALLOC, unlock_new_inode()
reinitializes ->i_rwsem, corrupting its state when it is already held.
Fix it by calling unlock_new_inode() before d_instantiate(). This
matches what other filesystems do.
Fixes: 57397d86c62d ("f2fs: add inode operations for special inodes")
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
fs/f2fs/namei.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index d5098efe577c..3a7ed962d2f7 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -294,8 +294,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
alloc_nid_done(sbi, ino);
- d_instantiate(dentry, inode);
unlock_new_inode(inode);
+ d_instantiate(dentry, inode);
if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);
@@ -597,8 +597,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
err = page_symlink(inode, disk_link.name, disk_link.len);
err_out:
- d_instantiate(dentry, inode);
unlock_new_inode(inode);
+ d_instantiate(dentry, inode);
/*
* Let's flush symlink data in order to avoid broken symlink as much as
@@ -661,8 +661,8 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
alloc_nid_done(sbi, inode->i_ino);
- d_instantiate(dentry, inode);
unlock_new_inode(inode);
+ d_instantiate(dentry, inode);
if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);
@@ -713,8 +713,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
alloc_nid_done(sbi, inode->i_ino);
- d_instantiate(dentry, inode);
unlock_new_inode(inode);
+ d_instantiate(dentry, inode);
if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);
--
2.17.0.484.g0c8726318c-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] f2fs: call unlock_new_inode() before d_instantiate()
2018-04-18 22:48 [PATCH] f2fs: call unlock_new_inode() before d_instantiate() Eric Biggers
@ 2018-04-23 3:25 ` Chao Yu
0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2018-04-23 3:25 UTC (permalink / raw)
To: Eric Biggers, linux-f2fs-devel, Jaegeuk Kim; +Cc: linux-fsdevel, Eric Biggers
On 2018/4/19 6:48, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> xfstest generic/429 sometimes hangs on f2fs, caused by a thread being
> unable to take a directory's i_rwsem for write in vfs_rmdir(). In the
> test, one thread repeatedly creates and removes a directory, and other
> threads repeatedly look up a file in the directory. The bug is that
> f2fs_mkdir() calls d_instantiate() before unlock_new_inode(), resulting
> in the directory inode being exposed to lookups before it has been fully
> initialized. And with CONFIG_DEBUG_LOCK_ALLOC, unlock_new_inode()
> reinitializes ->i_rwsem, corrupting its state when it is already held.
>
> Fix it by calling unlock_new_inode() before d_instantiate(). This
> matches what other filesystems do.
>
> Fixes: 57397d86c62d ("f2fs: add inode operations for special inodes")
> Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Thanks,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-23 3:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18 22:48 [PATCH] f2fs: call unlock_new_inode() before d_instantiate() Eric Biggers
2018-04-23 3:25 ` Chao Yu
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).