From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796199544; b=SjuETGK1yOEAIqyon6wBQTvyyw7nC4AthapRbQcpITgHrqWR1cyoY+aQkbBzB5A9SMMH 4c2qTxRAViaLZdD6b5qK/1XhbiwfgwCGu9ApB2FJjIZavXF2qyUycRDK7sOsNntJEpm+S HTloqLUtPxI/aEEuzfZFIRAyUvsU9AXu383SYNo8H2EgjclNCNb5attM0LowUm9l4HgYw voJiNKwOFJ9SXCYXReLVK6X2PYGmEA2WjMNMAUtHE9SEm/m9ymd/t21ubTGHR/Wo0kL2u +ZU+wHW5/uxXLQDjaOmNFllU+XrWMabQnr1zTsj+HCvYHOAGCvoPpd6xdfHqJlTgsbw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796199544; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=mQnwvjjTq/i+0Etx3k39Jrkhf62bzv0vML8aoRXWtm4=; b=NRPvVbkEptWunywzlY4d0ZUQiK3bKdAIvvJI6DLVy1mM9pVVGE3zfA/z5RPmW8zSZyTH 6acWhfX20NcNR8OMc+mkvOqZBEsEj+IcbckcqJkX6o2ikQL0ZyHEzkYaUE1OzyfAfBZAe craDYNeXu0mQQXqriUrkhcPa+z88ys2f2vDyoWS1WeYfkJqok1cWnKIp79pJ1PVl0S+rt zuZqvXjnvgwdB2UNwhb4zvshf8J6YHVqLYYHu1JMgCmMK9T9eb07az8kzQnoFjEXAxsoN vt2GKK6fTchJnlKDFZceaIWnoa6tho1GCpwWgPIhIxmX/MM5Q5f8FPMT6Apu0gto5kA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jrMmFkJw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9735A606A331 for ; Wed, 2 Dec 2026 08:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jrMmFkJw Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2A2B1F0089C; Wed, 2 Dec 2026 08:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796199543; bh=mQnwvjjTq/i+0Etx3k39Jrkhf62bzv0vML8aoRXWtm4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jrMmFkJwhLt2PVv++Rp1du0vW1xlWY03dOiZUzVzEraeNJ3VUT3//s9gm1E2TT4z4 ODaCLTNhRT7Q4FE6R4uNEPa1YzAI2jtk3YK3YoAa0dis+n1LvzIKlA07CSAMQ6U+0Z uQn+Ac2Hq6cfeoYUOYvTLSOgkQj5utTQNsWFJbuqApZzxv3XDkerdSFFs6DwD94zz7 Wrxr0Te/CADuPUPeEeCYVGo25Dw8251vzharaPL8XZspMtLeNCBaR2K0V5l6WbcDyJ ctV5InPJky2ZRZKFKJdIjU6e26PJFygKjO5nQ/k40lPHwZLukvN2sOemDmJioTDHXx wRc2GW8LomVDQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] iomap: disable I/O polling when direct I/O must wait Reply-To: sashiko-reviews@lists.linux.dev To: Fengnan Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: <84dd8106-5b90-4245-a44c-59375382e54f@bytedance.com> References: <20261201034922.203226-1-changfengnan@bytedance.com> <20261201-dagegen-dorthin-feinschliff-8edb53131611@brauner> <0afaa2fd-95d8-4b83-b863-bce2cc267ac4@bytedance.com> <84dd8106-5b90-4245-a44c-59375382e54f@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 08:19:03 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > iomap: disable I/O polling when direct I/O must wait >=20 > =E5=9C=A8 02/12/26 09:56, Fengnan =E5=86=99=E9=81=93: > > > > > > =E5=9C=A8 01/12/26 21:26, Christian Brauner =E5=86=99=E9=81=93: > >> On Tue, Dec 01, 2026 at 03:49:22AM +0000, Fengnan Chang wrote: > >>> + if (wait_for_completion) > >>> + iocb->ki_flags &=3D ~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. >=20 > Hi Christian, >=20 > 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. >=20 > 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() avoi= ds 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_it= er *iter, > =20 > atomic_inc(&dio->ref); > =20 > - /* 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 =3D=3D iocb->ki_pos && bio->bi_iter.bi_size =3D=3D iter->len) { > bio->bi_opf |=3D REQ_POLLED; > WRITE_ONCE(iocb->private, bio); > } [Severity: High] Can iocb_bio_iopoll() hit a use-after-free on the bio stored in iocb->priva= te 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 >=3D 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 >=3D i_size_read(inode))) { /* zero out from the end of the write to the end of the block */ pad =3D 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 n= ot 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 =3D=3D iocb->ki_pos && bio->bi_iter.bi_size =3D=3D 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-zeroi= ng bio is still in flight. iomap_dio_done() does not run to complete the kioc= b, leaving iocb->private pointing to the freed bio while subsequent iopoll pas= ses continue polling it. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/84dd8106-5b90-4245-= a44c-59375382e54f@bytedance.com?part=3D1