mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Brahmajit Das <listout@listout.xyz>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org
Cc: Chris Mason <mason@kernel.org>,
	David Hildenbrand <david@kernel.org>,
	Jason Gunthorpe <jgg@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	syzkaller-bugs@googlegroups.com,
	syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com,
	Brahmajit Das <bdas@suse.de>
Subject: Re: [PATCH v3 2/3] btrfs: sync the uptodate bitmap when attaching a data folio state
Date: Fri, 4 Dec 2026 07:06:46 +1030	[thread overview]
Message-ID: <2987f347-767b-43df-b114-b3ee1284a568@gmx.com> (raw)
In-Reply-To: <20261203133059.2193197-3-listout@listout.xyz>



在 2026/12/4 00:00, Brahmajit Das 写道:
> From: Brahmajit Das <bdas@suse.de>
> 
> A data folio can lose its private while it stays in the page cache, e.g.
> btrfs_release_folio() from a partial invalidation, or from a large folio
> split that then fails.  Such a folio was only released, not invalidated,
> so it can still be uptodate.
> 
> When something calls set_folio_extent_mapped() on it again, such as
> prepare_one_folio(), btrfs_page_mkwrite() or btrfs_truncate_block(), a
> new btrfs_folio_state is attached with empty bitmaps, while PG_uptodate
> is still set on the folio.  Those callers see an uptodate folio, skip
> reading it, and only update the uptodate bits of their own range.  The
> other blocks are left marked not uptodate in the subpage bitmap.
> 
> That can trip the ASSERT() in can_skip_one_ordered_range(), which
> expects the whole range up to the ordered extent end or folio end to be
> uptodate if its first block is.
> 
> Fix it by setting the uptodate bitmap in btrfs_attach_folio_state() if
> the data folio is uptodate.  On the read path, private is attached
> before the folio is uptodate, so nothing changes there.
> 
> Note: this was only build tested.
> 
> This patch was written with the help of an AI coding assistant (Claude),
> following a review comment from Sashiko AI review.
> 
> Signed-off-by: Brahmajit Das <bdas@suse.de>
> ---
>   fs/btrfs/subpage.c | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
> 
> diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c
> index ebf18efe1ea3..97d4824ae623 100644
> --- a/fs/btrfs/subpage.c
> +++ b/fs/btrfs/subpage.c
> @@ -63,6 +63,19 @@ int btrfs_attach_folio_state(const struct btrfs_fs_info *fs_info,
>   	if (IS_ERR(bfs))
>   		return PTR_ERR(bfs);
>   
> +	/*
> +	 * A data folio can lose its private while staying uptodate in the
> +	 * page cache, e.g. btrfs_release_folio() on a folio that then fails
> +	 * to be removed or split.  The new state starts with empty bitmaps,
> +	 * so sync the uptodate bitmap with the folio flag, or the blocks not
> +	 * touched by the caller would be considered not uptodate.
> +	 */
> +	if (type == BTRFS_SUBPAGE_DATA && folio_test_uptodate(folio)) {
> +		const unsigned int bpf = btrfs_blocks_per_folio(fs_info, folio);
> +
> +		bitmap_set(bfs->bitmaps, bpf * btrfs_bitmap_nr_uptodate, bpf);
> +	}

There is really only one call site requiring this.

Please do it in the btrfs_data_dirty_folio() call site.

> +
>   	folio_attach_private(folio, bfs);
>   	return 0;
>   }


  reply	other threads:[~2026-12-03 20:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 19:05 [syzbot] [btrfs?] kernel BUG in wait_subpage_spinlock syzbot
2026-11-30 18:26 ` [PATCH] btrfs: don't invalidate beyond-EOF folios without private in extent_writepage() Brahmajit Das
2026-11-30 20:47   ` Qu Wenruo
2026-12-01 13:14     ` listout
2026-12-01 20:27       ` Qu Wenruo
2026-12-02  3:34         ` Brahmajit Das
2026-12-02  3:55           ` Qu Wenruo
2026-12-03 13:30 ` [PATCH v3 0/3] btrfs: fix dirtying of folios that lost their private Brahmajit Das
2026-12-03 13:30   ` [PATCH v3 1/3] btrfs: don't dereference a missing folio private on writeback error Brahmajit Das
2026-12-03 13:30   ` [PATCH v3 2/3] btrfs: sync the uptodate bitmap when attaching a data folio state Brahmajit Das
2026-12-03 20:36     ` Qu Wenruo [this message]
2026-12-03 13:30   ` [PATCH v3 3/3] btrfs: re-attach folio private when a released folio gets dirtied Brahmajit Das
2026-12-03 20:36     ` Qu Wenruo

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=2987f347-767b-43df-b114-b3ee1284a568@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=bdas@suse.de \
    --cc=david@kernel.org \
    --cc=dsterba@suse.com \
    --cc=jgg@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=listout@listout.xyz \
    --cc=mason@kernel.org \
    --cc=peterx@redhat.com \
    --cc=syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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

all inboxes | Powered by JetHome®