From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1057B2D7DDC for ; Wed, 25 Feb 2026 18:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772043002; cv=none; b=iCDySHELtLjgtbmpyrHWTRaOhk7gS2bm6xFSAP1EE9xmmJrQYvwKeRxAE4e9P0RIQGY/kKy8bZP/uGQbeQEE1DEN3oeEdYasoAVaDct/q/2ShVpQC4pLBzF4DwyeJaY3BRobj75/l0HQw1j2n7cqPgdnZ7ThYXjN97fFJnPjBUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772043002; c=relaxed/simple; bh=uzZ6YX3bYCOcMX83EOTODFdJ9J+QSMpCvro1Sw0MYAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nivcaF/fhrNP09r8Xj6D5Gwk4Rr9PnjumKMb1z8gjBDYdSZaqgRnnwrpAey94YEtf6eKQoy0PfiUp9ZjnBh4BajsZqjw9qSTx5+7YljP4q0a6fegFAChPjCEqK4/cyR2LScl6CBzM2xMoTtXeHXAodaTJRO0mORgePZ3EGLb1d0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jpfNv3ZS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jpfNv3ZS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D13AFC19421; Wed, 25 Feb 2026 18:10:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772043001; bh=uzZ6YX3bYCOcMX83EOTODFdJ9J+QSMpCvro1Sw0MYAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jpfNv3ZSfEaAKnIRabV9taPdKwQ+v9W3Cl7KRMNlmeYnkYoiuEtHvp11HElv1oj+f jIYKLO+1Oy7VhJYMxOj9zbJxhxLDbMURQolmBJ9M+loX7EZNjoTmF5KqRygY2RukOv YBrshbn5ynDDsMw9CwH9B3HW4eBQRwPXE16DJnsTziYtqX1i+wH0FBvIlyRMJOPY0U fr1NoHMfyNoo5zZw9bIdv4SesFAnbWH9YO6NyZkKexmw1cwOSy+vI7OcXnwWFqFMI2 zsd2cIYo2x8vhSw9HhFPDVV3AJvU9GB4eX+1UXgA2zbzyuAmRoCfJRmcrQpUTOUN9i J8eYQlXPX0rsg== From: Sasha Levin To: stable@vger.kernel.org Cc: Jan Kara , Baokun Li , Zhang Yi , Pedro Falcato , stable@kernel.org, Theodore Ts'o , Sasha Levin Subject: [PATCH 6.12.y] ext4: always allocate blocks only from groups inode can use Date: Wed, 25 Feb 2026 13:09:58 -0500 Message-ID: <20260225180958.910206-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026022434-work-bust-f886@gregkh> References: <2026022434-work-bust-f886@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jan Kara [ Upstream commit 4865c768b563deff1b6a6384e74a62f143427b42 ] For filesystems with more than 2^32 blocks inodes using indirect block based format cannot use blocks beyond the 32-bit limit. ext4_mb_scan_groups_linear() takes care to not select these unsupported groups for such inodes however other functions selecting groups for allocation don't. So far this is harmless because the other selection functions are used only with mb_optimize_scan and this is currently disabled for inodes with indirect blocks however in the following patch we want to enable mb_optimize_scan regardless of inode format. Reviewed-by: Baokun Li Reviewed-by: Zhang Yi Signed-off-by: Jan Kara Acked-by: Pedro Falcato Cc: stable@kernel.org Link: https://patch.msgid.link/20260114182836.14120-3-jack@suse.cz Signed-off-by: Theodore Ts'o [ Drop a few hunks not needed in older trees ] Signed-off-by: Sasha Levin --- fs/ext4/mballoc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index ed2d63b2e91dc..86d037adfff97 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -884,6 +884,21 @@ mb_update_avg_fragment_size(struct super_block *sb, struct ext4_group_info *grp) } } +static ext4_group_t ext4_get_allocation_groups_count( + struct ext4_allocation_context *ac) +{ + ext4_group_t ngroups = ext4_get_groups_count(ac->ac_sb); + + /* non-extent files are limited to low blocks/groups */ + if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS))) + ngroups = EXT4_SB(ac->ac_sb)->s_blockfile_groups; + + /* Pairs with smp_wmb() in ext4_update_super() */ + smp_rmb(); + + return ngroups; +} + /* * Choose next group by traversing largest_free_order lists. Updates *new_cr if * cr level needs an update. @@ -2819,10 +2834,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) sb = ac->ac_sb; sbi = EXT4_SB(sb); - ngroups = ext4_get_groups_count(sb); - /* non-extent files are limited to low blocks/groups */ - if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS))) - ngroups = sbi->s_blockfile_groups; + ngroups = ext4_get_allocation_groups_count(ac); BUG_ON(ac->ac_status == AC_STATUS_FOUND); -- 2.51.0