mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Rik van Riel <riel@surriel.com>, linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
	Suren Baghdasaryan <surenb@google.com>,
	Yuan-Hao Hsu <aa9736195201@gmail.com>,
	Christoph Hellwig <hch@infradead.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH 1/8] mm/gup: break out gup_fill_pages() helper
Date: Tue, 3 Nov 2026 18:04:01 +0100	[thread overview]
Message-ID: <e610aa21-4d35-4d9d-8754-bbfdec57a9a5@kernel.org> (raw)
In-Reply-To: <4ffa2c82c538c12447d48fee2532f67c35f7eab7.camel@surriel.com>

On 11/3/26 18:00, Rik van Riel wrote:
> On Tue, 2026-11-03 at 17:39 +0100, David Hildenbrand (Arm) wrote:
>> On 11/3/26 17:29, Rik van Riel wrote:
>>>
>>> faultin_page_range() and populate_vma_page_range
>>> both call the GUP code with a NULL pages pointer.
>>
>> That's not what I meant. I know that we have GUP users without
>> pages array.
>>
>> In the code change you are performing the check is not required.
>>
>> That's why there wasn't one in the first place.
> 
> It looks like 2 of the 3 callers of gup_fill_pages()
> check for pages existing. The other does not.
> 
> Should we just have the check in this one place, and
> not depend on the caller?
> 

That should be spelled out in the patch description.

The change as it stands in this patch looks useless :)

Although trying to fill something that doesn't exist is a bit weird.

But if it makes the calling code nicer, sure.

>>
>>
>>>
>>> However, now we have a situation where:
>>> 1) Only a few oddball callers of GUP need the dcache flush, and
>>> 2) Those need to do their OWN flush after a write, and
>>> 3) The dcache flush is not needed for most other GUP callers.
>>>
>>> We could do two different things here to solve the
>>> asymmetry.
>>>
>>> Either we could add dcache flushing to 
>>> unpin_user_pages_dirty_lock(), and make sure all
>>> the callers that need to call that function, or
>>> we could move the cache flushing to the GUP callers.
>>>
>>> Then we have KSM, which uses GUP, and which would like
>>> to see the latest page contents...
>>
>> It's all very inconsistent. And undocumented. And error prone.
>>
>> Could we have GUP-fast also flush the dcache for consistency or
>> must that only be called with the PT lock held?
> 
> I think we could, but it does not look like any of
> them need it.

Sure, but it makes the code more consistent and from a GUP PoV easier to understand.

> 
> Out of the 83 callers of gup_fast, many DMA into the
> page, and the drivers do their own flushing. Also,
> flushing before the DMA write doesn't help.
> 
> KVM, Infiniband, and others pin the pages, sometimes
> for longer periods of time, and either flush around 
> their reads and writes, or run only on architectures
> where we don't need to.
> 
> The others access the page through the user's own
> virtual address, which again does not require a
> dcache flush.
> 
> Only a small number of slow GUP callers need dcache
> flushes.
> 
> It may make more sense to move the cache flushes
> all the way out into __get_user_pages() and away
> from the follow_page_mask() call chain, so we can
> maybe merge more of the helper functions between
> slow GUP and fast GUP.

That's likely more work, can you look into that?


-- 
Cheers,

David

  reply	other threads:[~2026-11-03 17:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 19:30 [RFC PATCH v5 0/8] batch lookups in follow_page_mask() Rik van Riel
2026-11-02 19:30 ` [PATCH 1/8] mm/gup: break out gup_fill_pages() helper Rik van Riel
2026-11-03  8:43   ` David Hildenbrand (Arm)
2026-11-03 16:29     ` Rik van Riel
2026-11-03 16:39       ` David Hildenbrand (Arm)
2026-11-03 17:00         ` Rik van Riel
2026-11-03 17:04           ` David Hildenbrand (Arm) [this message]
2026-11-03 19:30             ` Rik van Riel
2026-11-02 19:30 ` [PATCH 2/8] mm/gup: convert follow_page_mask() to return a long Rik van Riel
2026-11-02 19:30 ` [PATCH 3/8] mm/gup: split out folio grab-and-store helper Rik van Riel
2026-11-02 19:30 ` [PATCH 4/8] mm/gup: break out gup_lookup_pte() helper Rik van Riel
2026-11-02 19:30 ` [PATCH 5/8] mm/gup: fill the pages array outside the pud/pmd lock Rik van Riel
2026-11-02 19:30 ` [PATCH 6/8] mm/gup: return a huge page's full count from follow_page_mask() Rik van Riel
2026-11-02 19:30 ` [PATCH 7/8] mm/gup: walk multiple PTEs per follow_page_pte() call Rik van Riel
2026-11-02 19:30 ` [PATCH 8/8] mm/gup: batch contiguous same-folio PTEs into one refcount grab Rik van Riel
2026-11-03  8:35   ` David Hildenbrand (Arm)
2026-11-03 16:42     ` Rik van Riel
2026-11-03 16:55       ` 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=e610aa21-4d35-4d9d-8754-bbfdec57a9a5@kernel.org \
    --to=david@kernel.org \
    --cc=aa9736195201@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=riel@surriel.com \
    --cc=surenb@google.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®