[PATCH 4/4] mlockall() take mmap_sem a bit later

From: Chris Wright
Date: Wed Sep 29 2004 - 14:02:17 EST


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: Chris Wright <chrisw@xxxxxxxx>

--- 2.6.9-rc2/mm/mlock.c~move_sem 2004-09-28 23:46:01.000000000 -0700
+++ 2.6.9-rc2/mm/mlock.c 2004-09-29 00:22:25.625969360 -0700
@@ -119,7 +119,7 @@ asmlinkage long sys_mlock(unsigned long
lock_limit >>= PAGE_SHIFT;

/* 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);
up_write(&current->mm->mmap_sem);
return error;
@@ -167,7 +167,6 @@ asmlinkage long sys_mlockall(int flags)
unsigned long lock_limit;
int ret = -EINVAL;

- down_write(&current->mm->mmap_sem);
if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE)))
goto out;

@@ -175,6 +174,8 @@ asmlinkage long sys_mlockall(int flags)
if (!can_do_mlock())
goto out;

+ down_write(&current->mm->mmap_sem);
+
lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
lock_limit >>= PAGE_SHIFT;

@@ -182,8 +183,8 @@ asmlinkage long sys_mlockall(int flags)
if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
capable(CAP_IPC_LOCK))
ret = do_mlockall(flags);
-out:
up_write(&current->mm->mmap_sem);
+out:
return ret;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/