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 B88ACC2D0DB for ; Thu, 23 Jan 2020 18:47:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 73CAF21D7E for ; Thu, 23 Jan 2020 18:47:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PPeGBXKW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73CAF21D7E 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 11D366B000D; Thu, 23 Jan 2020 13:47:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A8496B000E; Thu, 23 Jan 2020 13:47:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED7276B0010; Thu, 23 Jan 2020 13:47:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id D53D46B000D for ; Thu, 23 Jan 2020 13:47:17 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 7ED258245571 for ; Thu, 23 Jan 2020 18:47:17 +0000 (UTC) X-FDA: 76409781714.27.skin47_2282ba326ce5a X-HE-Tag: skin47_2282ba326ce5a X-Filterd-Recvd-Size: 8592 Received: from mail-il1-f194.google.com (mail-il1-f194.google.com [209.85.166.194]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jan 2020 18:47:16 +0000 (UTC) Received: by mail-il1-f194.google.com with SMTP id l4so2418078ilj.1 for ; Thu, 23 Jan 2020 10:47:16 -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=93N1KprhRlAIC0qpRhLc4xc+fV5KOF7hJnKAxyl7DH4=; b=PPeGBXKWs1LJcJmOuqoTEL/Hu+S6w18lDAx1ebuFOnXj9o2n57uRh/XhSAtHVo0Mn6 7dU6iIk137lgv3kifMMtXRSMgLS7y7mVmmO6N1o8JQmix3K+QornwNZhsA/V4DmXk89h e7XnUtD3IIJo9D9lvXk1sFI7DYkXGic+5VvERkoZ4Vw0TaH/WOKrbfDiuoCV8fYmh1b1 IHSxxmoQ8Yt5LHjIOyYzG5GeT7+RkjBuyEYBbpou58bAedMsxb6taW5lbE1cDi9/tgYY 1aX3e22RB5M72sPbKVJgzbhhQ5Y7yjhEKl6++YbkssEQA++qAo8zSdjV9zwYeUpHGHzE HToA== 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=93N1KprhRlAIC0qpRhLc4xc+fV5KOF7hJnKAxyl7DH4=; b=QFE9lVJRJcKGReVSwabDF6xvfOEo2cmE3jxbNxi29khDsHjo/PaQaIOqQjSYHofsH/ m2yyUxjkNVg2WQXBPfs/uU62nhn1RRvzTnrrAKPicW2g4v2lGOFytu74O3ucDPUWH3/V RQoNny4HAhtRem9SsoVfRcuRX4lAwTx747n/hljl0kXYtEgH880DU7KpG0S0uD+lSW1F HeMZfBdFtwXxjzHmkDsnskDPyBKTQPeDjqCNIrBFTwMsiaYHzY4Lq9tf2UeIdeCe2tTT ctycyBcKB2BZ/J8Q23lA9tOCRddqiCudkhB/vlFEilWm4GbrTEivHs4SWyFb2Nwyf2Fj Y8Hg== X-Gm-Message-State: APjAAAVoyAAD+I/wpAlYeoqgWihdE9hCluWEa1hMOrxPHWYrrZC5zt6V XK4+tjVzKCa8MNUIyij83o5gTUgDyEdgZaXlY1vejw== X-Google-Smtp-Source: APXvYqwyaHFFBxXlBjrqNaBTQri/DLV1IkF4U4s+CMKpQWTh8tY3EoFi4oXuKkZlJtuV7VREYegkZFHBnw3CODdivuU= X-Received: by 2002:a05:6e02:8e2:: with SMTP id n2mr14295355ilt.167.1579805236133; Thu, 23 Jan 2020 10:47:16 -0800 (PST) MIME-Version: 1.0 References: <20200123014627.71720-1-bgeffon@google.com> In-Reply-To: From: Lokesh Gidra Date: Thu, 23 Jan 2020 10:47:05 -0800 Message-ID: Subject: Re: [PATCH] mm: Add MREMAP_DONTUNMAP to mremap(). To: Andy Lutomirski Cc: Brian Geffon , linux-mm@kvack.org, Andrew Morton , "Michael S . Tsirkin" , Arnd Bergmann , Sonny Rao , Minchan Kim , Joel Fernandes , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Yu Zhao , Jesse Barnes Content-Type: multipart/alternative; boundary="000000000000ea4935059cd3119f" 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: --000000000000ea4935059cd3119f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. > > This is the exact behaviour I'm looking for. > 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. --000000000000ea4935059cd3119f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
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.

This is the exact behaviour I'm looking for.
=C2=A0
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.
--000000000000ea4935059cd3119f--