lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <j5yxjikerrahb2yjvr3zkqktdycmdzetyk2kj2opqj3pakhu4b@ledyhgijmkqu>
Date: Tue, 6 Jan 2026 16:41:04 +0100
From: Jan Kara <jack@...e.cz>
To: Ojaswin Mujoo <ojaswin@...ux.ibm.com>
Cc: linux-ext4@...r.kernel.org, Theodore Ts'o <tytso@....edu>, 
	Ritesh Harjani <ritesh.list@...il.com>, Zhang Yi <yi.zhang@...wei.com>, Jan Kara <jack@...e.cz>, 
	libaokun1@...wei.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 7/7] ext4: Allow zeroout when doing written to unwritten
 split

On Sun 04-01-26 17:49:20, Ojaswin Mujoo wrote:
> Currently, when we are doing an extent split and convert operation of
> written to unwritten extent (example, as done by ZERO_RANGE), we don't
> allow the zeroout fallback in case the extent tree manipulation fails.
> This is mostly because zeroout might take unsually long and the fact that
> this code path is more tolerant to failures than endio.
> 
> Since we have zeroout machinery in place, we might as well use it hence
> lift this restriction. To mitigate zeroout taking too long respect the
> max zeroout limit here so that the operation finishes relatively fast.
> 
> Also, add kunit tests for this case.
> 
> Signed-off-by: Ojaswin Mujoo <ojaswin@...ux.ibm.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@...e.cz>

								Honza

> ---
>  fs/ext4/extents-test.c | 33 +++++++++++++++++++++++++++++++++
>  fs/ext4/extents.c      | 23 +++++++++++++++--------
>  2 files changed, 48 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c
> index 725d5e79be96..3b5274297fe9 100644
> --- a/fs/ext4/extents-test.c
> +++ b/fs/ext4/extents-test.c
> @@ -685,6 +685,39 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
>  	  .is_zeroout_test = 1,
>  	  .nr_exp_data_segs = 1,
>  	  .exp_data_state = { { .exp_char = 0, .off_blk = 0, .len_blk = 3 } } },
> +
> +	/* writ to unwrit splits */
> +	{ .desc = "split writ extent to 2 extents and convert 1st half unwrit (zeroout)",
> +	  .is_unwrit_at_start = 0,
> +	  .split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
> +	  .split_map = { .m_lblk = 10, .m_len = 1 },
> +	  .nr_exp_ext = 1,
> +	  .exp_ext_state = { { .ex_lblk = 10, .ex_len = 3, .is_unwrit = 0 } },
> +	  .is_zeroout_test = 1,
> +	  .nr_exp_data_segs = 2,
> +	  .exp_data_state = { { .exp_char = 0, .off_blk = 0, .len_blk = 1 },
> +			      { .exp_char = 'X', .off_blk = 1, .len_blk = 2 }}},
> +	{ .desc = "split writ extent to 2 extents and convert 2nd half unwrit (zeroout)",
> +	  .is_unwrit_at_start = 0,
> +	  .split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
> +	  .split_map = { .m_lblk = 11, .m_len = 2 },
> +	  .nr_exp_ext = 1,
> +	  .exp_ext_state = { { .ex_lblk = 10, .ex_len = 3, .is_unwrit = 0 } },
> +	  .is_zeroout_test = 1,
> +	  .nr_exp_data_segs = 2,
> +	  .exp_data_state = { { .exp_char = 'X', .off_blk = 0, .len_blk = 1 },
> +			      { .exp_char = 0, .off_blk = 1, .len_blk = 2 } } },
> +	{ .desc = "split writ extent to 3 extents and convert 2nd half unwrit (zeroout)",
> +	  .is_unwrit_at_start = 0,
> +	  .split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
> +	  .split_map = { .m_lblk = 11, .m_len = 1 },
> +	  .nr_exp_ext = 1,
> +	  .exp_ext_state = { { .ex_lblk = 10, .ex_len = 3, .is_unwrit = 0 } },
> +	  .is_zeroout_test = 1,
> +	  .nr_exp_data_segs = 3,
> +	  .exp_data_state = { { .exp_char = 'X', .off_blk = 0, .len_blk = 1 },
> +			      { .exp_char = 0, .off_blk = 1, .len_blk = 1 },
> +			      { .exp_char = 'X', .off_blk = 2, .len_blk = 1 }}},
>  };
>  
>  static const struct kunit_ext_test_param
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 9fb8a3220ae2..95dd88df8fe4 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -3485,7 +3485,19 @@ static struct ext4_ext_path *ext4_split_extent(handle_t *handle,
>  	 * to initialize as a last resort
>  	 */
>  	if (split_flag & EXT4_EXT_MAY_ZEROOUT) {
> -		path = ext4_find_extent(inode, map->m_lblk, NULL, flags);
> +		int max_zeroout_blks =
> +			EXT4_SB(inode->i_sb)->s_extent_max_zeroout_kb >>
> +			(inode->i_sb->s_blocksize_bits - 10);
> +		if (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN &&
> +		    map->m_len > max_zeroout_blks)
> +			/*
> +			 * Written to unwritten extent is not a critical path so
> +			 * lets respect the max zeroout
> +			 */
> +			return ERR_PTR(orig_err);
> +
> +		path = ext4_find_extent(inode, map->m_lblk, NULL,
> +						flags);
>  		if (IS_ERR(path))
>  			return path;
>  
> @@ -3863,15 +3875,10 @@ static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle,
>  		goto convert;
>  
>  	/*
> -	 * We don't use zeroout fallback for written to unwritten conversion as
> -	 * it is not as critical as endio and it might take unusually long.
> -	 * Also, it is only safe to convert extent to initialized via explicit
> +	 * It is only safe to convert extent to initialized via explicit
>  	 * zeroout only if extent is fully inside i_size or new_size.
>  	 */
> -	if (!(flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN))
> -		split_flag |= ee_block + ee_len <= eof_block ?
> -				      EXT4_EXT_MAY_ZEROOUT :
> -				      0;
> +	split_flag |= ee_block + ee_len <= eof_block ? EXT4_EXT_MAY_ZEROOUT : 0;
>  
>  	/*
>  	 * pass SPLIT_NOMERGE explicitly so we don't end up merging extents we
> -- 
> 2.51.0
> 
-- 
Jan Kara <jack@...e.com>
SUSE Labs, CR

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ