1. 25 Feb, 2024 26 commits
    • Zhihao Cheng's avatar
      ubifs: Queue up space reservation tasks if retrying many times · 556c19f5
      Zhihao Cheng authored
      Recently we catched ENOSPC returned by make_reservation() while doing
      fsstress on UBIFS, we got following information when it occurred (See
      details in Link):
      
       UBIFS error (ubi0:0 pid 3640152): make_reservation [ubifs]: cannot
       reserve 112 bytes in jhead 2, error -28
       CPU: 2 PID: 3640152 Comm: kworker/u16:2 Tainted: G    B   W
       Hardware name: Hisilicon PhosphorHi1230 EMU (DT)
       Workqueue: writeback wb_workfn (flush-ubifs_0_0)
       Call trace:
        dump_stack+0x114/0x198
        make_reservation+0x564/0x610 [ubifs]
        ubifs_jnl_write_data+0x328/0x48c [ubifs]
        do_writepage+0x2a8/0x3e4 [ubifs]
        ubifs_writepage+0x16c/0x374 [ubifs]
        generic_writepages+0xb4/0x114
        do_writepages+0xcc/0x11c
        writeback_sb_inodes+0x2d0/0x564
        wb_writeback+0x20c/0x2b4
        wb_workfn+0x404/0x510
        process_one_work+0x304/0x4ac
        worker_thread+0x31c/0x4e4
        kthread+0x23c/0x290
        Budgeting info: data budget sum 17576, total budget sum 17768
      	budg_data_growth 4144, budg_dd_growth 13432, budg_idx_growth 192
      	min_idx_lebs 13, old_idx_sz 988640, uncommitted_idx 0
      	page_budget 4144, inode_budget 160, dent_budget 312
      	nospace 0, nospace_rp 0
      	dark_wm 8192, dead_wm 4096, max_idx_node_sz 192
      	freeable_cnt 0, calc_idx_sz 988640, idx_gc_cnt 0
      	dirty_pg_cnt 4, dirty_zn_cnt 0, clean_zn_cnt 4811
      	gc_lnum 21, ihead_lnum 14
      	jhead 0 (GC)	 LEB 16
      	jhead 1 (base)	 LEB 34
      	jhead 2 (data)	 LEB 23
      	bud LEB 16
      	bud LEB 23
      	bud LEB 34
      	old bud LEB 33
      	old bud LEB 31
      	old bud LEB 15
      	commit state 4
       Budgeting predictions:
      	available: 33832, outstanding 17576, free 15356
       (pid 3640152) start dumping LEB properties
       (pid 3640152) Lprops statistics: empty_lebs 3, idx_lebs  11
      	taken_empty_lebs 1, total_free 1253376, total_dirty 2445736
      	total_used 3438712, total_dark 65536, total_dead 17248
       LEB 15 free 0      dirty 248000   used 5952   (taken)
       LEB 16 free 110592 dirty 896      used 142464 (taken, jhead 0 (GC))
       LEB 21 free 253952 dirty 0        used 0      (taken, GC LEB)
       LEB 23 free 0      dirty 248104   used 5848   (taken, jhead 2 (data))
       LEB 29 free 253952 dirty 0        used 0      (empty)
       LEB 33 free 0      dirty 253952   used 0      (taken)
       LEB 34 free 217088 dirty 36544    used 320    (taken, jhead 1 (base))
       LEB 37 free 253952 dirty 0        used 0      (empty)
       OTHERS: index lebs, zero-available non-index lebs
      
      According to the budget algorithm, there are 5 LEBs reserved for budget:
      three journal heads(16,23,34), 1 GC LEB(21) and 1 deletion LEB(can be
      used in make_reservation()). There are 2 empty LEBs used for index nodes,
      which is calculated as min_idx_lebs - idx_lebs = 2. In theory, LEB 15
      and 33 should be reclaimed as free state after committing, but it is now
      in taken state. After looking the realization of reserve_space(), there's
      a possible situation:
      
      LEB 15: free 2000 dirty 248000 used 3952 (jhead 2)
      LEB 23: free 2000 dirty 248104 used 3848 (bud, taken)
      LEB 33: free 2000 dirty 251952 used 0    (bud, taken)
      
            wb_workfn          wb_workfn_2
      do_writepage // write 3000 bytes
       ubifs_jnl_write_data
        make_reservation
         reserve_space
          ubifs_garbage_collect
           ubifs_find_dirty_leb // ret ENOSPC, dirty LEBs are taken
         nospc_retries++  // 1
         ubifs_run_commit
          do_commit
      
      LEB 15: free 2000 dirty 248000 used 3952 (jhead 2)
      LEB 23: free 2000 dirty 248104 used 3848 (dirty)
      LEB 33: free 2000 dirty 251952 used 0    (dirty)
      
                         do_writepage // write 2000 bytes for 3 times
      		    ubifs_jnl_write_data
      		    // grabs 15\23\33
      
      LEB 15: free 0    dirty 248000 used 5952 (bud, taken)
      LEB 23: free 0    dirty 248104 used 5848 (jhead 2)
      LEB 33: free 0    dirty 253952 used 0    (bud, taken)
      
         reserve_space
          ubifs_garbage_collect
           ubifs_find_dirty_leb // ret ENOSPC, dirty LEBs are taken
         if (nospc_retries++ < 2) // false
       ubifs_ro_mode !
      
      Fetch a reproducer in Link.
      
      The dirty LEBs could be grabbed by other threads, which fails finding dirty
      LEBs of GC in current thread, so make_reservation() could try many times to
      invoke GC&&committing, but current realization limits the times of retrying
      as 'nospc_retries'(twice).
      Fix it by adding a wait queue, start queuing up space reservation tasks
      when someone task has retried gc + commit for many times. Then there is
      only one task making space reservation at any time, and it can always make
      success under the premise of correct budgeting.
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=218164
      Fixes: 1e51764a ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      556c19f5
    • Zhihao Cheng's avatar
      ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path · 6379b44c
      Zhihao Cheng authored
      For error handling path in ubifs_symlink(), inode will be marked as
      bad first, then iput() is invoked. If inode->i_link is initialized by
      fscrypt_encrypt_symlink() in encryption scenario, inode->i_link won't
      be freed by callchain ubifs_free_inode -> fscrypt_free_inode in error
      handling path, because make_bad_inode() has changed 'inode->i_mode' as
      'S_IFREG'.
      Following kmemleak is easy to be reproduced by injecting error in
      ubifs_jnl_update() when doing symlink in encryption scenario:
       unreferenced object 0xffff888103da3d98 (size 8):
        comm "ln", pid 1692, jiffies 4294914701 (age 12.045s)
        backtrace:
         kmemdup+0x32/0x70
         __fscrypt_encrypt_symlink+0xed/0x1c0
         ubifs_symlink+0x210/0x300 [ubifs]
         vfs_symlink+0x216/0x360
         do_symlinkat+0x11a/0x190
         do_syscall_64+0x3b/0xe0
      There are two ways fixing it:
       1. Remove make_bad_inode() in error handling path. We can do that
          because ubifs_evict_inode() will do same processes for good
          symlink inode and bad symlink inode, for inode->i_nlink checking
          is before is_bad_inode().
       2. Free inode->i_link before marking inode bad.
      Method 2 is picked, it has less influence, personally, I think.
      
      Cc: stable@vger.kernel.org
      Fixes: 2c58d548 ("fscrypt: cache decrypted symlink target in ->i_link")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Suggested-by: default avatarEric Biggers <ebiggers@kernel.org>
      Reviewed-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      6379b44c
    • Zhihao Cheng's avatar
      ubifs: dbg_check_idx_size: Fix kmemleak if loading znode failed · 31a9d5f3
      Zhihao Cheng authored
      If function dbg_check_idx_size() failed by loading znode in mounting
      process, there are two problems:
        1. Allocated znodes won't be freed, which causes kmemleak in kernel:
           ubifs_mount
            dbg_check_idx_size
             dbg_walk_index
              c->zroot.znode = ubifs_load_znode
      	child = ubifs_load_znode // failed
      	// Loaded znodes won't be freed in error handling path.
        2. Global variable ubifs_clean_zn_cnt is not decreased, because
           ubifs_tnc_close() is not invoked in error handling path, which
           triggers a warning in ubifs_exit():
            WARNING: CPU: 1 PID: 1576 at fs/ubifs/super.c:2486 ubifs_exit
            Modules linked in: zstd ubifs(-) ubi nandsim
            CPU: 1 PID: 1576 Comm: rmmod Not tainted 6.7.0-rc6
            Call Trace:
      	ubifs_exit+0xca/0xc70 [ubifs]
      	__do_sys_delete_module+0x29a/0x4a0
      	do_syscall_64+0x6f/0x140
      
      Fix it by adding error handling path in dbg_check_idx_size() to release
      tnc tree.
      
      Fixes: 1e51764a ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Suggested-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      31a9d5f3
    • ZhaoLong Wang's avatar
      ubi: Correct the number of PEBs after a volume resize failure · 9277b3a6
      ZhaoLong Wang authored
      In the error handling path `out_acc` of `ubi_resize_volume()`,
      when `pebs < 0`, it indicates that the volume table record failed to
      update when the volume was shrunk. In this case, the number of `ubi->avail_pebs`
      and `ubi->rsvd_pebs` should be restored to their previous values to prevent
      the UBI layer from reporting an incorrect number of available PEBs.
      Signed-off-by: default avatarZhaoLong Wang <wangzhaolong1@huawei.com>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      9277b3a6
    • Guo Xuenan's avatar
      ubi: fix slab-out-of-bounds in ubi_eba_get_ldesc+0xfb/0x130 · fbed4bae
      Guo Xuenan authored
      When using the ioctl interface to resize a UBI volume, `ubi_resize_volume`
      resizes the EBA table first but does not change `vol->reserved_pebs` in
      the same atomic context, which may cause concurrent access to the EBA table.
      
      For example, when a user shrinks UBI volume A by calling `ubi_resize_volume`,
      while another thread is writing to volume B and triggering wear-leveling,
      which may call `ubi_write_fastmap`, under these circumstances, KASAN may
      report a slab-out-of-bounds error in `ubi_eba_get_ldesc+0xfb/0x130`.
      
      This patch fixes race conditions in `ubi_resize_volume` and
      `ubi_update_fastmap` to avoid out-of-bounds reads of `eba_tbl`. First,
      it ensures that updates to `eba_tbl` and `reserved_pebs` are protected
      by `vol->volumes_lock`. Second, it implements a rollback mechanism in case
      of resize failure. It is also worth mentioning that for volume shrinkage
      failures, since part of the volume has already been shrunk and unmapped,
      there is no need to recover `{rsvd/avail}_pebs`.
      
      ==================================================================
      BUG: KASAN: slab-out-of-bounds in ubi_eba_get_ldesc+0xfb/0x130 [ubi]
      Read of size 4 at addr ffff88800f43f570 by task kworker/u16:0/7
      CPU: 0 PID: 7 Comm: kworker/u16:0 Not tainted 5.16.0-rc7 #3
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
      Workqueue: writeback wb_workfn (flush-ubifs_0_0)
      Call Trace:
       <TASK>
       dump_stack_lvl+0x4d/0x66
       print_address_description.constprop.0+0x41/0x60
       kasan_report.cold+0x83/0xdf
       ubi_eba_get_ldesc+0xfb/0x130 [ubi]
       ubi_update_fastmap.cold+0x60f/0xc7d [ubi]
       ubi_wl_get_peb+0x25b/0x4f0 [ubi]
       try_write_vid_and_data+0x9a/0x4d0 [ubi]
       ubi_eba_write_leb+0x7e4/0x17d0 [ubi]
       ubi_leb_map+0x1a0/0x2c0 [ubi]
       ubifs_leb_map+0x139/0x270 [ubifs]
       ubifs_add_bud_to_log+0xb40/0xf30 [ubifs]
       make_reservation+0x86e/0xb00 [ubifs]
       ubifs_jnl_write_data+0x430/0x9d0 [ubifs]
       do_writepage+0x1d1/0x550 [ubifs]
       ubifs_writepage+0x37c/0x670 [ubifs]
       __writepage+0x67/0x170
       write_cache_pages+0x259/0xa90
       do_writepages+0x277/0x5d0
       __writeback_single_inode+0xb8/0x850
       writeback_sb_inodes+0x4b3/0xb20
       __writeback_inodes_wb+0xc1/0x220
       wb_writeback+0x59f/0x740
       wb_workfn+0x6d0/0xca0
       process_one_work+0x711/0xfc0
       worker_thread+0x95/0xd00
       kthread+0x3a6/0x490
       ret_from_fork+0x1f/0x30
       </TASK>
      
      Allocated by task 711:
       kasan_save_stack+0x1e/0x50
       __kasan_kmalloc+0x81/0xa0
       ubi_eba_create_table+0x88/0x1a0 [ubi]
       ubi_resize_volume.cold+0x175/0xae7 [ubi]
       ubi_cdev_ioctl+0x57f/0x1a60 [ubi]
       __x64_sys_ioctl+0x13a/0x1c0
       do_syscall_64+0x35/0x80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      Last potentially related work creation:
       kasan_save_stack+0x1e/0x50
       __kasan_record_aux_stack+0xb7/0xc0
       call_rcu+0xd6/0x1000
       blk_stat_free_callback+0x28/0x30
       blk_release_queue+0x8a/0x2e0
       kobject_put+0x186/0x4c0
       scsi_device_dev_release_usercontext+0x620/0xbd0
       execute_in_process_context+0x2f/0x120
       device_release+0xa4/0x240
       kobject_put+0x186/0x4c0
       put_device+0x20/0x30
       __scsi_remove_device+0x1c3/0x300
       scsi_probe_and_add_lun+0x2140/0x2eb0
       __scsi_scan_target+0x1f2/0xbb0
       scsi_scan_channel+0x11b/0x1a0
       scsi_scan_host_selected+0x24c/0x310
       do_scsi_scan_host+0x1e0/0x250
       do_scan_async+0x45/0x490
       async_run_entry_fn+0xa2/0x530
       process_one_work+0x711/0xfc0
       worker_thread+0x95/0xd00
       kthread+0x3a6/0x490
       ret_from_fork+0x1f/0x30
      The buggy address belongs to the object at ffff88800f43f500
       which belongs to the cache kmalloc-128 of size 128
      The buggy address is located 112 bytes inside of
       128-byte region [ffff88800f43f500, ffff88800f43f580)
      The buggy address belongs to the page:
      page:ffffea00003d0f00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xf43c
      head:ffffea00003d0f00 order:2 compound_mapcount:0 compound_pincount:0
      flags: 0x1fffff80010200(slab|head|node=0|zone=1|lastcpupid=0x1fffff)
      raw: 001fffff80010200 ffffea000046ba08 ffffea0000457208 ffff88810004d1c0
      raw: 0000000000000000 0000000000190019 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      Memory state around the buggy address:
       ffff88800f43f400: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
       ffff88800f43f480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      > ffff88800f43f500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fc fc
                                                                   ^
       ffff88800f43f580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
       ffff88800f43f600: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      
      The following steps can used to reproduce:
      Process 1: write and trigger ubi wear-leveling
          ubimkvol /dev/ubi0 -s 5000MiB -N v1
          ubimkvol /dev/ubi0 -s 2000MiB -N v2
          ubimkvol /dev/ubi0 -s 10MiB -N v3
          mount -t ubifs /dev/ubi0_0 /mnt/ubifs
          while true;
          do
              filename=/mnt/ubifs/$((RANDOM))
              dd if=/dev/random of=${filename} bs=1M count=$((RANDOM % 1000))
              rm -rf ${filename}
              sync /mnt/ubifs/
          done
      
      Process 2: do random resize
          struct ubi_rsvol_req req;
          req.vol_id = 1;
          req.bytes = (rand() % 50) * 512KB;
          ioctl(fd, UBI_IOCRSVOL, &req);
      
      V3:
       - Fix the commit message error.
      
      V2:
       - Add volumes_lock in ubi_eba_copy_leb() to avoid race caused by
         updating eba_tbl.
      
      V1:
       - Rebase the patch on the latest mainline.
      Signed-off-by: default avatarGuo Xuenan <guoxuenan@huawei.com>
      Signed-off-by: default avatarZhaoLong Wang <wangzhaolong1@huawei.com>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      fbed4bae
    • Zhang Yi's avatar
      ubi: correct the calculation of fastmap size · 7f174ae4
      Zhang Yi authored
      Now that the calculation of fastmap size in ubi_calc_fm_size() is
      incorrect since it miss each user volume's ubi_fm_eba structure and the
      Internal UBI volume info. Let's correct the calculation.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      7f174ae4
    • Kunwu Chan's avatar
      ubifs: Remove unreachable code in dbg_check_ltab_lnum · 788cd161
      Kunwu Chan authored
      Because there is no break statement in the dead loop above,it is
      impossible to execute the 'err=0' statement.Delete the code that
      will never execute.
      
      Fixes: 6fb324a4 ("UBIFS: allocate ltab checking buffer on demand")
      Signed-off-by: default avatarKunwu Chan <chentao@kylinos.cn>
      Cc: Kunwu Chan <kunwu.chan@hotmail.com>
      Suggested-by: default avatarRichard Weinberger <richard.weinberger@gmail.com>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      788cd161
    • Arnd Bergmann's avatar
      ubifs: fix function pointer cast warnings · ec724e53
      Arnd Bergmann authored
      ubifs has a number of callback functions for ubifs_lpt_scan_nolock() using
      two different prototypes, either passing a struct scan_data or
      a struct ubifs_lp_stats, but the caller expects a void pointer instead.
      
      clang-16 now warns about this:
      
      fs/ubifs/find.c:170:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct scan_data *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
        170 |                                     (ubifs_lpt_scan_callback)scan_for_dirty_cb,
            |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      fs/ubifs/find.c:449:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct scan_data *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
        449 |                                     (ubifs_lpt_scan_callback)scan_for_free_cb,
            |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      Change all of these callback functions to actually take the void * argument
      that is passed by their caller.
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      ec724e53
    • Arnd Bergmann's avatar
      ubifs: fix sort function prototype · 60f16e91
      Arnd Bergmann authored
      The global sort() function expects a callback pointer to a function with two
      void* arguments, but ubifs has a function with specific object types, which
      causes a warning in clang-16 and higher:
      
      fs/ubifs/lprops.c:1272:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct ubifs_lp_stats *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
       1272 |                                     (ubifs_lpt_scan_callback)scan_check_cb,
            |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      Change the prototype to the regular one and cast the object pointers
      locally instead.
      
      Fixes: 1e51764a ("UBIFS: add new flash file system")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      60f16e91
    • Richard Weinberger's avatar
      ubi: Check for too small LEB size in VTBL code · 68a24aba
      Richard Weinberger authored
      If the LEB size is smaller than a volume table record we cannot
      have volumes.
      In this case abort attaching.
      
      Cc: Chenyuan Yang <cy54@illinois.edu>
      Cc: stable@vger.kernel.org
      Fixes: 801c135c ("UBI: Unsorted Block Images")
      Reported-by: default avatarChenyuan Yang <cy54@illinois.edu>
      Closes: https://lore.kernel.org/linux-mtd/1433EB7A-FC89-47D6-8F47-23BE41B263B3@illinois.edu/Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      68a24aba
    • Richard Weinberger's avatar
      MAINTAINERS: Add Zhihao Cheng as UBI/UBIFS reviewer · eb542353
      Richard Weinberger authored
      Recognizing Zhihao Cheng's valuable contributions,
      let's officially appoint him as a UBI/UBIFS reviewer.
      His demonstrated expertise and assistance make him a valuable
      addition to the MTD community.
      
      Cc: Zhihao Cheng <chengzhihao1@huawei.com>
      Acked-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      eb542353
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert populate_page() to take a folio · a16bfab3
      Matthew Wilcox (Oracle) authored
      Both callers now have a folio, so pass it in.  This function contains
      several assumptions that folios are not large.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      a16bfab3
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Use a folio in ubifs_do_bulk_read() · d0619273
      Matthew Wilcox (Oracle) authored
      When looking in the page cache, retrieve a folio instead of a page.
      This would need some work to make it safe for large folios.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      d0619273
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Pass a folio into ubifs_bulk_read() and ubifs_do_bulk_read() · 7f348f8c
      Matthew Wilcox (Oracle) authored
      This saves a single call to compound_head().
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      7f348f8c
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert cancel_budget() to take a folio · 45d76698
      Matthew Wilcox (Oracle) authored
      The one caller already has a folio, so pass it in instead of the page.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      45d76698
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert allocate_budget() to work on a folio · a3c2f196
      Matthew Wilcox (Oracle) authored
      The one caller has a folio, so pass it in instead of the page.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      a3c2f196
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert do_readpage() to take a folio · b96af1fd
      Matthew Wilcox (Oracle) authored
      All the callers now have a folio, so pass it in, and convert do_readpage()
      to us folios directly.  Includes unifying the exit paths from this
      function and using kmap_local instead of plain kmap.  This function
      should now work with large folios, but this is not tested.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      b96af1fd
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert ubifs_write_end() to use a folio · ffdff813
      Matthew Wilcox (Oracle) authored
      Convert the incoming page pointer to a folio and use it throughout,
      saving several calls to compound_head().  Also remove some PAGE_SIZE
      assumptions.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      ffdff813
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert ubifs_write_begin() to use a folio · f60d356e
      Matthew Wilcox (Oracle) authored
      Save eight calls to compound_head() by using the new folio API.
      Remove a few assumptions that would break with large folios.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      f60d356e
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert write_begin_slow() to use a folio · 2ec71843
      Matthew Wilcox (Oracle) authored
      Update to new APIs, removing several calls to compound_head() and
      including support for large folios.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      2ec71843
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert ubifs_vm_page_mkwrite() to use a folio · 85ffbf55
      Matthew Wilcox (Oracle) authored
      Replace six implicit calls to compound_head() with one.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      85ffbf55
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert do_writepage() to take a folio · 0c2d140c
      Matthew Wilcox (Oracle) authored
      Replace the call to SetPageError() with a call to mapping_set_error().
      Support large folios by using kmap_local_folio() and remapping each time
      we cross a page boundary.  Saves a lot of hidden calls to compound_head().
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      0c2d140c
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Use a folio in do_truncation() · 783d0741
      Matthew Wilcox (Oracle) authored
      Convert from the old page APIs to the new folio APIs which saves
      a few hidden calls to compound_head().
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      783d0741
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert ubifs_writepage to use a folio · c35acef3
      Matthew Wilcox (Oracle) authored
      We still pass the page down to do_writepage(), but ubifs_writepage()
      itself is now large folio safe.  It also contains far fewer hidden calls
      to compound_head().
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      c35acef3
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Convert from writepage to writepages · 0df030d0
      Matthew Wilcox (Oracle) authored
      This is a simplistic conversion to separate out any effects of
      no longer having a writepage method.
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      0df030d0
    • Matthew Wilcox (Oracle)'s avatar
      ubifs: Set page uptodate in the correct place · 723012ca
      Matthew Wilcox (Oracle) authored
      Page cache reads are lockless, so setting the freshly allocated page
      uptodate before we've overwritten it with the data it's supposed to have
      in it will allow a simultaneous reader to see old data.  Move the call
      to SetPageUptodate into ubifs_write_end(), which is after we copied the
      new data into the page.
      
      Fixes: 1e51764a ("UBIFS: add new flash file system")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      723012ca
  2. 18 Feb, 2024 6 commits
    • Linus Torvalds's avatar
      Linux 6.8-rc5 · b401b621
      Linus Torvalds authored
      b401b621
    • Linus Torvalds's avatar
      Merge tag 'kbuild-fixes-v6.8-2' of... · 6c160f16
      Linus Torvalds authored
      Merge tag 'kbuild-fixes-v6.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
      
      Pull Kbuild fixes from Masahiro Yamada:
      
       - Reformat nested if-conditionals in Makefiles with 4 spaces
      
       - Fix CONFIG_DEBUG_INFO_BTF builds for big endian
      
       - Fix modpost for module srcversion
      
       - Fix an escape sequence warning in gen_compile_commands.py
      
       - Fix kallsyms to ignore ARMv4 thunk symbols
      
      * tag 'kbuild-fixes-v6.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
        kallsyms: ignore ARMv4 thunks along with others
        modpost: trim leading spaces when processing source files list
        gen_compile_commands: fix invalid escape sequence warning
        kbuild: Fix changing ELF file type for output of gen_btf for big endian
        docs: kconfig: Fix grammar and formatting
        kbuild: use 4-space indentation when followed by conditionals
      6c160f16
    • Linus Torvalds's avatar
      Merge tag 'x86_urgent_for_v6.8_rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · ddac3d8b
      Linus Torvalds authored
      Pull x86 fix from Borislav Petkov:
      
       - Use a GB page for identity mapping only when memory of this size is
         requested so that mapping of reserved regions is prevented which
         would otherwise lead to system crashes on UV machines
      
      * tag 'x86_urgent_for_v6.8_rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        x86/mm/ident_map: Use gbpages only where full GB page should be mapped.
      ddac3d8b
    • Linus Torvalds's avatar
      Merge tag 'irq_urgent_for_v6.8_rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · 7cb7c32d
      Linus Torvalds authored
      Pull irq fixes from Borislav Petkov:
      
       - Fix GICv4.1 affinity update
      
       - Restore a quirk for ACPI-based GICv4 systems
      
       - Handle non-coherent GICv4 redistributors properly
      
       - Prevent spurious interrupts on Broadcom devices using GIC v3
         architecture
      
       - Other minor fixes
      
      * tag 'irq_urgent_for_v6.8_rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        irqchip/gic-v3-its: Fix GICv4.1 VPE affinity update
        irqchip/gic-v3-its: Restore quirk probing for ACPI-based systems
        irqchip/gic-v3-its: Handle non-coherent GICv4 redistributors
        irqchip/qcom-mpm: Fix IS_ERR() vs NULL check in qcom_mpm_init()
        irqchip/loongson-eiointc: Use correct struct type in eiointc_domain_alloc()
        irqchip/irq-brcmstb-l2: Add write memory barrier before exit
      7cb7c32d
    • Linus Torvalds's avatar
      Merge tag 'i2c-for-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux · 626721ed
      Linus Torvalds authored
      Pull i2c fixes from Wolfram Sang:
       "Two fixes for i801 and qcom-geni devices. Meanwhile, a fix from Arnd
        addresses a compilation error encountered during compile test on
        powerpc"
      
      * tag 'i2c-for-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
        i2c: i801: Fix block process call transactions
        i2c: pasemi: split driver into two separate modules
        i2c: qcom-geni: Correct I2C TRE sequence
      626721ed
    • Linus Torvalds's avatar
      Merge tag 'powerpc-6.8-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux · c02197fc
      Linus Torvalds authored
      Pull powerpc fixes from Michael Ellerman:
       "This is a bit of a big batch for rc4, but just due to holiday hangover
        and because I didn't send any fixes last week due to a late revert
        request. I think next week should be back to normal.
      
         - Fix ftrace bug on boot caused by exit text sections with
           '-fpatchable-function-entry'
      
         - Fix accuracy of stolen time on pseries since the switch to
           VIRT_CPU_ACCOUNTING_GEN
      
         - Fix a crash in the IOMMU code when doing DLPAR remove
      
         - Set pt_regs->link on scv entry to fix BPF stack unwinding
      
         - Add missing PPC_FEATURE_BOOKE on 64-bit e5500/e6500, which broke
           gdb
      
         - Fix boot on some 6xx platforms with STRICT_KERNEL_RWX enabled
      
         - Fix build failures with KASAN enabled and 32KB stack size
      
         - Some other minor fixes
      
        Thanks to Arnd Bergmann, Benjamin Gray, Christophe Leroy, David
        Engraf, Gaurav Batra, Jason Gunthorpe, Jiangfeng Xiao, Matthias
        Schiffer, Nathan Lynch, Naveen N Rao, Nicholas Piggin, Nysal Jan K.A,
        R Nageswara Sastry, Shivaprasad G Bhat, Shrikanth Hegde, Spoorthy,
        Srikar Dronamraju, and Venkat Rao Bagalkote"
      
      * tag 'powerpc-6.8-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux:
        powerpc/iommu: Fix the missing iommu_group_put() during platform domain attach
        powerpc/pseries: fix accuracy of stolen time
        powerpc/ftrace: Ignore ftrace locations in exit text sections
        powerpc/cputable: Add missing PPC_FEATURE_BOOKE on PPC64 Book-E
        powerpc/kasan: Limit KASAN thread size increase to 32KB
        Revert "powerpc/pseries/iommu: Fix iommu initialisation during DLPAR add"
        powerpc: 85xx: mark local functions static
        powerpc: udbg_memcons: mark functions static
        powerpc/kasan: Fix addr error caused by page alignment
        powerpc/6xx: set High BAT Enable flag on G2_LE cores
        selftests/powerpc/papr_vpd: Check devfd before get_system_loc_code()
        powerpc/64: Set task pt_regs->link to the LR value on scv entry
        powerpc/pseries/iommu: Fix iommu initialisation during DLPAR add
        powerpc/pseries/papr-sysparm: use u8 arrays for payloads
      c02197fc
  3. 17 Feb, 2024 8 commits
    • Linus Torvalds's avatar
      Merge tag 'bcachefs-2024-02-17' of https://evilpiepirate.org/git/bcachefs · f2667e0c
      Linus Torvalds authored
      Pull bcachefs fixes from Kent Overstreet:
       "Mostly pretty trivial, the user visible ones are:
      
         - don't barf when replicas_required > replicas
      
         - fix check_version_upgrade() so it doesn't do something nonsensical
           when we're downgrading"
      
      * tag 'bcachefs-2024-02-17' of https://evilpiepirate.org/git/bcachefs:
        bcachefs: Fix missing va_end()
        bcachefs: Fix check_version_upgrade()
        bcachefs: Clamp replicas_required to replicas
        bcachefs: fix missing endiannes conversion in sb_members
        bcachefs: fix kmemleak in __bch2_read_super error handling path
        bcachefs: Fix missing bch2_err_class() calls
      f2667e0c
    • Linus Torvalds's avatar
      Merge tag 'driver-core-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core · ced59052
      Linus Torvalds authored
      Pull driver core fixes from Greg KH:
       "Here are some driver core fixes, a kobject fix, and a documentation
        update for 6.8-rc5. In detail these changes are:
      
         - devlink fixes for reported issues with 6.8-rc1
      
         - topology scheduling regression fix that has been reported by many
      
         - kobject loosening of checks change in -rc1 is now reverted as some
           codepaths seemed to need the checks
      
         - documentation update for the CVE process. Has been reviewed by
           many, the last minute change to the document was to bring the .rst
           format back into the the new style rules, the contents did not
           change.
      
        All of these, except for the documentation update, have been in
        linux-next for over a week. The documentation update has been reviewed
        for weeks by a group of developers, and in public for a week and the
        wording has stabilized for now. If future changes are needed, we can
        do so before 6.8-final is out (or anytime after that)"
      
      * tag 'driver-core-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
        Documentation: Document the Linux Kernel CVE process
        Revert "kobject: Remove redundant checks for whether ktype is NULL"
        driver core: fw_devlink: Improve logs for cycle detection
        driver core: fw_devlink: Improve detection of overlapping cycles
        driver core: Fix device_link_flag_is_sync_state_only()
        topology: Set capacity_freq_ref in all cases
      ced59052
    • Linus Torvalds's avatar
      Merge tag 'char-misc-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc · 7efc0eb8
      Linus Torvalds authored
      Pull char / miscdriver fixes from Greg KH:
       "Here is a small set of char/misc and IIO driver fixes for 6.8-rc5.
      
        Included in here are:
      
         - lots of iio driver fixes for reported issues
      
         - nvmem device naming fixup for reported problem
      
         - interconnect driver fixes for reported issues
      
        All of these have been in linux-next for a while with no reported the
        issues (the nvmem patch was included in a different branch in
        linux-next before sent to me for inclusion here)"
      
      * tag 'char-misc-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (21 commits)
        nvmem: include bit index in cell sysfs file name
        iio: adc: ad4130: only set GPIO_CTRL if pin is unused
        iio: adc: ad4130: zero-initialize clock init data
        interconnect: qcom: x1e80100: Add missing ACV enable_mask
        interconnect: qcom: sm8650: Use correct ACV enable_mask
        iio: accel: bma400: Fix a compilation problem
        iio: commom: st_sensors: ensure proper DMA alignment
        iio: hid-sensor-als: Return 0 for HID_USAGE_SENSOR_TIME_TIMESTAMP
        iio: move LIGHT_UVA and LIGHT_UVB to the end of iio_modifier
        staging: iio: ad5933: fix type mismatch regression
        iio: humidity: hdc3020: fix temperature offset
        iio: adc: ad7091r8: Fix error code in ad7091r8_gpio_setup()
        iio: adc: ad_sigma_delta: ensure proper DMA alignment
        iio: imu: adis: ensure proper DMA alignment
        iio: humidity: hdc3020: Add Makefile, Kconfig and MAINTAINERS entry
        iio: imu: bno055: serdev requires REGMAP
        iio: magnetometer: rm3100: add boundary check for the value read from RM3100_REG_TMRC
        iio: pressure: bmp280: Add missing bmp085 to SPI id table
        iio: core: fix memleak in iio_device_register_sysfs
        interconnect: qcom: sm8550: Enable sync_state
        ...
      7efc0eb8
    • Linus Torvalds's avatar
      Merge tag 'tty-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty · 4b2981b2
      Linus Torvalds authored
      Pull tty / serial fixes from Greg KH:
       "Here are three small tty and serial driver fixes for 6.8-rc5:
      
         - revert a 8250_pci1xxxx off-by-one change that was incorrect
      
         - two changes to fix the transmit path of the mxs-auart driver,
           fixing a regression in the 6.2 release
      
        All of these have been in linux-next for over a week with no reported
        issues"
      
      * tag 'tty-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty:
        serial: mxs-auart: fix tx
        serial: core: introduce uart_port_tx_flags()
        serial: 8250_pci1xxxx: partially revert off by one patch
      4b2981b2
    • Linus Torvalds's avatar
      Merge tag 'usb-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb · a3a7d162
      Linus Torvalds authored
      Pull USB / Thunderbolt fixes from Greg KH:
       "Here are two small fixes for 6.8-rc5:
      
         - thunderbolt to fix a reported issue on many platforms
      
         - dwc3 driver revert of a commit that caused problems in -rc1
      
        Both of these changes have been in linux-next for over a week with no
        reported issues"
      
      * tag 'usb-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb:
        Revert "usb: dwc3: Support EBC feature of DWC_usb31"
        thunderbolt: Fix setting the CNS bit in ROUTER_CS_5
      a3a7d162
    • Linus Torvalds's avatar
      Merge tag 'media/v6.8-4' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media · ac00b654
      Linus Torvalds authored
      Pull media fixes from Mauro Carvalho Chehab:
      
       - regression fix for rkisp1 shared IRQ logic
      
       - fix atomisp breakage due to a kAPI change
      
       - permission fix for remote controller BPF support
      
       - memleak fix in ir_toy driver
      
       - Kconfig dependency fix for pwm-ir-rx
      
      * tag 'media/v6.8-4' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media:
        media: pwm-ir-tx: Depend on CONFIG_HIGH_RES_TIMERS
        media: ir_toy: fix a memleak in irtoy_tx
        media: rc: bpf attach/detach requires write permission
        media: atomisp: Adjust for v4l2_subdev_state handling changes in 6.8
        media: rkisp1: Fix IRQ handling due to shared interrupts
        media: Revert "media: rkisp1: Drop IRQF_SHARED"
      ac00b654
    • Linus Torvalds's avatar
      Merge tag 'pci-v6.8-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci · 4a757148
      Linus Torvalds authored
      Pull pci fixes from Bjorn Helgaas:
      
       - Keep bridges in D0 if we need to poll downstream devices for PME to
         resolve a v6.6 regression where we failed to enumerate devices below
         bridges put in D3hot by runtime PM, e.g., NVMe drives connected via
         Thunderbolt or USB4 docks (Alex Williamson)
      
       - Add Siddharth Vadapalli as PCI TI DRA7XX/J721E reviewer
      
      * tag 'pci-v6.8-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci:
        MAINTAINERS: Add Siddharth Vadapalli as PCI TI DRA7XX/J721E reviewer
        PCI: Fix active state requirement in PME polling
      4a757148
    • Linus Torvalds's avatar
      Merge tag 'probes-fixes-v6.8-rc4' of... · ad645dea
      Linus Torvalds authored
      Merge tag 'probes-fixes-v6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
      
      Pull probes fix from Masami Hiramatsu:
      
       - tracing/probes: Fix BTF structure member finder to find the members
         which are placed after any anonymous union member correctly.
      
      * tag 'probes-fixes-v6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
        tracing/probes: Fix to search structure fields correctly
      ad645dea