xfs: fix an AGI lock acquisition ordering problem in xrep_dinode_findmode
authorDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:54:04 +0000 (14:54 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:54:04 +0000 (14:54 -0700)
commit2afd5276d314d775ae0bdaa6ec22069515bd9c70
treeb9002ba772eb5dd152cd5fac566b5e8124ccafc0
parent549d3c9a29921f388ef3bcfd1d4f669b7dd4eed2
xfs: fix an AGI lock acquisition ordering problem in xrep_dinode_findmode

While reviewing the next patch which fixes an ABBA deadlock between the
AGI and a directory ILOCK, someone asked a question about why we're
holding the AGI in the first place.  The reason for that is to quiesce
the inode structures for that AG while we do a repair.

I then realized that the xrep_dinode_findmode invokes xchk_iscan_iter,
which walks the inobts (and hence the AGIs) to find all the inodes.
This itself is also an ABBA vector, since the damaged inode could be in
AG 5, which we hold while we scan AG 0 for directories.  5 -> 0 is not
allowed.

To address this, modify the iscan to allow trylock of the AGI buffer
using the flags argument to xfs_ialloc_read_agi that the previous patch
added.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/scrub/inode_repair.c
fs/xfs/scrub/iscan.c
fs/xfs/scrub/iscan.h
fs/xfs/scrub/trace.h