Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5434634ybv; Tue, 11 Feb 2020 15:54:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyer5ceczRVfM/KDFVb/2HdAHhU4VLuXLvtvd8r9xbAywoFhSj1MHhQbVWivxR9FV3XvfLf X-Received: by 2002:a05:6830:1198:: with SMTP id u24mr6927619otq.215.1581465262465; Tue, 11 Feb 2020 15:54:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581465262; cv=none; d=google.com; s=arc-20160816; b=Bs7SINxiQfvhDG89I7HaIvw/ITJvaWTqAF+h0jQVvCr9XtP85ZfsDt48eKw2yWs5MR 4AHQfbIoTA7XJnMMUVaSg5Y5MdkWTMbNvUdvUsPSS09ufclsJ8mK+QCE1OBTQQFqbG9o jD0TWr0MU4I86Sr9MI/BLXXu1a5idH/FOASkpkg5+QEf8wXesmdsNpoasXXc8QosRvk4 F7ZtJN2QNRYa1LHu13s+hVkytKQ6efMqqAk4ywGXB5zPnVOAXqfhlalRqgTAYXDtjIi5 4d3TT11g54Ep3ybBLyBCWsSE4MNyfF8WCl0BeLvPz2y1Eq2KhCWVsWEJQSDr1Y56VqQg e7Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8pO1XQac3lRtY1M/28swyaSfh/76yG4K/A1KWDVLQMc=; b=rzY7VF1AxFbKKCfmKqNTyq3GveHF1jZmwUVyx78Hdaw7I8H4Gsprh5O2vMWWGotojG efqs1PlzAF8bqz5GZBPM0A4sLSHm34DVtQJ58uhkSHqANqiafkwohMF9fmJ29+Fn4xB1 3RAVqfz+ydoJIhEjEN2MAmzJGw1nWnnCYkfqBSzD7e/93UMPZveHzgm6SesoxRCVRmw/ V67OtOWOX3VroTexwpvT5cHRKXmg3vkcxp+q0kfywJLP7AjoLoNbDMnMEPFCH1SyxLYJ ZhzXW4eKkjB2scp+7W+oVz5qKbwwpYE+aHtqSCDkUBG0jwcOMzF7qP7G/uMnnzp6vruI ChEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="H7/LO54H"; 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 v17si2975706otp.244.2020.02.11.15.54.08; Tue, 11 Feb 2020 15:54:22 -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="H7/LO54H"; 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 S1728017AbgBKXxm (ORCPT + 99 others); Tue, 11 Feb 2020 18:53:42 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:32997 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727987AbgBKXxm (ORCPT ); Tue, 11 Feb 2020 18:53:42 -0500 Received: by mail-ot1-f65.google.com with SMTP id b18so141589otp.0 for ; Tue, 11 Feb 2020 15:53:40 -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=8pO1XQac3lRtY1M/28swyaSfh/76yG4K/A1KWDVLQMc=; b=H7/LO54HPXlaugVHdCUKWXQWNaqDJGRL9AP74RA+bD/0uYm1aIgRD9AZUMJv5rbHXO wa2TRAmOzpCukoY1O7GbT8ai4CWrjPZM3itJtBIsp3Nn3isaCmPTcimOh2zz+sayYYhJ A/CkBQVrCxAm4LLiWttL/NpJabvPU8I5ONb7moY9nbbT8qlyDkVHUdA5qm6HTF3muSjT EdcgHRgAbwNx/xFkJITYP94FV5vyTTADVzqHbeU8z9TOQvYPhWjTGm2cR6juMJADbRVu 1NoyZrnwbUSziuV8uMcwwujUEXiZt5lnnObwVAKMTTAe1OIQFmSgpbUu5o1D36oy9RPz nNmw== 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=8pO1XQac3lRtY1M/28swyaSfh/76yG4K/A1KWDVLQMc=; b=GjoDvFiPUNNQAlVWko3KxBkFItfAoX92ytUUMZ1JYPzWfJmOVWux2/AL/cSeQioGrl 61NAEZmG9Hb4hW/L01REsAcZOWQssxchxdGOnDn2cytrnwOzkuupZxC5iRyDFiVRaWh8 VfJyvjzFP28nfnFlLLmTzRBfcyY6/grls4ezfN/67ylQqzjFRiBSckN9E2IAVeJ50ORw pkF7nkLXLVY19b3qzXz29xu5gFWAOrkEkGkGwFJtl3f3VOEq/YN082zboZclLx5XGg8w ua6uObRabH9NdzCTVMO8ccfXF9DfwOO7AQTpzLx2OGHZuKJyPknqmADMX+dxJcqUe9mj 0NFQ== X-Gm-Message-State: APjAAAVR+9DKUSavQPWjnToUTDu3uA3GKtdPDRJWfW2Ew7F3dxc5hSJ7 Is57iuO81mMX05vAryIdk3Ou55xlhEiluPw28BtlJQ== X-Received: by 2002:a9d:34c:: with SMTP id 70mr138640otv.174.1581465219846; Tue, 11 Feb 2020 15:53:39 -0800 (PST) MIME-Version: 1.0 References: <20200207201856.46070-1-bgeffon@google.com> In-Reply-To: From: Daniel Colascione Date: Tue, 11 Feb 2020 15:53:03 -0800 Message-ID: Subject: Re: [PATCH v4] mm: Add MREMAP_DONTUNMAP to mremap(). To: Brian Geffon Cc: Andrew Morton , "Michael S . Tsirkin" , Arnd Bergmann , linux-kernel , linux-mm , Linux API , Andy Lutomirski , Will Deacon , Andrea Arcangeli , Sonny Rao , Minchan Kim , Joel Fernandes , Yu Zhao , Jesse Barnes , Nathan Chancellor , Florian Weimer , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 11, 2020 at 3:32 PM Brian Geffon wrote: > > Hi Daniel, > > > What about making the > > left-behind mapping PROT_NONE? This way, we'll still solve the > > address-space race in Lokesh's use case (because even a PROT_NONE > > mapping reserves address space) but won't incur any additional commit > > until someone calls mprotect(PROT_WRITE) on the left-behind mapping. > > This limits the usefulness of the feature IMO and really is too > specific to that one use case, suppose you want to snapshot a memory > region to disk without having to stop a thread you can > mremap(MREMAP_DONTUNMAP) it to another location and safely write it to > disk knowing the faulting thread will be stopped and you can handle it > later if it was registered with userfaultfd, if we were to also change > it to PROT_NONE that thread would see a SEGV. There are other examples > where you can possibly use this flag instead of VM_UFFD_WP, but > changing the protections of the mapping prevents you from being able > to do this without a funny signal handler dance. We seem to have identified two use cases which require contradictory things. We can handle this with an option. Maybe the new region's protection bits should be specified in the flags argument. The most general API would accept any set of mmap flags to apply to the left-behind region, but it's probably hard to squeeze that functionality into the existing API.