mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiaming Zhang <r772577952@gmail.com>
To: Carlos Maiolino <cem@kernel.org>, linux-xfs@vger.kernel.org
Cc: "Darrick J. Wong" <djwong@kernel.org>,
	Eric Sandeen <sandeen@redhat.com>,
	linux-kernel@vger.kernel.org,
	Jiaming Zhang <r772577952@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] xfs: exclude unlogged remote blocks from attr set log reservation
Date: Sat,  5 Dec 2026 18:06:43 +0800	[thread overview]
Message-ID: <20261205100643.3353410-1-r772577952@gmail.com> (raw)

In XFS, small local extended attributes fit inside a btree leaf block
and are written to the journal.  Large values live in separate remote
blocks written synchronously to disk without being logged, unless
experimental log-assisted xattrs are enabled.

When checking the minimum journal size at mount time,
xfs_log_calc_max_attrsetm_res() counts only the maximum local attribute
size and omits remote blocks.  At runtime, xfs_attr_set_resv()
reserves journal space for every block in args->total:

	.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
		    M_RES(mp)->tr_attrsetrt.tr_logres * args->total,

xfs_attr_calc_size() calculates args->total for disk space allocation.
For a remote attribute it counts both metadata btree blocks and the
remote value blocks themselves.  Using all of args->total here charges
per-block metadata log space against every unlogged remote value block.

On a 1KB block V5 filesystem with a minimum journal of 1,176 blocks
(1,204,224 bytes), a 64KB attribute adds 68 remote blocks to args->total.
Across XFS_ATTRSET_LOG_COUNT (i.e. 3) transactions with log header
overhead, xfs_log_reserve() asks for 1,228,800 bytes, exceeding
log->l_logsize and making xlog_grant_head_wait() sleep forever.

vfs_setxattr() holds the target inode's i_rwsem exclusively and freeze
protection before entering XFS.  On a directory, the sleeping task
blocks lookups (such as lookup_open()) and updates, prevents freeze and
unmount, and triggers a hung-task report.

Triggering this requires a small-block XFS filesystem with a
minimum-sized journal (CAP_SYS_ADMIN to mount an image, or unprivileged
setxattr() once such a filesystem is mounted).

Subtract xfs_attr3_rmt_blocks() from the block count in
xfs_attr_set_resv() for remote attributes when XFS_DA_OP_LOGGED is not
set, leaving args->total unchanged for disk block allocation.  Mark
xfs_attr_leaf_newentsize()'s args parameter const so xfs_attr_set_resv()
can check whether the attribute fits locally.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Closes: https://lore.kernel.org/lkml/CANypQFYgKv3Gs-sR1bO7W241rknGqx1byaP+sXQNiKMjQ6s=Sw@mail.gmail.com/
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:Gemini
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
 fs/xfs/libxfs/xfs_attr.c      | 11 +++++++++--
 fs/xfs/libxfs/xfs_attr_leaf.c |  4 ++--
 fs/xfs/libxfs/xfs_attr_leaf.h |  2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
index c4bb59633ce8..ef51158a1948 100644
--- a/fs/xfs/libxfs/xfs_attr.c
+++ b/fs/xfs/libxfs/xfs_attr.c
@@ -332,12 +332,19 @@ xfs_attr_set_resv(
 	const struct xfs_da_args	*args)
 {
 	struct xfs_mount		*mp = args->dp->i_mount;
+	unsigned int			nblks = args->total;
 	struct xfs_trans_res		ret = {
-		.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
-			    M_RES(mp)->tr_attrsetrt.tr_logres * args->total,
 		.tr_logcount		= XFS_ATTRSET_LOG_COUNT,
 		.tr_logflags		= XFS_TRANS_PERM_LOG_RES,
 	};
+	int				local;
+
+	xfs_attr_leaf_newentsize(args, &local);
+	if (!local && !(args->op_flags & XFS_DA_OP_LOGGED))
+		nblks -= xfs_attr3_rmt_blocks(mp, args->valuelen);
+
+	ret.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
+			M_RES(mp)->tr_attrsetrt.tr_logres * nblks;
 
 	return ret;
 }
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index 82932b5c02fd..a0ef5c557ef2 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -2920,8 +2920,8 @@ xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index)
  */
 int
 xfs_attr_leaf_newentsize(
-	struct xfs_da_args	*args,
-	int			*local)
+	const struct xfs_da_args	*args,
+	int				*local)
 {
 	int			size;
 
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.h b/fs/xfs/libxfs/xfs_attr_leaf.h
index 72639efe6ac3..b74fcf3a3041 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.h
+++ b/fs/xfs/libxfs/xfs_attr_leaf.h
@@ -100,7 +100,7 @@ void	xfs_attr3_leaf_unbalance(struct xfs_da_state *state,
 xfs_dahash_t	xfs_attr_leaf_lasthash(struct xfs_buf *bp, int *count);
 int	xfs_attr_leaf_order(struct xfs_buf *leaf1_bp,
 				   struct xfs_buf *leaf2_bp);
-int	xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local);
+int	xfs_attr_leaf_newentsize(const struct xfs_da_args *args, int *local);
 int	xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
 			xfs_ino_t owner, xfs_dablk_t bno, struct xfs_buf **bpp);
 void	xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo,

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.43.0


                 reply	other threads:[~2026-12-05 10:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261205100643.3353410-1-r772577952@gmail.com \
    --to=r772577952@gmail.com \
    --cc=cem@kernel.org \
    --cc=djwong@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    --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

all inboxes | Powered by JetHome®