All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brahmajit Das <bdas@suse.de>
To: Pedro Falcato <pfalcato@suse.de>
Cc: Qu Wenruo <wqu@suse.com>,
	dsterba@suse.com,  linux-btrfs@vger.kernel.org, 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,
	 syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com,
	willy@infradead.org, jack@suse.cz, hch@lst.de
Subject: Re: [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied
Date: Fri, 4 Dec 2026 18:18:18 +0530	[thread overview]
Message-ID: <axK2WiBIlr-a0_HR@suse.de> (raw)
In-Reply-To: <axKGJtCg4ZrHlqqA@pedro-suse.tail5790ac.ts.net>

On Fri, Dec 04, 2026 at 10:05:49 +0000, Pedro Falcato wrote:
> +CC willy, jack, hch
> 
> On Fri, Dec 04, 2026 at 07:13:08AM +1030, Qu Wenruo wrote:
> > 
> > 
> > 在 2026/12/3 23:58, Pedro Falcato 写道:
> > [...]
> > > > 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)
> > 
> > One assumption doesn't meet the current code.
> > 
> > >  - ->dirty_folio() relies on buffers/IFS/etc being attached to the
> > >   folios. It _cannot_ attach them itself, as dirty_folio() cannot
> > >   block.
> > 
> > Iomap is already attaching it:
> > 
> > iomap_dirty_folio()
> >   ifs_alloc(inode, folio, 0);
> >     gfp = GFP_NOFS | __GFP_NOFAIL;
> >     ifs = kzalloc_flex(..., gfp);
> > 
> > Either it's already a bug, or we won't hit such folio without private for
> > the non-sleeping routes.
> 
> This is, strictly speaking, a bug. Per Documentation/filesystems/locking.rst:
> 
> locking rules:
> 	All except dirty_folio and free_folio may block
> 
> I think currently, de facto, it's not very likely to be hit[1]. Mostly because,
> for writenotify filesystems/VMAs, you'll always trip over ->page_mkwrite()
> (marking the folio dirty), and cleaning will always write-protect it before
> clearing the dirty flag off the folio.
> 
> [1] I _think_ there are ways to hit it, if you go down funky folio_cancel_dirty()
> paths.
> 
> > 
> > > 
> > > > 
> > > > 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()?
> > 
> > If a folio is beyond EOF, we have no need to write it, thus can go
> > invalidating it directly.
> 
> Why would you not rely on truncation itself to invalidate it?
> 
> > 
> > Or is there any better solution from the perspective of MM?
> 
> My understanding is that the truncation logic should correctly handle
> the semantics you want. 
> 
> As for the GUP problem, yes, this is yet another issue. It is known.
> ->dirty_folio() implementations cannot assume the memory allocation will
> succeed. And there's no possible fallback to "failure to dirty a folio".
> 
> The real solution (in my series) is to simply not discard this at-will.
> invalidate_folio() seems to be yet another variant of this issue.
> 
> For what it's worth, I observed a similar issue in mm/truncate code. I don't
> know what the correct approach would be. Keep the private around for GUP pins?
> Reject the truncate altogether?
> 
> (I don't think it's possible to do this last option; keeping the private is
> also weird, and I don't see how you can possibly ditch it after the folio is
> orphaned)
> 
> -- 
> Pedro

Just to note by mistake I created v2 a separate thread. v4 is at:
https://lore.kernel.org/all/20261204063235.1033893-1-listout@listout.xyz/

-- 
Brahmajit Das
SUSE L3

  reply	other threads:[~2026-12-04 12:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  4:18 [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied Brahmajit Das
2026-12-03  4:19 ` sashiko-bot
2026-12-03 13:28 ` Pedro Falcato
2026-12-03 20:43   ` Qu Wenruo
2026-12-04 10:05     ` Pedro Falcato
2026-12-04 12:48       ` Brahmajit Das [this message]
2026-12-04 21:05       ` Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2026-12-02  4:11 Brahmajit Das
2026-12-03  4:11 ` sashiko-bot
2026-12-02  4:08 Brahmajit Das
2026-12-02  5:51 ` sashiko-bot
2026-12-02  7:17   ` 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=axK2WiBIlr-a0_HR@suse.de \
    --to=bdas@suse.de \
    --cc=clm@fb.com \
    --cc=david@kernel.org \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --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=mason@kernel.org \
    --cc=peterx@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.