From: Carlos Maiolino <cem@kernel.org>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: hch@lst.de, stable@vger.kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 7/7] xfs: advance the findparent inode scan cursor while holding ILOCK
Date: Thu, 10 Sep 2026 09:35:48 +0200 [thread overview]
Message-ID: <aqJdzuFlmlpjFKSV@andromeda.toxiclabs.cc> (raw)
In-Reply-To: <178892936771.4057962.16778990010632981835.stgit@frogsfrogsfrogs>
On Tue, Sep 08, 2026 at 11:06:08PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> LOLLM pointed out a race condition in xrep_findparent_scan -- the
> directory live update hook holds the directory ILOCK when it calls the
> xchk_iscan_want_live_update predicate to figure out if it needs to
> remember the live update, but xrep_findparent_scan drops the directory
> ILOCK before advancing the cursor. Therefore, it's possible for a live
> update to check the scan cursor after the scan drops the ILOCK but
> before the scan updates its cursor. If this happens, we'll fail to
> record the live update. Fix this by moving the cursor update logic
> inside xrep_findparent_walk_directory.
>
> Note that for non-directories it's ok to advance the cursor without
> holding any ILOCK because the findparent scan only cares about directory
> parents, not the children.
>
> Cc: <stable@vger.kernel.org> # v6.10
> Fixes: a07b45576264e7 ("xfs: scan the filesystem to repair a directory dotdot entry")
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> Assisted-by: LOLLM # finding obvious bugs
> ---
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
> fs/xfs/scrub/findparent.c | 54 ++++++++++++++++++++++++++++++---------------
> 1 file changed, 36 insertions(+), 18 deletions(-)
>
>
> diff --git a/fs/xfs/scrub/findparent.c b/fs/xfs/scrub/findparent.c
> index 04b6b96b0a30ed..eab3ac2704befe 100644
> --- a/fs/xfs/scrub/findparent.c
> +++ b/fs/xfs/scrub/findparent.c
> @@ -139,32 +139,52 @@ xrep_findparent_dirent(
> return 0;
> }
>
> -/*
> - * If this is a directory, walk the dirents looking for any that point to the
> - * scrub target inode.
> - */
> -STATIC int
> -xrep_findparent_walk_directory(
> - struct xrep_findparent_info *fpi)
> +static inline bool
> +xrep_findparent_want_scan_file(
> + const struct xrep_findparent_info *fpi)
> {
> - struct xfs_scrub *sc = fpi->sc;
> - struct xfs_inode *dp = fpi->dp;
> - unsigned int lock_mode;
> - int error = 0;
> + const struct xfs_scrub *sc = fpi->sc;
> + const struct xfs_inode *dp = fpi->dp;
> +
> + /* Only directories can be parents */
> + if (!S_ISDIR(VFS_IC(dp)->i_mode))
> + return false;
>
> /*
> * The inode being scanned cannot be its own parent, nor can any
> * temporary directory we created to stage this repair.
> */
> if (dp == sc->ip || dp == sc->tempip)
> - return 0;
> + return false;
>
> /*
> * Similarly, temporary files created to stage a repair cannot be the
> * parent of this inode.
> */
> if (xrep_is_tempfile(dp))
> + return false;
> +
> + return true;
> +}
> +
> +/*
> + * If this is a directory, walk the dirents looking for any that point to the
> + * scrub target inode.
> + */
> +STATIC int
> +xrep_findparent_walk_file(
> + struct xrep_findparent_info *fpi)
> +{
> + struct xfs_scrub *sc = fpi->sc;
> + struct xfs_inode *dp = fpi->dp;
> + unsigned int lock_mode;
> + int error = 0;
> +
> + if (!xrep_findparent_want_scan_file(fpi)) {
> + if (fpi->parent_scan)
> + xchk_iscan_mark_visited(&fpi->parent_scan->iscan, dp);
> return 0;
> + }
>
> /*
> * Scan the directory to see if there it contains an entry pointing to
> @@ -201,6 +221,8 @@ xrep_findparent_walk_directory(
> goto out_unlock;
>
> out_unlock:
> + if (fpi->parent_scan)
> + xchk_iscan_mark_visited(&fpi->parent_scan->iscan, dp);
> xfs_iunlock(dp, lock_mode);
> return error;
> }
> @@ -308,11 +330,7 @@ xrep_findparent_scan(
> ASSERT(S_ISDIR(VFS_IC(sc->ip)->i_mode));
>
> while ((ret = xchk_iscan_iter(&pscan->iscan, &fpi.dp)) == 1) {
> - if (S_ISDIR(VFS_I(fpi.dp)->i_mode))
> - ret = xrep_findparent_walk_directory(&fpi);
> - else
> - ret = 0;
> - xchk_iscan_mark_visited(&pscan->iscan, fpi.dp);
> + ret = xrep_findparent_walk_file(&fpi);
> xchk_irele(sc, fpi.dp);
> if (ret)
> break;
> @@ -401,7 +419,7 @@ xrep_findparent_confirm(
> goto out_rele;
> }
>
> - error = xrep_findparent_walk_directory(&fpi);
> + error = xrep_findparent_walk_file(&fpi);
> if (error)
> goto out_rele;
>
>
>
next prev parent reply other threads:[~2026-09-10 7:35 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 6:02 [PATCHSET 2/2] xfs: LLM-inspired bug fixes, part 12 Darrick J. Wong
2026-09-09 6:04 ` [PATCH 1/7] xfs: fix under-reservation of blocks when repairing sf directories Darrick J. Wong
2026-09-10 5:00 ` Christoph Hellwig
2026-09-10 5:31 ` Carlos Maiolino
2026-09-10 6:09 ` Darrick J. Wong
2026-09-10 6:27 ` Carlos Maiolino
2026-09-10 9:43 ` Christoph Hellwig
2026-09-10 15:08 ` Darrick J. Wong
2026-09-11 4:42 ` [PATCH v1.1 " Darrick J. Wong
2026-09-11 7:29 ` Carlos Maiolino
2026-09-11 11:46 ` Christoph Hellwig
2026-09-09 6:04 ` [PATCH 2/7] xfs: actually check internal-rtdev fields in the superblock Darrick J. Wong
2026-09-10 5:42 ` Carlos Maiolino
2026-09-11 7:29 ` Carlos Maiolino
2026-09-09 6:05 ` [PATCH 3/7] xfs: fix rtrmap cross-referencing elision logic Darrick J. Wong
2026-09-10 5:01 ` Christoph Hellwig
2026-09-10 5:46 ` Carlos Maiolino
2026-09-09 6:05 ` [PATCH 4/7] xfs: fix termination logic in xchk_bmap Darrick J. Wong
2026-09-10 5:01 ` Christoph Hellwig
2026-09-10 5:47 ` Carlos Maiolino
2026-09-09 6:05 ` [PATCH 5/7] xfs: fix replaying dirent removals into the temporary directory Darrick J. Wong
2026-09-10 5:01 ` Christoph Hellwig
2026-09-10 5:51 ` Carlos Maiolino
2026-09-09 6:05 ` [PATCH 6/7] xfs: reset parent pointer args before each dir tree unlink repair Darrick J. Wong
2026-09-10 5:02 ` Christoph Hellwig
2026-09-10 5:59 ` Carlos Maiolino
2026-09-09 6:06 ` [PATCH 7/7] xfs: advance the findparent inode scan cursor while holding ILOCK Darrick J. Wong
2026-09-10 5:04 ` Christoph Hellwig
2026-09-10 7:35 ` Carlos Maiolino [this message]
2026-09-11 7:28 ` [PATCHSET 2/2] xfs: LLM-inspired bug fixes, part 12 Carlos Maiolino
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=aqJdzuFlmlpjFKSV@andromeda.toxiclabs.cc \
--to=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
--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