From: akpm@linux-foundation.org
To: aarcange@redhat.com, axelrasmussen@google.com,
minhquangbui99@gmail.com, mm-commits@vger.kernel.org,
peterx@redhat.com
Subject: [withdrawn] userfaultfd-write-protect-when-virtual-memory-range-has-no-page-table-entry.patch removed from -mm tree
Date: Wed, 31 Mar 2021 17:24:06 -0700 [thread overview]
Message-ID: <20210401002406.Bhp2TXc4C%akpm@linux-foundation.org> (raw)
The patch titled
Subject: userfaultfd: write protect when virtual memory range has no page table entry
has been removed from the -mm tree. Its filename was
userfaultfd-write-protect-when-virtual-memory-range-has-no-page-table-entry.patch
This patch was dropped because it was withdrawn
------------------------------------------------------
From: Bui Quang Minh <minhquangbui99@gmail.com>
Subject: userfaultfd: write protect when virtual memory range has no page table entry
userfaultfd_writeprotect() use change_protection() to clear write bit in
page table entries (pte/pmd). So, later write to this virtual address
range causes a page fault, which is then handled by userspace program.
However, change_protection() has no effect when there is no page table
entries associated with that virtual memory range (a newly mapped memory
range). As a result, later access to that memory range causes allocating
a page table entry with write bit still set (due to VM_WRITE flag in
vma->vm_flags).
Add checks for VM_UFFD_WP in vma->vm_flags when allocating new page table
entry in missing page table entry page fault path.
Link: https://lkml.kernel.org/r/20210319152428.52683-1-minhquangbui99@gmail.com
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/huge_memory.c | 12 ++++++++++++
mm/memory.c | 10 ++++++++++
2 files changed, 22 insertions(+)
--- a/mm/huge_memory.c~userfaultfd-write-protect-when-virtual-memory-range-has-no-page-table-entry
+++ a/mm/huge_memory.c
@@ -636,6 +636,11 @@ static vm_fault_t __do_huge_pmd_anonymou
entry = mk_huge_pmd(page, vma->vm_page_prot);
entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
+ if (userfaultfd_wp(vma)) {
+ entry = pmd_wrprotect(entry);
+ entry = pmd_mkuffd_wp(entry);
+ }
+
page_add_new_anon_rmap(page, vma, haddr, true);
lru_cache_add_inactive_or_unevictable(page, vma);
pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, pgtable);
@@ -643,6 +648,13 @@ static vm_fault_t __do_huge_pmd_anonymou
update_mmu_cache_pmd(vma, vmf->address, vmf->pmd);
add_mm_counter(vma->vm_mm, MM_ANONPAGES, HPAGE_PMD_NR);
mm_inc_nr_ptes(vma->vm_mm);
+
+ if (userfaultfd_huge_pmd_wp(vma, *vmf->pmd)) {
+ spin_unlock(vmf->ptl);
+ count_vm_event(THP_FAULT_ALLOC);
+ count_memcg_event_mm(vma->vm_mm, THP_FAULT_ALLOC);
+ return handle_userfault(vmf, VM_UFFD_WP);
+ }
spin_unlock(vmf->ptl);
count_vm_event(THP_FAULT_ALLOC);
count_memcg_event_mm(vma->vm_mm, THP_FAULT_ALLOC);
--- a/mm/memory.c~userfaultfd-write-protect-when-virtual-memory-range-has-no-page-table-entry
+++ a/mm/memory.c
@@ -3564,6 +3564,11 @@ static vm_fault_t do_anonymous_page(stru
if (vma->vm_flags & VM_WRITE)
entry = pte_mkwrite(pte_mkdirty(entry));
+ if (userfaultfd_wp(vma)) {
+ entry = pte_wrprotect(entry);
+ entry = pte_mkuffd_wp(entry);
+ }
+
vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address,
&vmf->ptl);
if (!pte_none(*vmf->pte)) {
@@ -3590,6 +3595,11 @@ setpte:
/* No need to invalidate - it was non-present before */
update_mmu_cache(vma, vmf->address, vmf->pte);
+
+ if (userfaultfd_pte_wp(vma, *vmf->pte)) {
+ pte_unmap_unlock(vmf->pte, vmf->ptl);
+ return handle_userfault(vmf, VM_UFFD_WP);
+ }
unlock:
pte_unmap_unlock(vmf->pte, vmf->ptl);
return ret;
_
Patches currently in -mm which might be from minhquangbui99@gmail.com are
reply other threads:[~2021-04-01 0:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210401002406.Bhp2TXc4C%akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aarcange@redhat.com \
--cc=axelrasmussen@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minhquangbui99@gmail.com \
--cc=mm-commits@vger.kernel.org \
--cc=peterx@redhat.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).