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.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 8DFCCC33CAF for ; Thu, 23 Jan 2020 19:04:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 40FE521D7D for ; Thu, 23 Jan 2020 19:04:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UlikmW0l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 40FE521D7D 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 E56FA6B026D; Thu, 23 Jan 2020 14:04:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDF836B026E; Thu, 23 Jan 2020 14:04:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA8176B026F; Thu, 23 Jan 2020 14:04:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id B05236B026D for ; Thu, 23 Jan 2020 14:04:12 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 54E2B824556B for ; Thu, 23 Jan 2020 19:04:12 +0000 (UTC) X-FDA: 76409824344.04.mass46_24a08e7476d34 X-HE-Tag: mass46_24a08e7476d34 X-Filterd-Recvd-Size: 5465 Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jan 2020 19:04:11 +0000 (UTC) Received: by mail-ed1-f67.google.com with SMTP id b8so4437271edx.7 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=rYHyXjZiNXWVqH7S87lClm3e28hw4OyYMwr84dhYbJp5uIZbYtsT0ZuXoQL70RJu6O 1VwCHdgHJcSk3ZLuB9wS5o60FZ85alNd3lubO+YKyRGsnYeMCGjFZSw3jfWNk2QUbSa3 7sqaUsDFhsOEWp0xHFXQKrleEbX7ci8iBO57R9Jr8kXN7nK8pYSccYuwvbJEBm6RJpsQ EelcwtpCAKY3fvNa+4f7ttnk20yjd6BMgobByD8rT2DVMlfWirqXetUSoj29hD75Aflz lEVX2o98HNFDUGsUP62eSbnljJHM+MyCU++N8mzoPbzVLvk+47iV8s2YWgBpIzVDsOhQ V05g== X-Gm-Message-State: APjAAAUvauTLmcTPeXPBT3Blkc9H96ffZfFELtF77l9BIrzHN7XVy1l5 DLOyMcUkDNh27izyADaTbZOgBZph4PJPZ4BH5otaeA== X-Google-Smtp-Source: APXvYqz+g3XsKBoe1r6awz5wE3JqrkD3YD2kS/0bT9IOZn+i4OcdPU8HSsrlwBCCkON0WX50n+lqkzFTeklQPIQpxMY= 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 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: 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.