Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Andrey Albershteyn <aalbersh@kernel.org>
To: linux-xfs@vger.kernel.org
Cc: cem@kernel.org, cihan.cihan@gmail.com, cmaiolino@redhat.com,
	dchinner@redhat.com, dgc@kernel.org, djwong@kernel.org,
	floss@jetm.me, hch@lst.de, hemanth.selam@gmail.com,
	jiapenglin@tencent.com, johannes.thumshirn@wdc.com,
	kees+treewide@kernel.org, norbert@doyensec.com,
	syzbot+837bcd54843dd6262f2f@syzkaller.appspotmail.com,
	yijiangshan@kylinos.cn, yun.zhou@windriver.com,
	zenghongling@kylinos.cn
Subject: [PATCH 22/28] xfs: fix under-reservation of blocks when repairing sf directories
Date: Thu, 29 Oct 2026 13:06:19 +0100	[thread overview]
Message-ID: <20261029120631.803074-23-aalbersh@kernel.org> (raw)
In-Reply-To: <20261029120631.803074-1-aalbersh@kernel.org>

From: "Darrick J. Wong" <djwong@kernel.org>

Source kernel commit: 4d3c07591534517c633945c8d8e6526f10e3fabc

Whilst running QA on XFS for-next as of 7.3-rc2 with MKFS_OPTIONS="-n
size=8192", I observed the following (trimmed) dmesg splat:

XFS: Assertion failed: args->total >= dp->i_nblocks - nblks, file: fs/xfs/libxfs/xfs_da_btree.c, line: 2387
WARNING: fs/xfs/xfs_message.c:104 at assfail+0x46/0x4a [xfs], CPU#0: xfs_scrub/1426511
CPU: 0 UID: 0 PID: 1426511 Comm: xfs_scrub Tainted: G        W           7.3.0-rc2-djwx #rc2 PREEMPT(lazy)  6e418570b606a39783b0e7e7b30dc407b965f9e8
Tainted: [W]=WARN
RIP: 0010:assfail+0x46/0x4a [xfs]
RSP: 0018:ffffc900010d7890 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00000000ffffffd1
RDX: 0000000000000000 RSI: 0000000000000021 RDI: ffffffffa059fd38
RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000
R10: 000000000000000a R11: 000000007fffffff R12: ffffc900010d7940
R13: ffff888368d8f980 R14: ffffc900010d7a48 R15: ffffc900010d78d0
FS:  00007f445c5ce680(0000) GS:ffff8884a97ea000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f443803b9a8 CR3: 0000000107a4b000 CR4: 00000000003506f0
Call Trace:
<TASK>
xfs_da_grow_inode_int+0x2e0/0x300 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xfs_dir2_grow_inode+0x6e/0x150 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xfs_dir2_sf_to_block+0x149/0x870 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xrep_dir_swap_prep+0xe2/0x110 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xrep_dir_swap+0xfb/0x2f0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xrep_dir_rebuild_tree+0x99/0x100 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xrep_directory+0x83/0x1c0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xrep_attempt+0x4f/0x1e0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xfs_scrub_metadata+0x393/0x5b0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xfs_ioc_scrubv_metadata+0x306/0x570 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
xfs_file_ioctl+0xa4f/0x1150 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c]
__x64_sys_ioctl+0x76/0xc0
do_syscall_64+0x7a/0x3b0
entry_SYSCALL_64_after_hwframe+0x4b/0x53

This is a consequence of commit 0fe77e57588b98, which added the
following assertion to xfs_da_grow_inode_int:

ASSERT(args->total >= dp->i_nblocks - nblks);

Tracing this back to xrep_dir_swap_prep, I noticed that the xfs_da_args
object that's passed to xfs_dir2_sf_to_block sets args->total to 1.
This is incorrect because mkfs set the directory block size to 8k and
the filesystem block size to 4k.  In other words, args->total should be
2 here, not 1.

Dave Chinner tripped over the same problem with the same branch through
a different channel -- his test setup set the fs block size to 1k, in
which case the directory block size is still set to 4k.  Here,
args->total should be 4.

Changing the assignment of args->total to sc->mp->m_dir_geo->fsbcount
makes the assertion go away, but that isn't a complete fix.  In
xrep_tempexch_estimate, we also incorrectly assume that a shortform
conversion requires 1 fsblock when it should be m_dir_geo->fsbcount.
Without that, we can under-reserve space in the transaction and cause a
filesystem shutdown.

Note that the xfs_dabuf_nfsb helper will compute the correct value for
directories and xattr, so we use that instead of open-coding the logic.
Also fix xrep_xattr_swap_prep to assign args->total via xfs_dabuf_nfsb
to avoid one logic bomb if we ever support multi-fsblock attrs.

Cc: floss@jetm.me
Reported-by: dgc@kernel.org
Fixes: 629fdaf5f5b1b7 ("xfs: use atomic extent swapping to fix user file fork data")
Tripped-by: 0fe77e57588b98 ("xfs: assert the reservation covers each da fork growth")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
 libxfs/xfs_da_btree.c | 2 +-
 libxfs/xfs_da_btree.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c
index 8cbdd6574755..3d02a0d7ba44 100644
--- a/libxfs/xfs_da_btree.c
+++ b/libxfs/xfs_da_btree.c
@@ -130,7 +130,7 @@ xfs_da_state_reset(
 	state->mp = state->args->dp->i_mount;
 }
 
-static inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
+inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
 {
 	if (whichfork == XFS_DATA_FORK)
 		return mp->m_dir_geo->fsbcount;
diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h
index afcf2d3c7a21..a718b1ceb0aa 100644
--- a/libxfs/xfs_da_btree.h
+++ b/libxfs/xfs_da_btree.h
@@ -244,4 +244,6 @@ xfs_failaddr_t xfs_da3_node_header_check(struct xfs_buf *bp, xfs_ino_t owner);
 
 extern struct kmem_cache	*xfs_da_state_cache;
 
+int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork);
+
 #endif	/* __XFS_DA_BTREE_H__ */
-- 
2.54.0


  parent reply	other threads:[~2026-10-29 12:10 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 12:05 [PATCH 00/28] xfsprogs: libxfs sync for v7.3 Andrey Albershteyn
2026-10-29 12:05 ` [PATCH 01/28] xfs: add xfs_metadir_create_file helper Andrey Albershteyn
2026-10-29 12:05 ` [PATCH 02/28] xfs: create quota metadir inodes using xfs_metadir_create_file Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 03/28] xfs: create rtgroup " Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 04/28] xfs: mark internal metadir file creation helpers static Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 05/28] xfs: use kmalloc_objs() instead of kmalloc() in xfs_da_grow_inode_int Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 06/28] xfs: remove spurious XBF_DONE clearing on readahead validation failure Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 07/28] xfs: hide b_flags manipulation from code outside of xfs_buf.c Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 08/28] xfs: validate attr entry pointer before field access Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 09/28] xfs: don't hold buffer locks across sync transaction commit in xfs_sync_sb_buf Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 10/28] treewide: refresh kmalloc_obj() conversions Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 11/28] xfs: fix exchange-range reflink flag clearing issue with INO1_WRITTEN Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 12/28] xfs: initialise error in xfs_defer_finish_one() Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 13/28] xfs: give the deferred barrier op type a name Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 14/28] xfs: report the error that made deferred work shut down the fs Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 15/28] xfs: correct the parent pointer space reservation comment Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 16/28] xfs: initialise args->total for parent pointer updates Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 17/28] xfs: assert the reservation covers each da fork growth Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 18/28] xfs: fix the rtrmap and rtrefcount _maxlevels_ondisk functions Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 19/28] xfs: fix xfs_rtrmapbt_mem_cursor for non-rmap filesystems Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 20/28] xfs: preserve owner on in-memory btree creation Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 21/28] xfs: don't leak new_bp if xfs_btree_bload_drop_buf fails Andrey Albershteyn
2026-10-29 12:06 ` Andrey Albershteyn [this message]
2026-10-29 12:06 ` [PATCH 23/28] xfs: remove duplicate INO1_WRITTEN check Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 24/28] xfs: fix typos and repeated words in comments Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 25/28] xfs: don't let hidden_space go negative in xfs_metafile_resv_init Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 26/28] xfs: fix wild memcpy access when formatting ondisk rtrefcount btree roots Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 27/28] xfs: stop exchanging reflink flags when exchanging mappings Andrey Albershteyn
2026-10-29 12:06 ` [PATCH 28/28] xfs: fix exchange-range-to-eof file size exchange Andrey Albershteyn
2026-10-29 12:25 ` [PATCH 00/28] xfsprogs: libxfs sync for v7.3 Christoph Hellwig

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=20261029120631.803074-23-aalbersh@kernel.org \
    --to=aalbersh@kernel.org \
    --cc=cem@kernel.org \
    --cc=cihan.cihan@gmail.com \
    --cc=cmaiolino@redhat.com \
    --cc=dchinner@redhat.com \
    --cc=dgc@kernel.org \
    --cc=djwong@kernel.org \
    --cc=floss@jetm.me \
    --cc=hch@lst.de \
    --cc=hemanth.selam@gmail.com \
    --cc=jiapenglin@tencent.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=kees+treewide@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=norbert@doyensec.com \
    --cc=syzbot+837bcd54843dd6262f2f@syzkaller.appspotmail.com \
    --cc=yijiangshan@kylinos.cn \
    --cc=yun.zhou@windriver.com \
    --cc=zenghongling@kylinos.cn \
    /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