BACKPORT: mm: introduce vma detached flag
Per-vma locking mechanism will search for VMA under RCU protection and then after locking it, has to ensure it was not removed from the VMA tree after we found it. To make this check efficient, introduce a vma->detached flag to mark VMAs which were removed from the VMA tree. Link: https://lkml.kernel.org/r/20230227173632.3292573-23-surenb@google.com Signed-off-by: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 457f67be5910a2b5f1fda8af06bfe4d3492a0a4f) [surenb: vma_complete does not exist in 6.1, therefore patch is adjusted to mark VMAs detached directly in vma_expand and __vma_adjust] Bug: 161210518 Change-Id: Id1f31733cb7a36f3f1294b2be83cf3b87ba3f812 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
This commit is contained in:
parent
3c6748cd51
commit
35ffa4830e
3 changed files with 18 additions and 0 deletions
|
|
@ -711,6 +711,14 @@ static inline void vma_assert_write_locked(struct vm_area_struct *vma)
|
|||
VM_BUG_ON_VMA(!__is_vma_write_locked(vma, &mm_lock_seq), vma);
|
||||
}
|
||||
|
||||
static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached)
|
||||
{
|
||||
/* When detaching vma should be write-locked */
|
||||
if (detached)
|
||||
vma_assert_write_locked(vma);
|
||||
vma->detached = detached;
|
||||
}
|
||||
|
||||
#else /* CONFIG_PER_VMA_LOCK */
|
||||
|
||||
static inline void vma_init_lock(struct vm_area_struct *vma) {}
|
||||
|
|
@ -721,6 +729,8 @@ static inline void vma_start_write(struct vm_area_struct *vma) {}
|
|||
static inline bool vma_try_start_write(struct vm_area_struct *vma)
|
||||
{ return true; }
|
||||
static inline void vma_assert_write_locked(struct vm_area_struct *vma) {}
|
||||
static inline void vma_mark_detached(struct vm_area_struct *vma,
|
||||
bool detached) {}
|
||||
|
||||
#endif /* CONFIG_PER_VMA_LOCK */
|
||||
|
||||
|
|
@ -732,6 +742,7 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
|
|||
vma->vm_mm = mm;
|
||||
vma->vm_ops = &dummy_vm_ops;
|
||||
INIT_LIST_HEAD(&vma->anon_vma_chain);
|
||||
vma_mark_detached(vma, false);
|
||||
vma_init_lock(vma);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -476,6 +476,9 @@ struct vm_area_struct {
|
|||
#ifdef CONFIG_PER_VMA_LOCK
|
||||
int vm_lock_seq;
|
||||
struct rw_semaphore lock;
|
||||
|
||||
/* Flag to indicate areas detached from the mm->mm_mt tree */
|
||||
bool detached;
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -575,6 +575,8 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma,
|
|||
vma->vm_pgoff = pgoff;
|
||||
/* Note: mas must be pointing to the expanding VMA */
|
||||
vma_mas_store(vma, mas);
|
||||
if (remove_next)
|
||||
vma_mark_detached(next, true);
|
||||
|
||||
if (file) {
|
||||
vma_interval_tree_insert(vma, root);
|
||||
|
|
@ -857,6 +859,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
|
|||
|
||||
if (remove_next) {
|
||||
again:
|
||||
vma_mark_detached(next, true);
|
||||
if (file) {
|
||||
uprobe_munmap(next, next->vm_start, next->vm_end);
|
||||
fput(file);
|
||||
|
|
@ -2323,6 +2326,7 @@ static inline int munmap_sidetree(struct vm_area_struct *vma, int count,
|
|||
if (mas_store_gfp(mas_detach, vma, GFP_KERNEL))
|
||||
return -ENOMEM;
|
||||
|
||||
vma_mark_detached(vma, true);
|
||||
if (vma->vm_flags & VM_LOCKED)
|
||||
vma->vm_mm->locked_vm -= vma_pages(vma);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue