summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2022-08-17 09:33:53 -0700
committerDarrick J. Wong <djwong@kernel.org>2022-11-09 19:07:53 -0800
commit6a290d47a9f43d280653ab646eb9b600f459bff0 (patch)
tree93bdae0585e8716f4c4b8a86720792366ed05178
parentbafa814bb7d6b99822b434bd4bc9ed7360ed2d32 (diff)
xfs: make sure maxlen is still congruent with prod when rounding down
In commit 2a6ca4baed62, we tried to fix an overflow problem in the realtime allocator that was caused by an overly large maxlen value causing xfs_rtcheck_range to run off the end of the realtime bitmap. Unfortunately, there is a subtle bug here -- maxlen (and minlen) both have to be aligned with @prod, but @prod can be larger than 1 if the user has set an extent size hint on the file, and that extent size hint is larger than the realtime extent size. If the rt free space extents are not aligned to this file's extszhint because other files without extent size hints allocated space (or the number of rt extents is similarly not aligned), then it's possible that maxlen after clamping to sb_rextents will no longer be aligned to prod. The allocation will succeed just fine, but we still trip the assertion. Fix the problem by reducing maxlen by any misalignment with prod. While we're at it, split the assertions into two so that we can tell which value had the bad alignment. Fixes: 2a6ca4baed62 ("xfs: make sure the rt allocator doesn't run off the end") Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/xfs_rtalloc.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 3ac8ca845239..88faf7fb912d 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -252,8 +252,13 @@ xfs_rtallocate_extent_block(
end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1;
i <= end;
i++) {
- /* Make sure we don't scan off the end of the rt volume. */
+ /*
+ * Make sure we don't run off the end of the rt volume. Be
+ * careful that adjusting maxlen downwards doesn't cause us to
+ * fail the alignment checks.
+ */
maxlen = min(mp->m_sb.sb_rextents, i + maxlen) - i;
+ maxlen -= maxlen % prod;
/*
* See if there's a free extent of maxlen starting at i.
@@ -360,7 +365,8 @@ xfs_rtallocate_extent_exact(
int isfree; /* extent is free */
xfs_rtblock_t next; /* next block to try (dummy) */
- ASSERT(minlen % prod == 0 && maxlen % prod == 0);
+ ASSERT(minlen % prod == 0);
+ ASSERT(maxlen % prod == 0);
/*
* Check if the range in question (for maxlen) is free.
*/
@@ -443,7 +449,9 @@ xfs_rtallocate_extent_near(
xfs_rtblock_t n; /* next block to try */
xfs_rtblock_t r; /* result block */
- ASSERT(minlen % prod == 0 && maxlen % prod == 0);
+ ASSERT(minlen % prod == 0);
+ ASSERT(maxlen % prod == 0);
+
/*
* If the block number given is off the end, silently set it to
* the last block.
@@ -451,8 +459,13 @@ xfs_rtallocate_extent_near(
if (bno >= mp->m_sb.sb_rextents)
bno = mp->m_sb.sb_rextents - 1;
- /* Make sure we don't run off the end of the rt volume. */
+ /*
+ * Make sure we don't run off the end of the rt volume. Be careful
+ * that adjusting maxlen downwards doesn't cause us to fail the
+ * alignment checks.
+ */
maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno;
+ maxlen -= maxlen % prod;
if (maxlen < minlen) {
*rtblock = NULLRTBLOCK;
return 0;
@@ -643,7 +656,8 @@ xfs_rtallocate_extent_size(
xfs_rtblock_t r; /* result block number */
xfs_suminfo_t sum; /* summary information for extents */
- ASSERT(minlen % prod == 0 && maxlen % prod == 0);
+ ASSERT(minlen % prod == 0);
+ ASSERT(maxlen % prod == 0);
ASSERT(maxlen != 0);
/*