Commit 7d9ace4c authored by Chris Wright's avatar Chris Wright Committed by Linus Torvalds

[PATCH] mlockall() take mmap_sem a bit later

In sys_mlockall(), flags validation and can_do_mlock() check don't
require holding mmap_sem.  Move down_write() down a bit, and adjust
appropriately.
Signed-off-by: default avatarChris Wright <chrisw@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ead942ce
...@@ -119,7 +119,7 @@ asmlinkage long sys_mlock(unsigned long start, size_t len) ...@@ -119,7 +119,7 @@ asmlinkage long sys_mlock(unsigned long start, size_t len)
lock_limit >>= PAGE_SHIFT; lock_limit >>= PAGE_SHIFT;
/* check against resource limits */ /* check against resource limits */
if ( (locked <= lock_limit) || capable(CAP_IPC_LOCK)) if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
error = do_mlock(start, len, 1); error = do_mlock(start, len, 1);
up_write(&current->mm->mmap_sem); up_write(&current->mm->mmap_sem);
return error; return error;
...@@ -167,7 +167,6 @@ asmlinkage long sys_mlockall(int flags) ...@@ -167,7 +167,6 @@ asmlinkage long sys_mlockall(int flags)
unsigned long lock_limit; unsigned long lock_limit;
int ret = -EINVAL; int ret = -EINVAL;
down_write(&current->mm->mmap_sem);
if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE))) if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE)))
goto out; goto out;
...@@ -175,6 +174,8 @@ asmlinkage long sys_mlockall(int flags) ...@@ -175,6 +174,8 @@ asmlinkage long sys_mlockall(int flags)
if (!can_do_mlock()) if (!can_do_mlock())
goto out; goto out;
down_write(&current->mm->mmap_sem);
lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur; lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
lock_limit >>= PAGE_SHIFT; lock_limit >>= PAGE_SHIFT;
...@@ -182,8 +183,8 @@ asmlinkage long sys_mlockall(int flags) ...@@ -182,8 +183,8 @@ asmlinkage long sys_mlockall(int flags)
if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) || if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
capable(CAP_IPC_LOCK)) capable(CAP_IPC_LOCK))
ret = do_mlockall(flags); ret = do_mlockall(flags);
out:
up_write(&current->mm->mmap_sem); up_write(&current->mm->mmap_sem);
out:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment