From: Amir Goldstein <amir73il@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Sasha Levin <sashal@kernel.org>,
"Darrick J . Wong" <djwong@kernel.org>,
Leah Rumancik <leah.rumancik@gmail.com>,
Chandan Babu R <chandan.babu@oracle.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Adam Manzanares <a.manzanares@samsung.com>,
linux-xfs@vger.kernel.org, stable@vger.kernel.org,
Dave Chinner <dchinner@redhat.com>
Subject: [PATCH 5.10 v3 3/5] xfs: fix overfilling of reserve pool
Date: Thu, 1 Sep 2022 16:33:54 +0300 [thread overview]
Message-ID: <20220901133356.2473299-4-amir73il@gmail.com> (raw)
In-Reply-To: <20220901133356.2473299-1-amir73il@gmail.com>
From: "Darrick J. Wong" <djwong@kernel.org>
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.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
---
fs/xfs/xfs_fsops.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index dacead0d0934..775f833146e3 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -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) {
--
2.25.1
next prev parent reply other threads:[~2022-09-01 13:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-01 13:33 [PATCH 5.10 v3 0/5] xfs stable patches for 5.10.y (from v5.18+) Amir Goldstein
2022-09-01 13:33 ` [PATCH 5.10 v3 1/5] xfs: remove infinite loop when reserving free block pool Amir Goldstein
2022-09-02 6:16 ` Greg Kroah-Hartman
2022-09-02 7:04 ` Amir Goldstein
2022-09-01 13:33 ` [PATCH 5.10 v3 2/5] xfs: always succeed at setting the reserve pool size Amir Goldstein
2022-09-01 13:33 ` Amir Goldstein [this message]
2022-09-01 13:33 ` [PATCH 5.10 v3 4/5] xfs: fix soft lockup via spinning in filestream ag selection loop Amir Goldstein
2022-09-01 13:33 ` [PATCH 5.10 v3 5/5] xfs: revert "xfs: actually bump warning counts when we send warnings" Amir Goldstein
2022-09-02 6:17 ` [PATCH 5.10 v3 0/5] xfs stable patches for 5.10.y (from v5.18+) Greg Kroah-Hartman
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=20220901133356.2473299-4-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=a.manzanares@samsung.com \
--cc=chandan.babu@oracle.com \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=leah.rumancik@gmail.com \
--cc=linux-xfs@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=sashal@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).