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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61FBEC433EF for ; Thu, 3 Mar 2022 08:06:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC3BC8D0002; Thu, 3 Mar 2022 03:06:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E72628D0001; Thu, 3 Mar 2022 03:06:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3A5E8D0002; Thu, 3 Mar 2022 03:06:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id C32D28D0001 for ; Thu, 3 Mar 2022 03:06:07 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7CFC0A0F95 for ; Thu, 3 Mar 2022 08:06:07 +0000 (UTC) X-FDA: 79202341974.17.2476945 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id EA3BD1A0014 for ; Thu, 3 Mar 2022 08:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646294766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O+18ccVHSZPVWlkZVYCx2J+hQLbKBpCK4Sp27aR5tQA=; b=hTH2iAvy4m+o8y8SlrzauMb31NG+zxJFvkdlAuhCt0IC9c+q6MGWFtSwuHMSTaCfTxANde PFEhrzz/pnW6A4nqTKItxQBMm+WXHzxnRylJJymgB1oQ34f4Vm7TK1AqPqK5xwN7aJHldG aPQP3I/7YlE5HE8gSBQm8ZPCRV7/Unc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-206-zZZbcXo8PouKLxrECgAW_g-1; Thu, 03 Mar 2022 03:06:05 -0500 X-MC-Unique: zZZbcXo8PouKLxrECgAW_g-1 Received: by mail-wm1-f71.google.com with SMTP id f24-20020a1c6a18000000b00388874b17a8so65743wmc.3 for ; Thu, 03 Mar 2022 00:06:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=O+18ccVHSZPVWlkZVYCx2J+hQLbKBpCK4Sp27aR5tQA=; b=gzJyOavFDZR62wf/OUpdQyIbT/G8WNSpuFhFBqt6k0hzB0XQHPG10QEVlJGZhSD3Ps isCd5/XZLWiO9poLNlM5odWlA1EM3hk5mK+1dcHYByXXh3UcQtOBejhNBOHqNSqG39p9 FI2SzF1qOdfS7tDKc1ZxlAPjsJzxMSguWe/tGwqyngA1nWdSdOjfKlqfrfs+udFQSE0a p0SPHdS2Qngyk0x/j2fPVtbWz4AD302MA/D6gWbis2vd9MaOzpw8kz1xgg2t+km6+DHD gARXoBDqtCfWl7B26vt5W4YkcEy9yXLzs/ww2ty3iUp2NTLzD4+V9/EpBZeyLSQXkRHr JNBA== X-Gm-Message-State: AOAM532zhqa18yacsM+YOL2GrVHMOw5rvEcE52nw+4p0/dIpF+LrBrtP EMFF1eSc/Exa/c3TrFwrMwcK94zPoybZQtqPArjrOfzgArmpUSqY+9uOI1+h2u6SzFE5CM9SrTO lfjgDsl+uY6A= X-Received: by 2002:a1c:2644:0:b0:381:10f:503 with SMTP id m65-20020a1c2644000000b00381010f0503mr2758714wmm.188.1646294764255; Thu, 03 Mar 2022 00:06:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBSCJejeZJTX7rxYuswh4iEdesD4zS33EME8Lxvp5LQCRJwDndCVEPQpFlIXC0CKjKrPt6EA== X-Received: by 2002:a1c:2644:0:b0:381:10f:503 with SMTP id m65-20020a1c2644000000b00381010f0503mr2758674wmm.188.1646294763867; Thu, 03 Mar 2022 00:06:03 -0800 (PST) Received: from ?IPV6:2003:cb:c706:3600:f39a:d830:baab:42f0? (p200300cbc7063600f39ad830baab42f0.dip0.t-ipconnect.de. [2003:cb:c706:3600:f39a:d830:baab:42f0]) by smtp.gmail.com with ESMTPSA id v12-20020a5d4a4c000000b001e68ba61747sm1293716wrs.16.2022.03.03.00.06.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Mar 2022 00:06:03 -0800 (PST) Message-ID: <461e4d2b-9aa2-50d4-2c78-3f7fb3f6a2f6@redhat.com> Date: Thu, 3 Mar 2022 09:06:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 To: John Hubbard , Jason Gunthorpe Cc: linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , Pedro Gomes , Oded Gabbay , linux-mm@kvack.org References: <20220224122614.94921-1-david@redhat.com> <20220224122614.94921-13-david@redhat.com> <20220302165559.GU219866@nvidia.com> <0a159b65-cb80-c8eb-7ad1-24b83813531f@nvidia.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH RFC 12/13] mm/gup: trigger FAULT_FLAG_UNSHARE when R/O-pinning a possibly shared anonymous page In-Reply-To: <0a159b65-cb80-c8eb-7ad1-24b83813531f@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EA3BD1A0014 X-Stat-Signature: 51x7i7cmr3kdke56h5ta5e6ibfe1mu6r Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hTH2iAvy; spf=none (imf19.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1646294766-62994 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: On 03.03.22 02:47, John Hubbard wrote: > On 3/2/22 12:38, David Hildenbrand wrote: > ... >> BUT, once we actually write to the private mapping via the page table, >> the GUP pin would go out of sync with the now-anonymous page mapped into >> the page table. However, I'm having a hard time answering what's >> actually expected? >> >> It's really hard to tell what the user wants with MAP_PRIVATE file >> mappings and stumbles over a !anon page (no modifications so far): >> >> (a) I want a R/O pin to observe file modifications. >> (b) I want the R/O pin to *not* observe file modifications but observe >> my (eventual? if any) private modifications, >> > > On this aspect, I think it is easier than trying to discern user > intentions. Because it is less a question of what the user wants, and > more a question of how mmap(2) is specified. And the man page clearly > indicates that the user has no right to expect to see file > modifications. Here's the excerpt: > > "MAP_PRIVATE > > Create a private copy-on-write mapping. Updates to the mapping are not > visible to other processes mapping the same file, and are not carried > through to the underlying file. It is unspecified whether changes made > to the file after the mmap() call are visible in the mapped region. > " > >> Of course, if we already wrote to that page and now have an anon page, >> it's easy: we are already no longer following file changes. > > Yes, and in fact, I've always thought that the way this was written > means that it should be treated as a snapshot of the file contents, > and no longer reliably connected in either direction to the page(s). Thanks John, that's extremely helpful. I forgot about these MAP_PRIVATE mmap() details -- they help a lot to clarify which semantics to provide. So what we could do is: a) Extend FAULT_FLAG_UNSHARE to also unshare an !anon page in a MAP_RPIVATE mapping, replacing it with an (exclusive) anon page. R/O PTE permissions are maintained, just like unsharing in the context of this series. b) Similarly trigger FAULT_FLAG_UNSHARE from GUP when trying to take a R/O pin (FOLL_PIN) on a R/O-mapped !anon page in a MAP_PRIVATE mapping. c) Make R/O pins consistently use "FOLL_PIN" instead, getting rid of FOLL_FORCE|FOLL_WRITE. Of course, we can't detect MAP_PRIVATE vs. MAP_SHARED in GUP-fast (no VMA), so we'd always have to fallback in GUP-fast in case we intend to FOLL_PIN a R/O-mapped !anon page. That would imply that essentially any R/O pins (FOLL_PIN) would have to fallback to ordinary GUP. BUT, I mean we require FOLL_FORCE|FOLL_WRITE right now, which is not any different, so ... One optimization would be to trigger b) only for FOLL_LONGTERM. For !FOLL_LONGTERM there are "in theory" absolutely no guarantees which data will be observed if we modify concurrently to e.g., O_DIRECT IMHO. But that would require some more thought. Of course, that's all material for another journey, although it should be mostly straight forward. -- Thanks, David / dhildenb