mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] xfs: exclude unlogged remote blocks from attr set log reservation
@ 2026-12-05 10:06 Jiaming Zhang
  0 siblings, 0 replies; only message in thread
From: Jiaming Zhang @ 2026-12-05 10:06 UTC (permalink / raw)
  To: Carlos Maiolino, linux-xfs
  Cc: Darrick J. Wong, Eric Sandeen, linux-kernel, Jiaming Zhang, stable

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05 10:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 10:06 [PATCH] xfs: exclude unlogged remote blocks from attr set log reservation Jiaming Zhang

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®