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 762A03009CB for ; Wed, 25 Feb 2026 20:09:12 +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=1772050152; cv=none; b=erU6Af0QJRLmAk+pG04Xdy2hHbxMXPo4m+IrfCe0o5qSwuSpmjaaxmgzUYS8yvYok8dtDmM6mKdIDBedH6WhEU8hQTJZAM1MVpVoWrVNzFYRIKPFRyjASdnbANj74NBKoH2+g3Bsz/WOCkXYvpIB4FG3FOi24Q0EpH236gEPaLM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772050152; c=relaxed/simple; bh=TA2LTxnLBgWQHeWu8etuh4jeFmTqSirySXJoTkXs2a8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lMMyTca+IthMSdFrOLua+2P3iApp+Yio0Japl49DYjNHPxOGWoYy7uFhIzDKrGW+eG855R93e9/oiBJZRYfAh026CSjcSQJ3XW34/50Nm6f4SnV+AbQW0uLlEosIWH5ESWg84Y1l9ciNOWUwt+pIdUy7O2yCWA6p00L5uI9YkkM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bIWXU3qa; 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="bIWXU3qa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 346EEC116D0; Wed, 25 Feb 2026 20:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772050152; bh=TA2LTxnLBgWQHeWu8etuh4jeFmTqSirySXJoTkXs2a8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bIWXU3qaswSz/OQRMoiktYric3YZHfX8Q6ZsT79cmJCR3Wiqstcr1/y0nAoh4x/nF 9ESAhVecuP5WK1N/bgNQZOJ0WvhNxYm/4y3NMghWvh5i9Wz8Zm3gtDzxdC7k2A5bjX hIiY7PVMphH5rmYtGaY1CEhg7pXkCEHNW8DBNbTV3y3wyifzFoqEOoXw9hiNTvKa2S ztg4lsSSseOCqqHvhafs07JRVhyC6OGSimAV0OlVNinoNTDEfNn/bU8ztUM8c0l0HA dVypU9HBfjbuNB9zfb81kqn//mwbikRnlPBXLIZYq3lRkPPrgPwd/3F7WebX5elyW8 eQjAu6d6B+EwQ== 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 5.15.y] ext4: always allocate blocks only from groups inode can use Date: Wed, 25 Feb 2026 15:09:09 -0500 Message-ID: <20260225200909.1054153-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026022436-circle-accent-873c@gregkh> References: <2026022436-circle-accent-873c@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 0fd921ada8973..745aaf82c52cd 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -885,6 +885,21 @@ mb_update_avg_fragment_size(struct super_block *sb, struct ext4_group_info *grp) write_unlock(&sbi->s_mb_rb_lock); } +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. @@ -2702,10 +2717,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