From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796465214; b=p5imn0a8HgX5vtYQZ24Piq9DKV9LckPNbvXTpYO4/dMq4i3T5tLwOyM7YhHOSJ1vJl+t IHViLXMaTP3u7zOZ07iQw/LdTmjjxI9pJnfUg5m0tHRKQvUGzKQjvhLQoswcNNmsJBD3y NIe0V6IcLUIU3whl93Zuz4C75cCOUSxbIEI8+vTbdI7DQBnLXUnqnYf/lg1ZWclufI3TY JP8R6WVAFyv5U9ugcCwJbjmJzVDpuKpWXdqKh0x74JmkiE1/0xRClgazHOEpkEGnV+pmL j96dOOYTKQb3rNa1oYIJAIiaNA5kpcdzAEGdUXbl/90Rhhx0SOxIsE0Ny1CzEvs2ptg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796465214; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=be2cYY1kcz4lTb32EB8lEH9cPT3LeL8YKYLRbuILN5k=; b=0DlbsuGgJrS2AZKkx5UeNl/cM6j276OyVdn97txtATwEWNO0cnW4P/xW3azLfbt1vvuO jFYrkSKsig5I6G0ZPCDUagfiYM5hEjX8BLMpYuwT893+3xyAxEv6mLkMTu3gJD7howU30 zh7qaVQL8WNRBaGfIdbB4HKdiz3+/PVOXelqBri9dK6Oh16oW4P8Kgy/DmaY0U2RUgTG5 RTjRyqMPHpkfiJ/KiBvrT58ashaxjoPE6VAlHIC/aVes4LksnwFRojA0q02hCopola8rL 37sYUBIb58h7M6nLrR1OU60eB7HffcJOHNf7XC8sA4IGZVD9clxRlWVrXtm6ZkQ8kiw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=DC2jq7DT; arc=none smtp.remote-ip=209.85.215.181 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 500E9606A335 for ; Sat, 5 Dec 2026 10:06:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 500E9606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=DC2jq7DT Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-ce103a1cf0eso1304878a12.0 for ; Sat, 05 Dec 2026 02:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796465214; x=1797070014; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=be2cYY1kcz4lTb32EB8lEH9cPT3LeL8YKYLRbuILN5k=; b=DC2jq7DThNXu5fqIJ+s6jgL6Ket/L+Sh/84cw6JdrAG61dikrDoc0L6uAIFXoGEhsl hKeiIAVtIlMT1XYD0pDx5nOy7psMkwPGv8VA7YDrRTYieOxA8NDTB75J3cpqkWtO8l4N nK7mg878W4Z5eD6ydKMmKx6ZwN7UE5KRw9eKzGU2wGoExIbjNfEOb0I27WuKFFA28I9g YcS2Prp/9AN2gAupHNLAiInOTqCPL7Qx1k9nCUK390SeBYJg+HaDPSHiVEczhovc58fx 5Yz+DLfNsncsPGD/ZkAOcwCmQY1C1uk3HZNebA5ss10rNQaSSUZpfJ85OgLEHhzVJZ2t NDog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796465214; x=1797070014; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=be2cYY1kcz4lTb32EB8lEH9cPT3LeL8YKYLRbuILN5k=; b=0PbVSEbOpCkUL1+I0HsJgcjtmbGBD1KRUkeZsmLY+g+YepGj9A+5O7N7pEx+gl6rJl FbTgkx9Jt2kYTU9U3cK3ACiRaKs93b7JmIR9smdjjc2+PRi6Ab9zE/Dj4erElM54vf0o FQr/LrogrIn7IBS+V1GFbpm2rG9auXSytah8LMOiF/j7asfTBXZGXxf0uUJP7vFZpgPe 35miXt6Vl+EBNLps4opzmcwZKtRe+dc0x0G0cwAHPnnqN0llKIFwGUIlwONZUr+ioGqU dLBjU9XwM241OxNFMnyTZH+Ft029DV22K8ncCeaQlI43nCiApRlrfWsImjmiOfnmerXi My1A== X-Forwarded-Encrypted: i=1; AL+hErGqfVT5La/+LeMcAh2qt3QpNRW5V7EtcDwulq81nvmZ7Ici/B1yqg1AntJfmmgZhuswXnYaAgkRKRBcX+U=@vger.kernel.org X-Gm-Message-State: APuU4Z/z1lVzKm67tqznoGLbygtQmsvckkoz+tUb0Yw4H99AfO870PHC cmt0RIHVO9iUgotaDXmXpIapA0uhEEFCIRoocERLDC76WfbY8qLdgX6aq0CrRgY4RIg= X-Gm-Gg: AZFdTZfdYnKk/qf6z40sBvGVMTkBjSG2taC3VOO9LCssrsiC3//3CVkfngQmFIm0kwJ +Sloav1FtRLD2iPUlWp8FdHjxVANuMT8oY8IMWNy1n0anrl1ZpHFqh/eSR6o+Bxvz4m+UNn0o0y nl7IDtjLoKfMOvXJidka6lt8PA65nDH8W0mD/V+uWlWJSldzrgKlJ65Lfbda1G+zWuIBmOK3bKS cw/7yfrcsmJQxNPGvplTyo715Qn8XhXgS8JYWye2xv0qV/OyJ62G15LcQ8fdnaaFjpGbNtW4Yg3 4fmujYuTpk/i1yAHl1T0MMq1YivU8+BMe31Plh4R5aJgCwAHoz6b1UER5cAOcgziwY62l5gLwZC IO7tUxbELPOpEJB2ZNZVfsS3qjV9pwFNGmtgV2LQ0OfTTp3koMb3e/LUNw3zpa/iBRCd1neM3U+ 60dbpx9r/2SHAOKQbrKMIrohIiZLzTGc02R9s2o3Vz2SwHbIPcfB8r8dAiGQOlNOTJdwELcbn4K UNF8+S1Cs/4HJ1T/ToUgNPOfDl8HfNv7UJUZtaMwbpwrYNSbtWcH5Cx9yea1sT14IXM5zIqfpLs nnM6QVgaAGHjXjBiWOKkvsIPeiNDs0yI6Tun6gSqqg== X-Received: by 2002:a05:6a21:8cc1:b0:3e2:ea7:618 with SMTP id adf61e73a8af0-41561745001mr4489394637.18.1796465213365; Sat, 05 Dec 2026 02:06:53 -0800 (PST) Received: from ustb520lab-MS-7E07.. ([115.25.44.221]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ce1237e81c0sm2656666a12.26.2026.12.05.02.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 02:06:51 -0800 (PST) From: Jiaming Zhang To: Carlos Maiolino , linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Eric Sandeen , linux-kernel@vger.kernel.org, Jiaming Zhang , 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 Message-ID: <20261205100643.3353410-1-r772577952@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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