1. 10 Jan, 2022 1 commit
  2. 04 Jan, 2022 10 commits
  3. 14 Dec, 2021 2 commits
    • Hyeong-Jun Kim's avatar
      f2fs: compress: fix potential deadlock of compress file · 7377e853
      Hyeong-Jun Kim authored
      There is a potential deadlock between writeback process and a process
      performing write_begin() or write_cache_pages() while trying to write
      same compress file, but not compressable, as below:
      
      [Process A] - doing checkpoint
      [Process B]                     [Process C]
      f2fs_write_cache_pages()
      - lock_page() [all pages in cluster, 0-31]
      - f2fs_write_multi_pages()
       - f2fs_write_raw_pages()
        - f2fs_write_single_data_page()
         - f2fs_do_write_data_page()
           - return -EAGAIN [f2fs_trylock_op() failed]
         - unlock_page(page) [e.g., page 0]
                                      - generic_perform_write()
                                       - f2fs_write_begin()
                                        - f2fs_prepare_compress_overwrite()
                                         - prepare_compress_overwrite()
                                          - lock_page() [e.g., page 0]
                                          - lock_page() [e.g., page 1]
         - lock_page(page) [e.g., page 0]
      
      Since there is no compress process, it is no longer necessary to hold
      locks on every pages in cluster within f2fs_write_raw_pages().
      
      This patch changes f2fs_write_raw_pages() to release all locks first
      and then perform write same as the non-compress file in
      f2fs_write_cache_pages().
      
      Fixes: 4c8ff709 ("f2fs: support data compression")
      Signed-off-by: default avatarHyeong-Jun Kim <hj514.kim@samsung.com>
      Signed-off-by: default avatarSungjong Seo <sj1557.seo@samsung.com>
      Signed-off-by: default avatarYoungjin Gil <youngjin.gil@samsung.com>
      Reviewed-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      7377e853
    • Jaegeuk Kim's avatar
      f2fs: avoid EINVAL by SBI_NEED_FSCK when pinning a file · 19bdba52
      Jaegeuk Kim authored
      Android OTA failed due to SBI_NEED_FSCK flag when pinning the file. Let's avoid
      it since we can do in-place-updates.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      19bdba52
  4. 10 Dec, 2021 10 commits
    • Daeho Jeong's avatar
      f2fs: add gc_urgent_high_remaining sysfs node · 325163e9
      Daeho Jeong authored
      Added a new sysfs node called gc_urgent_high_remaining. The user can
      set the trial count limit for GC urgent high mode with this value. If
      GC thread gets to the limit, the mode will turn back to GC normal mode.
      By default, the value is zero, which means there is no limit like before.
      Signed-off-by: default avatarDaeho Jeong <daehojeong@google.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      325163e9
    • Chao Yu's avatar
      f2fs: fix to do sanity check in is_alive() · 77900c45
      Chao Yu authored
      In fuzzed image, SSA table may indicate that a data block belongs to
      invalid node, which node ID is out-of-range (0, 1, 2 or max_nid), in
      order to avoid migrating inconsistent data in such corrupted image,
      let's do sanity check anyway before data block migration.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      77900c45
    • Chao Yu's avatar
      f2fs: fix to avoid panic in is_alive() if metadata is inconsistent · f6db4307
      Chao Yu authored
      As report by Wenqing Liu in bugzilla:
      
      https://bugzilla.kernel.org/show_bug.cgi?id=215231
      
      If we enable CONFIG_F2FS_CHECK_FS config, and with fuzzed image attached
      in above link, we will encounter panic when executing below script:
      
      1. mkdir mnt
      2. mount -t f2fs tmp1.img mnt
      3. touch tmp
      
      F2FS-fs (loop11): mismatched blkaddr 5765 (source_blkaddr 1) in seg 3
      kernel BUG at fs/f2fs/gc.c:1042!
       do_garbage_collect+0x90f/0xa80 [f2fs]
       f2fs_gc+0x294/0x12a0 [f2fs]
       f2fs_balance_fs+0x2c5/0x7d0 [f2fs]
       f2fs_create+0x239/0xd90 [f2fs]
       lookup_open+0x45e/0xa90
       open_last_lookups+0x203/0x670
       path_openat+0xae/0x490
       do_filp_open+0xbc/0x160
       do_sys_openat2+0x2f1/0x500
       do_sys_open+0x5e/0xa0
       __x64_sys_openat+0x28/0x40
      
      Previously, f2fs tries to catch data inconcistency exception in between
      SSA and SIT table during GC, however once the exception is caught, it will
      call f2fs_bug_on to hang kernel, it's not needed, instead, let's set
      SBI_NEED_FSCK flag and skip migrating current block.
      
      Fixes: bbf9f7d9 ("f2fs: Fix indefinite loop in f2fs_gc()")
      Signed-off-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      f6db4307
    • Chao Yu's avatar
      f2fs: fix to do sanity check on inode type during garbage collection · 9056d648
      Chao Yu authored
      As report by Wenqing Liu in bugzilla:
      
      https://bugzilla.kernel.org/show_bug.cgi?id=215231
      
      - Overview
      kernel NULL pointer dereference triggered  in folio_mark_dirty() when mount and operate on a crafted f2fs image
      
      - Reproduce
      tested on kernel 5.16-rc3, 5.15.X under root
      
      1. mkdir mnt
      2. mount -t f2fs tmp1.img mnt
      3. touch tmp
      4. cp tmp mnt
      
      F2FS-fs (loop0): sanity_check_inode: inode (ino=49) extent info [5942, 4294180864, 4] is incorrect, run fsck to fix
      F2FS-fs (loop0): f2fs_check_nid_range: out-of-range nid=31340049, run fsck to fix.
      BUG: kernel NULL pointer dereference, address: 0000000000000000
       folio_mark_dirty+0x33/0x50
       move_data_page+0x2dd/0x460 [f2fs]
       do_garbage_collect+0xc18/0x16a0 [f2fs]
       f2fs_gc+0x1d3/0xd90 [f2fs]
       f2fs_balance_fs+0x13a/0x570 [f2fs]
       f2fs_create+0x285/0x840 [f2fs]
       path_openat+0xe6d/0x1040
       do_filp_open+0xc5/0x140
       do_sys_openat2+0x23a/0x310
       do_sys_open+0x57/0x80
      
      The root cause is for special file: e.g. character, block, fifo or socket file,
      f2fs doesn't assign address space operations pointer array for mapping->a_ops field,
      so, in a fuzzed image, SSA table indicates a data block belong to special file, when
      f2fs tries to migrate that block, it causes NULL pointer access once move_data_page()
      calls a_ops->set_dirty_page().
      
      Cc: stable@vger.kernel.org
      Reported-by: default avatarWenqing Liu <wenqingliu0120@gmail.com>
      Signed-off-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      9056d648
    • Jaegeuk Kim's avatar
      f2fs: avoid duplicate call of mark_inode_dirty · 766c6639
      Jaegeuk Kim authored
      Let's check the condition first before set|clear bit.
      Reviewed-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      766c6639
    • Jaegeuk Kim's avatar
      f2fs: show number of pending discard commands · ae2e2804
      Jaegeuk Kim authored
      This information can be used to check how much time we need to give to issue
      all the discard commands.
      Reviewed-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      ae2e2804
    • Fengnan Chang's avatar
      f2fs: support POSIX_FADV_DONTNEED drop compressed page cache · e64347ae
      Fengnan Chang authored
      Previously, compressed page cache drop when clean page cache, but
      POSIX_FADV_DONTNEED can't clean compressed page cache because raw page
      don't have private data, and won't call f2fs_invalidate_compress_pages.
      This commit call f2fs_invalidate_compress_pages() directly in
      f2fs_file_fadvise() for POSIX_FADV_DONTNEED case.
      Signed-off-by: default avatarFengnan Chang <changfengnan@vivo.com>
      Reviewed-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      e64347ae
    • Fengnan Chang's avatar
      f2fs: fix remove page failed in invalidate compress pages · d1917865
      Fengnan Chang authored
      Since compress inode not a regular file, generic_error_remove_page in
      f2fs_invalidate_compress_pages will always be failed, set compress
      inode as a regular file to fix it.
      
      Fixes: 6ce19aff ("f2fs: compress: add compress_inode to cache compressed blocks")
      Signed-off-by: default avatarFengnan Chang <changfengnan@vivo.com>
      Reviewed-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      d1917865
    • Jaegeuk Kim's avatar
      f2fs: show more DIO information in tracepoint · bd984c03
      Jaegeuk Kim authored
      This prints more information of DIO in tracepoint.
      Reviewed-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      bd984c03
    • Eric Biggers's avatar
      f2fs: use iomap for direct I/O · a1e09b03
      Eric Biggers authored
      Make f2fs_file_read_iter() and f2fs_file_write_iter() use the iomap
      direct I/O implementation instead of the fs/direct-io.c one.
      
      The iomap implementation is more efficient, and it also avoids the need
      to add new features and optimizations to the old implementation.
      
      This new implementation also eliminates the need for f2fs to hook bio
      submission and completion and to allocate memory per-bio.  This is
      because it's possible to correctly update f2fs's in-flight DIO counters
      using __iomap_dio_rw() in combination with an implementation of
      iomap_dio_ops::end_io() (as suggested by Christoph Hellwig).
      
      When possible, this new implementation preserves existing f2fs behavior
      such as the conditions for falling back to buffered I/O.
      
      This patch has been tested with xfstests by running 'gce-xfstests -c
      f2fs -g auto -X generic/017' with and without this patch; no regressions
      were seen.  (Some tests fail both before and after.  generic/017 hangs
      both before and after, so it had to be excluded.)
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      [Jaegeuk Kim: use spin_lock_bh for f2fs_update_iostat in softirq]
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      a1e09b03
  5. 04 Dec, 2021 4 commits
  6. 17 Nov, 2021 2 commits
  7. 15 Nov, 2021 3 commits
  8. 14 Nov, 2021 8 commits