All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH v3 1/20] ext4: set goal start correctly in ext4_mb_normalize_request
Date: Thu, 6 Apr 2023 01:18:27 -0400	[thread overview]
Message-ID: <20230406051827.GA149620@mit.edu> (raw)
In-Reply-To: <20230303172120.3800725-2-shikemeng@huaweicloud.com>

On Sat, Mar 04, 2023 at 01:21:01AM +0800, Kemeng Shi wrote:
> We need to set ac_g_ex to notify the goal start used in
> ext4_mb_find_by_goal. Set ac_g_ex instead of ac_f_ex in
> ext4_mb_normalize_request.
> Besides we should assure goal start is in range [first_data_block,
> blocks_count) as ext4_mb_initialize_context does.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> ---
>  fs/ext4/mballoc.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 5b2ae37a8b80..36cd545f5ab4 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3993,6 +3993,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
>  				struct ext4_allocation_request *ar)
>  {
>  	struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
> +	struct ext4_super_block *es = sbi->s_es;
>  	int bsbits, max;
>  	ext4_lblk_t end;
>  	loff_t size, start_off;
> @@ -4188,18 +4189,20 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
>  	ac->ac_g_ex.fe_len = EXT4_NUM_B2C(sbi, size);
>  
>  	/* define goal start in order to merge */
> -	if (ar->pright && (ar->lright == (start + size))) {
> +	if (ar->pright && (ar->lright == (start + size)) &&
> +	    ar->pright - size >= le32_to_cpu(es->s_first_data_block)) {
>  		/* merge to the right */

I had to ammend this commit to add this check:

 	/* define goal start in order to merge */
 	if (ar->pright && (ar->lright == (start + size)) &&
+	    ar->pright >= size &&
 	    ar->pright - size >= le32_to_cpu(es->s_first_data_block)) {

Without this check, it's possible for ar->pright - size to go negative
(well, underflow since it's an unsigned value).  This will later
trigger a BUG_ON, which was easily reproduced via:

   kvm-xfstests -c ext4/ext3conv generic/231

Cheers,

							- Ted

  parent reply	other threads:[~2023-04-06  5:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-03 17:21 [PATCH v3 00/20] Some bugfix and cleanup to mballoc Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 01/20] ext4: set goal start correctly in ext4_mb_normalize_request Kemeng Shi
2023-03-13  2:07   ` Ritesh Harjani
2023-04-06  5:18   ` Theodore Ts'o [this message]
2023-03-03 17:21 ` [PATCH v3 02/20] ext4: allow to find by goal if EXT4_MB_HINT_GOAL_ONLY is set Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 03/20] ext4: get correct ext4_group_info in ext4_mb_prefetch_fini Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 04/20] ext4: correct calculation of s_mb_preallocated Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 05/20] ext4: correct start of used group pa for debug in ext4_mb_use_group_pa Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 06/20] ext4: protect pa->pa_free in ext4_discard_allocated_blocks Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 07/20] ext4: add missed brelse in ext4_free_blocks_simple Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 08/20] ext4: remove unused return value of ext4_mb_try_best_found and ext4_mb_free_metadata Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 09/20] ext4: Remove unnecessary release when memory allocation failed in ext4_mb_init_cache Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 10/20] ext4: remove unnecessary e4b->bd_buddy_page check in ext4_mb_load_buddy_gfp Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 11/20] ext4: remove unnecessary check in ext4_mb_new_blocks Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 12/20] ext4: remove dead check in mb_buddy_mark_free Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 13/20] ext4: remove ac->ac_found > sbi->s_mb_min_to_scan dead check in ext4_mb_check_limits Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 14/20] ext4: use best found when complex scan of group finishs Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 15/20] ext4: remove unnecessary exit_meta_group_info tag Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 16/20] ext4: remove unnecessary count2 in ext4_free_data_in_buddy Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 17/20] ext4: remove unnecessary goto in ext4_mb_mark_diskspace_used Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 18/20] ext4: remove repeat assignment to ac_f_ex Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 19/20] ext4: remove comment code ext4_discard_preallocations Kemeng Shi
2023-03-03 17:21 ` [PATCH v3 20/20] ext4: simplify calculation of blkoff in ext4_mb_new_blocks_simple Kemeng Shi
2023-03-16  5:07   ` Theodore Ts'o
2023-03-16 10:19     ` Kemeng Shi
2023-03-17 15:50       ` Theodore Ts'o
2023-03-20  7:31         ` Kemeng Shi
2023-03-10  8:17 ` [PATCH v3 00/20] Some bugfix and cleanup to mballoc Kemeng Shi
2023-03-17  1:52 ` Theodore Ts'o

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=20230406051827.GA149620@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=shikemeng@huaweicloud.com \
    /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.