Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned

From: Linus Torvalds
Date: Tue Sep 22 2020 - 12:31:31 EST

On Tue, Sep 22, 2020 at 8:56 AM Jason Gunthorpe <jgg@xxxxxxxx> wrote:
> I thought MAP_PRIVATE without PROT_WRITE was nonsensical,

MAP_PRIVATE without PROT_WRITE is very common.

It's what happens for every executable mapping, for example.

And no, it's not the same as MAP_SHARED, for a couple of simple
reasons. It does end up being similar for all the *normal* cases, but
there are various cases where it isn't.

- mprotect() and friends. MAP_PRIVATE is fixed, but it might have
been writable in the past, and it might become writable in the future.

- breakpoints and ptrace. This will punch through even a non-writable
mapping and force a COW (since that's the whole point: executables are
not writable, but to do a SW breakpoint you have to write to the page)

So no, MAP_PRIVATE is not nonsensical without PROT_WRITE, and it's not
even remotely unusual.