From: Andrew Morton <akpm@linux-foundation.org>
To: Peter Xu <peterx@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Mike Kravetz <mike.kravetz@oracle.com>,
Mike Rapoport <rppt@linux.vnet.ibm.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Hugh Dickins <hughd@google.com>,
"Kirill A . Shutemov" <kirill@shutemov.name>,
Jerome Glisse <jglisse@redhat.com>
Subject: Re: [PATCH 2/6] mm/userfaultfd: Fix uffd-wp special cases for fork()
Date: Tue, 25 May 2021 17:15:58 -0700 [thread overview]
Message-ID: <20210525171558.3b223a89c16bdf002f3e83cf@linux-foundation.org> (raw)
In-Reply-To: <20210428225030.9708-3-peterx@redhat.com>
On Wed, 28 Apr 2021 18:50:26 -0400 Peter Xu <peterx@redhat.com> wrote:
> We tried to do something similar in b569a1760782 ("userfaultfd: wp: drop
> _PAGE_UFFD_WP properly when fork") previously, but it's not doing it all
> right.. A few fixes around the code path:
>
> 1. We were referencing VM_UFFD_WP vm_flags on the _old_ vma rather than the
> new vma. That's overlooked in b569a1760782, so it won't work as expected.
> Thanks to the recent rework on fork code (7a4830c380f3a8b3), we can easily
> get the new vma now, so switch the checks to that.
>
> 2. Dropping the uffd-wp bit in copy_huge_pmd() could be wrong if the huge pmd
> is a migration huge pmd. When it happens, instead of using pmd_uffd_wp(),
> we should use pmd_swp_uffd_wp(). The fix is simply to handle them separately.
>
> 3. Forget to carry over uffd-wp bit for a write migration huge pmd entry.
> This also happens in copy_huge_pmd(), where we converted a write huge
> migration entry into a read one.
>
> 4. In copy_nonpresent_pte(), drop uffd-wp if necessary for swap ptes.
>
> 5. In copy_present_page() when COW is enforced when fork(), we also need to
> pass over the uffd-wp bit if VM_UFFD_WP is armed on the new vma, and when
> the pte to be copied has uffd-wp bit set.
>
> Remove the comment in copy_present_pte() about this. It won't help a huge lot
> to only comment there, but comment everywhere would be an overkill. Let's
> assume the commit messages would help.
>
This run afoul of Alistair's "mm: Device exclusive memory access",
https://lkml.kernel.org/r/20210524132725.12697-8-apopple@nvidia.com
`vma' is now undeclared. I think this?
--- a/mm/memory.c~mm-userfaultfd-fix-uffd-wp-special-cases-for-fork-fix
+++ a/mm/memory.c
@@ -850,8 +850,8 @@ copy_nonpresent_pte(struct mm_struct *ds
* exclusive entries currently only support private writable
* (ie. COW) mappings.
*/
- VM_BUG_ON(!is_cow_mapping(vma->vm_flags));
- if (try_restore_exclusive_pte(src_mm, src_pte, vma, addr))
+ VM_BUG_ON(!is_cow_mapping(dst_vma->vm_flags));
+ if (try_restore_exclusive_pte(src_mm, src_pte, dst_vma, addr))
return -EBUSY;
return -ENOENT;
}
_
next prev parent reply other threads:[~2021-05-26 0:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 22:50 [PATCH 0/6] mm/uffd: Misc fix for uffd-wp and one more test Peter Xu
2021-04-28 22:50 ` [PATCH 1/6] mm/thp: Simplify copying of huge zero page pmd when fork Peter Xu
2021-04-29 8:03 ` David Hildenbrand
2021-04-28 22:50 ` [PATCH 2/6] mm/userfaultfd: Fix uffd-wp special cases for fork() Peter Xu
2021-05-26 0:15 ` Andrew Morton [this message]
2021-05-26 0:36 ` Peter Xu
2021-05-26 3:04 ` Andrew Morton
2021-04-28 22:50 ` [PATCH 3/6] mm/userfaultfd: Fix a few thp pmd missing uffd-wp bit Peter Xu
2021-04-28 22:50 ` [PATCH 4/6] mm/userfaultfd: Fail uffd-wp registeration if not supported Peter Xu
2021-04-28 22:50 ` [PATCH 5/6] mm/pagemap: Export uffd-wp protection information Peter Xu
2021-04-28 22:50 ` [PATCH 6/6] userfaultfd/selftests: Add pagemap uffd-wp test Peter Xu
2021-05-07 16:05 ` [PATCH 0/6] mm/uffd: Misc fix for uffd-wp and one more test Peter Xu
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=20210525171558.3b223a89c16bdf002f3e83cf@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aarcange@redhat.com \
--cc=axelrasmussen@google.com \
--cc=hughd@google.com \
--cc=jglisse@redhat.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.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).