From: Rik van Riel <riel@surriel.com>
To: Usama Arif <usama.arif@linux.dev>
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
kernel-team@meta.com, David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@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>,
linux-mm@kvack.org, Jason Gunthorpe <jgg@ziepe.ca>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH RFC v3 4/6] mm/gup: add get_user_page_vma() to fault in a page under a held lock
Date: Mon, 20 Jul 2026 11:24:48 -0400 [thread overview]
Message-ID: <61d21f204aedae44b2b5cbe2e7ffb1d72fedc5c6.camel@surriel.com> (raw)
In-Reply-To: <20260720123505.1234897-1-usama.arif@linux.dev>
On Mon, 2026-07-20 at 05:35 -0700, Usama Arif wrote:
> On Fri, 17 Jul 2026 13:00:34 -0400 Rik van Riel <riel@surriel.com>
> wrote:
>
> >
> > + /*
> > + * Validate the VMA up front, like __get_user_pages(). A
> > VM_IO/VM_PFNMAP
> > + * VMA is not rejected outright: it can hold COWed pages
> > that have a
> > + * struct page, so let follow_page_mask() look for one,
> > and treat only
> > + * its struct-page-less PFNs as unreachable. Any other
> > rejection
> > + * (secretmem, bad permissions, ...) is final.
> > + */
> > + ret = check_vma_flags(vma, gup_flags);
> > + if (ret && !(vma->vm_flags & (VM_IO | VM_PFNMAP)))
>
> Do you need to somehow restructure check_vma_flags()?
>
> The first thing that check_vma_flags() does is:
>
> if (vm_flags & (VM_IO | VM_PFNMAP))
> return -EFAULT;
>
> check_vma_flags() returns before evaluating VM_READ,
> FOLL_FORCE, FOLL_ANON or the architecture permission check.
>
> The code then ignores that early error and may return a COWed
> page through follow_page_mask(). A non-FOLL_FORCE caller
> can therefore read a COWed page from a PROT_NONE PFNMAP VMA.
In this code path, if we return an error to
__access_remote_vm(), we end up falling back
to the ->access() hook, and will end up reading
the memory that's "under" that COW, instead of
the COWed page that is currently in the process
we are accessing.
In other words, I think the behavior of this
code is the way we want, even though the
implementation should be cleaned up.
How about we change check_vma_flags() so it
ignores specified flags?
check_vma_flags(vma, gup_flags, ignore_flags)
Then this one call to check_vma_flags can have
it ignore VM_IO | VM_PFNMAP, since we want to
access the COWed pages in those VMAs in this
code path, but fall back to ->access when
there are no COW pages.
>
> > + goto fail;
> > + pfnmap = ret;
> > +
> > + for (;;) {
> > + if (fatal_signal_pending(current)) {
> > + ret = -EINTR;
> > + goto fail;
> > + }
> > + cond_resched();
> > +
> > + page = follow_page_mask(vma, addr,
> > + gup_flags | FOLL_TOUCH |
> > FOLL_GET,
> > + &page_mask);
> > + if (!IS_ERR_OR_NULL(page))
> > + return page;
>
> __get_user_pages() does
>
> flush_anon_page(vma, subpage, start + j * PAGE_SIZE);
> flush_dcache_page(subpage);
>
> before returning the page. Do you need to that here as well above?
I suppose on systems with virtually indexed caches
we do need that.
Thanks for spotting that!
Now I also wonder if I could restructure get_user_page_vma_remote()
to do the lookup before the get_user_pages_remote(), and have
it then use the new get_user_page_vma() function, to avoid
the double VMA lookup (why are we doing that, anyway?)
>
--
All Rights Reversed.
next prev parent reply other threads:[~2026-07-20 15:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 17:00 [PATCH v3 0/6] mm: access remote process memory under the per-VMA lock Rik van Riel
2026-07-17 17:00 ` [PATCH RFC v3 1/6] x86/mm: add untagged_addr_remote_unlocked() Rik van Riel
2026-07-20 11:12 ` Usama Arif
2026-07-17 17:00 ` [PATCH RFC v3 2/6] riscv/mm: " Rik van Riel
2026-07-20 11:57 ` Usama Arif
2026-07-20 15:08 ` Rik van Riel
2026-07-20 16:46 ` Usama Arif
2026-07-20 17:34 ` Rik van Riel
2026-07-20 18:46 ` Usama Arif
2026-07-20 19:21 ` Rik van Riel
2026-07-20 19:39 ` Usama Arif
2026-07-17 17:00 ` [PATCH RFC v3 3/6] mm: rename get_user_page_vma_remote() to get_user_page_lookup_vma() Rik van Riel
2026-07-20 12:00 ` Usama Arif
2026-07-17 17:00 ` [PATCH RFC v3 4/6] mm/gup: add get_user_page_vma() to fault in a page under a held lock Rik van Riel
2026-07-20 12:35 ` Usama Arif
2026-07-20 15:24 ` Rik van Riel [this message]
2026-07-17 17:00 ` [PATCH RFC v3 5/6] mm: use per-VMA lock in __access_remote_vm() for single-VMA accesses Rik van Riel
2026-07-17 17:00 ` [PATCH RFC v3 6/6] selftests/mm: cover /proc/pid/mem access to VM_PFNMAP memory Rik van Riel
2026-07-21 18:12 ` [PATCH v3 0/6] mm: access remote process memory under the per-VMA lock David Hildenbrand (Arm)
2026-07-22 17:33 ` Rik van Riel
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=61d21f204aedae44b2b5cbe2e7ffb1d72fedc5c6.camel@surriel.com \
--to=riel@surriel.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=kernel-team@meta.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=rppt@kernel.org \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--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
all inboxes | Powered by JetHome®