From: sashiko-bot@kernel.org
To: "Ojaswin Mujoo" <ojaswin@linux.ibm.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v2 05/13] ext4: add support to track convert pending ranges in ext4_map_blocks()
Date: Fri, 27 Nov 2026 17:19:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-237982@kernel.org> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-5-4106968e4d15@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ext4: double delalloc reservation update on retry in
__ext4_es_insert_extent()
- [Medium] ext4: ext4_map_blocks() clamping on CONVERT_PENDING splits
ioend and atomic IO
--
commit f21d7f26169cb4b1b89944929ad98cc0819cca34
Author: Ojaswin Mujoo <ojaswin@linux.ibm.com>
ext4: add support to track convert pending ranges in ext4_map_blocks()
This commit adds the EXT4_GET_BLOCKS_CONVERT_PENDING flag so that
ext4_map_blocks() and ext4_map_create_blocks() can mark unwritten ranges
in the extent status tree as EXTENT_STATUS_CONVERT_PENDING before I/O
submission.
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index f7fc5fb7e8197..3e4c0e1396ab1 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -750,6 +750,9 @@ int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
>
> status = map->m_flags & EXT4_MAP_UNWRITTEN ?
> EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
> + if (status == EXTENT_STATUS_UNWRITTEN &&
> + flags & EXT4_GET_BLOCKS_CONVERT_PENDING)
> + status = EXTENT_STATUS_CONVERT_PENDING;
> ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk,
> status, flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE);
> map->m_seq = READ_ONCE(EXT4_I(inode)->i_es_seq);
[Severity: Medium]
Can passing EXTENT_STATUS_CONVERT_PENDING to ext4_es_insert_extent() cause
__ext4_es_insert_extent() to deduct delayed allocation reservations twice
when __es_insert_extent() retries after -ENOMEM?
Previously, ext4_es_insert_extent() only inserted WRITTEN or UNWRITTEN
extents, for which ext4_es_must_keep() is false, so an -ENOMEM from
__es_insert_extent() was cleared to 0. Because ext4_es_must_keep() is
true for EXTENT_STATUS_CONVERT_PENDING, an initial GFP_ATOMIC failure in
__es_insert_extent() after __es_remove_extent() has already removed the
delayed extent (setting resv_used > 0) jumps to error:
fs/ext4/extents_status.c:__ext4_es_insert_extent() {
...
err2 = __es_insert_extent(inode, &newes, es2);
if (err2 == -ENOMEM && !ext4_es_must_keep(&newes))
err2 = 0;
if (err2 != 0)
goto error;
...
error:
write_unlock(&EXT4_I(inode)->i_es_lock);
resv_used += pending;
if (resv_used)
ext4_da_update_reserve_space(inode, resv_used,
delalloc_reserve_used);
if (err1 || err2 || err3 < 0)
goto retry;
}
Because resv_used and pending are initialized outside the retry loop and
__es_remove_extent() returns early on the retry pass without modifying
resv_used when no extents remain in the range, the second pass calls
ext4_da_update_reserve_space() again with the same resv_used count. This
underflows i_reserved_data_blocks, triggers a WARN_ON(1) in
ext4_da_update_reserve_space(), and corrupts delalloc block and quota
accounting.
> @@ -911,8 +914,17 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
> }
>
> /* If it is only a block(s) look up */
> - if ((flags & EXT4_GET_BLOCKS_CREATE) == 0)
> + if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
> + if (map->m_flags & EXT4_MAP_UNWRITTEN &&
> + flags & EXT4_GET_BLOCKS_CONVERT_PENDING &&
> + !ext4_map_mark_convert_pending(inode, map)) {
> + map->m_flags = 0;
> + map->m_len = orig_mlen;
> + goto create_retry;
> + }
> +
> return retval;
> + }
[Severity: Medium]
Does marking sub-ranges of an unwritten extent as
EXTENT_STATUS_CONVERT_PENDING fragment the extent status tree and clamp
later ext4_map_blocks() lookups across a contiguous on-disk unwritten
extent?
Because ext4_es_can_be_merged() refuses to merge any extent where
ext4_es_is_convert_pending() is true, each I/O submission over part of an
unwritten extent leaves a separate CONVERT_PENDING entry in i_es_tree, and
ext4_map_blocks() clamps map->m_len to a single es entry on cache hit.
When iomap merges completed ioends across a single on-disk unwritten
extent, ext4_convert_unwritten_extents() now has map.m_len clamped to each
unmerged CONVERT_PENDING entry, forcing ext4_split_convert_extents() to
repeatedly split and re-merge the on-disk extent on every sub-range. In
addition, if an atomic write (ext4_map_blocks_atomic_write()) queries a
contiguous on-disk unwritten extent that contains a CONVERT_PENDING
sub-range in i_es_tree, ext4_map_blocks() returns ret < m_len,
misclassifying the extent as a mixed mapping and demoting the atomic write
to ext4_map_blocks_atomic_write_slow() (synchronous zeroout and
ext4_force_commit()).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com?part=5
next prev parent reply other threads:[~2026-11-27 17:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:10 [PATCH v2 00/13] ext4: fix endio zeroout corruption by tracking to-be-converted unwritten IOs Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 01/13] ext4: disable zeroout fallback in ext4_split_extent() Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 02/13] ext4: introduce CONVERT_PENDING extent status type Ojaswin Mujoo
2026-11-27 15:58 ` sashiko-bot
2026-11-27 15:10 ` [PATCH v2 03/13] ext4: preserve convert pending extents when adding unwrit extents to es cache Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 04/13] ext4: add es helper to convert unwrit to convert pending without changing i_es_seq Ojaswin Mujoo
2026-11-27 16:46 ` sashiko-bot
2026-11-27 15:10 ` [PATCH v2 05/13] ext4: add support to track convert pending ranges in ext4_map_blocks() Ojaswin Mujoo
2026-11-27 17:19 ` sashiko-bot [this message]
2026-11-27 15:10 ` [PATCH v2 06/13] ext4: add tracking for unwritten to-be-converted ranges in dio write path Ojaswin Mujoo
2026-11-27 17:48 ` sashiko-bot
2026-11-27 15:10 ` [PATCH v2 07/13] ext4: add tracking for unwritten to-be-converted ranges in non iomap buffered path Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 08/13] ext4: add tracking for unwritten to-be-converted ranges in " Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 09/13] ext4: don't zeroout if conv pending ranges are present Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 10/13] ext4: add tracepoints for extent split and convert Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 11/13] ext4: update extent status cache when zeroing extents Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 12/13] ext4: don't drop the extents in case extent split fails Ojaswin Mujoo
2026-11-27 15:11 ` [PATCH v2 13/13] ext4: re-enable zeroout fallback Ojaswin Mujoo
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-237982@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox