From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D51EC2D0DB for ; Thu, 23 Jan 2020 19:02:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD31A2253D for ; Thu, 23 Jan 2020 19:02:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GeG+/+c5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD31A2253D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5F2A36B026B; Thu, 23 Jan 2020 14:02:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A4186B026C; Thu, 23 Jan 2020 14:02:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1196B026D; Thu, 23 Jan 2020 14:02:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 399F16B026B for ; Thu, 23 Jan 2020 14:02:32 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id CF8BD180AD804 for ; Thu, 23 Jan 2020 19:02:31 +0000 (UTC) X-FDA: 76409820102.14.idea09_1604bbe71aa3e X-HE-Tag: idea09_1604bbe71aa3e X-Filterd-Recvd-Size: 8799 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jan 2020 19:02:31 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id j17so4457200edp.3 for ; Thu, 23 Jan 2020 11:02:31 -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; bh=23O17Xx78RwezfLnE3hHGORs0xwEFDU8WwF8rN+uqHY=; b=GeG+/+c5WL4epx6nBNm6vED6eftkzGoKdF6r33O88Ohvzwv2FW+uk30TBZuRH6jooC X2KBWBsBDwyAhhqLNA/JnIELRieugi1xfXEOI8swoxoDUA0JRpmqgSDwExyI+h1xvwH9 vr7Ll6TZUmu7s5h/+JXyH1EguNw+H36c1S2Yenmf1RKdPnzvRCTqhOk1BQARXsnriLWj ZKF60i9kHuXRR9pMShXRposH8ivYc5zDVx21aRyi6E6+j2+koX9NnZVt6xBG9Gp6E4NL oK9NpXfiOW/foctv45pr7I3YVg8qYMNALI+lOkfbKnSO1aSnVpXG4DlEat/5uRSkMu+M Lz1g== 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; bh=23O17Xx78RwezfLnE3hHGORs0xwEFDU8WwF8rN+uqHY=; b=hdrk0EpjBXLyG8MhaaNxSA3LDNLe+P/bDQ3dRHhit0gsi3YbiS1WZSLL/RFs1UHwzH pdNToCXeDIum1qGDQRPVLsh68U5c6R7QEJcFv70Sal0bBN5SiAKjTjR39Tmejlr7dzMJ REX06v8xMx/w5DiGzNho4arCYvBY7uCET+HH2dyOLHb3G2UaLaeJ+RMytmVI6UUymFl+ XbfpbG/rLQLbAmXQHh+SitYMX368HAFuoAEERAYO+odhC0YXGCnJXqJgiL/003vSixDb PhsIWohZE+YegnNvpMo1wuVQU0UIom8W7xAkiC7z75FzMwAFActefz7ifNFnAmXruMY/ K56A== X-Gm-Message-State: APjAAAXqC8kqILkVKkuSH4rwOFazDlokEBKfigP3bJQ9X16R4XZrI1Rw 3YZUMre3OyJPK+0uXcgSX45r5KiN/mF7DeCKq45rIg== X-Google-Smtp-Source: APXvYqwjCAgSUGixagWQORyJ8EfHH6M8a68S2ngtKcPNUUy6k8FxuL+rldxnSTxPmcOxcVSE3ajeIYSOwOuWnxvGTgw= X-Received: by 2002:a50:c04f:: with SMTP id u15mr8192280edd.346.1579806149701; Thu, 23 Jan 2020 11:02:29 -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:02:03 -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: multipart/alternative; boundary="0000000000005e50b7059cd348ec" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --0000000000005e50b7059cd348ec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 = of > the mremap() call. If a userfaultfd was watching the source, it will > continue to watch the new mapping. For a mapping that is shared or not > anonymous, 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 > physical > > 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 > consuming > > 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. --0000000000005e50b7059cd348ec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Andy,

Thanks, yes, that's a much cle= arer description of the feature. I'll make sure to update the descripti= on with subsequent patches and with later man page updates.

<= /div>
Brian


On Wed, Jan 22, 2020 at 7= :02 PM Andy Lutomirski <luto@amacapital.net> wrote:


> On Jan 22, 2020, at 5:46 PM, Brian Geffon <bgeffon@google.com> wrote:
>
> =EF=BB=BFMREMAP_DONTUNMAP is an additional flag that can be used with<= br> > 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, t= he source mapping will not be removed. Instead it will be cleared as if a b= rand new anonymous, private mapping had been created atomically as part of = the mremap() call.=C2=A0 If a userfaultfd was watching the source, it will = continue to watch the new mapping.=C2=A0 For a mapping that is shared or no= t anonymous, 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<= br> > 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 physical
> 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 jav= a
> heap, its virtual mapping will be removed as well. Therefore, we'l= l
> require performing mmap immediately after. This is not only time consu= ming
> 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.
--0000000000005e50b7059cd348ec--