From: Hugh Dickins <hughd@google.com>
To: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@redhat.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Ives van Hoorne <ives@codesandbox.io>,
Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hughd@goole.com>,
Alistair Popple <apopple@nvidia.com>,
Mike Rapoport <rppt@linux.vnet.ibm.com>,
Nadav Amit <nadav.amit@gmail.com>,
Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH RFC] mm/userfaultfd: enable writenotify while userfaultfd-wp is enabled for a VMA
Date: Tue, 6 Dec 2022 11:09:40 -0800 (PST) [thread overview]
Message-ID: <22d8e8ac-d75-a66-2650-b4d59f89855e@google.com> (raw)
In-Reply-To: <92173bad-caa3-6b43-9d1e-9a471fdbc184@redhat.com>
On Tue, 6 Dec 2022, David Hildenbrand wrote:
...
>
> We never had to remove write permissions so far from the vma->vm_page_prot
> default. We always only added permissions.
>
>
> Now, uffd-wp on shmem as of now violates these semantics. vma->vm_page_prot
> cannot always be used as a safe default, because we might have to wrprotect
> individual PTEs. Note that for uffd-wp on anonymous memory this was not an
> issue, because we default to !write in vma->vm_page_prot.
>
>
> The two possible ways to approach this for uffd-wp on shmem are:
>
> (1) Obey existing vma->vm_page_prot semantics. Default to !write and
> optimize the relevant cases to *add* the write bit. This is
> essentially what this patch does, minus
> can_change_pte_writable() optimizations on relevant code paths where
> we'd want to maintain the write bit. For example, when removing
> uffd-wp protection we might want to restore the write bit directly.
>
> (2) Default to write permissions and check each and every code location
> where we remap for uffd-wp ptes, to manuall wrprotect -- *remove*
> the write bit. Alternatively, as you said, always wrprotect when
> setting the PTE bit, which might work as well.
>
>
> My claim is that (1) is less error prone, because in the worst case we forget
> to optimize one code location -- instead to resulting in a BUG if we forget to
> wrprotect (what we have now). But I am not going to fight for it, because I
> can see that (2) can be made to work as well, as you outline in your patch.
>
> You seem to have decided on (2). Fair enough, you know uffd-wp best. We just
> have to fix it properly and make the logic consistent whenever we remap a
> page.
>
...
>
> But I'm not going to argue about whats valid and whats not as long as it's
> documented ;). I primarily wanted to showcase that the same logic based on
> vma->vm_page_prot is used elsewhere, and that migration PTE restoration is not
> particularly special.
I have not been following the uffd-wp work, but I believe that David's
painstaking and excellent account of vm_page_prot is correct. Peter,
please I beg you to follow his advice and go for (1) for uffd-wp.
I do not share David's faith in "documented": documented or not,
depart from safe convention and you will be adding (at least the
opportunity for) serious bugs.
Hugh
next prev parent reply other threads:[~2022-12-06 19:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-02 12:27 [PATCH RFC] mm/userfaultfd: enable writenotify while userfaultfd-wp is enabled for a VMA David Hildenbrand
2022-12-02 16:33 ` Peter Xu
2022-12-02 16:56 ` David Hildenbrand
2022-12-02 17:11 ` David Hildenbrand
2022-12-05 21:08 ` Peter Xu
2022-12-06 0:46 ` [PATCH] mm/uffd: Always wr-protect pte in pte_mkuffd_wp() kernel test robot
2022-12-06 16:21 ` Peter Xu
2022-12-06 11:43 ` kernel test robot
2022-12-06 16:28 ` [PATCH RFC] mm/userfaultfd: enable writenotify while userfaultfd-wp is enabled for a VMA David Hildenbrand
2022-12-06 19:09 ` Hugh Dickins [this message]
2022-12-06 21:18 ` Peter Xu
2022-12-07 15:32 ` David Hildenbrand
2022-12-07 17:43 ` Peter Xu
2022-12-07 19:53 ` David Hildenbrand
2022-12-07 20:14 ` Peter Xu
2022-12-06 21:27 ` Peter Xu
2022-12-07 13:33 ` David Hildenbrand
2022-12-07 15:59 ` Peter Xu
2022-12-07 20:10 ` David Hildenbrand
2022-12-08 15:17 ` Peter Xu
2022-12-06 18:38 ` [PATCH] mm/uffd: Always wr-protect pte in pte_mkuffd_wp() kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=22d8e8ac-d75-a66-2650-b4d59f89855e@google.com \
--to=hughd@google.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=david@redhat.com \
--cc=hughd@goole.com \
--cc=ives@codesandbox.io \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nadav.amit@gmail.com \
--cc=peterx@redhat.com \
--cc=rppt@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).