From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com,
vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net,
dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com,
peterz@infradead.org, ldufour@linux.ibm.com,
laurent.dufour@fr.ibm.com, paulmck@kernel.org, riel@surriel.com,
luto@kernel.org, songliubraving@fb.com, peterx@redhat.com,
david@redhat.com, dhowells@redhat.com, hughd@google.com,
bigeasy@linutronix.de, kent.overstreet@linux.dev,
rientjes@google.com, axelrasmussen@google.com, joelaf@google.com,
minchan@google.com, surenb@google.com, kernel-team@android.com,
linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org,
linuxppc-dev@lists.ozlabs.org, x86@kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 06/28] mm: mark VMA as locked whenever vma->vm_flags are modified
Date: Mon, 29 Aug 2022 21:25:09 +0000 [thread overview]
Message-ID: <20220829212531.3184856-7-surenb@google.com> (raw)
In-Reply-To: <20220829212531.3184856-1-surenb@google.com>
VMA flag modifications should be done under VMA lock to prevent concurrent
page fault handling in that area.
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
fs/proc/task_mmu.c | 1 +
fs/userfaultfd.c | 6 ++++++
mm/madvise.c | 1 +
mm/mlock.c | 2 ++
mm/mmap.c | 1 +
mm/mprotect.c | 1 +
6 files changed, 12 insertions(+)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 4e0023643f8b..ceffa5c2c650 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1285,6 +1285,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
for (vma = mm->mmap; vma; vma = vma->vm_next) {
if (!(vma->vm_flags & VM_SOFTDIRTY))
continue;
+ vma_mark_locked(vma);
vma->vm_flags &= ~VM_SOFTDIRTY;
vma_set_page_prot(vma);
}
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 175de70e3adf..fe557b3d1c07 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -620,6 +620,7 @@ static void userfaultfd_event_wait_completion(struct userfaultfd_ctx *ctx,
mmap_write_lock(mm);
for (vma = mm->mmap; vma; vma = vma->vm_next)
if (vma->vm_userfaultfd_ctx.ctx == release_new_ctx) {
+ vma_mark_locked(vma);
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
vma->vm_flags &= ~__VM_UFFD_FLAGS;
}
@@ -653,6 +654,7 @@ int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs)
octx = vma->vm_userfaultfd_ctx.ctx;
if (!octx || !(octx->features & UFFD_FEATURE_EVENT_FORK)) {
+ vma_mark_locked(vma);
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
vma->vm_flags &= ~__VM_UFFD_FLAGS;
return 0;
@@ -734,6 +736,7 @@ void mremap_userfaultfd_prep(struct vm_area_struct *vma,
atomic_inc(&ctx->mmap_changing);
} else {
/* Drop uffd context if remap feature not enabled */
+ vma_mark_locked(vma);
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
vma->vm_flags &= ~__VM_UFFD_FLAGS;
}
@@ -891,6 +894,7 @@ static int userfaultfd_release(struct inode *inode, struct file *file)
vma = prev;
else
prev = vma;
+ vma_mark_locked(vma);
vma->vm_flags = new_flags;
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
}
@@ -1449,6 +1453,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
* the next vma was merged into the current one and
* the current one has not been updated yet.
*/
+ vma_mark_locked(vma);
vma->vm_flags = new_flags;
vma->vm_userfaultfd_ctx.ctx = ctx;
@@ -1630,6 +1635,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
* the next vma was merged into the current one and
* the current one has not been updated yet.
*/
+ vma_mark_locked(vma);
vma->vm_flags = new_flags;
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
diff --git a/mm/madvise.c b/mm/madvise.c
index 5f0f0948a50e..a173f0025abd 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -181,6 +181,7 @@ static int madvise_update_vma(struct vm_area_struct *vma,
/*
* vm_flags is protected by the mmap_lock held in write mode.
*/
+ vma_mark_locked(vma);
vma->vm_flags = new_flags;
if (!vma->vm_file) {
error = replace_anon_vma_name(vma, anon_name);
diff --git a/mm/mlock.c b/mm/mlock.c
index b14e929084cc..f62e1a4d05f2 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -380,6 +380,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
*/
if (newflags & VM_LOCKED)
newflags |= VM_IO;
+ vma_mark_locked(vma);
WRITE_ONCE(vma->vm_flags, newflags);
lru_add_drain();
@@ -456,6 +457,7 @@ static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev,
if ((newflags & VM_LOCKED) && (oldflags & VM_LOCKED)) {
/* No work to do, and mlocking twice would be wrong */
+ vma_mark_locked(vma);
vma->vm_flags = newflags;
} else {
mlock_vma_pages_range(vma, start, end, newflags);
diff --git a/mm/mmap.c b/mm/mmap.c
index 693e6776be39..f89c9b058105 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1818,6 +1818,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
out:
perf_event_mmap(vma);
+ vma_mark_locked(vma);
vm_stat_account(mm, vm_flags, len >> PAGE_SHIFT);
if (vm_flags & VM_LOCKED) {
if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) ||
diff --git a/mm/mprotect.c b/mm/mprotect.c
index bc6bddd156ca..df47fc21b0e4 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -621,6 +621,7 @@ mprotect_fixup(struct mmu_gather *tlb, struct vm_area_struct *vma,
* vm_flags and vm_page_prot are protected by the mmap_lock
* held in write mode.
*/
+ vma_mark_locked(vma);
vma->vm_flags = newflags;
/*
* We want to check manually if we can change individual PTEs writable
--
2.37.2.672.g94769d06f0-goog
next prev parent reply other threads:[~2022-08-29 21:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 21:25 [RFC PATCH 00/28] per-VMA locks proposal Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 01/28] mm: introduce CONFIG_PER_VMA_LOCK Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 02/28] mm: rcu safe VMA freeing Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 03/28] mm: introduce __find_vma to be used without mmap_lock protection Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 04/28] mm: move mmap_lock assert function definitions Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 05/28] mm: add per-VMA lock and helper functions to control it Suren Baghdasaryan
2022-08-29 21:25 ` Suren Baghdasaryan [this message]
2022-08-29 21:25 ` [RFC PATCH 07/28] kernel/fork: mark VMAs as locked before copying pages during fork Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 08/28] mm/khugepaged: mark VMA as locked while collapsing a hugepage Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 09/28] mm/mempolicy: mark VMA as locked when changing protection policy Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 10/28] mm/mmap: mark VMAs as locked in vma_adjust Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 11/28] mm/mmap: mark VMAs as locked before merging or splitting them Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 12/28] mm/mremap: mark VMA as locked while remapping it to a new address range Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 13/28] mm: conditionally mark VMA as locked in free_pgtables and unmap_page_range Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 14/28] mm: mark VMAs as locked before isolating them Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 15/28] mm/mmap: mark adjacent VMAs as locked if they can grow into unmapped area Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 16/28] kernel/fork: assert no VMA readers during its destruction Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 17/28] mm/mmap: prevent pagefault handler from racing with mmu_notifier registration Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 18/28] mm: add FAULT_FLAG_VMA_LOCK flag Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 19/28] mm: disallow do_swap_page to handle page faults under VMA lock Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 20/28] mm: introduce per-VMA lock statistics Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 21/28] mm: introduce find_and_lock_anon_vma to be used from arch-specific code Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 22/28] x86/mm: try VMA lock-based page fault handling first Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 23/28] x86/mm: define ARCH_SUPPORTS_PER_VMA_LOCK Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 24/28] arm64/mm: try VMA lock-based page fault handling first Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 25/28] arm64/mm: define ARCH_SUPPORTS_PER_VMA_LOCK Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 26/28] powerc/mm: try VMA lock-based page fault handling first Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 27/28] powerpc/mm: define ARCH_SUPPORTS_PER_VMA_LOCK Suren Baghdasaryan
2022-08-29 21:25 ` [RFC PATCH 28/28] kernel/fork: throttle call_rcu() calls in vm_area_free Suren Baghdasaryan
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=20220829212531.3184856-7-surenb@google.com \
--to=surenb@google.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=david@redhat.com \
--cc=dhowells@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=jglisse@google.com \
--cc=joelaf@google.com \
--cc=kent.overstreet@linux.dev \
--cc=kernel-team@android.com \
--cc=laurent.dufour@fr.ibm.com \
--cc=ldufour@linux.ibm.com \
--cc=liam.howlett@oracle.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=luto@kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@suse.com \
--cc=michel@lespinasse.org \
--cc=minchan@google.com \
--cc=paulmck@kernel.org \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=rientjes@google.com \
--cc=songliubraving@fb.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®