Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Pedro Falcato <pfalcato@suse.de>,
	John Hubbard <jhubbard@nvidia.com>,
	Christoph Hellwig <hch@infradead.org>, Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Zi Yan <ziy@nvidia.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Lorenzo Stoakes <ljs@kernel.org>, Peter Xu <peterx@redhat.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	linux-ext4@vger.kernel.org, linux-nfs@vger.kernel.org,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Nico Pache <nico.pache@linux.dev>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	Kiryl Shutsemau <kas@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Kairui Song <kasong@tencent.com>, Qi Zheng <qi.zheng@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
	Baoquan He <baoquan.he@linux.dev>,
	Michal Hocko <mhocko@kernel.org>,
	linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH RFC 0/5] mm: GUP dirty + ->release_folio() fixes
Date: Wed, 25 Nov 2026 10:50:42 +0100	[thread overview]
Message-ID: <55114986-0ba1-4a80-8498-bf674d64e01b@kernel.org> (raw)
In-Reply-To: <awWNyDZT2SVu2Zp9@pedro-suse.tail5790ac.ts.net>

On 11/24/26 14:37, Pedro Falcato wrote:
> Hi John, Christoph, Jan,
> 
> Thank you for your replies. Since you largely share the same point, I'll
> combine this into a single reply.
> 
> On Thu, Nov 19, 2026 at 04:55:30PM -0800, John Hubbard wrote:
>> On 11/19/26 12:10 PM, Pedro Falcato wrote:
>>> Sooo.... It turns out GUP dirty and ->release_folio() interact really
>>> weirdly. This was initially reported by some AI agent, and David let me
>>> know.
>>>
>>> The basic issue is:
>>
>> The basic issue is covered in a series of LWN articles that span 5 or
>> 6 years:
>>
>>     https://lwn.net/Kernel/Index/#Memory_management-get_user_pages
>>
>> Probably good to read and absorb that. There's a lot.
>>
> 
> Thanks. I was aware of some of this, but it's good to take a fresh look again :)
>  
>> The problem remains not fully solved. pin_user_pages() is a building
>> block, but we need to fully coordinate with filesystems in order to
>> finish. It's good that you are looking at this.
>>
>>>  - ->dirty_folio() relies on buffers/IFS/etc being attached to the
>>>    folios. It _cannot_ attach them itself, as dirty_folio() cannot
>>>    block.
>>>  - certain MM paths (reclaim, khugepaged, folio split, etc) are very
>>>    trigger-happy when it comes to asking filesystems to release them. In
>>>    most cases, barring any dirty folios, buffers, it will just drop
>>>    them.
>>>  - there is no problem in usual IO submission, but issues start to pop
>>>    up with GUP, where the code flow (roughly) becomes:
>>>         [get_user_pages(), etc]
>>>            ->page_mkwrite() called here, or before
>>>              ->private correctly populated with whatever the filesystem
>>>                expects.
>>>              folio is marked as dirty, initially.
>>>        *write finishes*
>>>        folio_lock();
>>>        folio_mark_dirty();
>>>          ->dirty_folio()
>>>               dirty_folio expects ->private to be populated by
>>>               ->page_mkwrite(), ->write_begin().
>>>        folio_unlock();
>>>
>>> What happens if any filemap_release_folio() runs (and succeeds) between
>>> the initial dirtying (plus eventually writeback) and the write to the
>>> folio completes? Welp, it's unpredictable. ext4 for example will
>>> WARN_ONCE, and likely drop data (see ext4_dirty_folio()).
>>>
>>> So, what can we do about it? It's complicated, hence why this is an RFC.
>>> For the possible solutions:
>>>  - ->dirty_folio() attaching this FS information itself is not really
>>>    possible in many cases. ->dirty_folio() can't block, nor is it even
>>>    guaranteed to hold the folio lock while being called.
>>>  - Can pincount help? Kind of. Things like folio_maybe_dma_pinned() are
>>>    rough, and don't deal with the usage of get_user_pages(FOLL_WRITE).
>>>    pincount itself isn't available in the common order-0 case, and not
>>>    available on order-1 as well on 32-bit, but who cares about that^W^W^W^W^W
>>>  - Could get_user_pages() ban FOLL_WRITE? Mayhaps. I would not be
>>>    opposed to that, but that's probably a larger change than ideal for stable,
>>>    and I'm not familiar enough with GUP requirements to decide to go that way.
>>>    This would require migrating all FOLL_WRITE users to
>>>    pin_user_pages().
>>>  - Can the whole system be reworked? Probably, but not for stable.
>>>
>>> This patch series is really rough but kind-of works. Instead of using
>>> folio_maybe_dma_pinned(), which only interacts with pin_user_pages(), I
>>
>> pin_user_pages() was specifically introduced for this exact class of
>> problem. get_user_pages() is now meant for other, much more limited cases.
>> I've attempted to document that, here:
>>
>>     https://docs.kernel.org/core-api/pin_user_pages.html
> 
> Ok, so I guess you want me to drop the hacks to make GUP FOLL_WRITE not
> screw itself over? To be clear, the rest is still broken, even with pin_user_pages().
> It just means we get nicer looking fixes, and I can drop patch 3.

I think focusing on pinned pages as the first approach+long-term solution is ok.

BUT

When I looked into this issue, there were some problematic things.

We have some odd drivers that use FOLL_GET|FOLL_WRITE, but I am not too
concerned about them.

But are ways where unprivileged users can mess with  FOLL_GET|FOLL_WRITE
references to trigger this.

I think the two that stand out are:

1) /proc/self/mem access using mem_rw() -> access_remote_vm()

User can write to a writable-mapped page-cache PTE. Then we can race with
removal of folio metadta, to then set the folio dirty afterwards.

I remember a good reason to not convert these paths in the past (we are not
performing DMA).


2) /dev/fuse using fuse_copy_fill() -> iov_iter_get_pages2()

Same problem, just through fuse.


So either

1) We fix all such cases now where unprivileged users can trigger this,
   converting to FOLL_PIN.

2) We handle it for now in reclaim code by checking for unexpected folio
   references instead of GUP pins. The spirit of this series.

3) We accept that unprivileged users can trigger unexpected behavior
   (WARN_ON_ONCE()) etc. I don't think that's an option.

4) We turn all these checks for unexpected behavior into soft warnings.

I think only ext4 is problematic, but I didn't check.

-- 
Cheers,

David

  parent reply	other threads:[~2026-11-25  9:50 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 20:10 [PATCH RFC 0/5] mm: GUP dirty + ->release_folio() fixes Pedro Falcato
2026-11-19 20:10 ` [PATCH RFC 1/5] mm/khugepaged: fix filemap_release_folio() interaction with GUP dirty Pedro Falcato
2026-11-19 20:10 ` [PATCH RFC 2/5] mm/huge_memory: " Pedro Falcato
2026-11-20 20:11   ` sashiko-bot
2026-11-19 20:10 ` [PATCH RFC 3/5] mm/vmscan: avoid releasing FS metadata for !FOLL_PIN gup folios Pedro Falcato
2026-11-19 20:10 ` [PATCH RFC 4/5] mm/vmscan: be more careful when releasing FS metadata if buffer_heads_over_limit Pedro Falcato
2026-11-25  8:45   ` Jan Kara
2026-11-19 20:10 ` [PATCH RFC 5/5] mm/filemap: refuse releasing maybe_dma_pinned folios Pedro Falcato
2026-11-20 20:11   ` sashiko-bot
2026-11-25  8:47   ` Jan Kara
2026-11-25  8:52     ` Jan Kara
2026-11-20  0:55 ` [PATCH RFC 0/5] mm: GUP dirty + ->release_folio() fixes John Hubbard
2026-11-24 13:37   ` Pedro Falcato
2026-11-25  7:36     ` Christoph Hellwig
2026-11-25  9:50     ` David Hildenbrand (Arm) [this message]
2026-11-25 10:05       ` Christoph Hellwig
2026-11-25 10:19         ` David Hildenbrand (Arm)
2026-11-20 11:57 ` Jan Kara
2026-11-20 17:39 ` Christoph Hellwig
2026-11-20 20:11 ` sashiko-bot
2026-11-24 19:15 ` [syzbot ci] " syzbot ci

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=55114986-0ba1-4a80-8498-bf674d64e01b@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --cc=jhubbard@nvidia.com \
    --cc=kas@kernel.org \
    --cc=kasong@tencent.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=peterx@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=willy@infradead.org \
    --cc=yuanchu@google.com \
    --cc=ziy@nvidia.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