mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Rik van Riel <riel@surriel.com>,
	"David Hildenbrand (Arm)" <david@kernel.org>,
	linux-kernel@vger.kernel.org
Cc: kernel-team@meta.com, Andrew Morton <akpm@linux-foundation.org>,
	Jason Gunthorpe <jgg@ziepe.ca>, Peter Xu <peterx@redhat.com>,
	linux-mm@kvack.org
Subject: Re: [RFC PATCH v3 3/8] mm/gup: split follow_page_pte_commit() out of follow_page_pte()
Date: Sat, 22 Aug 2026 14:31:40 -0700	[thread overview]
Message-ID: <42d8fc20-4ee6-4bed-b2b4-3f968bd29f5d@nvidia.com> (raw)
In-Reply-To: <f86ca125a9b63cdab8edeb3c3b02a29141f18c1a.camel@surriel.com>

On 8/22/26 6:20 AM, Rik van Riel wrote:
> On Fri, 2026-08-21 at 15:04 -0700, John Hubbard wrote:
>>
>> You have delved too deep, and now uncovered something that's been
>> a problem for the whole time. :)
>>
>> Specifically, "no, GUP should not be setting folios nor pages
>> dirty", because that generally needs to be done as part of a
>> filesystem
>> coordinated set of steps. If the page is dirty, and the filesystem
>> didn't expect it to be, that leads to problems.
>>
>> This is part of the big, remaining set of required fixes, that
>> launched the creation of pin_user_pages*() and related. Connecting
>> up the filesystems properly is yet to be done. And until then, this
>> is a real defect.
>>
> Not just filesystems.
> 
> I found about two dozen places where drivers
> fail to mark a page dirty after writing to
> it, after obtaining the page from GUP.
> 

Yes, I agree about that problem, but it's not the only one. It turns
out that the only thing worse than failing to mark a page dirty is
marking it dirty without coordinating with the filesystem.

> I'll get out patches for that, unless there's
> some reason I shouldn't.
> 

Well...on a file-backed page, marking it dirty is the *last* step of
a sequence, and a driver cannot run the earlier steps.

ext4_page_mkwrite() into ext4_block_page_mkwrite() runs it in this
order:

	sb_start_pagefault(inode->i_sb);	/* freeze protection */
	file_update_time(vma->vm_file);
	filemap_invalidate_lock_shared(mapping);	/* truncate */
	ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, credits);
	ext4_block_write_begin(handle, folio, 0, len, get_block);
	folio_mark_dirty(folio);
	ext4_journal_stop(handle);
	folio_wait_stable(folio);

A set_page_dirty() at the driver's write site is that
folio_mark_dirty(), but with none of the preparation above it.

ext4 documents this case already, in ext4_journalled_dirty_folio() on
the data=journal path:

  * ... except for the case when someone
  * had the page pinned and dirtied the page through this pin (e.g. by doing
  * direct IO to it). In that case we'd need to attach buffers here to the
  * transaction but we cannot due to lock ordering.

Its workaround is folio_set_checked(), which defers the real work to
ext4_writepages(). If ext4 can't do the preparation from inside the
dirty call, a driver can't either.

So for a file-backed page there's nothing the driver can add. What's
missing is a way for the filesystem to be told before the device
writes, and to revoke the pin when it needs to, which is where the
lease proposals come in. None of that exists today.

And yes, unpin_user_pages_dirty_lock() is in the same awkward mess.

thanks,
-- 
John Hubbard


  reply	other threads:[~2026-08-22 21:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11  2:51 [RFC PATCH v3 0/8] batch lookups in follow_page_mask() Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 1/8] mm/gup: break out gup_fill_pages() helper Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 2/8] mm/gup: convert follow_page_mask() to return a long Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 3/8] mm/gup: split follow_page_pte_commit() out of follow_page_pte() Rik van Riel
2026-08-12 11:50   ` David Hildenbrand (Arm)
2026-08-12 13:02     ` Rik van Riel
2026-08-12 13:23       ` David Hildenbrand (Arm)
2026-08-12 16:19         ` Rik van Riel
2026-08-21 17:38         ` Rik van Riel
2026-08-21 22:04           ` John Hubbard
2026-08-22 13:20             ` Rik van Riel
2026-08-22 21:31               ` John Hubbard [this message]
2026-08-24 13:20                 ` Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 4/8] mm/gup: break out follow_one_pte() helper Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 5/8] mm/gup: fill the pages array outside the pud/pmd lock Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 6/8] mm/gup: return a huge page's full count from follow_page_mask() Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 7/8] mm/gup: walk multiple PTEs per follow_page_pte() call Rik van Riel
2026-08-11  2:51 ` [RFC PATCH v3 8/8] mm/gup: batch contiguous same-folio PTEs into one refcount grab Rik van Riel
2026-08-12 11:41 ` [RFC PATCH v3 0/8] batch lookups in follow_page_mask() David Hildenbrand (Arm)

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=42d8fc20-4ee6-4bed-b2b4-3f968bd29f5d@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=riel@surriel.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®