lkml.org 
[lkml]   [2015]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Multiple potential races on vma->vm_flags
On 09/23, Oleg Nesterov wrote:
>
> On 09/11, Kirill A. Shutemov wrote:
> >
> > This one is tricky. I *assume* the mm cannot be generally accessible after
> > mm_users drops to zero, but I'm not entirely sure about it.
> > procfs? ptrace?
>
> Well, all I can say is that proc/ptrace look fine afaics...
>
> This is off-topic, but how about the patch below? Different threads can
> expand different vma's at the same time under read_lock(mmap_sem), so
> vma_lock_anon_vma() can't help to serialize "locked_vm += grow".

perhaps vm_stat_account() should be moved too, but total_vm/etc is less
important.

Or I missed something?

Oleg.

> --- x/mm/mmap.c
> +++ x/mm/mmap.c
> @@ -2146,9 +2146,6 @@ static int acct_stack_growth(struct vm_a
> if (security_vm_enough_memory_mm(mm, grow))
> return -ENOMEM;
>
> - /* Ok, everything looks good - let it rip */
> - if (vma->vm_flags & VM_LOCKED)
> - mm->locked_vm += grow;
> vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
> return 0;
> }
> @@ -2210,6 +2207,8 @@ int expand_upwards(struct vm_area_struct
> * against concurrent vma expansions.
> */
> spin_lock(&vma->vm_mm->page_table_lock);
> + if (vma->vm_flags & VM_LOCKED)
> + mm->locked_vm += grow;
> anon_vma_interval_tree_pre_update_vma(vma);
> vma->vm_end = address;
> anon_vma_interval_tree_post_update_vma(vma);
> @@ -2281,6 +2280,8 @@ int expand_downwards(struct vm_area_stru
> * against concurrent vma expansions.
> */
> spin_lock(&vma->vm_mm->page_table_lock);
> + if (vma->vm_flags & VM_LOCKED)
> + mm->locked_vm += grow;
> anon_vma_interval_tree_pre_update_vma(vma);
> vma->vm_start = address;
> vma->vm_pgoff -= grow;



\
 
 \ /
  Last update: 2015-09-23 18:01    [W:0.242 / U:2.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site