From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37C39CCA489 for ; Tue, 21 Jun 2022 21:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356402AbiFUVEN (ORCPT ); Tue, 21 Jun 2022 17:04:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355475AbiFUVAT (ORCPT ); Tue, 21 Jun 2022 17:00:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5D9344ED; Tue, 21 Jun 2022 13:52:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0F4626183B; Tue, 21 Jun 2022 20:51:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4E1FC341C4; Tue, 21 Jun 2022 20:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655844707; bh=w8zR6apZW3tp502uPKc8Cgocm1HyJka4DJrUGikSbPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bk2HqS+uiqReT5w6qt4LBE+Saka8v9E4KsqToyZ3vF9QA5TMOSNzonwUGQmm9czzs a76XLSajLmwWAMGoESCygC4duuDerqwtH+nYql49iQWWJQq+r7Wr0dgmXekwZzmHP3 uUwdHhANsMdN0LwTK0JVt9nb/NAD/TbI+dF6ZKcIu8wKMnta2nL4d3xMFCkh2DvKM0 tGRBKIIPzq5NyvhLoMZup6s8lC9g4aySs+845mgOeXL/S0EmRz4Nk4MNh8N8R+QGNy oUNDPT6CEZaDz5tE6B3FstTbsPFdfogg+jyT7+mjbmeT1F0JdADVLeftBrW55AApO9 NrpxVpprPCK8A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Baokun Li , Ritesh Harjani , Theodore Ts'o , Sasha Levin , adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 5/5] ext4: correct the judgment of BUG in ext4_mb_normalize_request Date: Tue, 21 Jun 2022 16:51:39 -0400 Message-Id: <20220621205140.250968-5-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220621205140.250968-1-sashal@kernel.org> References: <20220621205140.250968-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baokun Li [ Upstream commit cf4ff938b47fc5c00b0ccce53a3b50eca9b32281 ] ext4_mb_normalize_request() can move logical start of allocated blocks to reduce fragmentation and better utilize preallocation. However logical block requested as a start of allocation (ac->ac_o_ex.fe_logical) should always be covered by allocated blocks so we should check that by modifying and to or in the assertion. Signed-off-by: Baokun Li Reviewed-by: Ritesh Harjani Link: https://lore.kernel.org/r/20220528110017.354175-3-libaokun1@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/mballoc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 28bee66c5fbf..2be40fb67500 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3269,7 +3269,22 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac, } rcu_read_unlock(); - if (start + size <= ac->ac_o_ex.fe_logical && + /* + * In this function "start" and "size" are normalized for better + * alignment and length such that we could preallocate more blocks. + * This normalization is done such that original request of + * ac->ac_o_ex.fe_logical & fe_len should always lie within "start" and + * "size" boundaries. + * (Note fe_len can be relaxed since FS block allocation API does not + * provide gurantee on number of contiguous blocks allocation since that + * depends upon free space left, etc). + * In case of inode pa, later we use the allocated blocks + * [pa_start + fe_logical - pa_lstart, fe_len/size] from the preallocated + * range of goal/best blocks [start, size] to put it at the + * ac_o_ex.fe_logical extent of this inode. + * (See ext4_mb_use_inode_pa() for more details) + */ + if (start + size <= ac->ac_o_ex.fe_logical || start > ac->ac_o_ex.fe_logical) { ext4_msg(ac->ac_sb, KERN_ERR, "start %lu, size %lu, fe_logical %lu", -- 2.35.1