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=-19.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 172C8C433E6 for ; Fri, 19 Mar 2021 01:59:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D64C064EB6 for ; Fri, 19 Mar 2021 01:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbhCSB6w (ORCPT ); Thu, 18 Mar 2021 21:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230119AbhCSB62 (ORCPT ); Thu, 18 Mar 2021 21:58:28 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B73C06174A for ; Thu, 18 Mar 2021 18:58:28 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id 30so4267613qva.9 for ; Thu, 18 Mar 2021 18:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=JiVqDCFQoleLcPQiijGmNpe+GDIBYP9KaktrAuD4UeY=; b=cO4PvwPZhiVCZOO4Js5LQU0t1J6I3JMpIhjSa3v6KeWVX0N9Izb3Uaa/eNRzjBejAQ CwhTjbcdbJILCsEXAeNH42ehWKmLUTkUoygEsZMz505VcW28OuzdB6qsqecnHk09Gyk9 n+fI627jA2k5LPfSahTJ7iCKBmyf7oKOfCmOURgm/QGUUyKdpXDS8cWF/4kNobXdha9C SBuPLQ/4d1uS8Md3wIH6qKhBCxw7yCKB4uSP4JfCXG1X4vLD9m2D1bRWVFc38Pre3Kmw A3ahxOj2z/+ZkvcCXFCejzpuAH9UK+gIY/xh1cXlkj2MLeZ/1tNc6pJRMK7z6wBkCuT6 vWig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=JiVqDCFQoleLcPQiijGmNpe+GDIBYP9KaktrAuD4UeY=; b=rhmPZS3cRXedTOTESf7yUD0BoaAdPOIzjkhzdvwUHumGwcNT46RcyB3488M6d4snIV rdf1M6f44l5BYxBixpm48tZDsWveJlfSI5jihUttQTdDiyR9XBkR9cwjfxAb6f4g34UM qS8D0futd1jYJM0TBvlks/5nLCAb6zpQx3N3Wlb2VQtCTGOCnvHZDlTzXti/m7NCfdsa /V588swDRRqfzoidBe0uKbnv3AgsQQqIIwwuEKd9wMUFmGHYFwnoWM1LMpIQTGoZfaS7 bEaaW4z0bxI2U9ioIDCCXcngUK2hMtlj4z/L5XwdrjKrUDXKXEQV8zYO63jSAsBG0rNj DJYg== X-Gm-Message-State: AOAM533CwS9ivzjT/1DI7XZaBgJON+9smFN+kp8D4WOPFpgZsxpOYv8S QY6Mo9sEBsWr3YU/YXUCwYmuJQ== X-Google-Smtp-Source: ABdhPJwlcAocbwXbejNeQSSFfnPBhhYBU6u5C6+yT1lL+Fw+uGkbTnq8GUvnMW21Yldql/4+R6gHBw== X-Received: by 2002:a05:6214:268c:: with SMTP id gm12mr7129538qvb.36.1616119106845; Thu, 18 Mar 2021 18:58:26 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id f27sm3177041qkh.118.2021.03.18.18.58.24 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 18 Mar 2021 18:58:26 -0700 (PDT) Date: Thu, 18 Mar 2021 18:58:23 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Peter Xu cc: Hugh Dickins , Brian Geffon , Andrew Morton , Axel Rasmussen , Lokesh Gidra , Mike Rapoport , "Michael S . Tsirkin" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andy Lutomirski , Vlastimil Babka , Andrea Arcangeli , Sonny Rao , Minchan Kim , "Kirill A . Shutemov" , Dmitry Safonov , Michael Kerrisk , Alejandro Colomar Subject: Re: [PATCH] mm: Allow shmem mappings with MREMAP_DONTUNMAP In-Reply-To: <20210316201732.GD395976@xz-x1> Message-ID: References: <20210303175235.3308220-1-bgeffon@google.com> <20210316201732.GD395976@xz-x1> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 16 Mar 2021, Peter Xu wrote: > > I'm curious whether it's okay to expand MREMAP_DONTUNMAP to PFNMAP too.. > E.g. vfio maps device MMIO regions with both VM_DONTEXPAND|VM_PFNMAP, to me it > makes sense to allow the userspace to get such MMIO region remapped/duplicated > somewhere else as long as the size won't change. With the strict check as > above we kill all those possibilities. > > Though in that case we'll still need commits like cd544fd1dc92 to protect any > customized ->mremap() when they're not supported. It would take me many hours to arrive at a conclusion on that: I'm going to spend the time differently, and let whoever ends up wanting MREMAP_DONTUNMAP on a VM_PFNMAP area research the safety of that for existing users. I did look to see what added VM_PFNMAP to the original VM_DONTEXPAND: v2.6.15 commit 4d7672b46244abffea1953e55688c0ea143dd617 Author: Linus Torvalds Date: Fri Dec 16 10:21:23 2005 -0800 Make sure we copy pages inserted with "vm_insert_page()" on fork The logic that decides that a fork() might be able to avoid copying a VM area when it can be re-created by page faults didn't know about the new vm_insert_page() case. Also make some things a bit more anal wrt VM_PFNMAP. Pointed out by Hugh Dickins Signed-off-by: Linus Torvalds So apparently I do bear some anal responsibility. My concern seems to have been that in those days an unexpected page fault in a special driver area would end up allocating an anonymous page, which would never get freed later. Nowadays it looks like there's a SIGBUS for the equivalent situation. So probably VM_DONTEXPAND is less important than it was, and the additional VM_PFNMAP safety net no longer necessary, and you could strip it out of the old size check and Brian's new dontunmap check. But I give no guarantee: I don't know VM_PFNMAP users at all well. Hugh