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

From: Jason Gunthorpe
Date: Mon Apr 24 2023 - 14:00:15 EST


On Mon, Apr 24, 2023 at 04:40:26PM +0300, Kirill A. Shutemov wrote:
> > Something more general would be preferable, however I believe there were
> > concerns broader than write notify, for instance not correctly marking the
> > folio dirty after writing to it, though arguably the caller should
> > certainly be ensuring that (and in many cases, do).
>
> It doesn't make much sense to me.
>
> Shared writable mapping without page_mkwrite (or pfn_write) will setup
> writeable PTE even on read faults[1], so you will not get the page dirty,
> unless you scan page table entries for dirty bit.

The general statement for supporting GUP is that the VMA owner never
relies on write protect, either explicitly through removing the write
bit in the PTE or implicitly through zapping the inode and removing
all PTEs.

The general bug we have is that the FS does some action to prevent
writes and then becomes surprised that the page was made dirty.

GUP allows write access to the page to continue past any write protect
action the FS takes.

AFAIK all GUP users do correctly do mkdirty and we have helpers to
support this during unpin, that is not the bug.

So, I don't know about page_mkwrite, if it correlates with the abvoe
then great :)

Jason