1. 31 Mar, 2020 8 commits
    • Chao Yu's avatar
      f2fs: don't trigger data flush in foreground operation · 7bcd0cfa
      Chao Yu authored
      Data flush can generate heavy IO and cause long latency during
      flush, so it's not appropriate to trigger it in foreground
      operation.
      
      And also, we may face below potential deadlock during data flush:
      - f2fs_write_multi_pages
       - f2fs_write_raw_pages
        - f2fs_write_single_data_page
         - f2fs_balance_fs
          - f2fs_balance_fs_bg
           - f2fs_sync_dirty_inodes
            - filemap_fdatawrite   -- stuck on flush same cluster
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      7bcd0cfa
    • Chao Yu's avatar
      f2fs: fix NULL pointer dereference in f2fs_write_begin() · 62f63eea
      Chao Yu authored
      BUG: kernel NULL pointer dereference, address: 0000000000000000
      RIP: 0010:f2fs_write_begin+0x823/0xb90 [f2fs]
      Call Trace:
       f2fs_quota_write+0x139/0x1d0 [f2fs]
       write_blk+0x36/0x80 [quota_tree]
       get_free_dqblk+0x42/0xa0 [quota_tree]
       do_insert_tree+0x235/0x4a0 [quota_tree]
       do_insert_tree+0x26e/0x4a0 [quota_tree]
       do_insert_tree+0x26e/0x4a0 [quota_tree]
       do_insert_tree+0x26e/0x4a0 [quota_tree]
       qtree_write_dquot+0x70/0x190 [quota_tree]
       v2_write_dquot+0x43/0x90 [quota_v2]
       dquot_acquire+0x77/0x100
       f2fs_dquot_acquire+0x2f/0x60 [f2fs]
       dqget+0x310/0x450
       dquot_transfer+0x7e/0x120
       f2fs_setattr+0x11a/0x4a0 [f2fs]
       notify_change+0x349/0x480
       chown_common+0x168/0x1c0
       do_fchownat+0xbc/0xf0
       __x64_sys_fchownat+0x20/0x30
       do_syscall_64+0x5f/0x220
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Passing fsdata parameter to .write_{begin,end} in f2fs_quota_write(),
      so that if quota file is compressed one, we can avoid above NULL
      pointer dereference when updating quota content.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      62f63eea
    • Chao Yu's avatar
      f2fs: clean up f2fs_may_encrypt() · 8c7d4b57
      Chao Yu authored
      Merge below two conditions into f2fs_may_encrypt() for cleanup
      - IS_ENCRYPTED()
      - DUMMY_ENCRYPTION_ENABLED()
      
      Check IS_ENCRYPTED(inode) condition in f2fs_init_inode_metadata()
      is enough since we have already set encrypt flag in f2fs_new_inode().
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      8c7d4b57
    • Chao Yu's avatar
      f2fs: fix to avoid potential deadlock · b13f67ff
      Chao Yu authored
      We should always check F2FS_I(inode)->cp_task condition in prior to other
      conditions in __should_serialize_io() to avoid deadloop described in
      commit 040d2bb3 ("f2fs: fix to avoid deadloop if data_flush is on"),
      however we break this rule when we support compression, fix it.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      b13f67ff
    • Chao Yu's avatar
      f2fs: don't change inode status under page lock · 9995e401
      Chao Yu authored
      In order to shrink page lock coverage.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      9995e401
    • Chao Yu's avatar
      f2fs: fix potential deadlock on compressed quota file · 466357dc
      Chao Yu authored
      generic/232 reports below deadlock:
      
      fsstress        D    0 96980  96969 0x00084000
      Call Trace:
       schedule+0x4a/0xb0
       io_schedule+0x12/0x40
       __lock_page+0x127/0x1d0
       pagecache_get_page+0x1d8/0x250
       prepare_compress_overwrite+0xe0/0x490 [f2fs]
       f2fs_prepare_compress_overwrite+0x5d/0x80 [f2fs]
       f2fs_write_begin+0x833/0xb90 [f2fs]
       f2fs_quota_write+0x145/0x1e0 [f2fs]
       write_blk+0x36/0x80 [quota_tree]
       do_insert_tree+0x2ac/0x4a0 [quota_tree]
       do_insert_tree+0x26e/0x4a0 [quota_tree]
       qtree_write_dquot+0x70/0x190 [quota_tree]
       v2_write_dquot+0x43/0x90 [quota_v2]
       dquot_acquire+0x77/0x100
       f2fs_dquot_acquire+0x2f/0x60 [f2fs]
       dqget+0x310/0x450
       dquot_transfer+0xb2/0x120
       f2fs_setattr+0x11a/0x4a0 [f2fs]
       notify_change+0x349/0x480
       chown_common+0x168/0x1c0
       do_fchownat+0xbc/0xf0
       __x64_sys_lchown+0x21/0x30
       do_syscall_64+0x5f/0x220
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
        task                        PC stack   pid father
      kworker/u256:0  D    0 103444      2 0x80084000
      Workqueue: writeback wb_workfn (flush-251:1)
      Call Trace:
       schedule+0x4a/0xb0
       schedule_timeout+0x15e/0x2f0
       io_schedule_timeout+0x19/0x40
       congestion_wait+0x7e/0x120
       f2fs_write_multi_pages+0x12a/0x840 [f2fs]
       f2fs_write_cache_pages+0x48f/0x790 [f2fs]
       f2fs_write_data_pages+0x2db/0x330 [f2fs]
       do_writepages+0x1a/0x60
       __writeback_single_inode+0x3d/0x340
       writeback_sb_inodes+0x225/0x4a0
       wb_writeback+0xf7/0x320
       wb_workfn+0xba/0x470
       process_one_work+0x16c/0x3f0
       worker_thread+0x4c/0x440
       kthread+0xf8/0x130
       ret_from_fork+0x35/0x40
      
      fsstress        D    0  5277   5266 0x00084000
      Call Trace:
       schedule+0x4a/0xb0
       rwsem_down_write_slowpath+0x29d/0x540
       block_operations+0x105/0x360 [f2fs]
       f2fs_write_checkpoint+0x101/0x1010 [f2fs]
       f2fs_sync_fs+0xa8/0x130 [f2fs]
       f2fs_do_sync_file+0x1ad/0x890 [f2fs]
       do_fsync+0x38/0x60
       __x64_sys_fdatasync+0x13/0x20
       do_syscall_64+0x5f/0x220
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      The root cause is there is potential deadlock between quota data
      update and writeback.
      
      Kworker					Thread B			Thread C
      - f2fs_write_cache_pages
       - lock whole cluster	--- A
       - f2fs_write_multi_pages
        - f2fs_write_raw_pages
         - f2fs_write_single_data_page
          - f2fs_do_write_data_page
      					- f2fs_setattr
      					 - f2fs_lock_op	--- B
      									- f2fs_write_checkpoint
      									 - block_operations
      									  - f2fs_lock_all --- B
      					 - dquot_transfer
      					  - f2fs_quota_write
      					   - f2fs_prepare_compress_overwrite
      					    - pagecache_get_page --- A
           - f2fs_trylock_op failed	--- B
        - congestion_wait
        - goto rewrite
      
      To fix this issue, during quota file writeback, just redirty all pages
      left in cluster rather holding pages' lock in cluster and looping retrying
      lock cp_rwsem.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      466357dc
    • DongDongJu's avatar
      f2fs: delete DIO read lock · ad8d6a02
      DongDongJu authored
      This lock can be a contention with multi 4k random read IO with single inode.
      
      example) fio --output=test --name=test --numjobs=60 --filename=/media/samsung960pro/file_test --rw=randread --bs=4k
       --direct=1 --time_based --runtime=7 --ioengine=libaio --iodepth=256 --group_reporting --size=10G
      
      With this commit, it remove that possible lock contention.
      Signed-off-by: default avatarDongjoo Seo <commisori28@gmail.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      ad8d6a02
    • Chao Yu's avatar
      f2fs: don't mark compressed inode dirty during f2fs_iget() · 530e0704
      Chao Yu authored
      - f2fs_iget
       - do_read_inode
        - set_inode_flag(, FI_COMPRESSED_FILE)
         - __mark_inode_dirty_flag(, true)
      
      It's unnecessary, so let's just mark compressed inode dirty while
      compressed inode conversion.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      530e0704
  2. 23 Mar, 2020 6 commits
  3. 19 Mar, 2020 16 commits
  4. 11 Mar, 2020 3 commits
  5. 10 Mar, 2020 7 commits
    • Jaegeuk Kim's avatar
      f2fs: fix wrong check on F2FS_IOC_FSSETXATTR · 99eabb91
      Jaegeuk Kim authored
      This fixes the incorrect failure when enabling project quota on casefold-enabled
      file.
      
      Cc: Daniel Rosenberg <drosen@google.com>
      Cc: kernel-team@android.com
      Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      99eabb91
    • Chao Yu's avatar
      f2fs: fix to avoid use-after-free in f2fs_write_multi_pages() · 95978caa
      Chao Yu authored
      In compress cluster, if physical block number is less than logic
      page number, race condition will cause use-after-free issue as
      described below:
      
      - f2fs_write_compressed_pages
       - fio.page = cic->rpages[0];
       - f2fs_outplace_write_data
      					- f2fs_compress_write_end_io
      					 - kfree(cic->rpages);
      					 - kfree(cic);
       - fio.page = cic->rpages[1];
      
      f2fs_write_multi_pages+0xfd0/0x1a98
      f2fs_write_data_pages+0x74c/0xb5c
      do_writepages+0x64/0x108
      __writeback_single_inode+0xdc/0x4b8
      writeback_sb_inodes+0x4d0/0xa68
      __writeback_inodes_wb+0x88/0x178
      wb_writeback+0x1f0/0x424
      wb_workfn+0x2f4/0x574
      process_one_work+0x210/0x48c
      worker_thread+0x2e8/0x44c
      kthread+0x110/0x120
      ret_from_fork+0x10/0x18
      
      Fixes: 4c8ff709 ("f2fs: support data compression")
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      95978caa
    • Chao Yu's avatar
      f2fs: fix to avoid using uninitialized variable · 06c7540f
      Chao Yu authored
      In f2fs_vm_page_mkwrite(), if inode is compress one, and current mmapped
      page locates in compressed cluster, we have to call f2fs_get_dnode_of_data()
      to get its physical block address before f2fs_wait_on_block_writeback().
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      06c7540f
    • Chao Yu's avatar
      f2fs: fix inconsistent comments · 7a88ddb5
      Chao Yu authored
      Lack of maintenance on comments may mislead developers, fix them.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      7a88ddb5
    • Chao Yu's avatar
      f2fs: remove i_sem lock coverage in f2fs_setxattr() · 3addc1ae
      Chao Yu authored
      f2fs_inode.xattr_ver field was gone after commit d260081c
      ("f2fs: change recovery policy of xattr node block"), remove i_sem
      lock coverage in f2fs_setxattr()
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      3addc1ae
    • Chao Yu's avatar
      f2fs: cover last_disk_size update with spinlock · c10c9820
      Chao Yu authored
      This change solves below hangtask issue:
      
      INFO: task kworker/u16:1:58 blocked for more than 122 seconds.
            Not tainted 5.6.0-rc2-00590-g9983bdae4974e #11
      "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      kworker/u16:1   D    0    58      2 0x00000000
      Workqueue: writeback wb_workfn (flush-179:0)
      Backtrace:
       (__schedule) from [<c0913234>] (schedule+0x78/0xf4)
       (schedule) from [<c017ec74>] (rwsem_down_write_slowpath+0x24c/0x4c0)
       (rwsem_down_write_slowpath) from [<c0915f2c>] (down_write+0x6c/0x70)
       (down_write) from [<c0435b80>] (f2fs_write_single_data_page+0x608/0x7ac)
       (f2fs_write_single_data_page) from [<c0435fd8>] (f2fs_write_cache_pages+0x2b4/0x7c4)
       (f2fs_write_cache_pages) from [<c043682c>] (f2fs_write_data_pages+0x344/0x35c)
       (f2fs_write_data_pages) from [<c0267ee8>] (do_writepages+0x3c/0xd4)
       (do_writepages) from [<c0310cbc>] (__writeback_single_inode+0x44/0x454)
       (__writeback_single_inode) from [<c03112d0>] (writeback_sb_inodes+0x204/0x4b0)
       (writeback_sb_inodes) from [<c03115cc>] (__writeback_inodes_wb+0x50/0xe4)
       (__writeback_inodes_wb) from [<c03118f4>] (wb_writeback+0x294/0x338)
       (wb_writeback) from [<c0312dac>] (wb_workfn+0x35c/0x54c)
       (wb_workfn) from [<c014f2b8>] (process_one_work+0x214/0x544)
       (process_one_work) from [<c014f634>] (worker_thread+0x4c/0x574)
       (worker_thread) from [<c01564fc>] (kthread+0x144/0x170)
       (kthread) from [<c01010e8>] (ret_from_fork+0x14/0x2c)
      Reported-and-tested-by: default avatarOndřej Jirman <megi@xff.cz>
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      c10c9820
    • Chao Yu's avatar
      f2fs: fix to check i_compr_blocks correctly · d940aa07
      Chao Yu authored
      inode.i_blocks counts based on 512byte sector, we need to convert
      to 4kb sized block count before comparing to i_compr_blocks.
      
      In addition, add to print message when sanity check on inode
      compression configs failed.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      d940aa07