• Y
    xfs: fix warning in xfs_vm_writepages() · cabf5100
    Ye Bin 提交于
    Offering: HULK
    hulk inclusion
    category: bugfix
    bugzilla: 188782, https://gitee.com/openeuler/kernel/issues/I76JSK
    
    -----------------------------------------------
    
    When do BULKSTAT test got issues as follows:
    WARNING: CPU: 3 PID: 8425 at fs/xfs/xfs_aops.c:509 xfs_vm_writepages+0x184/0x1c0
    Modules linked in:
    CPU: 3 PID: 8425 Comm: xfs_bulkstat Not tainted 6.3.0-next-20230505-00003-gf3329adf5424-dirty #456
    RIP: 0010:xfs_vm_writepages+0x184/0x1c0
    RSP: 0018:ffffc90014bb7088 EFLAGS: 00010246
    RAX: 0000000000000000 RBX: 1ffff92002976e11 RCX: ffff88817aef8000
    RDX: 0000000000000000 RSI: ffff88817aef8000 RDI: 0000000000000002
    RBP: ffff888267dd2ad8 R08: ffffffff8313f414 R09: ffffed1022377c18
    R10: ffff888111bbe0bb R11: ffffed1022377c17 R12: ffff88817aef8000
    R13: ffffc90014bb7358 R14: dffffc0000000000 R15: ffffffff8313f290
    FS:  00007f9568bb0440(0000) GS:ffff88882fc80000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000000000d7a008 CR3: 000000024e11f000 CR4: 00000000000006e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
     <TASK>
     do_writepages+0x1a8/0x630
     __writeback_single_inode+0x126/0xe00
     writeback_single_inode+0x2ae/0x530
     write_inode_now+0x16e/0x1e0
     iput.part.0+0x46c/0x730
     iput+0x60/0x80
     xfs_bulkstat_one_int+0xd87/0x1580
     xfs_bulkstat_iwalk+0x6e/0xd0
     xfs_iwalk_ag_recs+0x449/0x770
     xfs_iwalk_run_callbacks+0x305/0x630
     xfs_iwalk_ag+0x819/0xae0
     xfs_iwalk+0x2d5/0x4e0
     xfs_bulkstat+0x358/0x520
     xfs_ioc_bulkstat.isra.0+0x242/0x340
     xfs_file_ioctl+0x1d6/0x1ba0
     __x64_sys_ioctl+0x197/0x210
     do_syscall_64+0x39/0xb0
     entry_SYSCALL_64_after_hwframe+0x63/0xcd
    
    Above issue may happens as follows:
    Porcess1          Process2           process3         process4
    xfs_bulkstat
     xfs_trans_alloc_empty
     xfs_bulkstat_one_int
       xfs_iget(XFS_IGET_DONTCACHE)
       ->Get inode from disk and mark
         inode with I_DONTCACHE
    
                                                         xfs_lookup
                                                           xfs_iget
                                                           ->Hold inode refcount
       xfs_irele
    
                     xfs_file_write_iter
                     ->Write file made some dirty pages
                     close file
    
                                        xfs_bulkstat
                                          xfs_trans_alloc_empty
                                          xfs_bulkstat_one_int
                                            xfs_iget(XFS_IGET_DONTCACHE)
    
                                                           -> process4 close file
    
            ******Trigger dentry reclaim, inode refcount is 1******
                                            xfs_irele
                                              iput ->Put the last refcount
                                                iput_final
                                                  write_inode_now
                                                    xfs_vm_writepages
                                                      WARN_ON_ONCE(current->journal_info)
                                                      ->Trigger warning
    
    As commit a6343e4d grab an empty transaction when do BULKSTAT. If put
    the last refcount of inode maybe cause writepages will trigger warning, and
    also lead to data loss.
    To solve above issue if xfs_iget_cache_hit() just clear inode's I_DONTCACHE
    flags.
    
    Fixes: a6343e4d ("xfs: avoid buffer deadlocks when walking fs inodes")
    Signed-off-by: NYe Bin <yebin10@huawei.com>
    Signed-off-by: NLong Li <leo.lilong@huawei.com>
    (cherry picked from commit 28ce0ae2)
    cabf5100
xfs_icache.c 56.6 KB