aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/mlock.c')
-rw-r--r--mm/mlock.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/mm/mlock.c b/mm/mlock.c
index 192e6eebe4f2..10819ed4df3e 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -709,19 +709,21 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
709 709
710 lru_add_drain_all(); /* flush pagevec */ 710 lru_add_drain_all(); /* flush pagevec */
711 711
712 down_write(&current->mm->mmap_sem);
713 len = PAGE_ALIGN(len + (start & ~PAGE_MASK)); 712 len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
714 start &= PAGE_MASK; 713 start &= PAGE_MASK;
715 714
716 locked = len >> PAGE_SHIFT;
717 locked += current->mm->locked_vm;
718
719 lock_limit = rlimit(RLIMIT_MEMLOCK); 715 lock_limit = rlimit(RLIMIT_MEMLOCK);
720 lock_limit >>= PAGE_SHIFT; 716 lock_limit >>= PAGE_SHIFT;
717 locked = len >> PAGE_SHIFT;
718
719 down_write(&current->mm->mmap_sem);
720
721 locked += current->mm->locked_vm;
721 722
722 /* check against resource limits */ 723 /* check against resource limits */
723 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK)) 724 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
724 error = do_mlock(start, len, 1); 725 error = do_mlock(start, len, 1);
726
725 up_write(&current->mm->mmap_sem); 727 up_write(&current->mm->mmap_sem);
726 if (!error) 728 if (!error)
727 error = __mm_populate(start, len, 0); 729 error = __mm_populate(start, len, 0);
@@ -732,11 +734,13 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
732{ 734{
733 int ret; 735 int ret;
734 736
735 down_write(&current->mm->mmap_sem);
736 len = PAGE_ALIGN(len + (start & ~PAGE_MASK)); 737 len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
737 start &= PAGE_MASK; 738 start &= PAGE_MASK;
739
740 down_write(&current->mm->mmap_sem);
738 ret = do_mlock(start, len, 0); 741 ret = do_mlock(start, len, 0);
739 up_write(&current->mm->mmap_sem); 742 up_write(&current->mm->mmap_sem);
743
740 return ret; 744 return ret;
741} 745}
742 746
@@ -781,12 +785,12 @@ SYSCALL_DEFINE1(mlockall, int, flags)
781 if (flags & MCL_CURRENT) 785 if (flags & MCL_CURRENT)
782 lru_add_drain_all(); /* flush pagevec */ 786 lru_add_drain_all(); /* flush pagevec */
783 787
784 down_write(&current->mm->mmap_sem);
785
786 lock_limit = rlimit(RLIMIT_MEMLOCK); 788 lock_limit = rlimit(RLIMIT_MEMLOCK);
787 lock_limit >>= PAGE_SHIFT; 789 lock_limit >>= PAGE_SHIFT;
788 790
789 ret = -ENOMEM; 791 ret = -ENOMEM;
792 down_write(&current->mm->mmap_sem);
793
790 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) || 794 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
791 capable(CAP_IPC_LOCK)) 795 capable(CAP_IPC_LOCK))
792 ret = do_mlockall(flags); 796 ret = do_mlockall(flags);