From: Eduard Zateev <hackerowskiy@gmail.com>
To: hackerowskiy@gmail.com
Cc: "Darrick J. Wong" <djwong@kernel.org>,
stable@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Carlos Maiolino <cem@kernel.org>
Subject: [PATCH 25/26] xfs: don't let hidden_space go negative in xfs_metafile_resv_init
Date: Tue, 22 Sep 2026 13:02:20 +0200 [thread overview]
Message-ID: <20260922110221.1431-25-hackerowskiy@gmail.com> (raw)
In-Reply-To: <20260922110221.1431-1-hackerowskiy@gmail.com>
From: "Darrick J. Wong" <djwong@kernel.org>
LOLLM points out that if the amount of fdblocks that we can reserve for
a metadata btree file goes below the space already used by that file,
then the hidden_space subtraction can underflow, causing
xfs_dec_fdblocks to subtract a huge amount of space. We never want the
target to be less than the used sapce, so fix the logic that adjusts
dblocks_avail downwards.
Also fix an error in the adjacent comment.
Cc: stable@vger.kernel.org # v6.15
Fixes: 1df8d75030b787 ("xfs: make metabtree reservations global")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Assisted-by: LOLLM # finding obvious bugs
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
fs/xfs/libxfs/xfs_metafile.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_metafile.c b/fs/xfs/libxfs/xfs_metafile.c
index 71f004e9dc64..1f54d39003c2 100644
--- a/fs/xfs/libxfs/xfs_metafile.c
+++ b/fs/xfs/libxfs/xfs_metafile.c
@@ -297,14 +297,14 @@ xfs_metafile_resv_init(
goto out_unlock;
/*
- * Space taken by the per-AG metadata btrees are accounted on-disk as
- * used space. We therefore only hide the space that is reserved but
- * not used by the trees.
+ * Space taken by metadata btrees are accounted on-disk as used space.
+ * We therefore only hide the space that is reserved but not used by
+ * the trees.
*/
if (used > target)
target = used;
else if (target > dblocks_avail)
- target = dblocks_avail;
+ target = max(dblocks_avail, used);
hidden_space = target - used;
error = xfs_dec_fdblocks(mp, hidden_space, true);
--
2.55.0
next prev parent reply other threads:[~2026-09-22 11:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260922110221.1431-1-hackerowskiy@gmail.com>
2026-09-22 11:01 ` [PATCH 02/26] xfs: don't assert when XFS_SCRUB_TYPE_HEALTHY scans return corruption Eduard Zateev
2026-09-22 11:01 ` [PATCH 03/26] xfs: fix attr fork block count checks in xrep_inode_blockcounts Eduard Zateev
2026-09-22 11:01 ` [PATCH 04/26] xfs: release orphanage dir inode if chown fails Eduard Zateev
2026-09-22 11:02 ` [PATCH 06/26] xfs: use correct jiffies comparison function in xchk_maybe_relax Eduard Zateev
2026-09-22 11:02 ` [PATCH 07/26] xfs: check padding field in xfs_ioc_commit_range Eduard Zateev
2026-09-22 11:02 ` [PATCH 08/26] xfs: don't call xfs_exchange_range_finish for a dry run Eduard Zateev
2026-09-22 11:02 ` [PATCH 09/26] xfs: use the correct reservations for rtrmap/refcount recovery Eduard Zateev
2026-09-22 11:02 ` [PATCH 11/26] xfs: only flag zero padding for dir3 data blocks, not dir3 block blocks Eduard Zateev
2026-09-22 11:02 ` [PATCH 12/26] xfs: check di_forkoff correctly in scrub Eduard Zateev
2026-09-22 11:02 ` [PATCH 17/26] xfs: call xfs_dquot_set_prealloc_limits if we installed default rtb limits Eduard Zateev
2026-09-22 11:02 ` [PATCH 18/26] xfs: fix rtgroup repair estimations Eduard Zateev
2026-09-22 11:02 ` [PATCH 19/26] xfs: don't cross reference rmapbt with bitmaps if they're incomplete Eduard Zateev
2026-09-22 11:02 ` [PATCH 20/26] xfs: don't let memory failures leak blocks and kill repairs Eduard Zateev
2026-09-22 11:02 ` [PATCH 21/26] xfs: don't merge different file IO error types Eduard Zateev
2026-09-22 11:02 ` [PATCH 22/26] xfs: fix blockgc group quota scanning when usrquota isn't enforced Eduard Zateev
2026-09-22 11:02 ` [PATCH 23/26] xfs: fix cursor and pointer handling when recovering iunlink buckets Eduard Zateev
2026-09-22 11:02 ` [PATCH 24/26] xfs: drop dquot flush lock when we can't find a buffer to flush Eduard Zateev
2026-09-22 11:02 ` Eduard Zateev [this message]
2026-09-22 11:02 ` [PATCH 26/26] xfs: fix wild memcpy access when formatting ondisk rtrefcount btree roots Eduard Zateev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260922110221.1431-25-hackerowskiy@gmail.com \
--to=hackerowskiy@gmail.com \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox