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>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	kernel-team@meta.com, Dave Hansen <dave.hansen@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	David Hildenbrand <david@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Peter Xu <peterx@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	Usama Arif <usamaarif642@gmail.com>
Subject: Re: [PATCH RFC v4 05/12] mm/gup: add get_user_page_vma() to fault in a page under a held lock
Date: Mon, 27 Jul 2026 19:45:21 -0700	[thread overview]
Message-ID: <e02b3b9f-85af-4df8-923a-cddf13afb6c7@nvidia.com> (raw)
In-Reply-To: <20260724222934.1463812-6-riel@surriel.com>

On 7/24/26 3:29 PM, Rik van Riel wrote:
...
> +struct page *get_user_page_vma(struct vm_area_struct *vma, unsigned long addr,
...
> +	ret = check_vma_flags(vma, gup_flags, VM_IO | VM_PFNMAP);
> +	if (ret)
> +		goto fail;
> +	pfnmap = vma->vm_flags & (VM_IO | VM_PFNMAP);

This treats VM_IO and VM_PFNMAP as the same exception, but they have
different meanings. VM_IO tells MM callers not to inspect the mapped
pages because accesses can have side effects. It does not imply that
the VMA contains raw PFNs!

For example, sg_mmap() creates a VM_IO-only VMA whose fault handler
installs ordinary pages from the SCSI reserve buffer. If such a page is
already present, follow_page_mask() returns it before the pfnmap test
below is reached. Patch 6 then lets /proc/PID/mem and ptrace copy that
page directly, even though sg provides no ->access callback and the
operation fails today. Writes can also modify the buffer when the
mapping is writable. Existing ptrace authorization still applies, so
this is not a privilege bypass, but it removes the VM_IO exclusion for
a driver that did not opt in through ->access.

An untouched page in the same VMA still fails because pfnmap is also
true for VM_IO and this function refuses to fault it. The result
therefore depends on whether the target previously touched the page.
The required exception is narrower. A remap_pfn_range() VMA has both
VM_IO and VM_PFNMAP, but VM_PFNMAP is what identifies the mapping whose
COWed page should be returned. 

So if you use the FOLL_PFNMAP_COW flag suggested on patch 4, and test
only VM_PFNMAP here:

	ret = check_vma_flags(vma, gup_flags);
	if (ret)
		goto fail;
	pfnmap = vma->vm_flags & VM_PFNMAP;

Patch 6 can set FOLL_PFNMAP_COW for __access_remote_vm().
check_vma_flags() then permits VM_IO | VM_PFNMAP for that caller while
continuing to reject VM_IO-only mappings. vm_normal_page() supplies the
remaining distinction: it returns the COWed normal page and rejects the
raw PFN.

Something like that.

thanks,
-- 
John Hubbard


  parent reply	other threads:[~2026-07-28  2:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 22:29 [PATCH RFC v4 0/12] mm: use per-VMA lock in __access_remote_vm for improved monitoring reliability Rik van Riel
2026-07-24 22:29 ` [PATCH RFC v4 01/12] x86/mm: add untagged_addr_remote_unlocked() Rik van Riel
2026-07-27 14:50   ` Suren Baghdasaryan
2026-07-28  1:39   ` John Hubbard
2026-07-24 22:29 ` [PATCH RFC v4 02/12] riscv/mm: " Rik van Riel
2026-07-27 14:53   ` Suren Baghdasaryan
2026-07-28  1:44   ` John Hubbard
2026-07-24 22:29 ` [PATCH RFC v4 03/12] mm: rename get_user_page_vma_remote() to get_user_page_lookup_vma() Rik van Riel
2026-07-27 14:58   ` Suren Baghdasaryan
2026-07-24 22:29 ` [PATCH RFC v4 04/12] mm/gup: let check_vma_flags() ignore selected VMA flags Rik van Riel
2026-07-27 15:03   ` Suren Baghdasaryan
2026-07-28  2:40   ` John Hubbard
2026-07-28 14:29     ` Rik van Riel
2026-07-24 22:29 ` [PATCH RFC v4 05/12] mm/gup: add get_user_page_vma() to fault in a page under a held lock Rik van Riel
2026-07-27 16:54   ` Suren Baghdasaryan
2026-07-28  2:45   ` John Hubbard [this message]
2026-07-24 22:29 ` [PATCH RFC v4 06/12] mm: use per-VMA lock in __access_remote_vm() for single-VMA accesses Rik van Riel
2026-07-27 18:51   ` Suren Baghdasaryan
2026-07-24 22:29 ` [PATCH RFC v4 07/12] mm: read remote strings under the per-VMA lock Rik van Riel
2026-07-24 22:29 ` [PATCH RFC v4 08/12] selftests/mm: cover /proc/pid/mem access to VM_PFNMAP memory Rik van Riel
2026-07-28 20:58   ` John Hubbard
2026-07-24 22:29 ` [PATCH RFC v4 09/12] mm/gup: build get_user_page_lookup_vma() on get_user_page_vma() Rik van Riel
2026-07-24 22:29 ` [PATCH RFC v4 10/12] mm/gup: pass an end address to follow_page_mask() and return a page count Rik van Riel
2026-07-24 22:29 ` [PATCH RFC v4 11/12] mm/gup: batch contiguous PTE-mapped large folios in follow_page_mask() Rik van Riel
2026-07-27 13:54   ` David Hildenbrand (Arm)
2026-07-28  0:37     ` Rik van Riel
2026-07-28 19:05       ` David Hildenbrand (Arm)
2026-07-28 20:49         ` Rik van Riel
2026-07-24 22:29 ` [PATCH RFC v4 12/12] selftests/mm: add a slow-GUP content and COW test for mTHP Rik van Riel
2026-07-26 11:56   ` Mike Rapoport
2026-07-27 14:05     ` David Hildenbrand (Arm)
2026-07-28 20:31       ` Rik van Riel
2026-07-27 13:53   ` 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=e02b3b9f-85af-4df8-923a-cddf13afb6c7@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=jgg@ziepe.ca \
    --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=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=usamaarif642@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.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®