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 9F8AC5F56B; Tue, 13 Feb 2024 17:33:34 +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=1707845614; cv=none; b=dyBUgAMYYuqPtUKXzVazzqg5fnOq7VeVS3VDqIplMTZ1a0iGJOD8++hbtb2qGq/Fs3CtcMQ3Vp4EwX6jCSnmC3XmD7/n4WWxUq1zp/BmS3SbvI5cvXxwmBS9o/swifqfkBYmlaf+45NUjcvZshPLMqjwOolPniDy47ua8UfQFyM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707845614; c=relaxed/simple; bh=lEIXvlL3sgyV8Td+xbVHp3ucke9pPBMyWx+Uxar21qM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NCFSEFzOFEkPFUNaRjsdAbZQpzE3yV0Yg3k4A2YJFn1z2QPYvJePIro2AnPhGAnavOkmRisWaZpQub5KQRNM+rTkgaoKrPylrwEOCc+eLS6N87PTSawPlzXTdyFkbVk+pAdHolQoYar/SzArAdpCC4mYk+2opK8xx12OIVOShBs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OS1w7rLI; 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="OS1w7rLI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04070C433C7; Tue, 13 Feb 2024 17:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1707845614; bh=lEIXvlL3sgyV8Td+xbVHp3ucke9pPBMyWx+Uxar21qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OS1w7rLIWOZVil5lwYm3chycMHk1ddZVXO8ulh1jdadYUBy7CEUY+ncO/Xa9Btom4 UzQrpXLjfMLVdtxTN3uAeNgI6f14bggOh2j+vTXEs8+0pywZbDhjK3UP73JG5ggxwb tQ6Jv0IFe8JT9eizkp2mzfK/dktau5pcj80bOtlU= 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.7 001/124] ext4: regenerate buddy after block freeing failed if under fc replay Date: Tue, 13 Feb 2024 18:20:23 +0100 Message-ID: <20240213171853.769579689@linuxfoundation.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240213171853.722912593@linuxfoundation.org> References: <20240213171853.722912593@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.7-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 8408318e1d32..3c5786841c6c 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1233,6 +1233,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 @@ -1921,6 +1939,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