11 Sep, 2020

1 commit


08 Jul, 2020

1 commit

  • Filesystem including f2fs should support stable page for special
    device like software raid, however there is one missing path that
    page could be updated while it is writeback state as below, fix
    this.

    - gc_node_segment
    - f2fs_move_node_page
    - __write_node_page
    - set_page_writeback

    - do_read_inode
    - f2fs_init_extent_tree
    - __f2fs_init_extent_tree
    i_ext->len = 0;

    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     

03 Jul, 2019

1 commit

  • - Add and use f2fs_ macros
    - Convert f2fs_msg to f2fs_printk
    - Remove level from f2fs_printk and embed the level in the format
    - Coalesce formats and align multi-line arguments
    - Remove unnecessary duplicate extern f2fs_msg f2fs.h

    Signed-off-by: Joe Perches
    Signed-off-by: Chao Yu
    Reviewed-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Joe Perches
     

23 Jan, 2019

1 commit

  • As Dan Carpenter as below:

    The patch df634f444ee9: "f2fs: use rb_*_cached friends" from Oct 4,
    2018, leads to the following static checker warning:

    fs/f2fs/extent_cache.c:606 f2fs_update_extent_tree_range()
    error: uninitialized symbol 'leftmost'.

    And also Eric Biggers, and Kyungtae Kim reported, there is an UBSAN
    warning described as below:

    We report a bug in linux-4.20.2: "UBSAN: Undefined behaviour in
    fs/f2fs/extent_cache.c"

    kernel config: https://kt0755.github.io/etc/config_v4.20_stable
    repro: https://kt0755.github.io/etc/repro.4a3e7.c (f2fs is mounted on
    /mnt/f2fs/)

    This arose in f2fs_update_extent_tree_range (fs/f2fs/extent_cache.c:605).
    It seems that, for some reason, its last argument became "24"
    although that was supposed to be bool type.

    =========================================
    UBSAN: Undefined behaviour in fs/f2fs/extent_cache.c:605:4
    load of value 24 is not a valid value for type '_Bool'
    CPU: 0 PID: 6774 Comm: syz-executor5 Not tainted 4.20.2 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
    Call Trace:
    __dump_stack lib/dump_stack.c:77 [inline]
    dump_stack+0xb1/0x118 lib/dump_stack.c:113
    ubsan_epilogue+0x12/0x94 lib/ubsan.c:159
    __ubsan_handle_load_invalid_value+0x17a/0x1be lib/ubsan.c:457
    f2fs_update_extent_tree_range+0x1d4a/0x1d50 fs/f2fs/extent_cache.c:605
    f2fs_update_extent_cache+0x2b6/0x350 fs/f2fs/extent_cache.c:804
    f2fs_update_data_blkaddr+0x61/0x70 fs/f2fs/data.c:656
    f2fs_outplace_write_data+0x1d6/0x4b0 fs/f2fs/segment.c:3140
    f2fs_convert_inline_page+0x86d/0x2060 fs/f2fs/inline.c:163
    f2fs_convert_inline_inode+0x6b5/0xad0 fs/f2fs/inline.c:208
    f2fs_preallocate_blocks+0x78b/0xb00 fs/f2fs/data.c:982
    f2fs_file_write_iter+0x31b/0xf40 fs/f2fs/file.c:3062
    call_write_iter include/linux/fs.h:1857 [inline]
    new_sync_write fs/read_write.c:474 [inline]
    __vfs_write+0x538/0x6e0 fs/read_write.c:487
    vfs_write+0x1b3/0x520 fs/read_write.c:549
    ksys_write+0xde/0x1c0 fs/read_write.c:598
    __do_sys_write fs/read_write.c:610 [inline]
    __se_sys_write fs/read_write.c:607 [inline]
    __x64_sys_write+0x7e/0xc0 fs/read_write.c:607
    do_syscall_64+0xbe/0x4f0 arch/x86/entry/common.c:290
    entry_SYSCALL_64_after_hwframe+0x49/0xbe
    RIP: 0033:0x4497b9
    Code: e8 8c 9f 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 00 48 89 f8 48
    89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 3d
    01 f0 ff ff 0f 83 9b 6b fc ff c3 66 2e 0f 1f 84 00 00 00 00
    RSP: 002b:00007f1ea15edc68 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
    RAX: ffffffffffffffda RBX: 00007f1ea15ee6cc RCX: 00000000004497b9
    RDX: 0000000000001000 RSI: 0000000020000140 RDI: 0000000000000013
    RBP: 000000000071bea0 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
    R13: 000000000000bb50 R14: 00000000006f4bf0 R15: 00007f1ea15ee700
    =========================================

    As I checked, this uninitialized variable won't cause extent cache
    corruption, but in order to avoid such kind of warning of both UBSAN
    and smatch, fix to initialize related variable.

    Reported-by: Dan Carpenter
    Reported-by: Eric Biggers
    Reported-by: Kyungtae Kim
    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     

17 Oct, 2018

1 commit

  • As rbtree supports caching leftmost node natively, update f2fs codes
    to use rb_*_cached helpers to speed up leftmost node visiting.

    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     

13 Sep, 2018

1 commit


12 Sep, 2018

1 commit

  • In the call trace below, we might sleep in function dput().

    So in order to avoid sleeping under spin_lock, we remove f2fs_mark_inode_dirty_sync
    from __try_update_largest_extent && __drop_largest_extent.

    BUG: sleeping function called from invalid context at fs/dcache.c:796
    Call trace:
    dump_backtrace+0x0/0x3f4
    show_stack+0x24/0x30
    dump_stack+0xe0/0x138
    ___might_sleep+0x2a8/0x2c8
    __might_sleep+0x78/0x10c
    dput+0x7c/0x750
    block_dump___mark_inode_dirty+0x120/0x17c
    __mark_inode_dirty+0x344/0x11f0
    f2fs_mark_inode_dirty_sync+0x40/0x50
    __insert_extent_tree+0x2e0/0x2f4
    f2fs_update_extent_tree_range+0xcf4/0xde8
    f2fs_update_extent_cache+0x114/0x12c
    f2fs_update_data_blkaddr+0x40/0x50
    write_data_page+0x150/0x314
    do_write_data_page+0x648/0x2318
    __write_data_page+0xdb4/0x1640
    f2fs_write_cache_pages+0x768/0xafc
    __f2fs_write_data_pages+0x590/0x1218
    f2fs_write_data_pages+0x64/0x74
    do_writepages+0x74/0xe4
    __writeback_single_inode+0xdc/0x15f0
    writeback_sb_inodes+0x574/0xc98
    __writeback_inodes_wb+0x190/0x204
    wb_writeback+0x730/0xf14
    wb_check_old_data_flush+0x1bc/0x1c8
    wb_workfn+0x554/0xf74
    process_one_work+0x440/0x118c
    worker_thread+0xac/0x974
    kthread+0x1a0/0x1c8
    ret_from_fork+0x10/0x1c

    Signed-off-by: Zhikang Zhang
    Reviewed-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Zhikang Zhang
     

01 Jun, 2018

1 commit

  • As Ted reported:

    "Hi, I was looking at f2fs's sources recently, and I noticed that there
    is a very large number of non-static symbols which don't have a f2fs
    prefix. There's well over a hundred (see attached below).

    As one example, in fs/f2fs/dir.c there is:

    unsigned char get_de_type(struct f2fs_dir_entry *de)

    This function is clearly only useful for f2fs, but it has a generic
    name. This means that if any other file system tries to have the same
    symbol name, there will be a symbol conflict and the kernel would not
    successfully build. It also means that when someone is looking f2fs
    sources, it's not at all obvious whether a function such as
    read_data_page(), invalidate_blocks(), is a generic kernel function
    found in the fs, mm, or block layers, or a f2fs specific function.

    You might want to fix this at some point. Hopefully Kent's bcachefs
    isn't similarly using genericly named functions, since that might
    cause conflicts with f2fs's functions --- but just as this would be a
    problem that we would rightly insist that Kent fix, this is something
    that we should have rightly insisted that f2fs should have fixed
    before it was integrated into the mainline kernel.

    acquire_orphan_inode
    add_ino_entry
    add_orphan_inode
    allocate_data_block
    allocate_new_segments
    alloc_nid
    alloc_nid_done
    alloc_nid_failed
    available_free_memory
    ...."

    This patch adds "f2fs_" prefix for all non-static symbols in order to:
    a) avoid conflict with other kernel generic symbols;
    b) to indicate the function is f2fs specific one instead of generic
    one;

    Reported-by: Theodore Ts'o
    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     

13 Mar, 2018

2 commits

  • Pointer p is initialized with a value that is never read and is later
    re-assigned a new value, hence the initialization is redundant and can
    be removed.

    Cleans up clang warning:
    fs/f2fs/extent_cache.c:463:19: warning: Value stored to 'p' during
    its initialization is never read

    Signed-off-by: Colin Ian King
    Reviewed-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Colin Ian King
     
  • If noextent_cache mount option is on, we will never initialize extent tree
    in inode, but still we're going to access it in f2fs_drop_extent_tree,
    result in kernel panic as below:

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000038
    IP: _raw_write_lock+0xc/0x30
    Call Trace:
    ? f2fs_drop_extent_tree+0x41/0x70 [f2fs]
    f2fs_fallocate+0x5a0/0xdd0 [f2fs]
    ? common_file_perm+0x47/0xc0
    ? apparmor_file_permission+0x1a/0x20
    vfs_fallocate+0x15b/0x290
    SyS_fallocate+0x44/0x70
    do_syscall_64+0x6e/0x160
    entry_SYSCALL64_slow_path+0x25/0x25

    This patch fixes to check extent cache status before using in
    f2fs_drop_extent_tree.

    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     

24 May, 2017

1 commit


20 Apr, 2017

2 commits


12 Apr, 2017

1 commit

  • rb-tree lookup/update functions are deeply coupled into extent cache
    codes, it's very hard to reuse these basic functions, this patch
    extracts common rb-tree operation infrastructure for latter reusing.

    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     

28 Feb, 2017

2 commits

  • Since commit ee6d182f2a19 ("f2fs: remove syncing inode page in all the
    cases") delayed inode element updating from inode cache to node page
    cache, so once largest cached extent is updated, we can make inode dirty
    immediately instead of checking and updating it in the end of extent
    cache update.

    The above commit didn't clean up unneeded codes in extent_cache.c, let's
    finish the job in this patch.

    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     
  • This patch replace rw semaphore extent_tree_lock with mutex lock
    for no read cases with this lock.

    Signed-off-by: Yunlei He
    Signed-off-by: Jaegeuk Kim

    Yunlei He
     

29 Jan, 2017

2 commits


24 Nov, 2016

1 commit

  • This is to avoid no free segment bug during checkpoint caused by a number of
    dirty inodes.

    The case was reported by Chao like this.
    1. mount with lazytime option
    2. fill 4k file until disk is full
    3. sync filesystem
    4. read all files in the image
    5. umount

    In this case, we actually don't need to flush dirty inode to inode page during
    checkpoint.

    Reviewed-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Jaegeuk Kim
     

16 Jul, 2016

1 commit


09 Jul, 2016

1 commit


03 Jun, 2016

3 commits


08 May, 2016

1 commit


27 Feb, 2016

1 commit


23 Feb, 2016

6 commits

  • There are redundant pointer conversion in following call stack:
    - at position a, inode was been converted to f2fs_file_info.
    - at position b, f2fs_file_info was been converted to inode again.

    - truncate_blocks(inode,..)
    - fi = F2FS_I(inode) ---a
    - ADDRS_PER_PAGE(node_page, fi)
    - addrs_per_inode(fi)
    - inode = &fi->vfs_inode ---b
    - f2fs_has_inline_xattr(inode)
    - fi = F2FS_I(inode)
    - is_inode_flag_set(fi,..)

    In order to avoid unneeded conversion, alter ADDRS_PER_PAGE and
    addrs_per_inode to acept parameter with type of inode pointer.

    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     
  • It needs to give a chance to be rescheduled while shrinking slab entries.

    Signed-off-by: Jaegeuk Kim

    Jaegeuk Kim
     
  • On the worst case, we need to scan the whole radix tree and every rb-tree to
    free the victimed extent_nodes when shrinking.

    Pengyang initially introduced a victim_list to record the victimed extent_nodes,
    and free these extent_nodes by just scanning a list.

    Later, Chao Yu enhances the original patch to improve memory footprint by
    removing victim list.

    The policy of lru list shrinking becomes:
    1) lock lru list's lock
    2) trylock extent tree's lock
    3) remove extent node from lru list
    4) unlock lru list's lock
    5) do shrink
    6) repeat 1) to 5)

    Signed-off-by: Hou Pengyang
    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Hou Pengyang
     
  • If en has empty list pointer, it will be freed sooner, so we don't need to
    set cached_en with it.

    Signed-off-by: Jaegeuk Kim

    Jaegeuk Kim
     
  • This patch moves extent_node list operations to be handled together with
    its rbtree operations.

    Signed-off-by: Jaegeuk Kim

    Jaegeuk Kim
     
  • There are three steps to free an extent node:
    1) list_del_init, 2)__detach_extent_node, 3) kmem_cache_free

    In path f2fs_destroy_extent_tree, 1->2->3 to free a node,
    But in path f2fs_update_extent_tree_range, it is 2->1->3.

    This patch makes all the order to be: 1->2->3
    It makes sense, since in the next patch, we import a victim list in the
    path shrink_extent_tree, we could check if the extent_node is in the victim
    list by checking the list_empty(). So it is necessary to put 1) first.

    Signed-off-by: Hou Pengyang
    Signed-off-by: Jaegeuk Kim

    Hou Pengyang
     

09 Jan, 2016

2 commits


01 Jan, 2016

1 commit


31 Dec, 2015

2 commits

  • Otherwise, we can get mismatched largest extent information.

    One example is:
    1. mount f2fs w/ extent_cache
    2. make a small extent
    3. umount
    4. mount f2fs w/o extent_cache
    5. update the largest extent
    6. umount
    7. mount f2fs w/ extent_cache
    8. get the old extent made by #2

    Signed-off-by: Jaegeuk Kim

    Jaegeuk Kim
     
  • If there is no candidates for shrinking slab entries, we don't need to traverse
    any trees at all.

    Reviewed-by: Chao Yu
    [Jaegeuk Kim: fix missing initialization reported by Yunlei He]
    Signed-off-by: Jaegeuk Kim

    Jaegeuk Kim
     

23 Dec, 2015

1 commit


05 Dec, 2015

2 commits

  • For direct IO, f2fs only allocate new address for the block which is not
    exist in the disk before, its mapping info should not exist in extent
    cache previously, so here we do not need to call f2fs_drop_largest_extent
    to drop related cache.

    Due to no more callers for f2fs_drop_largest_extent now, kill it.

    Signed-off-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Chao Yu
     
  • While handling extent trees, we can enter into a reclaiming path anytime.
    If it tries to release some extent nodes in the same extent tree,
    write_lock(&et->lock) would be hanged.
    In order to avoid the deadlock, we can just skip it.

    Note that, if it is an unreferenced tree, we should get write_lock(&et->lock)
    successfully and release all of therein nodes.

    Reviewed-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Jaegeuk Kim