All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Fengnan <changfengnan@bytedance.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] iomap: disable I/O polling when direct I/O must wait
Date: Wed, 02 Dec 2026 08:19:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-245146@kernel.org> (raw)
In-Reply-To: <84dd8106-5b90-4245-a44c-59375382e54f@bytedance.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] iomap: missing Signed-off-by trailer in commit message
- [High] iomap: polled bio use-after-free when iomap_dio_bio_iter()
  zeroes EOF tail
- [Low] iomap: raw mailing-list reply thread used as commit changelog
- [Low] iomap: missing Fixes trailer for commit 9650b453a3d4 in
  changelog
--

commit 4454ee3e347dd167e855abb07789ca87cc412b12
Author: Fengnan <changfengnan@bytedance.com>

> iomap: disable I/O polling when direct I/O must wait
> 
> 在 02/12/26 09:56, Fengnan 写道:
> >
> >
> > 在 01/12/26 21:26, Christian Brauner 写道:
> >> On Tue, Dec 01, 2026 at 03:49:22AM +0000, Fengnan Chang wrote:
> >>> +   if (wait_for_completion)
> >>> +           iocb->ki_flags &= ~IOCB_HIPRI;
> >>
> >> One question. wait_for_completion can also flip to true after we've
> >> already submitted, no?
> >>
> >> * partial -EFAULT with IOMAP_DIO_PARTIAL
> >> * -ENOTBLK fallback
> >>
> >> In both cases it's set after the iomap_iter() loop.
> >>
> >> By then the first bio might have gone out with REQ_POLLED. Can't that
> >> end up in the same stall? I might misunderstand.
> >>
> > Yes, you're right, thanks. Both the IOMAP_DIO_PARTIAL -EFAULT case and
> > the -ENOTBLK fallback set wait_for_completion after the iomap_iter()
> > loop, when the first bio may already have been submitted with
> > REQ_POLLED, so they can hit the same stall.
> >
> > Clearing IOCB_HIPRI up front can't cover those. For v2 I plan to poll
> > from the wait loop instead, i.e. call iocb_bio_iopoll() while
> > iocb->private is set and fall back to blk_io_schedule() otherwise,
> > similar to what the loop did before sync polling was removed. That
> > covers the FORCE_WAIT case and both late paths. I'll send v2 after
> > testing it.
> 
> Hi Christian,
> 
> A correction to my plan: polling from the wait loop doesn't work.
> blk_hctx_poll() gives up after two jiffies and no longer keeps the task
> running, so the waiter can sleep with nothing to wake it. I still saw
> 30 second stalls with it.
> 
> Instead I'd only poll a bio that carries the whole request:

[Severity: High]
The commit message is missing a Signed-off-by: trailer.

[Severity: Low]
The commit message body is an unedited mailing-list reply thread rather than
a standalone changelog explaining why __iomap_dio_rw() stalls when waiting on
a REQ_POLLED bio and how restricting polling in iomap_dio_submit_bio() avoids
it.

[Severity: Low]
This fixes the incomplete !is_sync_kiocb(iocb) check introduced when
synchronous DIO polling was removed.  Should it include:

  Fixes: 9650b453a3d4 ("block: ignore RWF_HIPRI hint for sync dio")

> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index f00b0841fdd08..6bc82a351cdbc 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -68,8 +68,14 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter,
>  
>  	atomic_inc(&dio->ref);
>  
> -	/* Sync dio can't be polled reliably */
> -	if ((iocb->ki_flags & IOCB_HIPRI) && !is_sync_kiocb(iocb)) {
> +	/*
> +	 * Only poll a bio that starts at the beginning of the request and
> +	 * carries all of it, and only if the dio does not wait for completion.
> +	 * Once that bio is submitted the iteration is done, so a short I/O
> +	 * can't make __iomap_dio_rw() wait for it later.
> +	 */
> +	if ((iocb->ki_flags & IOCB_HIPRI) && !dio->wait_for_completion &&
> +	    pos == iocb->ki_pos && bio->bi_iter.bi_size == iter->len) {
>  		bio->bi_opf |= REQ_POLLED;
>  		WRITE_ONCE(iocb->private, bio);
>  	}

[Severity: High]
Can iocb_bio_iopoll() hit a use-after-free on the bio stored in iocb->private
when iomap_dio_bio_iter() submits a second bio to zero the EOF tail?

__iomap_dio_rw() only sets IOMAP_DIO_COMP_WORK when iomi.pos + iomi.len >
dio->i_size, whereas iomap_dio_bio_iter() zeroes the tail block whenever
pos >= i_size_read(inode) and pos is not aligned to fs_block_size:

fs/iomap/direct-io.c:iomap_dio_bio_iter() {
	...
	if (need_zeroout ||
	    ((dio->flags & IOMAP_DIO_WRITE) && pos >= i_size_read(inode))) {
		/* zero out from the end of the write to the end of the block */
		pad = pos & (fs_block_size - 1);
		if (pad)
			iomap_dio_zero(iter, dio, pos, fs_block_size - pad);
	}
	...
}

For a non-extending async direct write to an already-mapped extent ending
exactly at an i_size that is aligned to the device logical block size but not
to fs_block_size (for example on ext4 or gfs2), wait_for_completion is false
and IOMAP_DIO_COMP_WORK is not set, so IOCB_HIPRI remains set.  The data bio
satisfies pos == iocb->ki_pos && bio->bi_iter.bi_size == iter->len, so
iomap_dio_submit_bio() marks it REQ_POLLED and stores it in iocb->private,
and iomap_dio_zero() then submits a second non-polled bio that increments
dio->ref.

CPU0 (io_uring iopoll)            CPU1 (zero bio IRQ)
----------------------            -------------------
io_do_iopoll()
  iocb_bio_iopoll()
    bio_poll(iocb->private)
      __iomap_dio_bio_end_io()
        bio_put(bio)
        atomic_dec_and_test(&dio->ref)
          -> false (zero bio in flight)

io_do_iopoll()
  iocb_bio_iopoll()
    bio_poll(iocb->private)  <-- use-after-free
                                  __iomap_dio_bio_end_io()
                                    atomic_dec_and_test(&dio->ref)
                                    iomap_dio_done()

When the polled data bio completes, __iomap_dio_bio_end_io() frees it via
bio_put(), but atomic_dec_and_test(&dio->ref) is false while the tail-zeroing
bio is still in flight.  iomap_dio_done() does not run to complete the kiocb,
leaving iocb->private pointing to the freed bio while subsequent iopoll passes
continue polling it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/84dd8106-5b90-4245-a44c-59375382e54f@bytedance.com?part=1

  reply	other threads:[~2026-12-02  8:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  3:49 [PATCH] iomap: disable I/O polling when direct I/O must wait Fengnan Chang
2026-12-01  4:06 ` sashiko-bot
2026-12-01  8:08 ` Christoph Hellwig
2026-12-01  8:48   ` Fengnan Chang
2026-12-01 13:25 ` Christian Brauner
2026-12-01 13:26 ` Christian Brauner
2026-12-02  1:56   ` Fengnan
2026-12-02  7:53     ` Fengnan
2026-12-02  8:19       ` sashiko-bot [this message]
2026-12-02  8:20       ` Christoph Hellwig
2026-12-02  8:43         ` changfengnan

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-245146@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=changfengnan@bytedance.com \
    --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.