Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: disk-io: output error message for tree block bytenr mismatch case
@ 2020-11-29 10:16 Qu Wenruo
  0 siblings, 0 replies; only message in thread
From: Qu Wenruo @ 2020-11-29 10:16 UTC (permalink / raw)
  To: linux-btrfs

[BUG]
There is a report from the community that, btrfs aborted transaction due
to page_offset() of a tree block doesn't match with its eb header.

The code looks like this:

	if (WARN_ON(found_start != start))
		return -EUCLEAN;

[CAUSE]
With extra debug patch and great help from the reporter, it turns out
that, there is a memory bitflip:

  [  471.998855] BTRFS warning (device sda1): page_start and eb_start
  mismatch, eb_start=17593525075968 page_start=1339031552

Note that:
eb_start   = 0x10004fd00000 (Extracted from in-memory tree block header)
page_start = 0x00004fd00000 (Page offset)

This is an obvious memory bitflip.

[ENHANCEMENT]
The check on extent buffer header can be considered as part of tree
checker, but more fundamental.

So it's reasonable to follow the tree-checker scheme to outputting human
readable error message, and output the "write time tree block corruption
detected" message.

Also with the human readable error message, there is no need to always
trigger a kernel warning, just trigger the warning for debug build.

Link: https://www.spinics.net/lists/linux-btrfs/msg107895.html
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/disk-io.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 37b2e0aad162..b6040f8ffb08 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -465,8 +465,16 @@ static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct bio_vec *bvec
 	 * Please do not consolidate these warnings into a single if.
 	 * It is useful to know what went wrong.
 	 */
-	if (WARN_ON(found_start != start))
+	if (unlikely(found_start != start)) {
+		btrfs_err(fs_info,
+		"tree block bytenr mismatch, page_offset=%llu header_bytenr=%llu",
+			  start, found_start);
+		btrfs_err(fs_info,
+		"block=%llu write time tree block corruption detected",
+			  eb->start);
+		WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
 		return -EUCLEAN;
+	}
 	if (WARN_ON(!PageUptodate(page)))
 		return -EUCLEAN;
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-29 10:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-29 10:16 [PATCH] btrfs: disk-io: output error message for tree block bytenr mismatch case Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox