From: Christoph Hellwig <hch@infradead.org>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: fix a crash in metadata repair path
Date: Fri, 26 May 2023 06:42:39 -0700 [thread overview]
Message-ID: <ZHC3T+OMEJ7VIkwi@infradead.org> (raw)
In-Reply-To: <cd4159ae5d32fdb87deba4bf6485819614016c11.1685088405.git.wqu@suse.com>
On Fri, May 26, 2023 at 08:30:20PM +0800, Qu Wenruo wrote:
> struct btrfs_fs_info *fs_info = eb->fs_info;
> - u64 start = eb->start;
> int i, num_pages = num_extent_pages(eb);
> int ret = 0;
>
> @@ -185,12 +184,14 @@ static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,
>
> for (i = 0; i < num_pages; i++) {
> struct page *p = eb->pages[i];
> + u64 start = max_t(u64, eb->start, page_offset(p));
> + u64 end = min_t(u64, eb->start + eb->len, page_offset(p) + PAGE_SIZE);
> + u32 len = end - start;
>
> - ret = btrfs_repair_io_failure(fs_info, 0, start, PAGE_SIZE,
> - start, p, start - page_offset(p), mirror_num);
> + ret = btrfs_repair_io_failure(fs_info, 0, start, len,
> + start, p, offset_in_page(start), mirror_num);
> if (ret)
> break;
> - start += PAGE_SIZE;
I actually just noticed this a week or so ago, but didn't have a
reproducer. My fix does this a little differeny by adding a branch
for nodesize < PAGE_SIZE similar to write_one_eb or
read_extent_buffer_pages, which feels a bit simpler and easier to read
to me:
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 48ac9fccca06ae..3d498d08e61b65 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -182,11 +182,19 @@ static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,
if (sb_rdonly(fs_info->sb))
return -EROFS;
+ if (fs_info->nodesize < PAGE_SIZE) {
+ struct page *p = eb->pages[0];
+
+ return btrfs_repair_io_failure(fs_info, 0, start, eb->len,
+ start, p, start - page_offset(p),
+ mirror_num);
+ }
+
for (i = 0; i < num_pages; i++) {
struct page *p = eb->pages[i];
ret = btrfs_repair_io_failure(fs_info, 0, start, PAGE_SIZE,
- start, p, start - page_offset(p), mirror_num);
+ start, p, 0, mirror_num);
if (ret)
break;
start += PAGE_SIZE;
next prev parent reply other threads:[~2023-05-26 13:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 12:30 [PATCH] btrfs: fix a crash in metadata repair path Qu Wenruo
2023-05-26 13:42 ` Christoph Hellwig [this message]
2023-05-26 22:28 ` Qu Wenruo
2023-06-05 16:44 ` David Sterba
2023-06-02 7:15 ` Qu Wenruo
2023-06-05 7:06 ` Christoph Hellwig
2023-06-05 16:40 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZHC3T+OMEJ7VIkwi@infradead.org \
--to=hch@infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox