From: Greg Kroah-Hartman Date: Sun, 23 Jan 2022 17:18:45 +0000 (+0100) Subject: 5.10-stable patches X-Git-Tag: v4.4.300~106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fa18ffca1a5ded42574e8fbc623dd23f2a26890;p=thirdparty%2Fkernel%2Fstable-queue.git 5.10-stable patches added patches: btrfs-check-the-root-node-for-uptodate-before-returning-it.patch btrfs-fix-deadlock-between-quota-enable-and-other-quota-operations.patch btrfs-respect-the-max-size-in-the-header-when-activating-swap-file.patch ext4-fix-a-possible-abba-deadlock-due-to-busy-pa.patch ext4-fix-fast-commit-may-miss-tracking-range-for-falloc_fl_zero_range.patch ext4-initialize-err_blk-before-calling-__ext4_get_inode_loc.patch ext4-make-sure-quota-gets-properly-shutdown-on-error.patch ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch --- diff --git a/queue-5.10/btrfs-check-the-root-node-for-uptodate-before-returning-it.patch b/queue-5.10/btrfs-check-the-root-node-for-uptodate-before-returning-it.patch new file mode 100644 index 00000000000..f50ed1c06c1 --- /dev/null +++ b/queue-5.10/btrfs-check-the-root-node-for-uptodate-before-returning-it.patch @@ -0,0 +1,68 @@ +From 120de408e4b97504a2d9b5ca534b383de2c73d49 Mon Sep 17 00:00:00 2001 +From: Josef Bacik +Date: Wed, 24 Nov 2021 14:14:24 -0500 +Subject: btrfs: check the root node for uptodate before returning it + +From: Josef Bacik + +commit 120de408e4b97504a2d9b5ca534b383de2c73d49 upstream. + +Now that we clear the extent buffer uptodate if we fail to write it out +we need to check to see if our root node is uptodate before we search +down it. Otherwise we could return stale data (or potentially corrupt +data that was caught by the write verification step) and think that the +path is OK to search down. + +CC: stable@vger.kernel.org # 5.4+ +Reviewed-by: Nikolay Borisov +Signed-off-by: Josef Bacik +Signed-off-by: David Sterba +Signed-off-by: Greg Kroah-Hartman +--- + fs/btrfs/ctree.c | 19 +++++++++++++++---- + 1 file changed, 15 insertions(+), 4 deletions(-) + +--- a/fs/btrfs/ctree.c ++++ b/fs/btrfs/ctree.c +@@ -2589,12 +2589,9 @@ static struct extent_buffer *btrfs_searc + { + struct btrfs_fs_info *fs_info = root->fs_info; + struct extent_buffer *b; +- int root_lock; ++ int root_lock = 0; + int level = 0; + +- /* We try very hard to do read locks on the root */ +- root_lock = BTRFS_READ_LOCK; +- + if (p->search_commit_root) { + /* + * The commit roots are read only so we always do read locks, +@@ -2632,6 +2629,9 @@ static struct extent_buffer *btrfs_searc + goto out; + } + ++ /* We try very hard to do read locks on the root */ ++ root_lock = BTRFS_READ_LOCK; ++ + /* + * If the level is set to maximum, we can skip trying to get the read + * lock. +@@ -2658,6 +2658,17 @@ static struct extent_buffer *btrfs_searc + level = btrfs_header_level(b); + + out: ++ /* ++ * The root may have failed to write out at some point, and thus is no ++ * longer valid, return an error in this case. ++ */ ++ if (!extent_buffer_uptodate(b)) { ++ if (root_lock) ++ btrfs_tree_unlock_rw(b, root_lock); ++ free_extent_buffer(b); ++ return ERR_PTR(-EIO); ++ } ++ + p->nodes[level] = b; + if (!p->skip_locking) + p->locks[level] = root_lock; diff --git a/queue-5.10/btrfs-fix-deadlock-between-quota-enable-and-other-quota-operations.patch b/queue-5.10/btrfs-fix-deadlock-between-quota-enable-and-other-quota-operations.patch new file mode 100644 index 00000000000..711d7c1541e --- /dev/null +++ b/queue-5.10/btrfs-fix-deadlock-between-quota-enable-and-other-quota-operations.patch @@ -0,0 +1,128 @@ +From 232796df8c1437c41d308d161007f0715bac0a54 Mon Sep 17 00:00:00 2001 +From: Filipe Manana +Date: Wed, 27 Oct 2021 18:30:25 +0100 +Subject: btrfs: fix deadlock between quota enable and other quota operations + +From: Filipe Manana + +commit 232796df8c1437c41d308d161007f0715bac0a54 upstream. + +When enabling quotas, we attempt to commit a transaction while holding the +mutex fs_info->qgroup_ioctl_lock. This can result on a deadlock with other +quota operations such as: + +- qgroup creation and deletion, ioctl BTRFS_IOC_QGROUP_CREATE; + +- adding and removing qgroup relations, ioctl BTRFS_IOC_QGROUP_ASSIGN. + +This is because these operations join a transaction and after that they +attempt to lock the mutex fs_info->qgroup_ioctl_lock. Acquiring that mutex +after joining or starting a transaction is a pattern followed everywhere +in qgroups, so the quota enablement operation is the one at fault here, +and should not commit a transaction while holding that mutex. + +Fix this by making the transaction commit while not holding the mutex. +We are safe from two concurrent tasks trying to enable quotas because +we are serialized by the rw semaphore fs_info->subvol_sem at +btrfs_ioctl_quota_ctl(), which is the only call site for enabling +quotas. + +When this deadlock happens, it produces a trace like the following: + + INFO: task syz-executor:25604 blocked for more than 143 seconds. + Not tainted 5.15.0-rc6 #4 + "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. + task:syz-executor state:D stack:24800 pid:25604 ppid: 24873 flags:0x00004004 + Call Trace: + context_switch kernel/sched/core.c:4940 [inline] + __schedule+0xcd9/0x2530 kernel/sched/core.c:6287 + schedule+0xd3/0x270 kernel/sched/core.c:6366 + btrfs_commit_transaction+0x994/0x2e90 fs/btrfs/transaction.c:2201 + btrfs_quota_enable+0x95c/0x1790 fs/btrfs/qgroup.c:1120 + btrfs_ioctl_quota_ctl fs/btrfs/ioctl.c:4229 [inline] + btrfs_ioctl+0x637e/0x7b70 fs/btrfs/ioctl.c:5010 + vfs_ioctl fs/ioctl.c:51 [inline] + __do_sys_ioctl fs/ioctl.c:874 [inline] + __se_sys_ioctl fs/ioctl.c:860 [inline] + __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860 + do_syscall_x64 arch/x86/entry/common.c:50 [inline] + do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 + entry_SYSCALL_64_after_hwframe+0x44/0xae + RIP: 0033:0x7f86920b2c4d + RSP: 002b:00007f868f61ac58 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 + RAX: ffffffffffffffda RBX: 00007f86921d90a0 RCX: 00007f86920b2c4d + RDX: 0000000020005e40 RSI: 00000000c0109428 RDI: 0000000000000008 + RBP: 00007f869212bd80 R08: 0000000000000000 R09: 0000000000000000 + R10: 0000000000000000 R11: 0000000000000246 R12: 00007f86921d90a0 + R13: 00007fff6d233e4f R14: 00007fff6d233ff0 R15: 00007f868f61adc0 + INFO: task syz-executor:25628 blocked for more than 143 seconds. + Not tainted 5.15.0-rc6 #4 + "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. + task:syz-executor state:D stack:29080 pid:25628 ppid: 24873 flags:0x00004004 + Call Trace: + context_switch kernel/sched/core.c:4940 [inline] + __schedule+0xcd9/0x2530 kernel/sched/core.c:6287 + schedule+0xd3/0x270 kernel/sched/core.c:6366 + schedule_preempt_disabled+0xf/0x20 kernel/sched/core.c:6425 + __mutex_lock_common kernel/locking/mutex.c:669 [inline] + __mutex_lock+0xc96/0x1680 kernel/locking/mutex.c:729 + btrfs_remove_qgroup+0xb7/0x7d0 fs/btrfs/qgroup.c:1548 + btrfs_ioctl_qgroup_create fs/btrfs/ioctl.c:4333 [inline] + btrfs_ioctl+0x683c/0x7b70 fs/btrfs/ioctl.c:5014 + vfs_ioctl fs/ioctl.c:51 [inline] + __do_sys_ioctl fs/ioctl.c:874 [inline] + __se_sys_ioctl fs/ioctl.c:860 [inline] + __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860 + do_syscall_x64 arch/x86/entry/common.c:50 [inline] + do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 + entry_SYSCALL_64_after_hwframe+0x44/0xae + +Reported-by: Hao Sun +Link: https://lore.kernel.org/linux-btrfs/CACkBjsZQF19bQ1C6=yetF3BvL10OSORpFUcWXTP6HErshDB4dQ@mail.gmail.com/ +Fixes: 340f1aa27f36 ("btrfs: qgroups: Move transaction management inside btrfs_quota_enable/disable") +CC: stable@vger.kernel.org # 4.19 +Reviewed-by: Qu Wenruo +Signed-off-by: Filipe Manana +Signed-off-by: David Sterba +Signed-off-by: Greg Kroah-Hartman +--- + fs/btrfs/qgroup.c | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +--- a/fs/btrfs/qgroup.c ++++ b/fs/btrfs/qgroup.c +@@ -941,6 +941,14 @@ int btrfs_quota_enable(struct btrfs_fs_i + int ret = 0; + int slot; + ++ /* ++ * We need to have subvol_sem write locked, to prevent races between ++ * concurrent tasks trying to enable quotas, because we will unlock ++ * and relock qgroup_ioctl_lock before setting fs_info->quota_root ++ * and before setting BTRFS_FS_QUOTA_ENABLED. ++ */ ++ lockdep_assert_held_write(&fs_info->subvol_sem); ++ + mutex_lock(&fs_info->qgroup_ioctl_lock); + if (fs_info->quota_root) + goto out; +@@ -1118,8 +1126,19 @@ out_add_root: + goto out_free_path; + } + ++ mutex_unlock(&fs_info->qgroup_ioctl_lock); ++ /* ++ * Commit the transaction while not holding qgroup_ioctl_lock, to avoid ++ * a deadlock with tasks concurrently doing other qgroup operations, such ++ * adding/removing qgroups or adding/deleting qgroup relations for example, ++ * because all qgroup operations first start or join a transaction and then ++ * lock the qgroup_ioctl_lock mutex. ++ * We are safe from a concurrent task trying to enable quotas, by calling ++ * this function, since we are serialized by fs_info->subvol_sem. ++ */ + ret = btrfs_commit_transaction(trans); + trans = NULL; ++ mutex_lock(&fs_info->qgroup_ioctl_lock); + if (ret) + goto out_free_path; + diff --git a/queue-5.10/btrfs-respect-the-max-size-in-the-header-when-activating-swap-file.patch b/queue-5.10/btrfs-respect-the-max-size-in-the-header-when-activating-swap-file.patch new file mode 100644 index 00000000000..e35ffa54ed0 --- /dev/null +++ b/queue-5.10/btrfs-respect-the-max-size-in-the-header-when-activating-swap-file.patch @@ -0,0 +1,65 @@ +From c2f822635df873c510bda6fb7fd1b10b7c31be2d Mon Sep 17 00:00:00 2001 +From: Filipe Manana +Date: Thu, 16 Dec 2021 15:00:32 +0000 +Subject: btrfs: respect the max size in the header when activating swap file + +From: Filipe Manana + +commit c2f822635df873c510bda6fb7fd1b10b7c31be2d upstream. + +If we extended the size of a swapfile after its header was created (by the +mkswap utility) and then try to activate it, we will map the entire file +when activating the swap file, instead of limiting to the max size defined +in the swap file's header. + +Currently test case generic/643 from fstests fails because we do not +respect that size limit defined in the swap file's header. + +So fix this by not mapping file ranges beyond the max size defined in the +swap header. + +This is the same type of bug that iomap used to have, and was fixed in +commit 36ca7943ac18ae ("mm/swap: consider max pages in +iomap_swapfile_add_extent"). + +Fixes: ed46ff3d423780 ("Btrfs: support swap files") +CC: stable@vger.kernel.org # 5.4+ +Reviewed-and-tested-by: Josef Bacik +Reviewed-by: David Sterba +Signed-off-by: David Sterba +Signed-off-by: Greg Kroah-Hartman +--- + fs/btrfs/inode.c | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +--- a/fs/btrfs/inode.c ++++ b/fs/btrfs/inode.c +@@ -10094,9 +10094,19 @@ static int btrfs_add_swap_extent(struct + struct btrfs_swap_info *bsi) + { + unsigned long nr_pages; ++ unsigned long max_pages; + u64 first_ppage, first_ppage_reported, next_ppage; + int ret; + ++ /* ++ * Our swapfile may have had its size extended after the swap header was ++ * written. In that case activating the swapfile should not go beyond ++ * the max size set in the swap header. ++ */ ++ if (bsi->nr_pages >= sis->max) ++ return 0; ++ ++ max_pages = sis->max - bsi->nr_pages; + first_ppage = ALIGN(bsi->block_start, PAGE_SIZE) >> PAGE_SHIFT; + next_ppage = ALIGN_DOWN(bsi->block_start + bsi->block_len, + PAGE_SIZE) >> PAGE_SHIFT; +@@ -10104,6 +10114,7 @@ static int btrfs_add_swap_extent(struct + if (first_ppage >= next_ppage) + return 0; + nr_pages = next_ppage - first_ppage; ++ nr_pages = min(nr_pages, max_pages); + + first_ppage_reported = first_ppage; + if (bsi->start == 0) diff --git a/queue-5.10/ext4-fix-a-possible-abba-deadlock-due-to-busy-pa.patch b/queue-5.10/ext4-fix-a-possible-abba-deadlock-due-to-busy-pa.patch new file mode 100644 index 00000000000..7dd8d9de399 --- /dev/null +++ b/queue-5.10/ext4-fix-a-possible-abba-deadlock-due-to-busy-pa.patch @@ -0,0 +1,154 @@ +From 8c80fb312d7abf8bcd66cca1d843a80318a2c522 Mon Sep 17 00:00:00 2001 +From: Chunguang Xu +Date: Tue, 23 Nov 2021 09:17:57 +0800 +Subject: ext4: fix a possible ABBA deadlock due to busy PA + +From: Chunguang Xu + +commit 8c80fb312d7abf8bcd66cca1d843a80318a2c522 upstream. + +We found on older kernel (3.10) that in the scenario of insufficient +disk space, system may trigger an ABBA deadlock problem, it seems that +this problem still exists in latest kernel, try to fix it here. The +main process triggered by this problem is that task A occupies the PA +and waits for the jbd2 transaction finish, the jbd2 transaction waits +for the completion of task B's IO (plug_list), but task B waits for +the release of PA by task A to finish discard, which indirectly forms +an ABBA deadlock. The related calltrace is as follows: + + Task A + vfs_write + ext4_mb_new_blocks() + ext4_mb_mark_diskspace_used() JBD2 + jbd2_journal_get_write_access() -> jbd2_journal_commit_transaction() + ->schedule() filemap_fdatawait() + | | + | Task B | + | do_unlinkat() | + | ext4_evict_inode() | + | jbd2_journal_begin_ordered_truncate() | + | filemap_fdatawrite_range() | + | ext4_mb_new_blocks() | + -ext4_mb_discard_group_preallocations() <----- + +Here, try to cancel ext4_mb_discard_group_preallocations() internal +retry due to PA busy, and do a limited number of retries inside +ext4_mb_discard_preallocations(), which can circumvent the above +problems, but also has some advantages: + +1. Since the PA is in a busy state, if other groups have free PAs, + keeping the current PA may help to reduce fragmentation. +2. Continue to traverse forward instead of waiting for the current + group PA to be released. In most scenarios, the PA discard time + can be reduced. + +However, in the case of smaller free space, if only a few groups have +space, then due to multiple traversals of the group, it may increase +CPU overhead. But in contrast, I feel that the overall benefit is +better than the cost. + +Signed-off-by: Chunguang Xu +Reported-by: kernel test robot +Reviewed-by: Jan Kara +Link: https://lore.kernel.org/r/1637630277-23496-1-git-send-email-brookxu.cn@gmail.com +Signed-off-by: Theodore Ts'o +Cc: stable@kernel.org +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/mballoc.c | 40 ++++++++++++++++++---------------------- + 1 file changed, 18 insertions(+), 22 deletions(-) + +--- a/fs/ext4/mballoc.c ++++ b/fs/ext4/mballoc.c +@@ -4234,7 +4234,7 @@ ext4_mb_release_group_pa(struct ext4_bud + */ + static noinline_for_stack int + ext4_mb_discard_group_preallocations(struct super_block *sb, +- ext4_group_t group, int needed) ++ ext4_group_t group, int *busy) + { + struct ext4_group_info *grp = ext4_get_group_info(sb, group); + struct buffer_head *bitmap_bh = NULL; +@@ -4242,8 +4242,7 @@ ext4_mb_discard_group_preallocations(str + struct list_head list; + struct ext4_buddy e4b; + int err; +- int busy = 0; +- int free, free_total = 0; ++ int free = 0; + + mb_debug(sb, "discard preallocation for group %u\n", group); + if (list_empty(&grp->bb_prealloc_list)) +@@ -4266,19 +4265,14 @@ ext4_mb_discard_group_preallocations(str + goto out_dbg; + } + +- if (needed == 0) +- needed = EXT4_CLUSTERS_PER_GROUP(sb) + 1; +- + INIT_LIST_HEAD(&list); +-repeat: +- free = 0; + ext4_lock_group(sb, group); + list_for_each_entry_safe(pa, tmp, + &grp->bb_prealloc_list, pa_group_list) { + spin_lock(&pa->pa_lock); + if (atomic_read(&pa->pa_count)) { + spin_unlock(&pa->pa_lock); +- busy = 1; ++ *busy = 1; + continue; + } + if (pa->pa_deleted) { +@@ -4318,22 +4312,13 @@ repeat: + call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); + } + +- free_total += free; +- +- /* if we still need more blocks and some PAs were used, try again */ +- if (free_total < needed && busy) { +- ext4_unlock_group(sb, group); +- cond_resched(); +- busy = 0; +- goto repeat; +- } + ext4_unlock_group(sb, group); + ext4_mb_unload_buddy(&e4b); + put_bh(bitmap_bh); + out_dbg: + mb_debug(sb, "discarded (%d) blocks preallocated for group %u bb_free (%d)\n", +- free_total, group, grp->bb_free); +- return free_total; ++ free, group, grp->bb_free); ++ return free; + } + + /* +@@ -4875,13 +4860,24 @@ static int ext4_mb_discard_preallocation + { + ext4_group_t i, ngroups = ext4_get_groups_count(sb); + int ret; +- int freed = 0; ++ int freed = 0, busy = 0; ++ int retry = 0; + + trace_ext4_mb_discard_preallocations(sb, needed); ++ ++ if (needed == 0) ++ needed = EXT4_CLUSTERS_PER_GROUP(sb) + 1; ++ repeat: + for (i = 0; i < ngroups && needed > 0; i++) { +- ret = ext4_mb_discard_group_preallocations(sb, i, needed); ++ ret = ext4_mb_discard_group_preallocations(sb, i, &busy); + freed += ret; + needed -= ret; ++ cond_resched(); ++ } ++ ++ if (needed > 0 && busy && ++retry < 3) { ++ busy = 0; ++ goto repeat; + } + + return freed; diff --git a/queue-5.10/ext4-fix-fast-commit-may-miss-tracking-range-for-falloc_fl_zero_range.patch b/queue-5.10/ext4-fix-fast-commit-may-miss-tracking-range-for-falloc_fl_zero_range.patch new file mode 100644 index 00000000000..e3ac83289aa --- /dev/null +++ b/queue-5.10/ext4-fix-fast-commit-may-miss-tracking-range-for-falloc_fl_zero_range.patch @@ -0,0 +1,54 @@ +From 5e4d0eba1ccaf19f93222abdeda5a368be141785 Mon Sep 17 00:00:00 2001 +From: Xin Yin +Date: Tue, 21 Dec 2021 10:28:39 +0800 +Subject: ext4: fix fast commit may miss tracking range for FALLOC_FL_ZERO_RANGE + +From: Xin Yin + +commit 5e4d0eba1ccaf19f93222abdeda5a368be141785 upstream. + +when call falloc with FALLOC_FL_ZERO_RANGE, to set an range to unwritten, +which has been already initialized. If the range is align to blocksize, +fast commit will not track range for this change. + +Also track range for unwritten range in ext4_map_blocks(). + +Signed-off-by: Xin Yin +Reviewed-by: Harshad Shirwadkar +Link: https://lore.kernel.org/r/20211221022839.374606-1-yinxin.x@bytedance.com +Signed-off-by: Theodore Ts'o +Cc: stable@kernel.org +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/extents.c | 2 -- + fs/ext4/inode.c | 7 ++++--- + 2 files changed, 4 insertions(+), 5 deletions(-) + +--- a/fs/ext4/extents.c ++++ b/fs/ext4/extents.c +@@ -4638,8 +4638,6 @@ static long ext4_zero_range(struct file + ret = ext4_mark_inode_dirty(handle, inode); + if (unlikely(ret)) + goto out_handle; +- ext4_fc_track_range(handle, inode, offset >> inode->i_sb->s_blocksize_bits, +- (offset + len - 1) >> inode->i_sb->s_blocksize_bits); + /* Zero out partial block at the edges of the range */ + ret = ext4_zero_partial_blocks(handle, inode, offset, len); + if (ret >= 0) +--- a/fs/ext4/inode.c ++++ b/fs/ext4/inode.c +@@ -741,10 +741,11 @@ out_sem: + if (ret) + return ret; + } +- ext4_fc_track_range(handle, inode, map->m_lblk, +- map->m_lblk + map->m_len - 1); + } +- ++ if (retval > 0 && (map->m_flags & EXT4_MAP_UNWRITTEN || ++ map->m_flags & EXT4_MAP_MAPPED)) ++ ext4_fc_track_range(handle, inode, map->m_lblk, ++ map->m_lblk + map->m_len - 1); + if (retval < 0) + ext_debug(inode, "failed with err %d\n", retval); + return retval; diff --git a/queue-5.10/ext4-initialize-err_blk-before-calling-__ext4_get_inode_loc.patch b/queue-5.10/ext4-initialize-err_blk-before-calling-__ext4_get_inode_loc.patch new file mode 100644 index 00000000000..02bfec33185 --- /dev/null +++ b/queue-5.10/ext4-initialize-err_blk-before-calling-__ext4_get_inode_loc.patch @@ -0,0 +1,43 @@ +From c27c29c6af4f3f4ce925a2111c256733c5a5b430 Mon Sep 17 00:00:00 2001 +From: Harshad Shirwadkar +Date: Wed, 1 Dec 2021 08:34:21 -0800 +Subject: ext4: initialize err_blk before calling __ext4_get_inode_loc + +From: Harshad Shirwadkar + +commit c27c29c6af4f3f4ce925a2111c256733c5a5b430 upstream. + +It is not guaranteed that __ext4_get_inode_loc will definitely set +err_blk pointer when it returns EIO. To avoid using uninitialized +variables, let's first set err_blk to 0. + +Reported-by: Dan Carpenter +Signed-off-by: Harshad Shirwadkar +Link: https://lore.kernel.org/r/20211201163421.2631661-1-harshads@google.com +Signed-off-by: Theodore Ts'o +Cc: stable@kernel.org +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/inode.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/fs/ext4/inode.c ++++ b/fs/ext4/inode.c +@@ -4445,7 +4445,7 @@ has_buffer: + static int __ext4_get_inode_loc_noinmem(struct inode *inode, + struct ext4_iloc *iloc) + { +- ext4_fsblk_t err_blk; ++ ext4_fsblk_t err_blk = 0; + int ret; + + ret = __ext4_get_inode_loc(inode->i_sb, inode->i_ino, iloc, 0, +@@ -4460,7 +4460,7 @@ static int __ext4_get_inode_loc_noinmem( + + int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) + { +- ext4_fsblk_t err_blk; ++ ext4_fsblk_t err_blk = 0; + int ret; + + /* We have all inode data except xattrs in memory here. */ diff --git a/queue-5.10/ext4-make-sure-quota-gets-properly-shutdown-on-error.patch b/queue-5.10/ext4-make-sure-quota-gets-properly-shutdown-on-error.patch new file mode 100644 index 00000000000..8b1b711a790 --- /dev/null +++ b/queue-5.10/ext4-make-sure-quota-gets-properly-shutdown-on-error.patch @@ -0,0 +1,51 @@ +From 15fc69bbbbbc8c72e5f6cc4e1be0f51283c5448e Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Thu, 7 Oct 2021 17:53:35 +0200 +Subject: ext4: make sure quota gets properly shutdown on error + +From: Jan Kara + +commit 15fc69bbbbbc8c72e5f6cc4e1be0f51283c5448e upstream. + +When we hit an error when enabling quotas and setting inode flags, we do +not properly shutdown quota subsystem despite returning error from +Q_QUOTAON quotactl. This can lead to some odd situations like kernel +using quota file while it is still writeable for userspace. Make sure we +properly cleanup the quota subsystem in case of error. + +Signed-off-by: Jan Kara +Cc: stable@kernel.org +Link: https://lore.kernel.org/r/20211007155336.12493-2-jack@suse.cz +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/super.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -6341,10 +6341,7 @@ static int ext4_quota_on(struct super_bl + + lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA); + err = dquot_quota_on(sb, type, format_id, path); +- if (err) { +- lockdep_set_quota_inode(path->dentry->d_inode, +- I_DATA_SEM_NORMAL); +- } else { ++ if (!err) { + struct inode *inode = d_inode(path->dentry); + handle_t *handle; + +@@ -6364,7 +6361,12 @@ static int ext4_quota_on(struct super_bl + ext4_journal_stop(handle); + unlock_inode: + inode_unlock(inode); ++ if (err) ++ dquot_quota_off(sb, type); + } ++ if (err) ++ lockdep_set_quota_inode(path->dentry->d_inode, ++ I_DATA_SEM_NORMAL); + return err; + } + diff --git a/queue-5.10/ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch b/queue-5.10/ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch new file mode 100644 index 00000000000..4c321779175 --- /dev/null +++ b/queue-5.10/ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch @@ -0,0 +1,49 @@ +From 4013d47a5307fdb5c13370b5392498b00fedd274 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Thu, 7 Oct 2021 17:53:36 +0200 +Subject: ext4: make sure to reset inode lockdep class when quota enabling fails + +From: Jan Kara + +commit 4013d47a5307fdb5c13370b5392498b00fedd274 upstream. + +When we succeed in enabling some quota type but fail to enable another +one with quota feature, we correctly disable all enabled quota types. +However we forget to reset i_data_sem lockdep class. When the inode gets +freed and reused, it will inherit this lockdep class (i_data_sem is +initialized only when a slab is created) and thus eventually lockdep +barfs about possible deadlocks. + +Reported-and-tested-by: syzbot+3b6f9218b1301ddda3e2@syzkaller.appspotmail.com +Signed-off-by: Jan Kara +Cc: stable@kernel.org +Link: https://lore.kernel.org/r/20211007155336.12493-3-jack@suse.cz +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/super.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -6427,8 +6427,19 @@ static int ext4_enable_quotas(struct sup + "Failed to enable quota tracking " + "(type=%d, err=%d). Please run " + "e2fsck to fix.", type, err); +- for (type--; type >= 0; type--) ++ for (type--; type >= 0; type--) { ++ struct inode *inode; ++ ++ inode = sb_dqopt(sb)->files[type]; ++ if (inode) ++ inode = igrab(inode); + dquot_quota_off(sb, type); ++ if (inode) { ++ lockdep_set_quota_inode(inode, ++ I_DATA_SEM_NORMAL); ++ iput(inode); ++ } ++ } + + return err; + } diff --git a/queue-5.10/series b/queue-5.10/series index fdb8100e099..f2a7a8d4e30 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -466,3 +466,11 @@ pci-pci-bridge-emul-fix-definitions-of-reserved-bits.patch pci-pci-bridge-emul-correctly-set-pcie-capabilities.patch pci-pci-bridge-emul-set-pci_status_cap_list-for-pcie-device.patch xfrm-fix-policy-lookup-for-ipv6-gre-packets.patch +btrfs-fix-deadlock-between-quota-enable-and-other-quota-operations.patch +btrfs-check-the-root-node-for-uptodate-before-returning-it.patch +btrfs-respect-the-max-size-in-the-header-when-activating-swap-file.patch +ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch +ext4-make-sure-quota-gets-properly-shutdown-on-error.patch +ext4-fix-a-possible-abba-deadlock-due-to-busy-pa.patch +ext4-initialize-err_blk-before-calling-__ext4_get_inode_loc.patch +ext4-fix-fast-commit-may-miss-tracking-range-for-falloc_fl_zero_range.patch