mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pedro Falcato <pfalcato@suse.de>
To: Brahmajit Das <listout@listout.xyz>
Cc: dsterba@suse.com, linux-btrfs@vger.kernel.org,
	quwenruo.btrfs@gmx.com,  clm@fb.com, mason@kernel.org,
	david@kernel.org, jgg@ziepe.ca,  jhubbard@nvidia.com,
	peterx@redhat.com, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	Brahmajit Das <bdas@suse.de>,
	 syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied
Date: Thu, 3 Dec 2026 13:28:27 +0000	[thread overview]
Message-ID: <axFtfUuAluTAYLb_@pedro-suse.tail5790ac.ts.net> (raw)
In-Reply-To: <20261202041853.4184717-1-listout@listout.xyz>

On Wed, Dec 02, 2026 at 09:48:53AM +0530, Brahmajit Das wrote:
> From: Brahmajit Das <bdas@suse.de>
> 
> syzbot reported an assertion failure in wait_subpage_spinlock():
> 
>   assertion failed: folio_test_private(folio) && folio_get_private(folio),
>   in fs/btrfs/inode.c:7616
>   kernel BUG at fs/btrfs/inode.c:7616!
>   Call Trace:
>    btrfs_invalidate_folio+0x26e/0xc50
>    extent_writepage fs/btrfs/extent_io.c:2058 [inline]
>    extent_write_cache_pages fs/btrfs/extent_io.c:2843 [inline]
>    btrfs_writepages+0x129f/0x28c0
>    do_writepages+0x338/0x560
>    filemap_fdatawrite_range+0x1ef/0x2f0
>    btrfs_start_ordered_extent_nowriteback+0x305/0x6e0
>    btrfs_page_mkwrite+0x856/0x1a40
>    ...
>    __gup_longterm_locked+0x1032/0x15c0
>    ...
>    blkdev_direct_IO+0x121d/0x17b0
>    aio_read+0x33a/0x4d0
> 
> The program does an O_DIRECT read into a MAP_SHARED mapping of a btrfs
> file, while the same file is being truncated.
> 
> A dirty folio of a btrfs data inode is expected to have folio::private,
> but a folio can lose it while it stays in the page cache and is pinned
> by an in-flight O_DIRECT read, e.g.:
> 
>   truncate_inode_partial_folio()
>     folio_invalidate(folio, offset, length)
>       btrfs_invalidate_folio()
>         btrfs_release_folio()          /* folio is clean */
>           __btrfs_release_folio()
>             clear_folio_extent_mapped()
>     folio_split_or_unmap()
>       folio_split()                    /* fails, the folio is pinned */
> 
> or from any failed large folio split, as __folio_freeze_split_file()
> calls filemap_release_folio() before folio_ref_freeze().
> 
> When the read completes, the folio is re-dirtied without notifying the
> fs:
> 
>   bio_release_pages()
>     folio_mark_dirty()
>       btrfs_data_dirty_folio()
>         filemap_dirty_folio()

FWIW, this sounds like a variant of
https://lore.kernel.org/linux-mm/20261119-gup-dirty-what-v1-0-236d69f25c24@suse.de/.
(which I will respin soon)

> 
> If the folio is beyond EOF by then, btrfs_data_dirty_folio() does not
> touch any btrfs state, and the next writeback calls folio_invalidate()
> on a folio without private, triggering the above ASSERT() in the

? why is writeback calling folio_invalidate()?

> bs < folio size case.  If the folio straddles EOF,
> btrfs_folio_set_fixup_dirty() dereferences the NULL folio private
> instead.
> 
> Fix it by re-attaching the folio private in btrfs_data_dirty_folio()
> if it is missing.  ->dirty_folio() may not block, so use GFP_NOWAIT.

NAK to this approach. I need to think about folio_invalidate() and its
interaction with GUP a little harder.

-- 
Pedro

  reply	other threads:[~2026-12-03 13:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  4:18 Brahmajit Das
2026-12-03 13:28 ` Pedro Falcato [this message]
2026-12-03 20:43   ` Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2026-12-02  4:11 Brahmajit Das
2026-12-02  4:08 Brahmajit Das

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=axFtfUuAluTAYLb_@pedro-suse.tail5790ac.ts.net \
    --to=pfalcato@suse.de \
    --cc=bdas@suse.de \
    --cc=clm@fb.com \
    --cc=david@kernel.org \
    --cc=dsterba@suse.com \
    --cc=jgg@ziepe.ca \
    --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=quwenruo.btrfs@gmx.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®