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=-7.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 19994C433DB for ; Tue, 16 Mar 2021 19:31:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 920BD64E07 for ; Tue, 16 Mar 2021 19:31:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 920BD64E07 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=arista.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 184DC6B0036; Tue, 16 Mar 2021 15:31:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 135DA6B006C; Tue, 16 Mar 2021 15:31:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF0A46B006E; Tue, 16 Mar 2021 15:31:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id D38176B0036 for ; Tue, 16 Mar 2021 15:31:16 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8D008180AD838 for ; Tue, 16 Mar 2021 19:31:16 +0000 (UTC) X-FDA: 77926730952.12.306E7AF Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf07.hostedemail.com (Postfix) with ESMTP id 064ABA001AB1 for ; Tue, 16 Mar 2021 19:31:13 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id q5so10630316pgk.5 for ; Tue, 16 Mar 2021 12:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=ekMKxv3xoEv56PIX/8u6+v+e3tG7LJLMlBeqZEO46pI=; b=iouit/h+6MqphTGzWcQ8N+tNTFxpPm8zhlVMVH6yh3QXNXaTzgAH92BSeqUkabxVVG Bz7XXzgV1OhK1f+sf6ggCh/m26z/h7goie6JPNqNEA6ZWeffPt7IrIxw0Ko8Hs5+/qKl xUVS8/U6IdUSV2TXm5nxf9V7w1jDrfc8rpiygjP50ADf/r1at+dct8MeOpC6jfeRaG7N sCZgwIl7lKP5uoyGPUqkXHYFoQ744alahJdlhbQ950koKsMRyocE8j6I7GaxUoVuCvo+ mzpyGkSnl6hmPQqiXFfDzumOgA932tyl4Da6eHXPnQWBtV65AXfzcxPYhRAkiCiGcBLX 4BlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ekMKxv3xoEv56PIX/8u6+v+e3tG7LJLMlBeqZEO46pI=; b=eL6RosJZIEgT6ynPlQk7d0McbYyVAs1Ml3zuOYYUs9YKgbsrWMs2Y/Ax6XYoPlNAbi mxTf9dIbadODCk6Uojdm3wi9akbyCKL2pYecAb+Vh4plUoDaPpP8PePZ/5RhL44TFQaK cypEDfDn1FFT1YHf8vGLxPkRKfz4T6H4/U5zYUI3eURtR5vZXqILs0SCYNd+YUfmMSpd B1q+EwNrUEX/RD2IEo3BDSfYE/Rgv26cnEU74UzKGHjeWyo4eAedllXw7n2ABvsRj1DF ofO207tK1UhwCUbtAfP9NNw510sXySPKVNBCAWga/W3Hth0kL1gSZFF9ADNPzOw/AKzi q8wQ== X-Gm-Message-State: AOAM533eYXRoPsbqErICL2bHXlgdCsvPM0dERZoIAhXrIO/2uWfegkSc JwyEV4aLmqvoFi/D4KKJOzke3Q== X-Google-Smtp-Source: ABdhPJx3vy5Om6W53Jw+2UZUw99YwawZ3UKAZ4rXRb27866O0JGa9hH+eG64CaVVdyO7TwbO8Vm5AA== X-Received: by 2002:a62:3503:0:b029:1aa:6f15:b9fe with SMTP id c3-20020a6235030000b02901aa6f15b9femr955714pfa.65.1615923072796; Tue, 16 Mar 2021 12:31:12 -0700 (PDT) Received: from ?IPv6:2a02:8084:e84:2480:228:f8ff:fe6f:83a8? ([2a02:8084:e84:2480:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id u24sm17928529pfm.214.2021.03.16.12.31.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Mar 2021 12:31:12 -0700 (PDT) Subject: Re: [PATCH] mm: Allow shmem mappings with MREMAP_DONTUNMAP To: Brian Geffon , Hugh Dickins Cc: Andrew Morton , Axel Rasmussen , Lokesh Gidra , Mike Rapoport , Peter Xu , "Michael S . Tsirkin" , LKML , linux-mm , Andy Lutomirski , Vlastimil Babka , Andrea Arcangeli , Sonny Rao , Minchan Kim , "Kirill A . Shutemov" , Michael Kerrisk , Alejandro Colomar References: <20210303175235.3308220-1-bgeffon@google.com> From: Dmitry Safonov Message-ID: <98716204-0440-9550-e067-41a984a29512@arista.com> Date: Tue, 16 Mar 2021 19:31:05 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: e84i1autoyecmx581ihiomozhsgzaq4a X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 064ABA001AB1 Received-SPF: none (arista.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=mail-pg1-f179.google.com; client-ip=209.85.215.179 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615923073-125492 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: Hi Brian, Hugh, On 3/16/21 7:18 PM, Brian Geffon wrote: > Hi Hugh, > Thanks for this suggestion, responses in line. > >> A better patch would say: >> >> - if (flags & MREMAP_DONTUNMAP && (!vma_is_anonymous(vma) || >> - vma->vm_flags & VM_SHARED)) >> + if ((flags & MREMAP_DONTUNMAP) && >> + (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP))) >> return ERR_PTR(-EINVAL); >> >> VM_DONTEXPAND is what has long been used on special mappings, to prevent >> surprises from mremap changing the size of the mapping: MREMAP_DONTUNMAP >> introduced a different way of expanding the mapping, so VM_DONTEXPAND >> still seems a reasonable name (I've thrown in VM_PFNMAP there because >> it's in the VM_DONTEXPAND test lower down: for safety I guess, and best >> if both behave the same - though one says -EINVAL and the other -EFAULT). > > I like this idea and am happy to mail a new patch. I think it may make > sense to bring the lower block up here so that it becomes more clear > that it's not duplicate code and that the MREMAP_DONTUNMAP case > returns -EINVAL and other cases return -EFAULT. I wonder if the > -EFAULT error code would have made more sense from the start for both > cases, do you have any thoughts on changing the error code at this > point? > >> With that VM_DONTEXPAND check in, Dmitry's commit cd544fd1dc92 >> ("mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio") >> can still be reverted (as you agreed on 28th December), even though >> vma_is_anonymous() will no longer protect it. > > I agree and if Dmitry does not have time I would be happy to mail a > revert to cd544fd1dc92 as we discussed in [1]. Dmitry, would you like > me to do that? Ack. I was planning to send a patches set that includes the revert, but that's stalled a bit. As the patch just adds excessive checks, but doesn't introduce an issue, I haven't sent it separately. Feel free to revert it :-) Thanks, Dmitry