]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: don't get FREEZE lock in f2fs_evict_inode in frozen fs
authorJaegeuk Kim <jaegeuk@kernel.org>
Fri, 4 Mar 2022 17:40:05 +0000 (09:40 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:06:36 +0000 (14:06 +0200)
[ Upstream commit ba900534f807f0b327c92d5141c85d2313e2d55c ]

Let's purge inode cache in order to avoid the below deadlock.

[freeze test]                         shrinkder
freeze_super
 - pwercpu_down_write(SB_FREEZE_FS)
                                       - super_cache_scan
                                         - down_read(&sb->s_umount)
                                           - prune_icache_sb
                                            - dispose_list
                                             - evict
                                              - f2fs_evict_inode
thaw_super
 - down_write(&sb->s_umount);
                                              - __percpu_down_read(SB_FREEZE_FS)

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Documentation/ABI/testing/sysfs-fs-f2fs
fs/f2fs/debug.c
fs/f2fs/f2fs.h
fs/f2fs/inode.c
fs/f2fs/super.c

index b268e3e18b4a3552506cc94f9281fe81b15f50b3..91e2b549f817227829d734010a6020818960bb12 100644 (file)
@@ -425,6 +425,7 @@ Description:        Show status of f2fs superblock in real time.
                0x800  SBI_QUOTA_SKIP_FLUSH  skip flushing quota in current CP
                0x1000 SBI_QUOTA_NEED_REPAIR quota file may be corrupted
                0x2000 SBI_IS_RESIZEFS       resizefs is in process
+               0x4000 SBI_IS_FREEZING       freefs is in process
                ====== ===================== =================================
 
 What:          /sys/fs/f2fs/<disk>/ckpt_thread_ioprio
index 8c50518475a99a32e7ac9c4f724a982c745ad46b..07ad0d81f0c514fbd2197553697cff4c658e4b2c 100644 (file)
@@ -338,6 +338,7 @@ static char *s_flag[] = {
        [SBI_QUOTA_SKIP_FLUSH]  = " quota_skip_flush",
        [SBI_QUOTA_NEED_REPAIR] = " quota_need_repair",
        [SBI_IS_RESIZEFS]       = " resizefs",
+       [SBI_IS_FREEZING]       = " freezefs",
 };
 
 static int stat_show(struct seq_file *s, void *v)
index d753094a4919f122217064478b89eb1237f8aa91..980c0c2b6350a7c87a458ad717da3ba2c6ad417f 100644 (file)
@@ -1259,6 +1259,7 @@ enum {
        SBI_QUOTA_SKIP_FLUSH,                   /* skip flushing quota in current CP */
        SBI_QUOTA_NEED_REPAIR,                  /* quota file may be corrupted */
        SBI_IS_RESIZEFS,                        /* resizefs is in process */
+       SBI_IS_FREEZING,                        /* freezefs is in process */
 };
 
 enum {
index 5a10f98dbbc36f188dac0e90334241a301cea68f..a40e52ba5ec84d272cdef0d4875907d1efa4d7cd 100644 (file)
@@ -769,7 +769,8 @@ void f2fs_evict_inode(struct inode *inode)
        f2fs_remove_ino_entry(sbi, inode->i_ino, UPDATE_INO);
        f2fs_remove_ino_entry(sbi, inode->i_ino, FLUSH_INO);
 
-       sb_start_intwrite(inode->i_sb);
+       if (!is_sbi_flag_set(sbi, SBI_IS_FREEZING))
+               sb_start_intwrite(inode->i_sb);
        set_inode_flag(inode, FI_NO_ALLOC);
        i_size_write(inode, 0);
 retry:
@@ -800,7 +801,8 @@ retry:
                if (dquot_initialize_needed(inode))
                        set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
        }
-       sb_end_intwrite(inode->i_sb);
+       if (!is_sbi_flag_set(sbi, SBI_IS_FREEZING))
+               sb_end_intwrite(inode->i_sb);
 no_delete:
        dquot_drop(inode);
 
index 45106b426e8d93b3f67ef632c0200dedc1d36720..9402d5b2c7fdae2dd5169fb313062bcb328a99bb 100644 (file)
@@ -1668,11 +1668,15 @@ static int f2fs_freeze(struct super_block *sb)
        /* ensure no checkpoint required */
        if (!llist_empty(&F2FS_SB(sb)->cprc_info.issue_list))
                return -EINVAL;
+
+       /* to avoid deadlock on f2fs_evict_inode->SB_FREEZE_FS */
+       set_sbi_flag(F2FS_SB(sb), SBI_IS_FREEZING);
        return 0;
 }
 
 static int f2fs_unfreeze(struct super_block *sb)
 {
+       clear_sbi_flag(F2FS_SB(sb), SBI_IS_FREEZING);
        return 0;
 }