Re: [PATCH v2] mm/gup: disallow GUP writing to file-backed mappings by default

Jason Gunthorpe
2023-04-24T23:30:15Z

On Tue, Apr 25, 2023 at 12:26:25AM +0100, Lorenzo Stoakes wrote:
> On Mon, Apr 24, 2023 at 08:17:11PM -0300, Jason Gunthorpe wrote:
> > On Tue, Apr 25, 2023 at 12:03:34AM +0100, Lorenzo Stoakes wrote:
> >
> > > Except you dirty a page that is mapped elsewhere that thought everything
> > > was cleaned and... not sure the PTLs really help you much?
> >
> > If we have a writable PTE then while the PTE's PTL is held it is impossible
> > for a FS to make the page clean as any cleaning action has to also
> > take the PTL to make the PTE non-present or non-writable.
> >
>
> That's a very good point! Passing things back with a spinlock held feels
> pretty icky though, and obviously a no-go for a FOLL_PIN. Perhaps for a
> FOLL_GET this would be workable.

I didn't look closely at the ptrace code but maybe it would work to
lock the folio and pass back a locked folio. Interacting with the PTLs
to make the lock reliable. It is the logical inverse of the code I
pointed to for inserting a folio into the page table. (but I've never
looked at the folio lock or how the FSs use it, so don't belive me on
this)

Another interesting idea would be to use mm/pagewalk.c to implement
the memory copy fully under the PTLs.

Jason