Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Rik van Riel <riel@surriel.com>, Yuan-Hao Hsu <aa9736195201@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
	Lorenzo Stoakes <ljs@kernel.org>,
	liam@infradead.org, Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Aristeu Rozanski <aris@ruivo.org>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/gup: batch PTE-mapped large folios in gup_fast_pte_range()
Date: Mon, 12 Oct 2026 21:05:55 +0200	[thread overview]
Message-ID: <c3c6f83d-380f-4a9b-a204-fd157ee77648@kernel.org> (raw)
In-Reply-To: <ff62aeaeb5ced49640c959c047b2e9f320f5c10f.camel@surriel.com>

On 10/12/26 19:58, Rik van Riel wrote:
> On Sun, 2026-10-11 at 03:52 +0800, Yuan-Hao Hsu wrote:
>> On Wed, 07 Oct 2026 06:47:06 -0400, Rik van Riel wrote:
>>> Since this is lockless, the PTEs could change under
>>> us between when we walk them in folio_pte_batch_flags()
>>> and the batched try_grab_folio().
>>>
>>> Is that race condition safe, or do we need to re-check
>>> afterward that:
>>> 1) the ptes still point at the same folio, and/or
>>> 2) the folio still spans the entire range, and was
>>>    not split before we grabbed the refcount?
>>
>> It is safe, because the batch only runs after the first page of the
>> run has gone through the unchanged per-page path: the folio reference
>> is already held (and for FOLL_PIN the _pincount already raised, with
>> the smp_mb__after_atomic() in try_grab_folio_fast()) before any of
>> the other ptes is read.
>>
>> 2) With that reference held the folio cannot be split:
> 
> You are right. The page tables can still be remapped
> to point at something else after gup_fast_pte_range()
> grabs a reference to the folio, but that can happen
> no matter what precautions we take inside gup_fast,
> because it can happen after gup_fast has returned.
> 
> I have no other concerns, so feel free to add my:
> 
> Reviewed-by: Rik van Riel <riel@surriel.com>

There are a bunch of things I don't like about this, including suspiciously LLM
-sloppy looking stuff like

+	if (!pte_write(pte)) {
+		for (i = 1; i < nr; i++) {
+			if (gup_must_unshare(NULL, flags, page + i))
+				break;
+		}
+		nr = i;
+	}

I'll find someone to polish this up.

-- 
Cheers,

David


      reply	other threads:[~2026-10-12 19:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17  8:37 [PATCH] mm/gup: batch PTE-mapped large folios in gup_fast_pte_range() Yuan-Hao Hsu
2026-09-17  8:42 ` David Hildenbrand (Arm)
2026-09-17  8:43   ` David Hildenbrand (Arm)
2026-09-17  9:01     ` Yuan-Hao Hsu
2026-10-07 10:07   ` Rik van Riel
2026-10-07 10:14     ` David Hildenbrand (Arm)
2026-10-07 10:47 ` Rik van Riel
2026-10-10 19:52   ` Yuan-Hao Hsu
2026-10-12 17:58     ` Rik van Riel
2026-10-12 19:05       ` David Hildenbrand (Arm) [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=c3c6f83d-380f-4a9b-a204-fd157ee77648@kernel.org \
    --to=david@kernel.org \
    --cc=aa9736195201@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=aris@ruivo.org \
    --cc=dev.jain@arm.com \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=peterx@redhat.com \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /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