xfs stable candidate patches for 5.10.y (from v5.18+)
cover xfs stable candidate patches for 5.10.y (from v5.18+)
Hi Darrick,
This 5.10.y backport series contains fixes from v5.18 and v5.19 releases.
Patches 1-5 in this series have already been applied to 5.15.y in Leah's latest update [1], so this 5.10.y is is mostly catching up with 5.15.y.
Patches 2-3 from the last 5.15.y update have not been picked for 5.10.y, because they were not trivial to backport as the quota code is quite different betrween 5.10.y and upstream.
This omission leave fstests generic/681,682 broken on 5.10.y.
Patches 6-7 in this 5.10.y update have not been applied to 5.15.y yet. I pointed Leah's attention to these patches and she said she will include them in a following 5.15.y update.
In particular, Darrick has pointed me at the fix in patch 6 a long time ago, but I was waiting to apply fixes to 5.10.y in chronoligal order.
Please note that the upstream fix 6f5097e3367a ("xfs: fix xfs_ifree() error handling to not leak perag ref") Which Fixes: 9a5280b312e2e ("xfs: reorder iunlink remove operation in xfs_ifree")
is not relevant for the 5.10.y backport.
These patches has gone through the usual 30 auto group runs x 5 configs on kdevops.
Thanks,
Amir.
[1] https://lore.kernel.org/linux-xfs/[email protected]/
Amir Goldstein (1):
xfs: remove infinite loop when reserving free block pool
Brian Foster (1):
xfs: fix soft lockup via spinning in filestream ag selection loop
Darrick J. Wong (2):
xfs: always succeed at setting the reserve pool size
xfs: fix overfilling of reserve pool
Dave Chinner (2):
xfs: reorder iunlink remove operation in xfs_ifree
xfs: validate inode fork size against fork format
Eric Sandeen (1):
xfs: revert "xfs: actually bump warning counts when we send warnings"
fs/xfs/libxfs/xfs_inode_buf.c | 35 +++++++++++++++++------ fs/xfs/xfs_filestream.c | 7 +++-- fs/xfs/xfs_fsops.c | 52 ++++++++++++++--------------------- fs/xfs/xfs_inode.c | 22 ++++++++------- fs/xfs/xfs_mount.h | 8 ++++++ fs/xfs/xfs_trans_dquot.c | 1 - 6 files changed, 71 insertions(+), 54 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/7 xfs: remove infinite loop when reserving free block pool
commit 15f04fdc75aaaa1cccb0b8b3af1be290e118a7bc upstream.
[Added wrapper xfs_fdblocks_unavailable() for 5.10.y backport]
Infinite loops in kernel code are scary. Calls to xfs_reserve_blocks should be rare (people should just use the defaults!) so we really don't need to try so hard. Simplify the logic here by removing the infinite loop.
--- fs/xfs/xfs_fsops.c | 52 +++++++++++++++++++--------------------------- fs/xfs/xfs_mount.h | 8 +++++++ 2 files changed, 29 insertions(+), 31 deletions(-)
fs/xfs/xfs_fsops.c +21 -31
@@ -376,46 +376,36 @@ xfs_reserve_blocks(* If the request is larger than the current reservation, reserve the * blocks before we update the reserve counters. Sample m_fdblocks and * perform a partial reservation if the request exceeds free space. +* +* The code below estimates how many blocks it can request from +* fdblocks to stash in the reserve pool. This is a classic TOCTOU +* race since fdblocks updates are not always coordinated via +* m_sb_lock. */ - error = -ENOSPC ; -do { - free =percpu_counter_sum (&mp->m_fdblocks) - - mp->m_alloc_set_aside; -if (free <=0 ) -break ; - - delta = request - mp->m_resblks; - lcounter = free - delta; -if (lcounter <0 ) -/* We can't satisfy the request, just get what we can */ - fdblks_delta = free; -else - fdblks_delta = delta; - + free =percpu_counter_sum (&mp->m_fdblocks) - +xfs_fdblocks_unavailable (mp); + delta = request - mp->m_resblks; +if (delta >0 && free >0 ) {/* * We'll either succeed in getting space from the free block -* count or we'll get an ENOSPC. If we get a ENOSPC, it means -* things changed while we were calculating fdblks_delta and so -* we should try again to see if there is anything left to -* reserve. -* -* Don't set the reserved flag here - we don't want to reserve -* the extra reserve blocks from the reserve..... +* count or we'll get an ENOSPC. Don't set the reserved flag +* here - we don't want to reserve the extra reserve blocks +* from the reserve. */ + fdblks_delta =min (free, delta);spin_unlock (&mp->m_sb_lock); error =xfs_mod_fdblocks (mp, -fdblks_delta,0 );spin_lock (&mp->m_sb_lock); - }while (error == -ENOSPC ); -/* -* Update the reserve counters if blocks have been successfully -* allocated. -*/ -if (!error && fdblks_delta) { - mp->m_resblks += fdblks_delta; - mp->m_resblks_avail += fdblks_delta; +/* +* Update the reserve counters if blocks have been successfully +* allocated. +*/ +if (!error) { + mp->m_resblks += fdblks_delta; + mp->m_resblks_avail += fdblks_delta; + } } - out:if (outval) { outval->resblks = mp->m_resblks;
fs/xfs/xfs_mount.h +8 -0
@@ -406,6 +406,14 @@ extern int xfs_initialize_perag(xfs_mount_t *mp, xfs_agnumber_t agcount, xfs_agnumber_t *maxagi);extern void xfs_unmountfs (xfs_mount_t *); +/* Accessor added for 5.10.y backport */ +static inline uint64_t +xfs_fdblocks_unavailable ( +struct xfs_mount *mp) +{ +return mp->m_alloc_set_aside; +} +extern int xfs_mod_fdblocks (struct xfs_mount *mp,int64_t delta,bool reserved);extern int xfs_mod_frextents (struct xfs_mount *mp,int64_t delta);
Signature · 1 line
2.25.1
PATCH 2/7 xfs: always succeed at setting the reserve pool size
In reply to Amir GoldsteinFrom: "Darrick J. Wong" <[email protected]>
commit 0baa2657dc4d79202148be79a3dc36c35f425060 upstream.
Nowadays, xfs_mod_fdblocks will always choose to fill the reserve pool with freed blocks before adding to fdblocks. Therefore, we can change the behavior of xfs_reserve_blocks slightly -- setting the target size of the pool should always succeed, since a deficiency will eventually be made up as blocks get freed.
--- fs/xfs/xfs_fsops.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/xfs/xfs_fsops.c +5 -4
@@ -380,11 +380,14 @@ xfs_reserve_blocks(* The code below estimates how many blocks it can request from * fdblocks to stash in the reserve pool. This is a classic TOCTOU * race since fdblocks updates are not always coordinated via -* m_sb_lock. +* m_sb_lock. Set the reserve size even if there's not enough free +* space to fill it because mod_fdblocks will refill an undersized +* reserve when it can. */ free =percpu_counter_sum (&mp->m_fdblocks) -xfs_fdblocks_unavailable (mp); delta = request - mp->m_resblks; + mp->m_resblks = request;if (delta >0 && free >0 ) {/* * We'll either succeed in getting space from the free block
@@ -401,10 +404,8 @@ xfs_reserve_blocks(* Update the reserve counters if blocks have been successfully * allocated. */ -if (!error) { - mp->m_resblks += fdblks_delta; +if (!error) mp->m_resblks_avail += fdblks_delta; - } } out:if (outval) {
Signature · 1 line
2.25.1
PATCH 3/7 xfs: fix overfilling of reserve pool
In reply to Amir GoldsteinFrom: "Darrick J. Wong" <[email protected]>
commit 82be38bcf8a2e056b4c99ce79a3827fa743df6ec upstream.
Due to cycling of m_sb_lock, it's possible for multiple callers of xfs_reserve_blocks to race at changing the pool size, subtracting blocks from fdblocks, and actually putting it in the pool. The result of all this is that we can overfill the reserve pool to hilarious levels.
xfs_mod_fdblocks, when called with a positive value, already knows how to take freed blocks and either fill the reserve until it's full, or put them in fdblocks. Use that instead of setting m_resblks_avail directly.
--- fs/xfs/xfs_fsops.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/xfs/xfs_fsops.c +6 -7
@@ -394,18 +394,17 @@ xfs_reserve_blocks(* count or we'll get an ENOSPC. Don't set the reserved flag * here - we don't want to reserve the extra reserve blocks * from the reserve. +* +* The desired reserve size can change after we drop the lock. +* Use mod_fdblocks to put the space into the reserve or into +* fdblocks as appropriate. */ fdblks_delta =min (free, delta);spin_unlock (&mp->m_sb_lock); error =xfs_mod_fdblocks (mp, -fdblks_delta,0 ); -spin_lock (&mp->m_sb_lock); - -/* -* Update the reserve counters if blocks have been successfully -* allocated. -*/ if (!error) - mp->m_resblks_avail += fdblks_delta; +xfs_mod_fdblocks (mp, fdblks_delta,0 ); +spin_lock (&mp->m_sb_lock); } out:if (outval) {
Signature · 1 line
2.25.1
PATCH 4/7 xfs: fix soft lockup via spinning in filestream ag selection loop
In reply to Amir GoldsteinFrom: Brian Foster <[email protected]>
commit f650df7171b882dca737ddbbeb414100b31f16af upstream.
The filestream AG selection loop uses pagf data to aid in AG selection, which depends on pagf initialization. If the in-core structure is not initialized, the caller invokes the AGF read path to do so and carries on. If another task enters the loop and finds a pagf init already in progress, the AGF read returns -EAGAIN and the task continues the loop. This does not increment the current ag index, however, which means the task spins on the current AGF buffer until unlocked.
If the AGF read I/O submitted by the initial task happens to be delayed for whatever reason, this results in soft lockup warnings via the spinning task. This is reproduced by xfs/170. To avoid this problem, fix the AGF trylock failure path to properly iterate to the next AG. If a task iterates all AGs without making progress, the trylock behavior is dropped in favor of blocking locks and thus a soft lockup is no longer possible.
--- fs/xfs/xfs_filestream.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/xfs_filestream.c +4 -3
@@ -128,11 +128,12 @@ xfs_filestream_pick_ag(if (!pag->pagf_init) { err =xfs_alloc_pagf_init (mp,NULL , ag, trylock);if (err) { -xfs_perag_put (pag); -if (err != -EAGAIN ) +if (err != -EAGAIN ) { +xfs_perag_put (pag);return err; + }/* Couldn't lock the AGF, skip this AG. */ -continue ; + goto next_ag; } }
Signature · 1 line
2.25.1
PATCH 5/7 xfs: revert "xfs: actually bump warning counts when we send warnings"
In reply to Amir GoldsteinFrom: Eric Sandeen <[email protected]>
commit bc37e4fb5cac2925b2e286b1f1d4fc2b519f7d92 upstream.
This reverts commit 4b8628d57b725b32616965e66975fcdebe008fe7.
XFS quota has had the concept of a "quota warning limit" since the earliest Irix implementation, but a mechanism for incrementing the warning counter was never implemented, as documented in the xfs_quota(8) man page. We do know from the historical archive that it was never incremented at runtime during quota reservation operations.
With this commit, the warning counter quickly increments for every allocation attempt after the user has crossed a quote soft limit threshold, and this in turn transitions the user to hard quota failures, rendering soft quota thresholds and timers useless. This was reported as a regression by users.
Because the intended behavior of this warning counter has never been understood or documented, and the result of this change is a regression in soft quota functionality, revert this commit to make soft quota limits and timers operable again.
--- fs/xfs/xfs_trans_dquot.c | 1 - 1 file changed, 1 deletion(-)
fs/xfs/xfs_trans_dquot.c +0 -1
@@ -615,7 +615,6 @@ xfs_dqresv_check(return QUOTA_NL_ISOFTLONGWARN ; } - res->warnings++;return QUOTA_NL_ISOFTWARN ; }
Signature · 1 line
2.25.1
PATCH 6/7 xfs: reorder iunlink remove operation in xfs_ifree
In reply to Amir GoldsteinFrom: Dave Chinner <[email protected]>
commit 9a5280b312e2e7898b6397b2ca3cfd03f67d7be1 upstream.
[backport for 5.10.y]
The O_TMPFILE creation implementation creates a specific order of operations for inode allocation/freeing and unlinked list modification. Currently both are serialised by the AGI, so the order doesn't strictly matter as long as the are both in the same transaction.
However, if we want to move the unlinked list insertions largely out from under the AGI lock, then we have to be concerned about the order in which we do unlinked list modification operations. O_TMPFILE creation tells us this order is inode allocation/free, then unlinked list modification.
Change xfs_ifree() to use this same ordering on unlinked list removal. This way we always guarantee that when we enter the iunlinked list removal code from this path, we already have the AGI locked and we don't have to worry about lock nesting AGI reads inside unlink list locks because it's already locked and attached to the transaction.
We can do this safely as the inode freeing and unlinked list removal are done in the same transaction and hence are atomic operations with respect to log recovery.
--- fs/xfs/xfs_inode.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
fs/xfs/xfs_inode.c +12 -10
@@ -2669,14 +2669,13 @@ xfs_ifree_cluster( }/* -* This is called to return an inode to the inode free list. -* The inode should already be truncated to 0 length and have -* no pages associated with it. This routine also assumes that -* the inode is already a part of the transaction. +* This is called to return an inode to the inode free list. The inode should +* already be truncated to 0 length and have no pages associated with it. This +* routine also assumes that the inode is already a part of the transaction. * -* The on-disk copy of the inode will have been added to the list -* of unlinked inodes in the AGI. We need to remove the inode from -* that list atomically with respect to freeing it here. +* The on-disk copy of the inode will have been added to the list of unlinked +* inodes in the AGI. We need to remove the inode from that list atomically with +* respect to freeing it here. */ int xfs_ifree(
@@ -2694,13 +2693,16 @@ xfs_ifree(ASSERT (ip->i_d.di_nblocks ==0 );/* -* Pull the on-disk inode from the AGI unlinked list. +* Free the inode first so that we guarantee that the AGI lock is going +* to be taken before we remove the inode from the unlinked list. This +* makes the AGI lock -> unlinked list modification order the same as +* used in O_TMPFILE creation. */ - error =xfs_iunlink_remove (tp, ip); + error =xfs_difree (tp, ip->i_ino, &xic);if (error)return error; - error =xfs_difree (tp, ip->i_ino, &xic); + error =xfs_iunlink_remove (tp, ip);if (error)return error;
Signature · 1 line
2.25.1
PATCH 7/7 xfs: validate inode fork size against fork format
In reply to Amir GoldsteinFrom: Dave Chinner <[email protected]>
commit 1eb70f54c445fcbb25817841e774adb3d912f3e8 upstream.
[backport for 5.10.y]
xfs_repair catches fork size/format mismatches, but the in-kernel verifier doesn't, leading to null pointer failures when attempting to perform operations on the fork. This can occur in the xfs_dir_is_empty() where the in-memory fork format does not match the size and so the fork data pointer is accessed incorrectly.
Note: this causes new failures in xfs/348 which is testing mode vs ftype mismatches. We now detect a regular file that has been changed to a directory or symlink mode as being corrupt because the data fork is for a symlink or directory should be in local form when there are only 3 bytes of data in the data fork. Hence the inode verify for the regular file now fires w/ -EFSCORRUPTED because the inode fork format does not match the format the corrupted mode says it should be in.
--- fs/xfs/libxfs/xfs_inode_buf.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_inode_buf.c +26 -9
@@ -358,19 +358,36 @@ xfs_dinode_verify_fork( int whichfork) {uint32_t di_nextents =XFS_DFORK_NEXTENTS (dip, whichfork); +mode_t mode =be16_to_cpu (dip->di_mode); +uint32_t fork_size =XFS_DFORK_SIZE (dip, mp, whichfork); +uint32_t fork_format =XFS_DFORK_FORMAT (dip, whichfork); -switch (XFS_DFORK_FORMAT (dip, whichfork)) { +/* +* For fork types that can contain local data, check that the fork +* format matches the size of local data contained within the fork. +* +* For all types, check that when the size says the should be in extent +* or btree format, the inode isn't claiming it is in local format. +*/ +if (whichfork ==XFS_DATA_FORK ) { +if (S_ISDIR (mode) ||S_ISLNK (mode)) { +if (be64_to_cpu (dip->di_size) <= fork_size && + fork_format !=XFS_DINODE_FMT_LOCAL ) +return __this_address; + } + +if (be64_to_cpu (dip->di_size) > fork_size && + fork_format ==XFS_DINODE_FMT_LOCAL ) +return __this_address; + } + +switch (fork_format) {case XFS_DINODE_FMT_LOCAL :/* -* no local regular files yet +* No local regular files yet. */ -if (whichfork ==XFS_DATA_FORK ) { -if (S_ISREG (be16_to_cpu (dip->di_mode))) -return __this_address; -if (be64_to_cpu (dip->di_size) > -XFS_DFORK_SIZE (dip, mp, whichfork)) -return __this_address; - } +if (S_ISREG (mode) && whichfork ==XFS_DATA_FORK ) +return __this_address;if (di_nextents)return __this_address;break ;
Signature · 1 line
2.25.1
Quoted 12 lines · Amir Goldstein
Hi Darrick,
This 5.10.y backport series contains fixes from v5.18 and v5.19 releases.
Patches 1-5 in this series have already been applied to 5.15.y in Leah's latest update [1], so this 5.10.y is is mostly catching up with 5.15.y.
Patches 2-3 from the last 5.15.y update have not been picked for 5.10.y, because they were not trivial to backport as the quota code is quite different betrween 5.10.y and upstream.
This omission leave fstests generic/681,682 broken on 5.10.y.
Quoted 7 lines
Patches 6-7 in this 5.10.y update have not been applied to 5.15.y yet. I pointed Leah's attention to these patches and she said she will include them in a following 5.15.y update.
In particular, Darrick has pointed me at the fix in patch 6 a long time ago, but I was waiting to apply fixes to 5.10.y in chronoligal order.
Woot! :)
--D
Quoted 42 lines
Please note that the upstream fix
6f5097e3367a("xfs: fixxfs_ifree()error handling to not leak perag ref") Which Fixes:9a5280b312e2e("xfs: reorder iunlink remove operation inxfs_ifree")
is not relevant for the 5.10.y backport.These patches has gone through the usual 30 auto group runs x 5 configs on kdevops.
Thanks,
Amir.[1] https://lore.kernel.org/linux-xfs/[email protected]/
Amir Goldstein (1):
xfs: remove infinite loop when reserving free block poolBrian Foster (1):
xfs: fix soft lockup via spinning in filestream ag selection loopDarrick J. Wong (2):
xfs: always succeed at setting the reserve pool size
xfs: fix overfilling of reserve poolDave Chinner (2):
xfs: reorder iunlink remove operation inxfs_ifree
xfs: validate inode fork size against fork formatEric Sandeen (1):
xfs: revert "xfs: actually bump warning counts when we send warnings"fs/xfs/libxfs/xfs_inode_buf.c | 35 +++++++++++++++++------ fs/xfs/xfs_filestream.c | 7 +++-- fs/xfs/xfs_fsops.c | 52 ++++++++++++++--------------------- fs/xfs/xfs_inode.c | 22 ++++++++------- fs/xfs/xfs_mount.h | 8 ++++++ fs/xfs/xfs_trans_dquot.c | 1 - 6 files changed, 71 insertions(+), 54 deletions(-)Signature · 1 line
2.25.1