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

Jason Gunthorpe
2022-03-02T21:00:04Z

On Wed, Mar 02, 2022 at 09:38:09PM +0100, David Hildenbrand wrote:

> (a) I want a R/O pin to observe file modifications.
> (b) I want the R/O pin to *not* observe file modifications but observe
> my (eventual? if any) private modifications,

A scenario I know that motivated this is fairly straightfoward:

static char data[] = {};

ibv_reg_mr(data, READ_ONLY)
data[0] = 1
.. go touch data via DMA ..

We want to reliably observe the '1'

What is happening under the covers is that 'data' is placed in the
.data segment and becomes a file backed MAP_PRIVATE page. The write
COWs that page

It would work OK if it was in .bss instead

I think the FOLL_FORCE is there because otherwise the trick doesn't
work on true RO pages and the API becomes broken.

Jason