mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: listout@listout.xyz
Cc: dsterba@suse.com, linux-btrfs@vger.kernel.org, clm@fb.com,
	mason@kernel.org, linux-kernel@vger.kernel.org,
	syzkaller-bugs@googlegroups.com,
	syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com
Subject: Re: [PATCH] btrfs: don't invalidate beyond-EOF folios without private in extent_writepage()
Date: Wed, 2 Dec 2026 06:57:02 +1030	[thread overview]
Message-ID: <fdcf86b0-4003-4f9b-a0fb-b02b1d11f441@gmx.com> (raw)
In-Reply-To: <20261201131410.2434793-1-listout@listout.xyz>



在 2026/12/1 23:44, listout@listout.xyz 写道:
> On 2026/12/1 Qu Wenruo wrote:
>> Mind to explain this a little more? On exact which path the folio's
>> private is cleared?
>>
>> Better with a calltrace showing the situation.
> 
> Unfortunately the console log doesn't show where private was dropped, and
> syzbot has no reproducer, so I can't give you a trace from the actual
> crash. From code reading, a pinned folio can lose its private but stay in
> the page cache in two ways:
> 
> 1) Partial invalidation in btrfs itself. For a range smaller than the
>     whole folio, btrfs_invalidate_folio() calls btrfs_release_folio(),
>     which only checks dirty/writeback:
> 
>     truncate_pagecache()
>       truncate_inode_pages_range()
>         truncate_inode_partial_folio()
>           folio_invalidate(folio, offset, length)
>             btrfs_invalidate_folio()
>               btrfs_release_folio()
>                 __btrfs_release_folio()
>                   clear_folio_extent_mapped()
>           folio_split_or_unmap()
>             folio_split()   <- fails, folio pinned by an in-flight O_DIRECT read
> 
> 2) Any failed large folio split. __folio_freeze_split_file() calls
>     filemap_release_folio() before folio_ref_freeze(), with no pin check,
>     so a split failing on a pinned folio leaves it without private
>     (reachable from truncate and from migration).
> 
> When the O_DIRECT read completes, bio_release_pages() -> folio_mark_dirty()
> -> btrfs_data_dirty_folio() re-dirties the folio. If it's beyond EOF by
> then, nothing is attached and we get the reported crash. If it straddles
> EOF, btrfs_subpage_set_fixup_dirty() would dereference the NULL private
> instead.
> 
>> Can we fix the bug by ensuring even filemap folios beyond EOF will have
>> proper private set?
> 
> Agreed, that's better. For v2 I'm thinking of making btrfs_release_folio()
> refuse to release while folio_maybe_dma_pinned(),

Would that race? E.g. at the time of btrfs_release_folio(), the folio is 
not yet pinned, but after the check, GUP pinned the folio, resulting the 
same folio private cleared problem.

I'm wondering if we can re-attach the private structure during 
btrfs_data_dirty_folio() to close the loop?

Thanks,
Qu

> so any folio that can
> still be re-dirtied without btrfs knowing keeps its private. That covers
> both paths above.
> 
> The remaining case is the full invalidation extent_writepage() does on
> beyond-EOF folios, which clears private unconditionally while the folio
> may stay in the page cache until truncate removes it. Would you prefer
> to skip that invalidation for pinned folios, or to re-attach private
> there before invalidating?
> 
> Thanks,
> Brahmajit


      reply	other threads:[~2026-12-01 20:27 UTC|newest]

Thread overview: 5+ 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 [this message]

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=fdcf86b0-4003-4f9b-a0fb-b02b1d11f441@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=listout@listout.xyz \
    --cc=mason@kernel.org \
    --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®