Re: [PATCH RFC 12/13] mm/gup: trigger FAULT_FLAG_UNSHARE when R/O-pinning a possibly shared anonymous page

Jason Gunthorpe
2022-03-02T16:56:09Z

On Thu, Feb 24, 2022 at 01:26:13PM +0100, David Hildenbrand wrote:
> Whenever GUP currently ends up taking a R/O pin on an anonymous page that
> might be shared -- mapped R/O and !PageAnonExclusive() -- any write fault
> on the page table entry will end up replacing the mapped anonymous page
> due to COW, resulting in the GUP pin no longer being consistent with the
> page actually mapped into the page table.
>
> The possible ways to deal with this situation are:
> (1) Ignore and pin -- what we do right now.
> (2) Fail to pin -- which would be rather surprising to callers and
> could break user space.
> (3) Trigger unsharing and pin the now exclusive page -- reliable R/O
> pins.

How does this mesh with the common FOLL_FORCE|FOLL_WRITE|FOLL_PIN
pattern used for requesting read access? Can they be converted to
just FOLL_WRITE|FOLL_PIN after this?

Jason