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 2D5565FEE0; Tue, 13 Feb 2024 17:22:47 +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=1707844968; cv=none; b=Z+FSB9NpKH3xupM91B/znDjdW6syDGXSIYLFKb3bbfZfHghat4npIUoPv9bg9fM79Qd8JGidYS012qVBDHSvedrZuOHzop4AW6Mzyu3xYHnW/iYRZ9jwS4eJyQr3ahTT8/9gRtylljP09O9aQOySCjMhEV5X1QjlkkyLWqERyEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707844968; c=relaxed/simple; bh=3g8Nemr0zMza+0JOPJ9o5aIFMdCU9upyTCLAiz9Co2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BDnd0MUaCnZDLYvBQkuZwXBWVBdSeKfOBKpb7jisVh+OXkzbbORi/B75Vl8/m139Gj1x5apk1LB4HyodRJ6/tRm5G2nZds0BvCWYsr4Sb7rt+ItphjvVeGfapBp9SX8sKQlwDAdJ8Z3JLL20OVEEHsVs2uwisf2M1t5g0g3I5Aw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bn3AHGI+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bn3AHGI+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4D32C433F1; Tue, 13 Feb 2024 17:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1707844967; bh=3g8Nemr0zMza+0JOPJ9o5aIFMdCU9upyTCLAiz9Co2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bn3AHGI+9bMZlM97eXMsFjKn7Xctw3WTV2eZQXZYKtBef55DEde9ZRPT3LUrjs1Fl VB9EladAuYqdMrH4WrDjIIsT5FLWpg+m/bbxcidFIdWVSOZFo0p6YefGXzqjCH7nmU jCc5U3VfZ0XceSfwCqUY+noQRZMxj7v6q5+wYQgA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara , Baokun Li , Theodore Tso , Sasha Levin Subject: [PATCH 6.1 01/64] ext4: regenerate buddy after block freeing failed if under fc replay Date: Tue, 13 Feb 2024 18:20:47 +0100 Message-ID: <20240213171844.758023871@linuxfoundation.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240213171844.702064831@linuxfoundation.org> References: <20240213171844.702064831@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Baokun Li [ Upstream commit c9b528c35795b711331ed36dc3dbee90d5812d4e ] This mostly reverts commit 6bd97bf273bd ("ext4: remove redundant mb_regenerate_buddy()") and reintroduces mb_regenerate_buddy(). Based on code in mb_free_blocks(), fast commit replay can end up marking as free blocks that are already marked as such. This causes corruption of the buddy bitmap so we need to regenerate it in that case. Reported-by: Jan Kara Fixes: 6bd97bf273bd ("ext4: remove redundant mb_regenerate_buddy()") Signed-off-by: Baokun Li Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20240104142040.2835097-4-libaokun1@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/mballoc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index c1515daf1def..40903c172a34 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1118,6 +1118,24 @@ void ext4_mb_generate_buddy(struct super_block *sb, atomic64_add(period, &sbi->s_mb_generation_time); } +static void mb_regenerate_buddy(struct ext4_buddy *e4b) +{ + int count; + int order = 1; + void *buddy; + + while ((buddy = mb_find_buddy(e4b, order++, &count))) + mb_set_bits(buddy, 0, count); + + e4b->bd_info->bb_fragments = 0; + memset(e4b->bd_info->bb_counters, 0, + sizeof(*e4b->bd_info->bb_counters) * + (e4b->bd_sb->s_blocksize_bits + 2)); + + ext4_mb_generate_buddy(e4b->bd_sb, e4b->bd_buddy, + e4b->bd_bitmap, e4b->bd_group, e4b->bd_info); +} + /* The buddy information is attached the buddy cache inode * for convenience. The information regarding each group * is loaded via ext4_mb_load_buddy. The information involve @@ -1796,6 +1814,8 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, ext4_mark_group_bitmap_corrupted( sb, e4b->bd_group, EXT4_GROUP_INFO_BBITMAP_CORRUPT); + } else { + mb_regenerate_buddy(e4b); } goto done; } -- 2.43.0