Skip to content
  1. Jul 19, 2023
    • Krzysztof Kozlowski's avatar
      regulator: tps65219: Fix matching interrupts for their regulators · 3f6af56d
      Krzysztof Kozlowski authored
      commit f050e56d upstream.
      
      The driver's probe() first registers regulators in a loop and then in a
      second loop passes them as irq data to the interrupt handlers.  However
      the function to get the regulator for given name
      tps65219_get_rdev_by_name() was a no-op due to argument passed by value,
      not pointer, thus the second loop assigned always same value - from
      previous loop.  The interrupts, when fired, where executed with wrong
      data.  Compiler also noticed it:
      
        drivers/regulator/tps65219-regulator.c: In function ‘tps65219_get_rdev_by_name’:
        drivers/regulator/tps65219-regulator.c:292:60: error: parameter ‘dev’ set but not used [-Werror=unused-but-set-parameter]
      
      Fixes: c12ac5fc
      
       ("regulator: drivers: Add TI TPS65219 PMIC regulators support")
      Cc: <stable@vger.kernel.org
      Signed-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
      Reviewed-by: default avatarMarkus Schneider-Pargmann <msp@baylibre.com>
      Link: https://lore.kernel.org/r/20230507144656.192800-1-krzysztof.kozlowski@linaro.org
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3f6af56d
    • Ricardo Ribalda Delgado's avatar
      ASoC: mediatek: mt8173: Fix snd_soc_component_initialize error path · a9414756
      Ricardo Ribalda Delgado authored
      commit a46d3701
      
       upstream.
      
      If the second component fails to initialize, cleanup the first on.
      
      Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Cc: stable@kernel.org
      Fixes: f1b5bf07
      
       ("ASoC: mt2701/mt8173: replace platform to component")
      Signed-off-by: default avatarRicardo Ribalda Delgado <ribalda@chromium.org>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Link: https://lore.kernel.org/r/20230612-mt8173-fixup-v2-1-432aa99ce24d@chromium.org
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a9414756
    • Ricardo Ribalda Delgado's avatar
      ASoC: mediatek: mt8173: Fix irq error path · 05be6ada
      Ricardo Ribalda Delgado authored
      commit f9c058d1
      
       upstream.
      
      After reordering the irq probe, the error path was not properly done.
      Lets fix it.
      
      Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Cc: stable@kernel.org
      Fixes: 4cbb264d
      
       ("ASoC: mediatek: mt8173: Enable IRQ when pdata is ready")
      Signed-off-by: default avatarRicardo Ribalda Delgado <ribalda@chromium.org>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Link: https://lore.kernel.org/r/20230612-mt8173-fixup-v2-2-432aa99ce24d@chromium.org
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      05be6ada
    • Filipe Manana's avatar
      btrfs: do not BUG_ON() on tree mod log failure at __btrfs_cow_block() · 82270e7f
      Filipe Manana authored
      commit 40b0a749
      
       upstream.
      
      At __btrfs_cow_block(), instead of doing a BUG_ON() in case we fail to
      record a tree mod log root insertion operation, do a transaction abort
      instead. There's really no need for the BUG_ON(), we can properly
      release all resources in this context and turn the filesystem to RO mode
      and in an error state instead.
      
      CC: stable@vger.kernel.org # 5.4+
      Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      82270e7f
    • Filipe Manana's avatar
      btrfs: fix extent buffer leak after tree mod log failure at split_node() · 796eb12a
      Filipe Manana authored
      commit ede600e4 upstream.
      
      At split_node(), if we fail to log the tree mod log copy operation, we
      return without unlocking the split extent buffer we just allocated and
      without decrementing the reference we own on it. Fix this by unlocking
      it and decrementing the ref count before returning.
      
      Fixes: 5de865ee
      
       ("Btrfs: fix tree mod logging")
      CC: stable@vger.kernel.org # 5.4+
      Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      796eb12a
    • Filipe Manana's avatar
      btrfs: add missing error handling when logging operation while COWing extent buffer · 6df630a1
      Filipe Manana authored
      commit d09c5152 upstream.
      
      When COWing an extent buffer that is not the root node, we need to log in
      the tree mod log that we replaced a pointer in the parent node, otherwise
      a tree mod log user doing a search on the b+tree can return incorrect
      results (that miss something). We are doing the call to
      btrfs_tree_mod_log_insert_key() but we totally ignore its return value.
      
      So fix this by adding the missing error handling, resulting in a
      transaction abort and freeing the COWed extent buffer.
      
      Fixes: f230475e
      
       ("Btrfs: put all block modifications into the tree mod log")
      CC: stable@vger.kernel.org # 5.4+
      Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6df630a1
    • Filipe Manana's avatar
      btrfs: fix race when deleting quota root from the dirty cow roots list · a5cdc401
      Filipe Manana authored
      commit b31cb5a6 upstream.
      
      When disabling quotas we are deleting the quota root from the list
      fs_info->dirty_cowonly_roots without taking the lock that protects it,
      which is struct btrfs_fs_info::trans_lock. This unsynchronized list
      manipulation may cause chaos if there's another concurrent manipulation
      of this list, such as when adding a root to it with
      ctree.c:add_root_to_dirty_list().
      
      This can result in all sorts of weird failures caused by a race, such as
      the following crash:
      
        [337571.278245] general protection fault, probably for non-canonical address 0xdead000000000108: 0000 [#1] PREEMPT SMP PTI
        [337571.278933] CPU: 1 PID: 115447 Comm: btrfs Tainted: G        W          6.4.0-rc6-btrfs-next-134+ #1
        [337571.279153] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
        [337571.279572] RIP: 0010:commit_cowonly_roots+0x11f/0x250 [btrfs]
        [337571.279928] Code: 85 38 06 00 (...)
        [337571.280363] RSP: 0018:ffff9f63446efba0 EFLAGS: 00010206
        [337571.280582] RAX: ffff942d98ec2638 RBX: ffff9430b82b4c30 RCX: 0000000449e1c000
        [337571.280798] RDX: dead000000000100 RSI: ffff9430021e4900 RDI: 0000000000036070
        [337571.281015] RBP: ffff942d98ec2000 R08: ffff942d98ec2000 R09: 000000000000015b
        [337571.281254] R10: 0000000000000009 R11: 0000000000000001 R12: ffff942fe8fbf600
        [337571.281476] R13: ffff942dabe23040 R14: ffff942dabe20800 R15: ffff942d92cf3b48
        [337571.281723] FS:  00007f478adb7340(0000) GS:ffff94349fa40000(0000) knlGS:0000000000000000
        [337571.281950] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [337571.282184] CR2: 00007f478ab9a3d5 CR3: 000000001e02c001 CR4: 0000000000370ee0
        [337571.282416] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        [337571.282647] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        [337571.282874] Call Trace:
        [337571.283101]  <TASK>
        [337571.283327]  ? __die_body+0x1b/0x60
        [337571.283570]  ? die_addr+0x39/0x60
        [337571.283796]  ? exc_general_protection+0x22e/0x430
        [337571.284022]  ? asm_exc_general_protection+0x22/0x30
        [337571.284251]  ? commit_cowonly_roots+0x11f/0x250 [btrfs]
        [337571.284531]  btrfs_commit_transaction+0x42e/0xf90 [btrfs]
        [337571.284803]  ? _raw_spin_unlock+0x15/0x30
        [337571.285031]  ? release_extent_buffer+0x103/0x130 [btrfs]
        [337571.285305]  reset_balance_state+0x152/0x1b0 [btrfs]
        [337571.285578]  btrfs_balance+0xa50/0x11e0 [btrfs]
        [337571.285864]  ? __kmem_cache_alloc_node+0x14a/0x410
        [337571.286086]  btrfs_ioctl+0x249a/0x3320 [btrfs]
        [337571.286358]  ? mod_objcg_state+0xd2/0x360
        [337571.286577]  ? refill_obj_stock+0xb0/0x160
        [337571.286798]  ? seq_release+0x25/0x30
        [337571.287016]  ? __rseq_handle_notify_resume+0x3ba/0x4b0
        [337571.287235]  ? percpu_counter_add_batch+0x2e/0xa0
        [337571.287455]  ? __x64_sys_ioctl+0x88/0xc0
        [337571.287675]  __x64_sys_ioctl+0x88/0xc0
        [337571.287901]  do_syscall_64+0x38/0x90
        [337571.288126]  entry_SYSCALL_64_after_hwframe+0x72/0xdc
        [337571.288352] RIP: 0033:0x7f478aaffe9b
      
      So fix this by locking struct btrfs_fs_info::trans_lock before deleting
      the quota root from that list.
      
      Fixes: bed92eae
      
       ("Btrfs: qgroup implementation and prototypes")
      CC: stable@vger.kernel.org # 4.14+
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a5cdc401
    • Naohiro Aota's avatar
      btrfs: reinsert BGs failed to reclaim · 6c65062f
      Naohiro Aota authored
      commit 7e271809 upstream.
      
      The reclaim process can temporarily fail. For example, if the space is
      getting tight, it fails to make the block group read-only. If there are no
      further writes on that block group, the block group will never get back to
      the reclaim list, and the BG never gets reclaimed. In a certain workload,
      we can leave many such block groups never reclaimed.
      
      So, let's get it back to the list and give it a chance to be reclaimed.
      
      Fixes: 18bb8bbf
      
       ("btrfs: zoned: automatically reclaim zones")
      CC: stable@vger.kernel.org # 5.15+
      Signed-off-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6c65062f
    • David Sterba's avatar
      btrfs: add block-group tree to lockdep classes · 7b063701
      David Sterba authored
      commit 1a1b0e72
      
       upstream.
      
      The block group tree was not present among the lockdep classes. We could
      get potentially lockdep warnings but so far none has been seen, also
      because block-group-tree is a relatively new feature.
      
      CC: stable@vger.kernel.org # 6.1+
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7b063701
    • Naohiro Aota's avatar
      btrfs: bail out reclaim process if filesystem is read-only · f6102927
      Naohiro Aota authored
      commit 93463ff7 upstream.
      
      When a filesystem is read-only, we cannot reclaim a block group as it
      cannot rewrite the data. Just bail out in that case.
      
      Note that it can drop block groups in this case. As we did
      sb_start_write(), read-only filesystem means we got a fatal error and
      forced read-only. There is no chance to reclaim them again.
      
      Fixes: 18bb8bbf
      
       ("btrfs: zoned: automatically reclaim zones")
      CC: stable@vger.kernel.org # 5.15+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Signed-off-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f6102927
    • Naohiro Aota's avatar
      btrfs: delete unused BGs while reclaiming BGs · 9d9586ef
      Naohiro Aota authored
      commit 3ed01616 upstream.
      
      The reclaiming process only starts after the filesystem volumes are
      allocated to a certain level (75% by default). Thus, the list of
      reclaiming target block groups can build up so huge at the time the
      reclaim process kicks in. On a test run, there were over 1000 BGs in the
      reclaim list.
      
      As the reclaim involves rewriting the data, it takes really long time to
      reclaim the BGs. While the reclaim is running, btrfs_delete_unused_bgs()
      won't proceed because the reclaim side is holding
      fs_info->reclaim_bgs_lock. As a result, we will have a large number of
      unused BGs kept in the unused list. On my test run, I got 1057 unused BGs.
      
      Since deleting a block group is relatively easy and fast work, we can call
      btrfs_delete_unused_bgs() while it reclaims BGs, to avoid building up
      unused BGs.
      
      Fixes: 18bb8bbf
      
       ("btrfs: zoned: automatically reclaim zones")
      CC: stable@vger.kernel.org # 5.15+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Signed-off-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9d9586ef
    • Boris Burkov's avatar
      btrfs: warn on invalid slot in tree mod log rewind · 987cf649
      Boris Burkov authored
      commit 95c8e349
      
       upstream.
      
      The way that tree mod log tracks the ultimate length of the eb, the
      variable 'n', eventually turns up the correct value, but at intermediate
      steps during the rewind, n can be inaccurate as a representation of the
      end of the eb. For example, it doesn't get updated on move rewinds, and
      it does get updated for add/remove in the middle of the eb.
      
      To detect cases with invalid moves, introduce a separate variable called
      max_slot which tries to track the maximum valid slot in the rewind eb.
      We can then warn if we do a move whose src range goes beyond the max
      valid slot.
      
      There is a commented caveat that it is possible to have this value be an
      overestimate due to the challenge of properly handling 'add' operations
      in the middle of the eb, but in practice it doesn't cause enough of a
      problem to throw out the max idea in favor of tracking every valid slot.
      
      CC: stable@vger.kernel.org # 5.15+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarBoris Burkov <boris@bur.io>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      987cf649
    • Boris Burkov's avatar
      btrfs: insert tree mod log move in push_node_left · 11f14402
      Boris Burkov authored
      commit 5cead542
      
       upstream.
      
      There is a fairly unlikely race condition in tree mod log rewind that
      can result in a kernel panic which has the following trace:
      
        [530.569] BTRFS critical (device sda3): unable to find logical 0 length 4096
        [530.585] BTRFS critical (device sda3): unable to find logical 0 length 4096
        [530.602] BUG: kernel NULL pointer dereference, address: 0000000000000002
        [530.618] #PF: supervisor read access in kernel mode
        [530.629] #PF: error_code(0x0000) - not-present page
        [530.641] PGD 0 P4D 0
        [530.647] Oops: 0000 [#1] SMP
        [530.654] CPU: 30 PID: 398973 Comm: below Kdump: loaded Tainted: G S         O  K   5.12.0-0_fbk13_clang_7455_gb24de3bdb045 #1
        [530.680] Hardware name: Quanta Mono Lake-M.2 SATA 1HY9U9Z001G/Mono Lake-M.2 SATA, BIOS F20_3A15 08/16/2017
        [530.703] RIP: 0010:__btrfs_map_block+0xaa/0xd00
        [530.755] RSP: 0018:ffffc9002c2f7600 EFLAGS: 00010246
        [530.767] RAX: ffffffffffffffea RBX: ffff888292e41000 RCX: f2702d8b8be15100
        [530.784] RDX: ffff88885fda6fb8 RSI: ffff88885fd973c8 RDI: ffff88885fd973c8
        [530.800] RBP: ffff888292e410d0 R08: ffffffff82fd7fd0 R09: 00000000fffeffff
        [530.816] R10: ffffffff82e57fd0 R11: ffffffff82e57d70 R12: 0000000000000000
        [530.832] R13: 0000000000001000 R14: 0000000000001000 R15: ffffc9002c2f76f0
        [530.848] FS:  00007f38d64af000(0000) GS:ffff88885fd80000(0000) knlGS:0000000000000000
        [530.866] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [530.880] CR2: 0000000000000002 CR3: 00000002b6770004 CR4: 00000000003706e0
        [530.896] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        [530.912] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        [530.928] Call Trace:
        [530.934]  ? btrfs_printk+0x13b/0x18c
        [530.943]  ? btrfs_bio_counter_inc_blocked+0x3d/0x130
        [530.955]  btrfs_map_bio+0x75/0x330
        [530.963]  ? kmem_cache_alloc+0x12a/0x2d0
        [530.973]  ? btrfs_submit_metadata_bio+0x63/0x100
        [530.984]  btrfs_submit_metadata_bio+0xa4/0x100
        [530.995]  submit_extent_page+0x30f/0x360
        [531.004]  read_extent_buffer_pages+0x49e/0x6d0
        [531.015]  ? submit_extent_page+0x360/0x360
        [531.025]  btree_read_extent_buffer_pages+0x5f/0x150
        [531.037]  read_tree_block+0x37/0x60
        [531.046]  read_block_for_search+0x18b/0x410
        [531.056]  btrfs_search_old_slot+0x198/0x2f0
        [531.066]  resolve_indirect_ref+0xfe/0x6f0
        [531.076]  ? ulist_alloc+0x31/0x60
        [531.084]  ? kmem_cache_alloc_trace+0x12e/0x2b0
        [531.095]  find_parent_nodes+0x720/0x1830
        [531.105]  ? ulist_alloc+0x10/0x60
        [531.113]  iterate_extent_inodes+0xea/0x370
        [531.123]  ? btrfs_previous_extent_item+0x8f/0x110
        [531.134]  ? btrfs_search_path_in_tree+0x240/0x240
        [531.146]  iterate_inodes_from_logical+0x98/0xd0
        [531.157]  ? btrfs_search_path_in_tree+0x240/0x240
        [531.168]  btrfs_ioctl_logical_to_ino+0xd9/0x180
        [531.179]  btrfs_ioctl+0xe2/0x2eb0
      
      This occurs when logical inode resolution takes a tree mod log sequence
      number, and then while backref walking hits a rewind on a busy node
      which has the following sequence of tree mod log operations (numbers
      filled in from a specific example, but they are somewhat arbitrary)
      
        REMOVE_WHILE_FREEING slot 532
        REMOVE_WHILE_FREEING slot 531
        REMOVE_WHILE_FREEING slot 530
        ...
        REMOVE_WHILE_FREEING slot 0
        REMOVE slot 455
        REMOVE slot 454
        REMOVE slot 453
        ...
        REMOVE slot 0
        ADD slot 455
        ADD slot 454
        ADD slot 453
        ...
        ADD slot 0
        MOVE src slot 0 -> dst slot 456 nritems 533
        REMOVE slot 455
        REMOVE slot 454
        REMOVE slot 453
        ...
        REMOVE slot 0
      
      When this sequence gets applied via btrfs_tree_mod_log_rewind, it
      allocates a fresh rewind eb, and first inserts the correct key info for
      the 533 elements, then overwrites the first 456 of them, then decrements
      the count by 456 via the add ops, then rewinds the move by doing a
      memmove from 456:988->0:532. We have never written anything past 532, so
      that memmove writes garbage into the 0:532 range. In practice, this
      results in a lot of fully 0 keys. The rewind then puts valid keys into
      slots 0:455 with the last removes, but 456:532 are still invalid.
      
      When search_old_slot uses this eb, if it uses one of those invalid
      slots, it can then read the extent buffer and issue a bio for offset 0
      which ultimately panics looking up extent mappings.
      
      This bad tree mod log sequence gets generated when the node balancing
      code happens to do a balance_node_right followed by a push_node_left
      while logging in the tree mod log. Illustrated for ebs L and R (left and
      right):
      
      	L                 R
        start:
        [XXX|YYY|...]      [ZZZ|...|...]
        balance_node_right:
        [XXX|YYY|...]      [...|ZZZ|...] move Z to make room for Y
        [XXX|...|...]      [YYY|ZZZ|...] copy Y from L to R
        push_node_left:
        [XXX|YYY|...]      [...|ZZZ|...] copy Y from R to L
        [XXX|YYY|...]      [ZZZ|...|...] move Z into emptied space (NOT LOGGED!)
      
      This is because balance_node_right logs a move, but push_node_left
      explicitly doesn't. That is because logging the move would remove the
      overwritten src < dst range in the right eb, which was already logged
      when we called btrfs_tree_mod_log_eb_copy. The correct sequence would
      include a move from 456:988 to 0:532 after remove 0:455 and before
      removing 0:532. Reversing that sequence would entail creating keys for
      0:532, then moving those keys out to 456:988, then creating more keys
      for 0:455.
      
      i.e.,
      
        REMOVE_WHILE_FREEING slot 532
        REMOVE_WHILE_FREEING slot 531
        REMOVE_WHILE_FREEING slot 530
        ...
        REMOVE_WHILE_FREEING slot 0
        MOVE src slot 456 -> dst slot 0 nritems 533
        REMOVE slot 455
        REMOVE slot 454
        REMOVE slot 453
        ...
        REMOVE slot 0
        ADD slot 455
        ADD slot 454
        ADD slot 453
        ...
        ADD slot 0
        MOVE src slot 0 -> dst slot 456 nritems 533
        REMOVE slot 455
        REMOVE slot 454
        REMOVE slot 453
        ...
        REMOVE slot 0
      
      Fix this to log the move but avoid the double remove by putting all the
      logging logic in btrfs_tree_mod_log_eb_copy which has enough information
      to detect these cases and properly log moves, removes, and adds. Leave
      btrfs_tree_mod_log_insert_move to handle insert_ptr and delete_ptr's
      tree mod logging.
      
      (Un)fortunately, this is quite difficult to reproduce, and I was only
      able to reproduce it by adding sleeps in btrfs_search_old_slot that
      would encourage more log rewinding during ino_to_logical ioctls. I was
      able to hit the warning in the previous patch in the series without the
      fix quite quickly, but not after this patch.
      
      CC: stable@vger.kernel.org # 5.15+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarBoris Burkov <boris@bur.io>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      11f14402
    • Christoph Hellwig's avatar
      btrfs: fix dirty_metadata_bytes for redirtied buffers · 1ea89213
      Christoph Hellwig authored
      commit f18cc978 upstream.
      
      dirty_metadata_bytes is decremented in both places that clear the dirty
      bit in a buffer, but only incremented in btrfs_mark_buffer_dirty, which
      means that a buffer that is redirtied using btrfs_redirty_list_add won't
      be added to dirty_metadata_bytes, but it will be subtracted when written
      out, leading an inconsistency in the counter.
      
      Move the dirty_metadata_bytes from btrfs_mark_buffer_dirty into
      set_extent_buffer_dirty to also account for the redirty case, and remove
      the now unused set_extent_buffer_dirty return value.
      
      Fixes: d3575156
      
       ("btrfs: zoned: redirty released extent buffers")
      CC: stable@vger.kernel.org # 5.15+
      Reviewed-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ea89213
    • Matt Corallo's avatar
      btrfs: add handling for RAID1C23/DUP to btrfs_reduce_alloc_profile · 1b532748
      Matt Corallo authored
      commit 160fe8f6 upstream.
      
      Callers of `btrfs_reduce_alloc_profile` expect it to return exactly
      one allocation profile flag, and failing to do so may ultimately
      result in a WARN_ON and remount-ro when allocating new blocks, like
      the below transaction abort on 6.1.
      
      `btrfs_reduce_alloc_profile` has two ways of determining the profile,
      first it checks if a conversion balance is currently running and
      uses the profile we're converting to. If no balance is currently
      running, it returns the max-redundancy profile which at least one
      block in the selected block group has.
      
      This works by simply checking each known allocation profile bit in
      redundancy order. However, `btrfs_reduce_alloc_profile` has not been
      updated as new flags have been added - first with the `DUP` profile
      and later with the RAID1C34 profiles.
      
      Because of the way it checks, if we have blocks with different
      profiles and at least one is known, that profile will be selected.
      However, if none are known we may return a flag set with multiple
      allocation profiles set.
      
      This is currently only possible when a balance from one of the three
      unhandled profiles to another of the unhandled profiles is canceled
      after allocating at least one block using the new profile.
      
      In that case, a transaction abort like the below will occur and the
      filesystem will need to be mounted with -o skip_balance to get it
      mounted rw again (but the balance cannot be resumed without a
      similar abort).
      
        [770.648] ------------[ cut here ]------------
        [770.648] BTRFS: Transaction aborted (error -22)
        [770.648] WARNING: CPU: 43 PID: 1159593 at fs/btrfs/extent-tree.c:4122 find_free_extent+0x1d94/0x1e00 [btrfs]
        [770.648] CPU: 43 PID: 1159593 Comm: btrfs Tainted: G        W 6.1.0-0.deb11.7-powerpc64le #1  Debian 6.1.20-2~bpo11+1a~test
        [770.648] Hardware name: T2P9D01 REV 1.00 POWER9 0x4e1202 opal:skiboot-bc106a0 PowerNV
        [770.648] NIP:  c00800000f6784fc LR: c00800000f6784f8 CTR: c000000000d746c0
        [770.648] REGS: c000200089afe9a0 TRAP: 0700   Tainted: G        W (6.1.0-0.deb11.7-powerpc64le Debian 6.1.20-2~bpo11+1a~test)
        [770.648] MSR:  9000000002029033 <SF,HV,VEC,EE,ME,IR,DR,RI,LE>  CR: 28848282  XER: 20040000
        [770.648] CFAR: c000000000135110 IRQMASK: 0
      	    GPR00: c00800000f6784f8 c000200089afec40 c00800000f7ea800 0000000000000026
      	    GPR04: 00000001004820c2 c000200089afea00 c000200089afe9f8 0000000000000027
      	    GPR08: c000200ffbfe7f98 c000000002127f90 ffffffffffffffd8 0000000026d6a6e8
      	    GPR12: 0000000028848282 c000200fff7f3800 5deadbeef0000122 c00000002269d000
      	    GPR16: c0002008c7797c40 c000200089afef17 0000000000000000 0000000000000000
      	    GPR20: 0000000000000000 0000000000000001 c000200008bc5a98 0000000000000001
      	    GPR24: 0000000000000000 c0000003c73088d0 c000200089afef17 c000000016d3a800
      	    GPR28: c0000003c7308800 c00000002269d000 ffffffffffffffea 0000000000000001
        [770.648] NIP [c00800000f6784fc] find_free_extent+0x1d94/0x1e00 [btrfs]
        [770.648] LR [c00800000f6784f8] find_free_extent+0x1d90/0x1e00 [btrfs]
        [770.648] Call Trace:
        [770.648] [c000200089afec40] [c00800000f6784f8] find_free_extent+0x1d90/0x1e00 [btrfs] (unreliable)
        [770.648] [c000200089afed30] [c00800000f681398] btrfs_reserve_extent+0x1a0/0x2f0 [btrfs]
        [770.648] [c000200089afeea0] [c00800000f681bf0] btrfs_alloc_tree_block+0x108/0x670 [btrfs]
        [770.648] [c000200089afeff0] [c00800000f66bd68] __btrfs_cow_block+0x170/0x850 [btrfs]
        [770.648] [c000200089aff100] [c00800000f66c58c] btrfs_cow_block+0x144/0x288 [btrfs]
        [770.648] [c000200089aff1b0] [c00800000f67113c] btrfs_search_slot+0x6b4/0xcb0 [btrfs]
        [770.648] [c000200089aff2a0] [c00800000f679f60] lookup_inline_extent_backref+0x128/0x7c0 [btrfs]
        [770.648] [c000200089aff3b0] [c00800000f67b338] lookup_extent_backref+0x70/0x190 [btrfs]
        [770.648] [c000200089aff470] [c00800000f67b54c] __btrfs_free_extent+0xf4/0x1490 [btrfs]
        [770.648] [c000200089aff5a0] [c00800000f67d770] __btrfs_run_delayed_refs+0x328/0x1530 [btrfs]
        [770.648] [c000200089aff740] [c00800000f67ea2c] btrfs_run_delayed_refs+0xb4/0x3e0 [btrfs]
        [770.648] [c000200089aff800] [c00800000f699aa4] btrfs_commit_transaction+0x8c/0x12b0 [btrfs]
        [770.648] [c000200089aff8f0] [c00800000f6dc628] reset_balance_state+0x1c0/0x290 [btrfs]
        [770.648] [c000200089aff9a0] [c00800000f6e2f7c] btrfs_balance+0x1164/0x1500 [btrfs]
        [770.648] [c000200089affb40] [c00800000f6f8e4c] btrfs_ioctl+0x2b54/0x3100 [btrfs]
        [770.648] [c000200089affc80] [c00000000053be14] sys_ioctl+0x794/0x1310
        [770.648] [c000200089affd70] [c00000000002af98] system_call_exception+0x138/0x250
        [770.648] [c000200089affe10] [c00000000000c654] system_call_common+0xf4/0x258
        [770.648] --- interrupt: c00 at 0x7fff94126800
        [770.648] NIP:  00007fff94126800 LR: 0000000107e0b594 CTR: 0000000000000000
        [770.648] REGS: c000200089affe80 TRAP: 0c00   Tainted: G        W (6.1.0-0.deb11.7-powerpc64le Debian 6.1.20-2~bpo11+1a~test)
        [770.648] MSR:  900000000000d033 <SF,HV,EE,PR,ME,IR,DR,RI,LE>  CR: 24002848  XER: 00000000
        [770.648] IRQMASK: 0
      	    GPR00: 0000000000000036 00007fffc9439da0 00007fff94217100 0000000000000003
      	    GPR04: 00000000c4009420 00007fffc9439ee8 0000000000000000 0000000000000000
      	    GPR08: 00000000803c7416 0000000000000000 0000000000000000 0000000000000000
      	    GPR12: 0000000000000000 00007fff9467d120 0000000107e64c9c 0000000107e64d0a
      	    GPR16: 0000000107e64d06 0000000107e64cf1 0000000107e64cc4 0000000107e64c73
      	    GPR20: 0000000107e64c31 0000000107e64bf1 0000000107e64be7 0000000000000000
      	    GPR24: 0000000000000000 00007fffc9439ee0 0000000000000003 0000000000000001
      	    GPR28: 00007fffc943f713 0000000000000000 00007fffc9439ee8 0000000000000000
        [770.648] NIP [00007fff94126800] 0x7fff94126800
        [770.648] LR [0000000107e0b594] 0x107e0b594
        [770.648] --- interrupt: c00
        [770.648] Instruction dump:
        [770.648] 3b00ffe4 e8898828 481175f5 60000000 4bfff4fc 3be00000 4bfff570 3d220000
        [770.648] 7fc4f378 e8698830 4811cd95 e8410018 <0fe00000> f9c10060 f9e10068 fa010070
        [770.648] ---[ end trace 0000000000000000 ]---
        [770.648] BTRFS: error (device dm-2: state A) in find_free_extent_update_loop:4122: errno=-22 unknown
        [770.648] BTRFS info (device dm-2: state EA): forced readonly
        [770.648] BTRFS: error (device dm-2: state EA) in __btrfs_free_extent:3070: errno=-22 unknown
        [770.648] BTRFS error (device dm-2: state EA): failed to run delayed ref for logical 17838685708288 num_bytes 24576 type 184 action 2 ref_mod 1: -22
        [770.648] BTRFS: error (device dm-2: state EA) in btrfs_run_delayed_refs:2144: errno=-22 unknown
        [770.648] BTRFS: error (device dm-2: state EA) in reset_balance_state:3599: errno=-22 unknown
      
      Fixes: 47e6f742 ("btrfs: add support for 3-copy replication (raid1c3)")
      Fixes: 8d6fac00
      
       ("btrfs: add support for 4-copy replication (raid1c4)")
      CC: stable@vger.kernel.org # 5.10+
      Signed-off-by: default avatarMatt Corallo <blnxfsl@bluematt.me>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1b532748
    • Abhijeet Rastogi's avatar
      ipvs: increase ip_vs_conn_tab_bits range for 64BIT · b9a6e005
      Abhijeet Rastogi authored
      commit 04292c69
      
       upstream.
      
      Current range [8, 20] is set purely due to historical reasons
      because at the time, ~1M (2^20) was considered sufficient.
      With this change, 27 is the upper limit for 64-bit, 20 otherwise.
      
      Previous change regarding this limit is here.
      
      Link: https://lore.kernel.org/all/86eabeb9dd62aebf1e2533926fdd13fed48bab1f.1631289960.git.aclaudi@redhat.com/T/#u
      
      Signed-off-by: default avatarAbhijeet Rastogi <abhijeet.1989@gmail.com>
      Acked-by: default avatarJulian Anastasov <ja@ssi.bg>
      Acked-by: default avatarSimon Horman <horms@kernel.org>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Cc: Allen Pais <apais@linux.microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b9a6e005
    • Mario Limonciello's avatar
      usb: typec: ucsi: Mark dGPUs as DEVICE scope · 7e3b21eb
      Mario Limonciello authored
      commit a7fbfd44 upstream.
      
      power_supply_is_system_supplied() checks whether any power
      supplies are present that aren't batteries to decide whether
      the system is running on DC or AC.  Downstream drivers use
      this to make performance decisions.
      
      Navi dGPUs include an UCSI function that has been exported
      since commit 17631e8c ("i2c: designware: Add driver
      support for AMD NAVI GPU").
      
      This UCSI function registers a power supply since commit
      992a60ed
      
       ("usb: typec: ucsi: register with power_supply class")
      but this is not a system power supply.
      
      As the power supply for a dGPU is only for powering devices connected
      to dGPU, create a device property to indicate that the UCSI endpoint
      is only for the scope of `POWER_SUPPLY_SCOPE_DEVICE`.
      
      Link: https://lore.kernel.org/lkml/20230516182541.5836-2-mario.limonciello@amd.com/
      Reviewed-by: default avatarEvan Quan <evan.quan@amd.com>
      Tested-by: default avatarEvan Quan <evan.quan@amd.com>
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Reviewed-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
      Acked-by: default avatarAndi Shyti <andi.shyti@kernel.org>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7e3b21eb
    • Jan Kara's avatar
      fs: Lock moved directories · 059484d3
      Jan Kara authored
      commit 28eceeda
      
       upstream.
      
      When a directory is moved to a different directory, some filesystems
      (udf, ext4, ocfs2, f2fs, and likely gfs2, reiserfs, and others) need to
      update their pointer to the parent and this must not race with other
      operations on the directory. Lock the directories when they are moved.
      Although not all filesystems need this locking, we perform it in
      vfs_rename() because getting the lock ordering right is really difficult
      and we don't want to expose these locking details to filesystems.
      
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Message-Id: <20230601105830.13168-5-jack@suse.cz>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      059484d3
    • Jan Kara's avatar
      fs: Establish locking order for unrelated directories · 4cbd5eb1
      Jan Kara authored
      commit f23ce757
      
       upstream.
      
      Currently the locking order of inode locks for directories that are not
      in ancestor relationship is not defined because all operations that
      needed to lock two directories like this were serialized by
      sb->s_vfs_rename_mutex. However some filesystems need to lock two
      subdirectories for RENAME_EXCHANGE operations and for this we need the
      locking order established even for two tree-unrelated directories.
      Provide a helper function lock_two_inodes() that establishes lock
      ordering for any two inodes and use it in lock_two_directories().
      
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Message-Id: <20230601105830.13168-4-jack@suse.cz>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4cbd5eb1
    • Jan Kara's avatar
      Revert "udf: Protect rename against modification of moved directory" · f55aaecb
      Jan Kara authored
      commit 7517ce5d upstream.
      
      This reverts commit f950fd05
      
      . The
      locking is going to be provided by vfs_rename() in the following
      patches.
      
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Message-Id: <20230601105830.13168-2-jack@suse.cz>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f55aaecb
    • Jan Kara's avatar
      Revert "f2fs: fix potential corruption when moving a directory" · 0b6f613e
      Jan Kara authored
      commit cde3c9d7 upstream.
      
      This reverts commit d9477215
      
      . The
      locking is going to be provided by VFS.
      
      CC: Jaegeuk Kim <jaegeuk@kernel.org>
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Message-Id: <20230601105830.13168-3-jack@suse.cz>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0b6f613e
    • Jan Kara's avatar
      ext4: Remove ext4 locking of moved directory · cf9b6fe9
      Jan Kara authored
      commit 3658840c upstream.
      
      Remove locking of moved directory in ext4_rename2(). We will take care
      of it in VFS instead. This effectively reverts commit 0813299c
      
      
      ("ext4: Fix possible corruption when moving a directory") and followup
      fixes.
      
      CC: Ted Tso <tytso@mit.edu>
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Message-Id: <20230601105830.13168-1-jack@suse.cz>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cf9b6fe9
    • Thomas Weißschuh's avatar
      fs: avoid empty option when generating legacy mount string · f80436e4
      Thomas Weißschuh authored
      commit 62176420
      
       upstream.
      
      As each option string fragment is always prepended with a comma it would
      happen that the whole string always starts with a comma. This could be
      interpreted by filesystem drivers as an empty option and may produce
      errors.
      
      For example the NTFS driver from ntfs.ko behaves like this and fails
      when mounted via the new API.
      
      Link: https://github.com/util-linux/util-linux/issues/2298
      Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
      Fixes: 3e1aeb00
      
       ("vfs: Implement a filesystem superblock creation/configuration context")
      Cc: stable@vger.kernel.org
      Message-Id: <20230607-fs-empty-option-v1-1-20c8dbf4671b@weissschuh.net>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f80436e4
    • Fabian Frederick's avatar
      jffs2: reduce stack usage in jffs2_build_xattr_subsystem() · fb306470
      Fabian Frederick authored
      commit 1168f095 upstream.
      
      Use kcalloc() for allocation/flush of 128 pointers table to
      reduce stack usage.
      
      Function now returns -ENOMEM or 0 on success.
      
      stackusage
      Before:
      ./fs/jffs2/xattr.c:775  jffs2_build_xattr_subsystem     1208
      dynamic,bounded
      
      After:
      ./fs/jffs2/xattr.c:775  jffs2_build_xattr_subsystem     192
      dynamic,bounded
      
      Also update definition when CONFIG_JFFS2_FS_XATTR is not enabled
      
      Tested with an MTD mount point and some user set/getfattr.
      
      Many current target on OpenWRT also suffer from a compilation warning
      (that become an error with CONFIG_WERROR) with the following output:
      
      fs/jffs2/xattr.c: In function 'jffs2_build_xattr_subsystem':
      fs/jffs2/xattr.c:887:1: error: the frame size of 1088 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
        887 | }
            | ^
      
      Using dynamic allocation fix this compilation warning.
      
      Fixes: c9f700f8
      
       ("[JFFS2][XATTR] using 'delete marker' for xdatum/xref deletion")
      Reported-by: default avatarTim Gardner <tim.gardner@canonical.com>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Reported-by: default avatarRon Economos <re@w6rz.net>
      Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarFabian Frederick <fabf@skynet.be>
      Signed-off-by: default avatarChristian Marangi <ansuelsmth@gmail.com>
      Cc: stable@vger.kernel.org
      Message-Id: <20230506045612.16616-1-ansuelsmth@gmail.com>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fb306470
    • Christian Brauner's avatar
      nfsd: use vfs setgid helper · 7fd2ca4a
      Christian Brauner authored
      commit 2d8ae8c4 upstream.
      
      We've aligned setgid behavior over multiple kernel releases. The details
      can be found in commit cf619f89 ("Merge tag 'fs.ovl.setgid.v6.2' of
      git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and
      commit 426b4ca2
      
       ("Merge tag 'fs.setgid.v6.0' of
      git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
      Consistent setgid stripping behavior is now encapsulated in the
      setattr_should_drop_sgid() helper which is used by all filesystems that
      strip setgid bits outside of vfs proper. Usually ATTR_KILL_SGID is
      raised in e.g., chown_common() and is subject to the
      setattr_should_drop_sgid() check to determine whether the setgid bit can
      be retained. Since nfsd is raising ATTR_KILL_SGID unconditionally it
      will cause notify_change() to strip it even if the caller had the
      necessary privileges to retain it. Ensure that nfsd only raises
      ATR_KILL_SGID if the caller lacks the necessary privileges to retain the
      setgid bit.
      
      Without this patch the setgid stripping tests in LTP will fail:
      
      > As you can see, the problem is S_ISGID (0002000) was dropped on a
      > non-group-executable file while chown was invoked by super-user, while
      
      [...]
      
      > fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
      
      [...]
      
      > chown02.c:57: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
      
      With this patch all tests pass.
      
      Reported-by: default avatarSherry Yang <sherry.yang@oracle.com>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7fd2ca4a
    • Roberto Sassu's avatar
      shmem: use ramfs_kill_sb() for kill_sb method of ramfs-based tmpfs · ebe07db8
      Roberto Sassu authored
      commit 36ce9d76 upstream.
      
      As the ramfs-based tmpfs uses ramfs_init_fs_context() for the
      init_fs_context method, which allocates fc->s_fs_info, use ramfs_kill_sb()
      to free it and avoid a memory leak.
      
      Link: https://lkml.kernel.org/r/20230607161523.2876433-1-roberto.sassu@huaweicloud.com
      Fixes: c3b1b1cb
      
       ("ramfs: add support for "mode=" mount option")
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ebe07db8
    • Ryan Roberts's avatar
      mm/damon/ops-common: atomically test and clear young on ptes and pmds · 35cbaf35
      Ryan Roberts authored
      commit c11d34fa upstream.
      
      It is racy to non-atomically read a pte, then clear the young bit, then
      write it back as this could discard dirty information.  Further, it is bad
      practice to directly set a pte entry within a table.  Instead clearing
      young must go through the arch-provided helper,
      ptep_test_and_clear_young() to ensure it is modified atomically and to
      give the arch code visibility and allow it to check (and potentially
      modify) the operation.
      
      Link: https://lkml.kernel.org/r/20230602092949.545577-3-ryan.roberts@arm.com
      Fixes: 3f49584b
      
       ("mm/damon: implement primitives for the virtual memory address spaces").
      Signed-off-by: default avatarRyan Roberts <ryan.roberts@arm.com>
      Reviewed-by: default avatarZi Yan <ziy@nvidia.com>
      Reviewed-by: default avatarSeongJae Park <sj@kernel.org>
      Reviewed-by: default avatarMike Rapoport (IBM) <rppt@kernel.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Cc: Lorenzo Stoakes <lstoakes@gmail.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
      Cc: Yu Zhao <yuzhao@google.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      35cbaf35
    • Arnd Bergmann's avatar
      autofs: use flexible array in ioctl structure · 3fd41a97
      Arnd Bergmann authored
      commit e910c8e3 upstream.
      
      Commit df8fc4e9
      
       ("kbuild: Enable -fstrict-flex-arrays=3") introduced a warning
      for the autofs_dev_ioctl structure:
      
      In function 'check_name',
          inlined from 'validate_dev_ioctl' at fs/autofs/dev-ioctl.c:131:9,
          inlined from '_autofs_dev_ioctl' at fs/autofs/dev-ioctl.c:624:8:
      fs/autofs/dev-ioctl.c:33:14: error: 'strchr' reading 1 or more bytes from a region of size 0 [-Werror=stringop-overread]
         33 |         if (!strchr(name, '/'))
            |              ^~~~~~~~~~~~~~~~~
      In file included from include/linux/auto_dev-ioctl.h:10,
                       from fs/autofs/autofs_i.h:10,
                       from fs/autofs/dev-ioctl.c:14:
      include/uapi/linux/auto_dev-ioctl.h: In function '_autofs_dev_ioctl':
      include/uapi/linux/auto_dev-ioctl.h:112:14: note: source object 'path' of size 0
        112 |         char path[0];
            |              ^~~~
      
      This is easily fixed by changing the gnu 0-length array into a c99
      flexible array. Since this is a uapi structure, we have to be careful
      about possible regressions but this one should be fine as they are
      equivalent here. While it would break building with ancient gcc versions
      that predate c99, it helps building with --std=c99 and -Wpedantic builds
      in user space, as well as non-gnu compilers. This means we probably
      also want it fixed in stable kernels.
      
      Cc: stable@vger.kernel.org
      Cc: Kees Cook <keescook@chromium.org>
      Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20230523081944.581710-1-arnd@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3fd41a97
    • Tianjia Zhang's avatar
      integrity: Fix possible multiple allocation in integrity_inode_get() · fd768cc2
      Tianjia Zhang authored
      commit 9df6a487 upstream.
      
      When integrity_inode_get() is querying and inserting the cache, there
      is a conditional race in the concurrent environment.
      
      The race condition is the result of not properly implementing
      "double-checked locking". In this case, it first checks to see if the
      iint cache record exists before taking the lock, but doesn't check
      again after taking the integrity_iint_lock.
      
      Fixes: bf2276d1
      
       ("ima: allocating iint improvements")
      Signed-off-by: default avatarTianjia Zhang <tianjia.zhang@linux.alibaba.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: <stable@vger.kernel.org> # v3.10+
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fd768cc2
    • Kees Cook's avatar
      um: Use HOST_DIR for mrproper · d363ac7b
      Kees Cook authored
      commit a5a319ec upstream.
      
      When HEADER_ARCH was introduced, the MRPROPER_FILES (then MRPROPER_DIRS)
      list wasn't adjusted, leaving SUBARCH as part of the path argument.
      This resulted in the "mrproper" target not cleaning up arch/x86/... when
      SUBARCH was specified. Since HOST_DIR is arch/$(HEADER_ARCH), use it
      instead to get the correct path.
      
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
      Cc: Johannes Berg <johannes@sipsolutions.net>
      Cc: Azeem Shaikh <azeemshaikh38@gmail.com>
      Cc: linux-um@lists.infradead.org
      Fixes: 7bbe7204
      
       ("um: merge Makefile-{i386,x86_64}")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20230606222442.never.807-kees@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d363ac7b
    • Siddh Raman Pant's avatar
      watch_queue: prevent dangling pipe pointer · bec85c4d
      Siddh Raman Pant authored
      commit 943211c8
      
       upstream.
      
      NULL the dangling pipe reference while clearing watch_queue.
      
      If not done, a reference to a freed pipe remains in the watch_queue,
      as this function is called before freeing a pipe in free_pipe_info()
      (see line 834 of fs/pipe.c).
      
      The sole use of wqueue->defunct is for checking if the watch queue has
      been cleared, but wqueue->pipe is also NULLed while clearing.
      
      Thus, wqueue->defunct is superfluous, as wqueue->pipe can be checked
      for NULL. Hence, the former can be removed.
      
      Tested with keyutils testsuite.
      
      Cc: stable@vger.kernel.org # 6.1
      Signed-off-by: default avatarSiddh Raman Pant <code@siddh.me>
      Acked-by: default avatarDavid Howells <dhowells@redhat.com>
      Message-Id: <20230605143616.640517-1-code@siddh.me>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bec85c4d
    • Zheng Wang's avatar
      bcache: Fix __bch_btree_node_alloc to make the failure behavior consistent · 4514847a
      Zheng Wang authored
      commit 80fca8a1 upstream.
      
      In some specific situations, the return value of __bch_btree_node_alloc
      may be NULL. This may lead to a potential NULL pointer dereference in
      caller function like a calling chain :
      btree_split->bch_btree_node_alloc->__bch_btree_node_alloc.
      
      Fix it by initializing the return value in __bch_btree_node_alloc.
      
      Fixes: cafe5635
      
       ("bcache: A block layer cache")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarZheng Wang <zyytlz.wz@163.com>
      Signed-off-by: default avatarColy Li <colyli@suse.de>
      Link: https://lore.kernel.org/r/20230615121223.22502-6-colyli@suse.de
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4514847a
    • Zheng Wang's avatar
      bcache: Remove unnecessary NULL point check in node allocations · 0cabf9e1
      Zheng Wang authored
      commit 028ddcac upstream.
      
      Due to the previous fix of __bch_btree_node_alloc, the return value will
      never be a NULL pointer. So IS_ERR is enough to handle the failure
      situation. Fix it by replacing IS_ERR_OR_NULL check by an IS_ERR check.
      
      Fixes: cafe5635
      
       ("bcache: A block layer cache")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarZheng Wang <zyytlz.wz@163.com>
      Signed-off-by: default avatarColy Li <colyli@suse.de>
      Link: https://lore.kernel.org/r/20230615121223.22502-5-colyli@suse.de
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0cabf9e1
    • Mingzhe Zou's avatar
      bcache: fixup btree_cache_wait list damage · 2882a4c4
      Mingzhe Zou authored
      commit f0854489 upstream.
      
      We get a kernel crash about "list_add corruption. next->prev should be
      prev (ffff9c801bc01210), but was ffff9c77b688237c.
      (next=ffffae586d8afe68)."
      
      crash> struct list_head 0xffff9c801bc01210
      struct list_head {
        next = 0xffffae586d8afe68,
        prev = 0xffffae586d8afe68
      }
      crash> struct list_head 0xffff9c77b688237c
      struct list_head {
        next = 0x0,
        prev = 0x0
      }
      crash> struct list_head 0xffffae586d8afe68
      struct list_head struct: invalid kernel virtual address: ffffae586d8afe68  type: "gdb_readmem_callback"
      Cannot access memory at address 0xffffae586d8afe68
      
      [230469.019492] Call Trace:
      [230469.032041]  prepare_to_wait+0x8a/0xb0
      [230469.044363]  ? bch_btree_keys_free+0x6c/0xc0 [escache]
      [230469.056533]  mca_cannibalize_lock+0x72/0x90 [escache]
      [230469.068788]  mca_alloc+0x2ae/0x450 [escache]
      [230469.080790]  bch_btree_node_get+0x136/0x2d0 [escache]
      [230469.092681]  bch_btree_check_thread+0x1e1/0x260 [escache]
      [230469.104382]  ? finish_wait+0x80/0x80
      [230469.115884]  ? bch_btree_check_recurse+0x1a0/0x1a0 [escache]
      [230469.127259]  kthread+0x112/0x130
      [230469.138448]  ? kthread_flush_work_fn+0x10/0x10
      [230469.149477]  ret_from_fork+0x35/0x40
      
      bch_btree_check_thread() and bch_dirty_init_thread() may call
      mca_cannibalize() to cannibalize other cached btree nodes. Only one thread
      can do it at a time, so the op of other threads will be added to the
      btree_cache_wait list.
      
      We must call finish_wait() to remove op from btree_cache_wait before free
      it's memory address. Otherwise, the list will be damaged. Also should call
      bch_cannibalize_unlock() to release the btree_cache_alloc_lock and wake_up
      other waiters.
      
      Fixes: 8e710227 ("bcache: make bch_btree_check() to be multithreaded")
      Fixes: b144e45f
      
       ("bcache: make bch_sectors_dirty_init() to be multithreaded")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMingzhe Zou <mingzhe.zou@easystack.cn>
      Signed-off-by: default avatarColy Li <colyli@suse.de>
      Link: https://lore.kernel.org/r/20230615121223.22502-7-colyli@suse.de
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2882a4c4
    • Quan Zhou's avatar
      wifi: mt76: mt7921e: fix init command fail with enabled device · 53e89d83
      Quan Zhou authored
      commit 525c469e upstream.
      
      For some cases as below, we may encounter the unpreditable chip stats
      in driver probe()
      * The system reboot flow do not work properly, such as kernel oops while
        rebooting, and then the driver do not go back to default status at
        this moment.
      * Similar to the flow above. If the device was enabled in BIOS or UEFI,
        the system may switch to Linux without driver fully shutdown.
      
      To avoid the problem, force push the device back to default in probe()
      * mt7921e_mcu_fw_pmctrl() : return control privilege to chip side.
      * mt7921_wfsys_reset()    : cleanup chip config before resource init.
      
      Error log
      [59007.600714] mt7921e 0000:02:00.0: ASIC revision: 79220010
      [59010.889773] mt7921e 0000:02:00.0: Message 00000010 (seq 1) timeout
      [59010.889786] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59014.217839] mt7921e 0000:02:00.0: Message 00000010 (seq 2) timeout
      [59014.217852] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59017.545880] mt7921e 0000:02:00.0: Message 00000010 (seq 3) timeout
      [59017.545893] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59020.874086] mt7921e 0000:02:00.0: Message 00000010 (seq 4) timeout
      [59020.874099] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59024.202019] mt7921e 0000:02:00.0: Message 00000010 (seq 5) timeout
      [59024.202033] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59027.530082] mt7921e 0000:02:00.0: Message 00000010 (seq 6) timeout
      [59027.530096] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59030.857888] mt7921e 0000:02:00.0: Message 00000010 (seq 7) timeout
      [59030.857904] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59034.185946] mt7921e 0000:02:00.0: Message 00000010 (seq 8) timeout
      [59034.185961] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59037.514249] mt7921e 0000:02:00.0: Message 00000010 (seq 9) timeout
      [59037.514262] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59040.842362] mt7921e 0000:02:00.0: Message 00000010 (seq 10) timeout
      [59040.842375] mt7921e 0000:02:00.0: Failed to get patch semaphore
      [59040.923845] mt7921e 0000:02:00.0: hardware init failed
      
      Cc: stable@vger.kernel.org
      Fixes: 5c14a5f9
      
       ("mt76: mt7921: introduce mt7921e support")
      Tested-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
      Tested-by: default avatarJuan Martinez <juan.martinez@amd.com>
      Co-developed-by: default avatarLeon Yen <leon.yen@mediatek.com>
      Signed-off-by: default avatarLeon Yen <leon.yen@mediatek.com>
      Signed-off-by: default avatarQuan Zhou <quan.zhou@mediatek.com>
      Signed-off-by: default avatarDeren Wu <deren.wu@mediatek.com>
      Message-ID: <39fcb7cee08d4ab940d38d82f21897483212483f.1688569385.git.deren.wu@mediatek.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      53e89d83
    • Felix Fietkau's avatar
      wifi: cfg80211: fix receiving mesh packets without RFC1042 header · 54c1b922
      Felix Fietkau authored
      commit fec3ebb5 upstream.
      
      Fix ethernet header length field after stripping the mesh header
      
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/all/CT5GNZSK28AI.2K6M69OXM9RW5@syracuse/
      Fixes: 986e43b1
      
       ("wifi: mac80211: fix receiving A-MSDU frames on mesh interfaces")
      Reported-and-tested-by: default avatarNicolas Escande <nico.escande@gmail.com>
      Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
      Link: https://lore.kernel.org/r/20230711115052.68430-1-nbd@nbd.name
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      54c1b922
    • Alexander Wetzel's avatar
      wifi: ath10k: Serialize wake_tx_queue ops · 1a9f0e23
      Alexander Wetzel authored
      commit b719ebc3 upstream.
      
      Serialize the ath10k implementation of the wake_tx_queue ops.
      ath10k_mac_op_wake_tx_queue() must not run concurrent since it's using
      ieee80211_txq_schedule_start().
      
      The intend of this patch is to sort out an issue discovered in the discussion
      referred to by the Link tag.
      
      I can't test it with real hardware and thus just implemented the per-ac queue
      lock Felix suggested. One obvious alternative to the per-ac lock would be to
      bring back the txqs_lock commit bb2edb73 ("ath10k: migrate to mac80211 txq
      scheduling") dropped.
      
      Fixes: bb2edb73
      
       ("ath10k: migrate to mac80211 txq scheduling")
      Reported-by: default avatarFelix Fietkau <nbd@nbd.name>
      Link: https://lore.kernel.org/r/519b5bb9-8899-ae7c-4eff-f3116cdfdb56@nbd.name
      CC: <stable@vger.kernel.org>
      Signed-off-by: default avatarAlexander Wetzel <alexander@wetzel-home.de>
      Signed-off-by: default avatarKalle Valo <quic_kvalo@quicinc.com>
      Link: https://lore.kernel.org/r/20230323165527.156414-1-alexander@wetzel-home.de
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1a9f0e23
    • Johannes Berg's avatar
      wifi: cfg80211: fix regulatory disconnect for non-MLO · 12627f20
      Johannes Berg authored
      commit b22552fc upstream.
      
      The multi-link loop here broke disconnect when multi-link
      operation (MLO) isn't active for a given interface, since
      in that case valid_links is 0 (indicating no links, i.e.
      no MLO.)
      
      Fix this by taking that into account properly and skipping
      the link only if there are valid_links in the first place.
      
      Cc: stable@vger.kernel.org
      Fixes: 7b0a0e3c
      
       ("wifi: cfg80211: do some rework towards MLO link APIs")
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Link: https://lore.kernel.org/r/20230616222844.eb073d650c75.I72739923ef80919889ea9b50de9e4ba4baa836ae@changeid
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12627f20
    • Chevron Li's avatar
      mmc: sdhci: fix DMA configure compatibility issue when 64bit DMA mode is used. · cfc67827
      Chevron Li authored
      commit 20dbd07e
      
       upstream.
      
      Bayhub SD host has hardware limitation:
      1.The upper 32bit address is inhibited to be written at SD Host Register
        [03E][13]=0 (32bits addressing) mode, is admitted to be written only at
        SD Host Register [03E][13]=1 (64bits addressing) mode.
      2.Because of above item#1, need to configure SD Host Register [03E][13] to
        1(64bits addressing mode) before set 64bit ADMA system address's higher
        32bits SD Host Register [05F~05C] if 64 bits addressing mode is used.
      
      The hardware limitation is reasonable for below reasons:
      1.Normal flow should set DMA working mode first, then do
        DMA-transfer-related configuration, such as system address.
      2.The hardware limitation may avoid the software to configure wrong higher
        32bit address at 32bits addressing mode although it is redundant.
      
      The change that set 32bits/64bits addressing mode before set ADMA address,
        has no side-effect to other host IPs for below reason:
      The setting order is reasonable and standard: DMA Mode setting first and
        then DMA address setting. It meets all DMA setting sequence.
      
      Signed-off-by: default avatarChevron Li <chevron.li@bayhubtech.com>
      Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230523111114.18124-1-chevron_li@126.com
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cfc67827
    • Ulf Hansson's avatar
      mmc: mmci: Set PROBE_PREFER_ASYNCHRONOUS · 0d8292bb
      Ulf Hansson authored
      commit 3108eb2e upstream.
      
      All mmc host drivers should have the asynchronous probe option enabled, but
      it seems like we failed to set it for mmci, so let's do that now.
      
      Fixes: 21b2cec6
      
       ("mmc: Set PROBE_PREFER_ASYNCHRONOUS for drivers that existed in v4.4")
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Tested-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Tested-by: default avatarYann Gautier <yann.gautier@foss.st.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230612143730.210390-1-ulf.hansson@linaro.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0d8292bb