Blob Blame History Raw
From 25b7077e30eed17c05cc73272d7e2e026ee20f34 Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk@kernel.org>
Date: Tue, 7 Sep 2021 10:24:21 -0700
Subject: [PATCH] f2fs: should use GFP_NOFS for directory inodes
Git-commit: 92d602bc7177325e7453189a22e0c8764ed3453e
Patch-mainline: v5.16-rc1
References: stable-5.14.19

commit 92d602bc7177325e7453189a22e0c8764ed3453e upstream.

We use inline_dentry which requires to allocate dentry page when adding a link.
If we allow to reclaim memory from filesystem, we do down_read(&sbi->cp_rwsem)
twice by f2fs_lock_op(). I think this should be okay, but how about stopping
the lockdep complaint [1]?

f2fs_create()
 - f2fs_lock_op()
 - f2fs_do_add_link()
  - __f2fs_find_entry
   - f2fs_get_read_data_page()
   -> kswapd
    - shrink_node
     - f2fs_evict_inode
      - f2fs_lock_op()

[1]

fs_reclaim
){+.+.}-{0:0}
: 
Kswapd0: lock_acquire+0x114/0x394
Kswapd0: __fs_reclaim_acquire+0x40/0x50
Kswapd0: prepare_alloc_pages+0x94/0x1ec
Kswapd0: __alloc_pages_nodemask+0x78/0x1b0
Kswapd0: pagecache_get_page+0x2e0/0x57c
Kswapd0: f2fs_get_read_data_page+0xc0/0x394
Kswapd0: f2fs_find_data_page+0xa4/0x23c
Kswapd0: find_in_level+0x1a8/0x36c
Kswapd0: __f2fs_find_entry+0x70/0x100
Kswapd0: f2fs_do_add_link+0x84/0x1ec
Kswapd0: f2fs_mkdir+0xe4/0x1e4
Kswapd0: vfs_mkdir+0x110/0x1c0
Kswapd0: do_mkdirat+0xa4/0x160
Kswapd0: __arm64_sys_mkdirat+0x24/0x34
Kswapd0: el0_svc_common.llvm.17258447499513131576+0xc4/0x1e8
Kswapd0: do_el0_svc+0x28/0xa0
Kswapd0: el0_svc+0x24/0x38
Kswapd0: el0_sync_handler+0x88/0xec
Kswapd0: el0_sync+0x1c0/0x200
Kswapd0: 
-> #1
(
&sbi->cp_rwsem
){++++}-{3:3}
Kswapd0: down_read+0x7c/0x98
Kswapd0: f2fs_do_truncate_blocks+0x78/0x3dc
Kswapd0: f2fs_truncate+0xc8/0x128
Kswapd0: f2fs_evict_inode+0x2b8/0x8b8
Kswapd0: evict+0xd4/0x2f8
Kswapd0: iput+0x1c0/0x258
Kswapd0: do_unlinkat+0x170/0x2a0
Kswapd0: __arm64_sys_unlinkat+0x4c/0x68

Cc: stable@vger.kernel.org
Fixes: bdbc90fa55af ("f2fs: don't put dentry page in pagecache into highmem")
Reviewed-by: Chao Yu <chao@kernel.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Reviewed-by: Light Hsieh <light.hsieh@mediatek.com>
Tested-by: Light Hsieh <light.hsieh@mediatek.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 fs/f2fs/inode.c | 2 +-
 fs/f2fs/namei.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 9141147b5bb0..1213f15ffd68 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -527,7 +527,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
 		inode->i_op = &f2fs_dir_inode_operations;
 		inode->i_fop = &f2fs_dir_operations;
 		inode->i_mapping->a_ops = &f2fs_dblock_aops;
-		inode_nohighmem(inode);
+		mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
 	} else if (S_ISLNK(inode->i_mode)) {
 		if (file_is_encrypt(inode))
 			inode->i_op = &f2fs_encrypted_symlink_inode_operations;
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 9c528e583c9d..ae0838001480 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -757,7 +757,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
 	inode->i_op = &f2fs_dir_inode_operations;
 	inode->i_fop = &f2fs_dir_operations;
 	inode->i_mapping->a_ops = &f2fs_dblock_aops;
-	inode_nohighmem(inode);
+	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
 
 	set_inode_flag(inode, FI_INC_LINK);
 	f2fs_lock_op(sbi);
-- 
2.26.2