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=1796223027; b=gTCvGMM9VgM2X3ebOmiyYlamKVHiLbJoXROAt9czp2lnVoPpVQkdyo0hZfHnKAZnHT0Z 23Ko9cXVRV9bXeb35ck9gsxfolJq21Vmw5VwWL3Fuv7fVOWpNW/EIOFxIbcv0fhcVQRk/ 8b5qfPH9uEBiqcumpMDPdEN8CW1KlcwVAqSSd5yokDUEszLkQG8z3rupr4PscZSkhpmGG fEjaugGsuCVW/9ma9VQGMvEoM2cobneAentY8B4T/qOEeiE0jjTATqBHUeLO24uKa20CO mZA3etTQS4zYNj6+jP8qtz2IHGz2ycQ/HBmAtnBDp1ZM2s8pe+YxunSBMBts9HWEagg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796223027; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Wn86oDssOprwt9nDg9DN01LLILXUnGLybeR82ZHpZQE=; b=Wb0qzKMIRO7rJPBP+Ik3xKkHqTIau3cpRhCIm8uyAYDpLRRdDPGLPGqq6GlUyZoGKria GtrOavi3XbjOhwj9Wqg4xrdoqMlBqXAznYRpf4DJZb0jJdc0xoK5Z3Tx5ehgnRQrxLGpp zJGYzTSnWrkkY75G81JaFjeUUyo7HAWlLIro3ZbBxUCwHUUdaf+wUmds1yIo0xprROxLr B4W2LsNw1ZfODuZTTqxBc5CTYlEST3/uT7C5ZZ/BeZMzOrHVtGSFS1ViZERvzbc+rVBZJ qMOllGW04VwRGB4j++ZEaP5GXXvPTK80+WVBTIJsWVy4X7iLN4maC1zCGmeB+/aC4tg== 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=VlbbzXX5; 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 33D45606A322 for ; Wed, 2 Dec 2026 14:50:26 +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=VlbbzXX5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15E2C1F00896; Wed, 2 Dec 2026 14:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796223026; bh=Wn86oDssOprwt9nDg9DN01LLILXUnGLybeR82ZHpZQE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=VlbbzXX54MFQNJnKruAPAXKDmJVUv0NqBMEsQTDeWuCcwLFXjRg02vPFqG3qvHf61 jWKlB1WCE0uQ8bNt7YBQ8L32OavKwteNsB1OCTZH4jNoFqt4BslQu1xyBJ3J11fOnJ Ks0IMMHhv5i3THuGFdA9WlJwCOi/qEPxB/McwFQHwScERek3EyUEM0VLr4fUJQCZ0P IDaSqXNdRb+knLGsJ+PXw5gGRZBNOfGXojwPP4NpXxD01AlB/cp7WaNXABM6JDM89w nsogX9cuFacgTQ0HM4uydpErek2xb2YqMt85oYSW4pCtF9Der0O40OPpQ2+SqSRglY /JZKv+okIKA3g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ext4: restore group extend counters when the bitmap update fails Reply-To: sashiko-reviews@lists.linux.dev To: Alan <3164729207@qq.com> Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 14:50:25 +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 3 potential issues to consider: - [Medium] ext4: superblock rollback in ext4_group_extend_no_check() runs after commit - [Medium] ext4: partial rollback in ext4_group_extend_no_check() after bitmap update - [Low] ext4: unlocked o_free_blocks_count read in ext4_group_extend_no_check() -- commit 6330aec87a7c1cfd65a1603ed9df385751f61752 Author: Alan <3164729207@qq.com> ext4: restore group extend counters when the bitmap update fails This commit restores the superblock block and free block counts in ext4_group_extend_no_check() if ext4_group_add_blocks() or ext4_handle_dirty_metadata() fails. > diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c > index 5e3ad8393cf83..0a99ce4d1c2ba 100644 > --- a/fs/ext4/resize.c > +++ b/fs/ext4/resize.c > @@ -1774,6 +1774,7 @@ static int ext4_group_extend_no_check(struct super_= block *sb, > ext4_fsblk_t o_blocks_count, ext4_grpblk_t add) > { > struct ext4_super_block *es =3D EXT4_SB(sb)->s_es; > + ext4_fsblk_t o_free_blocks_count =3D ext4_free_blocks_count(es); [Severity: Low] Should o_free_blocks_count be sampled under lock_buffer(EXT4_SB(sb)->s_sbh) when the superblock counters are updated? Reading ext4_free_blocks_count(es) at function entry happens without the superblock buffer lock and before ext4_journal_start_sb() and ext4_journal_get_write_access(), both of which can sleep while a concurrent ext4_update_super() updates s_free_blocks_count_lo and s_free_blocks_count_= hi under lock_buffer(s_sbh). A rollback could then write back a stale or torn 64-bit free block count. > handle_t *handle; > int err =3D 0, err2; > =20 > @@ -1805,10 +1806,20 @@ static int ext4_group_extend_no_check(struct supe= r_block *sb, > /* We add the blocks to the bitmap and set the group need init bit */ > err =3D ext4_group_add_blocks(handle, sb, o_blocks_count, add); > if (err) > - goto errout; > - ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh); > + goto rollback; > + err =3D ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh); > + if (err) > + goto rollback; [Severity: Medium] If ext4_handle_dirty_metadata() fails here (or inside ext4_mb_mark_context() after clearing the bitmap bits and setting changed > 0), does jumping to rollback leave the superblock inconsistent with the bitmap and in-memory allocator state? By this point ext4_group_add_blocks() has already marked the new blocks free in the block bitmap, updated the group descriptor and flex_bg free cluster counts, freed the clusters into the buddy cache via mb_free_blocks(), and added changed to sbi->s_freeclusters_counter. Reverting only the superblock counters leaves the buddy allocator able to hand out blocks above the restored o_blocks_count (which then fail ext4_sb_block_valid()), and the ne= xt ext4_update_super() will overwrite es->s_free_blocks_count from sbi->s_freeclusters_counter. > ext4_debug("freed blocks %llu through %llu\n", o_blocks_count, > o_blocks_count + add); > + goto errout; > + > +rollback: > + lock_buffer(EXT4_SB(sb)->s_sbh); > + ext4_blocks_count_set(es, o_blocks_count); > + ext4_free_blocks_count_set(es, o_free_blocks_count); > + ext4_superblock_csum_set(sb); > + unlock_buffer(EXT4_SB(sb)->s_sbh); [Severity: Medium] Does this rollback run too late when ext4_group_add_blocks() hits an error = on a filesystem mounted with errors=3Dremount-ro or without a journal? When ext4_group_add_blocks() fails (for example, on a block bitmap read EIO= in ext4_wait_block_bitmap()), it calls ext4_error_err() and ext4_std_error() -> ext4_handle_error() before returning to ext4_group_extend_no_check(): fs/ext4/super.c:ext4_handle_error() { ... if (continue_fs && journal && !ext4_test_mount_flag(sb, EXT4_MF_JOURNAL_DESTROY)) schedule_work(&EXT4_SB(sb)->s_sb_upd_work); else ext4_commit_super(sb); ... } When !continue_fs or !journal, ext4_handle_error() synchronously calls ext4_commit_super(sb) while es->s_blocks_count in s_sbh is still set to o_blocks_count + add, writing the un-rolled-back counts to disk. For errors=3Dremount-ro it also sets EXT4_FLAGS_EMERGENCY_RO, which causes ext4_put_super() to skip ext4_commit_super(sb) on unmount, so the subsequent in-memory rollback is never written out. Even with errors=3Dcontinue and a journal, schedule_work(&EXT4_SB(sb)->s_sb_upd_work) races with the rollback label. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_D418BD3910B= 101F7FD61B0E136A583DE8C0A@qq.com?part=3D1