All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrey Albershteyn" <aalbersh@kernel.org>,
	linux-ext4 <linux-ext4@vger.kernel.org>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Christoph Hellwig" <hch@lst.de>,
	"Carlos Maiolino" <cem@kernel.org>,
	fsverity <fsverity@lists.linux.dev>
Cc: "Christian Brauner" <brauner@kernel.org>,
	david@fromorbit.com, dsterba@suse.cz, tytso@mit.edu
Subject: Re: [PATCH v20 14/23] xfs: use read ioend for fsverity data verification
Date: Wed, 02 Dec 2026 17:15:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-246315@kernel.org> (raw)
In-Reply-To: <20261202165653.767961-15-aalbersh@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] xfs: workqueue deadlock on mempool_alloc() in xfs_end_io_read()
--

commit 8bb973f44a8ada1e9937d03966b5a5b1e3c30932
Author: Andrey Albershteyn <aalbersh@kernel.org>

xfs: use read ioend for fsverity data verification

This commit uses read ioends to defer fsverity data verification to the
fsverity workqueue, passing fsverity_info down from the iomap read context.

> diff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c
> index 7f4a4a95afe50..61f211a3b8052 100644
> --- a/fs/xfs/xfs_ioend.c
> +++ b/fs/xfs/xfs_ioend.c
> @@ -18,7 +18,26 @@
>  #include "xfs_ioend.h"
>  #include "xfs_error.h"
>  #include "xfs_errortag.h"
> +#include "xfs_fsverity.h"
>  #include <linux/bio-integrity.h>
> +#include <linux/fsverity.h>
> +
> +static void
> +xfs_end_fsverity_io_read(
> +	struct work_struct		*work)
> +{
> +	struct xfs_fsverity_ioend	*fsv_ioend =
> +			container_of(work, struct xfs_fsverity_ioend, work);
> +	struct iomap_ioend		*ioend = fsv_ioend->ioend;
> +	struct bio			*bio = &ioend->io_bio;
> +
> +	mempool_free(fsv_ioend, &xfs_fsverity_ioend_pool);
> +
> +	if (!bio->bi_status)
> +		fsverity_verify_bio(ioend->io_vi, bio);
> +
> +	iomap_finish_ioends(ioend, blk_status_to_errno(bio->bi_status));
> +}

[ ... ]

> @@ -117,6 +138,24 @@ xfs_end_io_read(
>  		}
>  	}
>  
> +	/*
> +	 * If we have fsverity on this bio, we need to run fsverity verification
> +	 * of data folios from a separate fsverity workqueue. This is necessary
> +	 * to avoid deadlocking due to fsverity issuing more reads of fsverity
> +	 * metadata which would be processed by the same worker in the BIO
> +	 * completion workqueue.
> +	 */
> +	if (IS_ENABLED(CONFIG_FS_VERITY) && !error && ioend->io_vi &&
> +			xfs_fsverity_is_file_data(ip, ioend->io_offset)) {
> +		fsv_ioend = mempool_alloc(&xfs_fsverity_ioend_pool,
> +				GFP_NOFS);
> +		fsv_ioend->ioend = ioend;
> +		INIT_WORK(&fsv_ioend->work, xfs_end_fsverity_io_read);
> +
> +		fsverity_enqueue_verify_work(&fsv_ioend->work);
> +		return;
> +	}
> +
>  	iomap_finish_ioends(ioend, error);
>  }

[Severity: High]
Can mempool_alloc(&xfs_fsverity_ioend_pool, GFP_NOFS) here deadlock
bio_complete_wq against fsverity_read_workqueue?

xfs_ioend_submit_read() sets BIO_COMPLETE_IN_TASK, so xfs_end_io_read()
runs from bio_complete_work_fn() on the per-CPU bio_complete_wq.
Because bio_complete_batch has a single work_struct per CPU and drains
completed bios sequentially, blocking in xfs_end_io_read() stalls all
later BIO_COMPLETE_IN_TASK completions queued on that CPU.

Meanwhile, fsv_ioend is only returned to xfs_fsverity_ioend_pool once
xfs_end_fsverity_io_read() begins executing on fsverity_read_workqueue.
Under memory pressure, if the active fsverity_read_workqueue workers are
blocked in fsverity_verify_bio() waiting for Merkle tree metadata reads
or memory reclaim, pending work items on fsverity_read_workqueue can
hold all 128 preallocated pool elements:

bio_complete_wq                   fsverity_read_workqueue
---------------                   -----------------------
bio_complete_work_fn()            xfs_end_fsverity_io_read()
  (128 data bios allocate           fsverity_verify_bio()
   fsv_ioend and queue work)          read_merkle_tree_page()
                                        (waits for metadata read /
                                         reclaim BIO_COMPLETE_IN_TASK
                                         completion on bio_complete_wq)
  xfs_end_io_read() (129th bio)
    mempool_alloc(&xfs_fsverity_ioend_pool, GFP_NOFS)
      <-- sleeps waiting for queued xfs_end_fsverity_io_read()
          to call mempool_free()

 *** DEADLOCK ***

When bdev_has_integrity_csum() is true, xfs_get_iomap_read_ops() selects
xfs_iomap_read_ops for Merkle tree metadata reads as well, so their
completions also require bio_complete_work_fn() on bio_complete_wq, as
do failed metadata read bios that defer completion via
bio_complete_in_task() in iomap_read_end_io() and reclaim I/O
completions on bio_complete_wq.

Could fsv_ioend be allocated before submit_bio() (or embedded in the
read ioend) so the bio completion path never blocks on the mempool?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202165653.767961-1-aalbersh@kernel.org?part=14

  reply	other threads:[~2026-12-02 17:15 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 16:56 [PATCH v20 00/23] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 01/23] fs: constify inode argument of inode_state_read_once() Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 02/23] fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 03/23] fs,fsverity: add I_VERITY_BUILDING inode state flag Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] [PATCH v20 03/23] fs, fsverity: " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 04/23] fs,fsverity: reject S_APPEND on fsverity inodes Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] [PATCH v20 04/23] fs, fsverity: " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 05/23] iomap: use fsverity_is_building() to check for fsverity IO Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:09   ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 06/23] btrfs: use I_VERITY_BUILDING instead of private flags Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 07/23] ext4: " Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 08/23] f2fs: " Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 09/23] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 10/23] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 11/23] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 12/23] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 13/23] xfs: handle fsverity I/O in write/read path Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:28   ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 14/23] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:15   ` sashiko-bot [this message]
2026-12-02 16:56 ` [PATCH v20 15/23] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:09   ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 16/23] xfs: don't remove written extents past EOF on fsverity inodes Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 17/23] xfs: add fs-verity support Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 18/23] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 19/23] xfs: add fs-verity ioctls Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 20/23] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 21/23] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:35   ` sashiko-bot
2026-12-02 17:35     ` sashiko-bot--- via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 22/23] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:17   ` sashiko-bot
2026-12-02 17:17     ` sashiko-bot--- via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 23/23] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-12-02 16:56   ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:17   ` sashiko-bot
2026-12-02 17:17     ` sashiko-bot--- via Linux-f2fs-devel

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=sashiko-outbox-246315@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aalbersh@kernel.org \
    --cc=brauner@kernel.org \
    --cc=cem@kernel.org \
    --cc=david@fromorbit.com \
    --cc=dsterba@suse.cz \
    --cc=ebiggers@kernel.org \
    --cc=fsverity@lists.linux.dev \
    --cc=hch@lst.de \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.