Linux EXT4 FS development
 help / color / mirror / Atom feed
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 13/13] ext4: re-enable zeroout fallback
Date: Fri, 27 Nov 2026 20:20:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-238228@kernel.org> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-13-4106968e4d15@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ext4: extent status conflict warning in
  ext4_split_convert_extents()
- [Medium] ext4: unmerged CONVERT_PENDING entries defeat zeroout in
  endio conversion
--

commit 675f4feafaf06eedfd7ad9cbdb682ca8af60a9aa
Author: Ojaswin Mujoo <ojaswin@linux.ibm.com>

ext4: re-enable zeroout fallback

This commit removes the unconditional goto in ext4_split_extent() to
re-enable the zeroout fallback path when splitting an extent fails with
-ENOSPC, -EDQUOT or -ENOMEM.

> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 5130416aa8b43..df3085f2fc446 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -3567,9 +3567,6 @@ static struct ext4_ext_path *ext4_split_extent(handle_t *handle,
>  	if (orig_err != -ENOSPC && orig_err != -EDQUOT && orig_err != -ENOMEM)
>  		goto out_orig_err;
>  
> -	/* zeroout fallback disabled: always return the original err */
> -	goto out_orig_err;
> -
>  	/* we can't zeroout? just return the original err */
>  	if (!(split_flag & EXT4_EXT_MAY_ZEROOUT))
>  		goto out_orig_err;

[Severity: Medium]
Can re-enabling the zeroout fallback trigger an extent status cache
conflict warning in ext4_es_cache_extent() when
ext4_split_convert_extents() is called without EXT4_EX_NOCACHE?

When ext4_split_extent() falls back to ext4_split_extent_zeroout() for
EXT4_GET_BLOCKS_CONVERT, ext4_split_extent_zeroout() marks the entire
on-disk extent initialized with ext4_ext_mark_initialized(ex), but only
inserts EXTENT_STATUS_WRITTEN into the extent status tree for the zeroed
prefix and suffix ranges:

fs/ext4/extents.c:ext4_split_extent_zeroout() {
	...
	ext4_ext_mark_initialized(ex);

	for (i = 0; i < nr_zeroed; i++)
		ext4_es_insert_extent(inode, zeroed[i].lblk, zeroed[i].len,
				      zeroed[i].pblk, EXTENT_STATUS_WRITTEN,
				      false);
	...
}

Because the failed ext4_split_extent_at() call leaves the original
unwritten entry in i_es_tree, the target map subrange remains
EXTENT_STATUS_UNWRITTEN.  When ext4_split_extent() returns to
ext4_split_convert_extents() with did_zeroout set, the convert label runs
ext4_find_extent(inode, map->m_lblk, path, flags) using the caller's flags
(where EXT4_EX_NOCACHE is not set, unlike the local copy in
ext4_split_extent()) before updating i_es_tree:

fs/ext4/extents.c:ext4_split_convert_extents() {
	...
convert:
	path = ext4_find_extent(inode, map->m_lblk, path, flags);
	if (IS_ERR(path))
		return path;
	...
	/* Lets update the extent status tree after conversion */
	if (!(flags & EXT4_EX_NOCACHE))
		ext4_es_insert_extent(inode, le32_to_cpu(ex->ee_block),
	...
}

On an inline extent tree (or unverified leaf block), ext4_find_extent()
calls ext4_cache_extents() -> ext4_es_cache_extent() with
EXTENT_STATUS_WRITTEN for the full on-disk extent while the mapped subrange
in i_es_tree is still EXTENT_STATUS_UNWRITTEN, triggering
ext4_warning_inode() ("ES cache extent failed: add [...] conflict with
existing [...]").

Passing EXT4_EX_NOCACHE to ext4_find_extent() in
ext4_split_convert_extents() (or skipping the lookup and full-extent status
insertion when did_zeroout is true and instead inserting only the mapped
range in ext4_split_extent_zeroout()) would avoid this conflict.

[Severity: Medium]
Can adjacent unmerged EXTENT_STATUS_CONVERT_PENDING entries in the same
unwritten extent cause ext4_split_extent_zeroout() to reject the zeroout
fallback with -EINVAL during endio conversion?

In ext4_es_can_be_merged(), EXTENT_STATUS_CONVERT_PENDING entries are never
merged with adjacent EXTENT_STATUS_CONVERT_PENDING entries.  When an I/O
completion range passed to ext4_convert_unwritten_extents() spans two
adjacent EXTENT_STATUS_CONVERT_PENDING entries inside the same on-disk
unwritten extent (for example, after ext4_iomap_end_io() merges adjacent
completed ioends via iomap_ioend_try_merge()), ext4_map_blocks() looks up
only the first entry and clamps map->m_len to its length:

fs/ext4/inode.c:ext4_map_blocks() {
	...
	if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) {
		if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) {
			...
			retval = es.es_len - (map->m_lblk - es.es_lblk);
			if (retval > map->m_len)
				retval = map->m_len;
			map->m_len = retval;
	...
}

If splitting the on-disk extent at the boundary between the two entries
then fails with -ENOSPC, ext4_split_extent_zeroout() scans [map_end,
ex_end) for ext4_es_is_convert_pending, hits the second
EXTENT_STATUS_CONVERT_PENDING entry waiting for the next iteration of
ext4_convert_unwritten_extents(), and returns -EINVAL:

fs/ext4/extents.c:ext4_split_extent_zeroout() {
	...
	/* Check right side */
	lblk = map_end;
	len = ex_end > map_end ? ex_end - map_end : 0;
	if (len > 0 && ext4_es_scan_range(inode, &ext4_es_is_convert_pending,
					  lblk, lblk + len - 1))
		return -EINVAL;
	...
}

That aborts the zeroout fallback and fails the endio conversion with
-ENOSPC.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com?part=13

  reply	other threads:[~2026-11-27 20:20 UTC|newest]

Thread overview: 23+ 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
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 18:17   ` sashiko-bot
2026-11-27 15:10 ` [PATCH v2 08/13] ext4: add tracking for unwritten to-be-converted ranges in " Ojaswin Mujoo
2026-11-27 18:30   ` sashiko-bot
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 19:32   ` sashiko-bot
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
2026-11-27 20:20   ` sashiko-bot [this message]
2026-11-27 20:20 ` [PATCH v2 00/13] ext4: fix endio zeroout corruption by tracking to-be-converted unwritten IOs sashiko-bot

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-238228@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