Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp972315ybl; Thu, 23 Jan 2020 11:07:07 -0800 (PST) X-Google-Smtp-Source: APXvYqze0ifEdE/ez2nxsG1/zAZjOeOLWTrU1lbadaeEenBsUDRsanRHP07GBv9oxvexCmDEHTc5 X-Received: by 2002:a05:6808:197:: with SMTP id w23mr11924377oic.46.1579806427689; Thu, 23 Jan 2020 11:07:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579806427; cv=none; d=google.com; s=arc-20160816; b=tCSIaLG7me4nqbPQBpBcWLpF+ccrOw/9+NgvhhTy6wxRa9EAyZlFAqSorsfKmMsUgg lBSq1DwlLv176odk5LaljxvKZ5ARVaEcZ+9wEK45e0VsfghMeMIdYPVNWHqj3SgrGTko mnSYJlqZ2MN11JdexV6Lqz7U+Ab8OMx9ZsPr3LntR0X6rR144jsLZZZSE4FKduPIHEV9 iaXicOUVKH459w8toWi6ylLmeNZ4itRNgekke2bJZweFb6eOM6kLVEIdP4KhZgm4ACEC Z+Cb2zLWVJ14Uz2SZbOHns4h16JSfM9OlaLIolHGHbVAlppWMiHDiwnQiZK9G8ZR3AgY WRKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=HbVZOQvmDLYul0lKSvQQMmCFWhXIMyG0jD9qHeDuze0=; b=tmdNBUN/HgpkIomKjoKUj6Nszn3dXPhuYYaepk/GA9grpT+z733Y35hxRlyJEwEt0J IQVVRBTKJkGUSHji43hjcgAkl9X72XNSQX1SXdF6wzyH8W4IFx079tX4sWVx1HbjBv0S YqjpPd0WXUjFqdT93YJbiy+Pa1i32CzQ/zOO9ew/zRZgbZC4t+c4ue15zZcNuFXtQ+/C tlQIhgdZIJ0vwxvdalTnASBdrZmiOmJ1O0zi1Dtjq1WC0mMw9J6ANp/JW39T/eE2xsn2 nNvvE4kuELNBVvfpSq7WRWKZR7AUs7PN+STsK4/DjlqXG0GYbvtPVFTrZ3mQWdpB/Hn5 o+xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UlikmW0l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l18si1487531oth.236.2020.01.23.11.06.55; Thu, 23 Jan 2020 11:07:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UlikmW0l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728853AbgAWTEM (ORCPT + 99 others); Thu, 23 Jan 2020 14:04:12 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:42397 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727590AbgAWTEL (ORCPT ); Thu, 23 Jan 2020 14:04:11 -0500 Received: by mail-ed1-f65.google.com with SMTP id e10so4421753edv.9 for ; Thu, 23 Jan 2020 11:04:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=HbVZOQvmDLYul0lKSvQQMmCFWhXIMyG0jD9qHeDuze0=; b=UlikmW0lzuBMSt5Oc/ZFq3MNhzsCt5bC0Aba93HdKIJCtCGnlHvWPekf5GiVNW6lIV iGlx/8rBEIvVjU2KGoUFrUuHmLyC6YnTYhk60424Tp2gjjHOaReX4D3vxtXY9fg1mc43 ZhsbXm6qygilUWFEdsgbkFOUA1s7ZgfSduXUB99GvqzGBsXeYFUSupq7AwVzhels6MOb S1Ulo8jVifExSZG3UToV6XVlRQXpc0p37UqCNyAMyFT7zZ8jLIA0/p0Hxv/G/11lpYLK VYJTfoi9D32v4+h+DBR9Lc3zlZkici+0e3OXmrK3DV6cBhYD51Iwl39qfDvluakamOH9 o3iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=HbVZOQvmDLYul0lKSvQQMmCFWhXIMyG0jD9qHeDuze0=; b=QDUrRHGjvXTWUWjp5oRD8hcuPkUGKh4e+JIRfAdtBygtIEai3cd5uwfBkvyQJsevRP EgeR1VUCNxpHbBqs3yopZcYIwUgBkY2/ettXfLUXMr9Y9H6807eLLiNesRawx9UQ838V RTxQY/pmmKxPvzcgSDBcFIRd3pAjRoL1dr8qZk9nSyZnkZmCY7O/+RaLp3QljSjkBxDD Hq9YSB55eCvEpf8uRaEGOyFpcSHICi/1QVYxSNfBRcTbtZx+qt9/ZWHDbqOZq4g2OxqC R1dQ/hbrgg7visuoOo1krjxins5rXiNYK1cMwym2P31KFNq7J7Aua26Rhi1Xy9a4z+ah w9aw== X-Gm-Message-State: APjAAAWUPUGIMbec185jl2apHKqtT14ySxISLSOdhpV7ir2Y20PnOEKr y0rkoBgPMwXTCdp+nAFr74oewFhN+mO3ZvI3cDa8+A== X-Received: by 2002:a17:906:1e48:: with SMTP id i8mr7637324ejj.189.1579806250136; Thu, 23 Jan 2020 11:04:10 -0800 (PST) MIME-Version: 1.0 References: <20200123014627.71720-1-bgeffon@google.com> In-Reply-To: From: Brian Geffon Date: Thu, 23 Jan 2020 11:03:44 -0800 Message-ID: Subject: Re: [PATCH] mm: Add MREMAP_DONTUNMAP to mremap(). To: Andy Lutomirski Cc: linux-mm , Andrew Morton , "Michael S . Tsirkin" , Arnd Bergmann , Sonny Rao , Minchan Kim , Joel Fernandes , Lokesh Gidra , LKML , linux-api@vger.kernel.org, Yu Zhao , Jesse Barnes Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andy, Thanks, yes, that's a much clearer description of the feature. I'll make sure to update the description with subsequent patches and with later man page updates. Brian On Wed, Jan 22, 2020 at 7:02 PM Andy Lutomirski wrote= : > > > > > On Jan 22, 2020, at 5:46 PM, Brian Geffon wrote: > > > > =EF=BB=BFMREMAP_DONTUNMAP is an additional flag that can be used with > > MREMAP_FIXED to move a mapping to a new address. Normally, mremap(2) > > would then tear down the old vma so subsequent accesses to the vma > > cause a segfault. However, with this new flag it will keep the old > > vma with zapping PTEs so any access to the old VMA after that point > > will result in a pagefault. > > This needs a vastly better description. Perhaps: > > When remapping an anonymous, private mapping, if MREMAP_DONTUNMAP is set,= the source mapping will not be removed. Instead it will be cleared as if a= brand new anonymous, private mapping had been created atomically as part o= f the mremap() call. If a userfaultfd was watching the source, it will con= tinue to watch the new mapping. For a mapping that is shared or not anonym= ous, MREMAP_DONTUNMAP will cause the mremap() call to fail. > > Or is it something else? > > > > > This feature will find a use in ChromeOS along with userfaultfd. > > Specifically we will want to register a VMA with userfaultfd and then > > pull it out from under a running process. By using MREMAP_DONTUNMAP we > > don't have to worry about mprotecting and then potentially racing with > > VMA permission changes from a running process. > > Does this mean you yank it out but you want to replace it simultaneously? > > > > > This feature also has a use case in Android, Lokesh Gidra has said > > that "As part of using userfaultfd for GC, We'll have to move the physi= cal > > pages of the java heap to a separate location. For this purpose mremap > > will be used. Without the MREMAP_DONTUNMAP flag, when I mremap the java > > heap, its virtual mapping will be removed as well. Therefore, we'll > > require performing mmap immediately after. This is not only time consum= ing > > but also opens a time window where a native thread may call mmap and > > reserve the java heap's address range for its own usage. This flag > > solves the problem." > > Cute.