Re: [RFC PATCH 1/1] mm/mremap: add MREMAP_MIRROR flag for existing mirroring functionality

From: Michal Hocko
Date: Wed Jul 12 2017 - 07:47:04 EST

On Tue 11-07-17 11:23:19, Mike Kravetz wrote:
> On 07/11/2017 05:36 AM, Michal Hocko wrote:
> > Anyway the patch should fail with -EINVAL on private mappings as Kirill
> > already pointed out
> Yes. I think this should be a separate patch. As mentioned earlier,
> mremap today creates a new/additional private mapping if called in this
> way with old_size == 0. To me, this is a bug.

Not only that. It clears existing ptes in the old mapping so the content
is lost. That is quite unexpected behavior. Now it is hard to assume
whether somebody relies on the behavior (I can easily imagine somebody
doing backup&clear in atomic way) so failing with EINVAL might break
userspace so I am not longer sure. Anyway this really needs to be
Michal Hocko