* [PATCH] mlock-as-user for 2.6.8-rc2-mm2
@ 2004-08-04 17:55 Rik van Riel
2004-08-04 21:01 ` Chris Wright
0 siblings, 1 reply; 7+ messages in thread
From: Rik van Riel @ 2004-08-04 17:55 UTC (permalink / raw)
To: Andrew Morton; +Cc: Arjan Van de Ven, linux-kernel, Chris Wright
Hi Andrew,
here is the last agreed-on patch that lets normal users mlock
pages up to their rlimit. This patch addresses all the issues
brought up by Chris and Andrea.
Please apply this patch for your next release.
thanks,
Rik
Signed-off-by: Rik van Riel <riel@redhat.com>
--- linux-2.6.8-rc2/include/asm-ppc64/resource.h.mlock 2004-07-18 00:58:57.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-ppc64/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -45,7 +45,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-m68k/resource.h.mlock 2004-07-18 00:57:38.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-m68k/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-parisc/resource.h.mlock 2004-07-18 00:58:57.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-parisc/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-ppc/resource.h.mlock 2004-07-18 00:58:21.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-ppc/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -36,7 +36,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-x86_64/resource.h.mlock 2004-07-18 00:58:57.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-x86_64/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE , PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-ia64/resource.h.mlock 2004-07-18 00:59:03.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-ia64/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -46,7 +46,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/linux/mm.h.mlock 2004-08-04 13:23:15.000000000 -0400
+++ linux-2.6.8-rc2/include/linux/mm.h 2004-08-04 13:25:33.000000000 -0400
@@ -498,9 +498,20 @@ int shmem_set_policy(struct vm_area_stru
struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
unsigned long addr);
struct file *shmem_file_setup(char * name, loff_t size, unsigned long flags);
-void shmem_lock(struct file * file, int lock);
+int shmem_lock(struct file * file, int lock, struct user_struct *);
int shmem_zero_setup(struct vm_area_struct *);
+static inline int can_do_mlock(void)
+{
+ if (capable(CAP_IPC_LOCK))
+ return 1;
+ if (current->rlim[RLIMIT_MEMLOCK].rlim_cur != 0)
+ return 1;
+ return 0;
+}
+extern int user_can_mlock(size_t, struct user_struct *);
+extern void user_subtract_mlock(size_t, struct user_struct *);
+
/*
* Parameter block passed down to zap_pte_range in exceptional cases.
*/
--- linux-2.6.8-rc2/include/linux/shm.h.mlock 2004-07-18 00:59:02.000000000 -0400
+++ linux-2.6.8-rc2/include/linux/shm.h 2004-08-04 13:25:33.000000000 -0400
@@ -84,6 +84,7 @@ struct shmid_kernel /* private to the ke
time_t shm_ctim;
pid_t shm_cprid;
pid_t shm_lprid;
+ struct user_struct * mlock_user;
};
/* shm_mode upper byte flags */
--- linux-2.6.8-rc2/include/linux/sched.h.mlock 2004-08-04 13:23:17.000000000 -0400
+++ linux-2.6.8-rc2/include/linux/sched.h 2004-08-04 13:25:33.000000000 -0400
@@ -333,6 +333,7 @@ struct user_struct {
atomic_t sigpending; /* How many pending signals does this user have? */
/* protected by mq_lock */
unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
+ unsigned long locked_shm; /* How many pages of mlocked shm ? */
/* Hash table maintenance information */
struct list_head uidhash_list;
--- linux-2.6.8-rc2/include/asm-arm/resource.h.mlock 2004-07-18 00:59:06.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-arm/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linux-2.6.8-rc2/include/asm-v850/resource.h.mlock 2004-07-18 00:57:40.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-v850/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-sparc/resource.h.mlock 2004-07-18 00:57:42.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-sparc/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -44,7 +44,7 @@
{ 0, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{INR_OPEN, INR_OPEN}, {0, 0}, \
- {RLIM_INFINITY, RLIM_INFINITY}, \
+ {PAGE_SIZE, PAGE_SIZE}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linux-2.6.8-rc2/include/asm-alpha/resource.h.mlock 2004-07-18 00:57:41.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-alpha/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -41,7 +41,7 @@
{INR_OPEN, INR_OPEN}, /* RLIMIT_NOFILE */ \
{LONG_MAX, LONG_MAX}, /* RLIMIT_AS */ \
{LONG_MAX, LONG_MAX}, /* RLIMIT_NPROC */ \
- {LONG_MAX, LONG_MAX}, /* RLIMIT_MEMLOCK */ \
+ {PAGE_SIZE, PAGE_SIZE}, /* RLIMIT_MEMLOCK */ \
{LONG_MAX, LONG_MAX}, /* RLIMIT_LOCKS */ \
{MAX_SIGPENDING, MAX_SIGPENDING}, /* RLIMIT_SIGPENDING */ \
{MQ_BYTES_MAX, MQ_BYTES_MAX}, /* RLIMIT_MSGQUEUE */ \
--- linux-2.6.8-rc2/include/asm-i386/resource.h.mlock 2004-07-18 00:59:32.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-i386/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -40,7 +40,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-h8300/resource.h.mlock 2004-07-18 00:57:40.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-h8300/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-s390/resource.h.mlock 2004-07-18 00:58:13.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-s390/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -47,7 +47,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-cris/resource.h.mlock 2004-07-18 00:58:54.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-cris/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/include/asm-sparc64/resource.h.mlock 2004-07-18 00:57:38.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-sparc64/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -43,7 +43,7 @@
{ 0, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{INR_OPEN, INR_OPEN}, {0, 0}, \
- {RLIM_INFINITY, RLIM_INFINITY}, \
+ {PAGE_SIZE, PAGE_SIZE }, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linux-2.6.8-rc2/include/asm-arm26/resource.h.mlock 2004-07-18 00:57:38.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-arm26/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linux-2.6.8-rc2/include/asm-sh/resource.h.mlock 2004-07-18 00:58:54.000000000 -0400
+++ linux-2.6.8-rc2/include/asm-sh/resource.h 2004-08-04 13:25:33.000000000 -0400
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { RLIM_INFINITY, RLIM_INFINITY }, \
+ { PAGE_SIZE, PAGE_SIZE }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linux-2.6.8-rc2/fs/hugetlbfs/inode.c.mlock 2004-08-04 13:23:11.000000000 -0400
+++ linux-2.6.8-rc2/fs/hugetlbfs/inode.c 2004-08-04 13:27:11.000000000 -0400
@@ -742,7 +742,7 @@ static int can_do_hugetlb_shm(void)
struct file *hugetlb_zero_setup(size_t size)
{
- int error;
+ int error = -ENOMEM;
struct file *file;
struct inode *inode;
struct dentry *dentry, *root;
@@ -755,6 +755,9 @@ struct file *hugetlb_zero_setup(size_t s
if (!is_hugepage_mem_enough(size))
return ERR_PTR(-ENOMEM);
+ if (!user_can_mlock(size, current->user))
+ return ERR_PTR(-ENOMEM);
+
root = hugetlbfs_vfsmount->mnt_root;
snprintf(buf, 16, "%lu", hugetlbfs_counter());
quick_string.name = buf;
@@ -762,7 +765,7 @@ struct file *hugetlb_zero_setup(size_t s
quick_string.hash = 0;
dentry = d_alloc(root, &quick_string);
if (!dentry)
- return ERR_PTR(-ENOMEM);
+ goto out_subtract_mlock;
error = -ENFILE;
file = get_empty_filp();
@@ -789,6 +792,8 @@ out_file:
put_filp(file);
out_dentry:
dput(dentry);
+out_subtract_mlock:
+ user_subtract_mlock(size, current->user);
return ERR_PTR(error);
}
--- linux-2.6.8-rc2/kernel/user.c.mlock 2004-07-18 00:58:20.000000000 -0400
+++ linux-2.6.8-rc2/kernel/user.c 2004-08-04 13:25:33.000000000 -0400
@@ -32,7 +32,8 @@ struct user_struct root_user = {
.processes = ATOMIC_INIT(1),
.files = ATOMIC_INIT(0),
.sigpending = ATOMIC_INIT(0),
- .mq_bytes = 0
+ .mq_bytes = 0,
+ .locked_shm = 0
};
/*
@@ -113,6 +114,7 @@ struct user_struct * alloc_uid(uid_t uid
atomic_set(&new->sigpending, 0);
new->mq_bytes = 0;
+ new->locked_shm = 0;
/*
* Before adding this, check whether we raced
--- linux-2.6.8-rc2/ipc/shm.c.mlock 2004-08-04 13:23:18.000000000 -0400
+++ linux-2.6.8-rc2/ipc/shm.c 2004-08-04 13:25:33.000000000 -0400
@@ -114,7 +114,10 @@ static void shm_destroy (struct shmid_ke
shm_rmid (shp->id);
shm_unlock(shp);
if (!is_file_hugepages(shp->shm_file))
- shmem_lock(shp->shm_file, 0);
+ shmem_lock(shp->shm_file, 0, shp->mlock_user);
+ else
+ user_subtract_mlock(shp->shm_file->f_dentry->d_inode->i_size,
+ shp->mlock_user);
fput (shp->shm_file);
security_shm_free(shp);
ipc_rcu_putref(shp);
@@ -190,6 +193,7 @@ static int newseg (key_t key, int shmflg
shp->shm_perm.key = key;
shp->shm_flags = (shmflg & S_IRWXUGO);
+ shp->mlock_user = NULL;
shp->shm_perm.security = NULL;
error = security_shm_alloc(shp);
@@ -198,9 +202,11 @@ static int newseg (key_t key, int shmflg
return error;
}
- if (shmflg & SHM_HUGETLB)
+ if (shmflg & SHM_HUGETLB) {
+ /* hugetlb_zero_setup takes care of mlock user accounting */
file = hugetlb_zero_setup(size);
- else {
+ shp->mlock_user = current->user;
+ } else {
sprintf (name, "SYSV%08x", key);
file = shmem_file_setup(name, size, VM_ACCOUNT);
}
@@ -504,14 +510,11 @@ asmlinkage long sys_shmctl (int shmid, i
case SHM_LOCK:
case SHM_UNLOCK:
{
-/* Allow superuser to lock segment in memory */
-/* Should the pages be faulted in here or leave it to user? */
-/* need to determine interaction with current->swappable */
- if (!capable(CAP_IPC_LOCK)) {
+ /* Allow superuser to lock segment in memory */
+ if (!can_do_mlock() && cmd == SHM_LOCK) {
err = -EPERM;
goto out;
}
-
shp = shm_lock(shmid);
if(shp==NULL) {
err = -EINVAL;
@@ -526,13 +529,18 @@ asmlinkage long sys_shmctl (int shmid, i
goto out_unlock;
if(cmd==SHM_LOCK) {
- if (!is_file_hugepages(shp->shm_file))
- shmem_lock(shp->shm_file, 1);
- shp->shm_flags |= SHM_LOCKED;
- } else {
- if (!is_file_hugepages(shp->shm_file))
- shmem_lock(shp->shm_file, 0);
+ struct user_struct * user = current->user;
+ if (!is_file_hugepages(shp->shm_file)) {
+ err = shmem_lock(shp->shm_file, 1, current->user);
+ if (!err) {
+ shp->shm_flags |= SHM_LOCKED;
+ shp->mlock_user = user;
+ }
+ }
+ } else if (!is_file_hugepages(shp->shm_file)) {
+ shmem_lock(shp->shm_file, 0, shp->mlock_user);
shp->shm_flags &= ~SHM_LOCKED;
+ shp->mlock_user = NULL;
}
shm_unlock(shp);
goto out;
--- linux-2.6.8-rc2/mm/mlock.c.mlock 2004-07-18 00:57:40.000000000 -0400
+++ linux-2.6.8-rc2/mm/mlock.c 2004-08-04 13:25:33.000000000 -0400
@@ -60,7 +60,7 @@ static int do_mlock(unsigned long start,
struct vm_area_struct * vma, * next;
int error;
- if (on && !capable(CAP_IPC_LOCK))
+ if (on && !can_do_mlock())
return -EPERM;
len = PAGE_ALIGN(len);
end = start + len;
@@ -118,7 +118,7 @@ asmlinkage long sys_mlock(unsigned long
lock_limit >>= PAGE_SHIFT;
/* check against resource limits */
- if (locked <= lock_limit)
+ if ( (locked <= lock_limit) || capable(CAP_IPC_LOCK))
error = do_mlock(start, len, 1);
up_write(¤t->mm->mmap_sem);
return error;
@@ -142,7 +142,7 @@ static int do_mlockall(int flags)
unsigned int def_flags;
struct vm_area_struct * vma;
- if (!capable(CAP_IPC_LOCK))
+ if (!can_do_mlock())
return -EPERM;
def_flags = 0;
@@ -177,7 +177,7 @@ asmlinkage long sys_mlockall(int flags)
lock_limit >>= PAGE_SHIFT;
ret = -ENOMEM;
- if (current->mm->total_vm <= lock_limit)
+ if ((current->mm->total_vm <= lock_limit) || capable(CAP_IPC_LOCK))
ret = do_mlockall(flags);
out:
up_write(¤t->mm->mmap_sem);
@@ -193,3 +193,36 @@ asmlinkage long sys_munlockall(void)
up_write(¤t->mm->mmap_sem);
return ret;
}
+
+/*
+ * Objects with different lifetime than processes (mlocked shm segments
+ * and hugetlb files) get accounted against the user_struct instead.
+ */
+static spinlock_t mlock_user_lock = SPIN_LOCK_UNLOCKED;
+
+int user_can_mlock(size_t size, struct user_struct * user)
+{
+ unsigned long lock_limit, locked;
+ int allowed = 0;
+
+ spin_lock(&mlock_user_lock);
+ locked = size >> PAGE_SHIFT;
+ lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
+ lock_limit >>= PAGE_SHIFT;
+ if (locked + user->locked_shm > lock_limit)
+ goto out;
+ get_uid(user);
+ user->locked_shm += locked;
+ allowed = 1;
+out:
+ spin_unlock(&mlock_user_lock);
+ return allowed;
+}
+
+void user_subtract_mlock(size_t size, struct user_struct * user)
+{
+ spin_lock(&mlock_user_lock);
+ user->locked_shm -= (size >> PAGE_SHIFT);
+ spin_unlock(&mlock_user_lock);
+ free_uid(user);
+}
--- linux-2.6.8-rc2/mm/mmap.c.mlock 2004-08-04 13:23:18.000000000 -0400
+++ linux-2.6.8-rc2/mm/mmap.c 2004-08-04 13:25:33.000000000 -0400
@@ -796,15 +796,17 @@ unsigned long do_mmap_pgoff(struct file
mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
if (flags & MAP_LOCKED) {
- if (!capable(CAP_IPC_LOCK))
+ if (!can_do_mlock())
return -EPERM;
vm_flags |= VM_LOCKED;
}
/* mlock MCL_FUTURE? */
if (vm_flags & VM_LOCKED) {
- unsigned long locked = mm->locked_vm << PAGE_SHIFT;
+ unsigned long locked, lock_limit;
+ locked = mm->locked_vm << PAGE_SHIFT;
+ lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
locked += len;
- if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
+ if (locked > lock_limit && !capable(CAP_IPC_LOCK))
return -EAGAIN;
}
@@ -1723,9 +1725,11 @@ unsigned long do_brk(unsigned long addr,
* mlock MCL_FUTURE?
*/
if (mm->def_flags & VM_LOCKED) {
- unsigned long locked = mm->locked_vm << PAGE_SHIFT;
+ unsigned long locked, lock_limit;
+ locked = mm->locked_vm << PAGE_SHIFT;
+ lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
locked += len;
- if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
+ if (locked > lock_limit && !capable(CAP_IPC_LOCK))
return -EAGAIN;
}
--- linux-2.6.8-rc2/mm/mremap.c.mlock 2004-07-18 00:58:37.000000000 -0400
+++ linux-2.6.8-rc2/mm/mremap.c 2004-08-04 13:25:33.000000000 -0400
@@ -324,10 +324,12 @@ unsigned long do_mremap(unsigned long ad
goto out;
}
if (vma->vm_flags & VM_LOCKED) {
- unsigned long locked = current->mm->locked_vm << PAGE_SHIFT;
+ unsigned long locked, lock_limit;
+ locked = current->mm->locked_vm << PAGE_SHIFT;
+ lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
locked += new_len - old_len;
ret = -EAGAIN;
- if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
+ if (locked > lock_limit && !capable(CAP_IPC_LOCK))
goto out;
}
ret = -ENOMEM;
--- linux-2.6.8-rc2/mm/shmem.c.mlock 2004-08-04 13:23:18.000000000 -0400
+++ linux-2.6.8-rc2/mm/shmem.c 2004-08-04 13:25:33.000000000 -0400
@@ -1151,17 +1151,29 @@ shmem_get_policy(struct vm_area_struct *
}
#endif
-void shmem_lock(struct file *file, int lock)
+int shmem_lock(struct file *file, int lock, struct user_struct * user)
{
struct inode *inode = file->f_dentry->d_inode;
struct shmem_inode_info *info = SHMEM_I(inode);
+ int retval = -ENOMEM;
+
+ if (lock && !can_do_mlock())
+ return -EPERM;
spin_lock(&info->lock);
- if (lock)
+ if (lock && !(info->flags & VM_LOCKED)) {
+ if (!user_can_mlock(inode->i_size, user) && !capable(CAP_IPC_LOCK))
+ goto out_nomem;
info->flags |= VM_LOCKED;
- else
+ }
+ if (!lock && (info->flags & VM_LOCKED) && user) {
+ user_subtract_mlock(inode->i_size, user);
info->flags &= ~VM_LOCKED;
+ }
+ retval = 0;
+out_nomem:
spin_unlock(&info->lock);
+ return retval;
}
static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mlock-as-user for 2.6.8-rc2-mm2
2004-08-04 17:55 [PATCH] mlock-as-user for 2.6.8-rc2-mm2 Rik van Riel
@ 2004-08-04 21:01 ` Chris Wright
2004-08-04 21:06 ` Rik van Riel
0 siblings, 1 reply; 7+ messages in thread
From: Chris Wright @ 2004-08-04 21:01 UTC (permalink / raw)
To: Rik van Riel; +Cc: Andrew Morton, Arjan Van de Ven, linux-kernel, Chris Wright
* Rik van Riel (riel@redhat.com) wrote:
> Hi Andrew,
>
> here is the last agreed-on patch that lets normal users mlock
> pages up to their rlimit. This patch addresses all the issues
> brought up by Chris and Andrea.
>
> Please apply this patch for your next release.
Couple more nits.
The default lockable amount is one page now (first patch is was 0).
Why don't we keep it as 0, with the CAP_IPC_LOCK overrides in place?
That way nothing is changed from user perspective, and the rest of the
policy can be done by userspace as it should.
This patch breaks in one scenario. When ulimit == 0, process has
CAP_IPC_LOCK, and does SHM_LOCK. The subsequent unlock or destroy will
corrupt the locked_shm count.
It's also inconsistent in handling user_can_mlock/CAP_IPC_LOCK
interaction betwen shm_lock and shm_hugetlb.
SHM_HUGETLB can now only be done by the shm_group or CAP_IPC_LOCK.
Not any can_do_mlock() user.
Double check of can_do_mlock isn't needed in SHM_LOCK path.
Interface names user_can_mlock and user_substract_mlock could be better.
Incremental update below. Ran some simple sanity tests on this plus my
patch below and didn't find any problems.
thanks,
-chris
--
* Make default RLIM_MEMLOCK limit 0.
* Move CAP_IPC_LOCK check into user_can_mlock to be consistent
and fix but with ulimit == 0 && CAP_IPC_LOCK with SHM_LOCK.
* Allow can_do_mlock() user to try SHM_HUGETLB setup.
* Remove unecessary extra can_do_mlock() test in shmem_lock().
* Rename user_can_mlock to user_shm_lock and user_subtract_mlock
to user_shm_unlock.
* Use user instead of current->user to fit in 80 cols on SHM_LOCK.
--- linus-2.5/fs/hugetlbfs/inode.c~mlock_rlimit 2004-08-04 12:44:19.000000000 -0700
+++ linus-2.5/fs/hugetlbfs/inode.c 2004-08-04 13:21:53.000000000 -0700
@@ -721,7 +721,8 @@
static int can_do_hugetlb_shm(void)
{
return likely(capable(CAP_IPC_LOCK) ||
- in_group_p(sysctl_hugetlb_shm_group));
+ in_group_p(sysctl_hugetlb_shm_group) ||
+ can_do_mlock());
}
struct file *hugetlb_zero_setup(size_t size)
@@ -739,7 +740,7 @@
if (!is_hugepage_mem_enough(size))
return ERR_PTR(-ENOMEM);
- if (!user_can_mlock(size, current->user))
+ if (!user_shm_lock(size, current->user))
return ERR_PTR(-ENOMEM);
root = hugetlbfs_vfsmount->mnt_root;
@@ -749,7 +750,7 @@
quick_string.hash = 0;
dentry = d_alloc(root, &quick_string);
if (!dentry)
- goto out_subtract_mlock;
+ goto out_shm_unlock;
error = -ENFILE;
file = get_empty_filp();
@@ -776,8 +777,8 @@
put_filp(file);
out_dentry:
dput(dentry);
-out_subtract_mlock:
- user_subtract_mlock(size, current->user);
+out_shm_unlock:
+ user_shm_unlock(size, current->user);
return ERR_PTR(error);
}
--- linus-2.5/include/asm-alpha/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-alpha/resource.h 2004-08-04 12:34:40.000000000 -0700
@@ -41,7 +41,7 @@
{INR_OPEN, INR_OPEN}, /* RLIMIT_NOFILE */ \
{LONG_MAX, LONG_MAX}, /* RLIMIT_AS */ \
{LONG_MAX, LONG_MAX}, /* RLIMIT_NPROC */ \
- {PAGE_SIZE, PAGE_SIZE}, /* RLIMIT_MEMLOCK */ \
+ {0, 0 }, /* RLIMIT_MEMLOCK */ \
{LONG_MAX, LONG_MAX}, /* RLIMIT_LOCKS */ \
{MAX_SIGPENDING, MAX_SIGPENDING}, /* RLIMIT_SIGPENDING */ \
{MQ_BYTES_MAX, MQ_BYTES_MAX}, /* RLIMIT_MSGQUEUE */ \
--- linus-2.5/include/asm-arm/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-arm/resource.h 2004-08-04 12:34:40.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linus-2.5/include/asm-cris/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-cris/resource.h 2004-08-04 12:34:40.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-h8300/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-h8300/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-i386/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-i386/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -40,7 +40,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-ia64/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-ia64/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -46,7 +46,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-m68k/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-m68k/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-parisc/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-parisc/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-ppc/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-ppc/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -36,7 +36,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-ppc64/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-ppc64/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -45,7 +45,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-s390/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-s390/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -47,7 +47,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-sh/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-sh/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-sparc/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-sparc/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -44,7 +44,7 @@
{ 0, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{INR_OPEN, INR_OPEN}, {0, 0}, \
- {PAGE_SIZE, PAGE_SIZE}, \
+ {0, 0}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linus-2.5/include/asm-sparc64/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-sparc64/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -43,7 +43,7 @@
{ 0, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{INR_OPEN, INR_OPEN}, {0, 0}, \
- {PAGE_SIZE, PAGE_SIZE }, \
+ {0, 0 }, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{RLIM_INFINITY, RLIM_INFINITY}, \
{MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linus-2.5/include/asm-v850/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-v850/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/asm-x86_64/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-x86_64/resource.h 2004-08-04 12:34:41.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE , PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING }, \
--- linus-2.5/include/linux/mm.h~mlock_rlimit 2004-08-04 12:43:32.000000000 -0700
+++ linus-2.5/include/linux/mm.h 2004-08-04 12:44:03.000000000 -0700
@@ -507,8 +507,8 @@
return 1;
return 0;
}
-extern int user_can_mlock(size_t, struct user_struct *);
-extern void user_subtract_mlock(size_t, struct user_struct *);
+extern int user_shm_lock(size_t, struct user_struct *);
+extern void user_shm_unlock(size_t, struct user_struct *);
/*
* Parameter block passed down to zap_pte_range in exceptional cases.
--- linus-2.5/include/asm-arm26/resource.h~mlock_rlimit 2004-08-04 12:33:48.000000000 -0700
+++ linus-2.5/include/asm-arm26/resource.h 2004-08-04 12:34:40.000000000 -0700
@@ -39,7 +39,7 @@
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ 0, 0 }, \
{ INR_OPEN, INR_OPEN }, \
- { PAGE_SIZE, PAGE_SIZE }, \
+ { 0, 0 }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ RLIM_INFINITY, RLIM_INFINITY }, \
{ MAX_SIGPENDING, MAX_SIGPENDING}, \
--- linus-2.5/ipc/shm.c~mlock_rlimit 2004-08-04 12:37:39.000000000 -0700
+++ linus-2.5/ipc/shm.c 2004-08-04 13:03:46.000000000 -0700
@@ -116,7 +116,7 @@
if (!is_file_hugepages(shp->shm_file))
shmem_lock(shp->shm_file, 0, shp->mlock_user);
else
- user_subtract_mlock(shp->shm_file->f_dentry->d_inode->i_size,
+ user_shm_unlock(shp->shm_file->f_dentry->d_inode->i_size,
shp->mlock_user);
fput (shp->shm_file);
security_shm_free(shp);
@@ -531,7 +531,7 @@
if(cmd==SHM_LOCK) {
struct user_struct * user = current->user;
if (!is_file_hugepages(shp->shm_file)) {
- err = shmem_lock(shp->shm_file, 1, current->user);
+ err = shmem_lock(shp->shm_file, 1, user);
if (!err) {
shp->shm_flags |= SHM_LOCKED;
shp->mlock_user = user;
--- linus-2.5/mm/mlock.c~mlock_rlimit 2004-08-04 13:39:43.483698800 -0700
+++ linus-2.5/mm/mlock.c 2004-08-04 13:39:59.681236400 -0700
@@ -195,34 +195,34 @@
}
/*
- * Objects with different lifetime than processes (mlocked shm segments
- * and hugetlb files) get accounted against the user_struct instead.
+ * Objects with different lifetime than processes (SHM_LOCK and SHM_HUGETLB
+ * shm segments) get accounted against the user_struct instead.
*/
-static spinlock_t mlock_user_lock = SPIN_LOCK_UNLOCKED;
+static spinlock_t shmlock_user_lock = SPIN_LOCK_UNLOCKED;
-int user_can_mlock(size_t size, struct user_struct * user)
+int user_shm_lock(size_t size, struct user_struct * user)
{
unsigned long lock_limit, locked;
int allowed = 0;
- spin_lock(&mlock_user_lock);
+ spin_lock(&shmlock_user_lock);
locked = size >> PAGE_SHIFT;
lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
lock_limit >>= PAGE_SHIFT;
- if (locked + user->locked_shm > lock_limit)
+ if (locked + user->locked_shm > lock_limit && !capable(CAP_IPC_LOCK))
goto out;
get_uid(user);
user->locked_shm += locked;
allowed = 1;
out:
- spin_unlock(&mlock_user_lock);
+ spin_unlock(&shmlock_user_lock);
return allowed;
}
-void user_subtract_mlock(size_t size, struct user_struct * user)
+void user_shm_unlock(size_t size, struct user_struct * user)
{
- spin_lock(&mlock_user_lock);
+ spin_lock(&shmlock_user_lock);
user->locked_shm -= (size >> PAGE_SHIFT);
- spin_unlock(&mlock_user_lock);
+ spin_unlock(&shmlock_user_lock);
free_uid(user);
}
--- linus-2.5/mm/shmem.c~mlock_rlimit 2004-08-04 12:38:01.000000000 -0700
+++ linus-2.5/mm/shmem.c 2004-08-04 12:40:06.000000000 -0700
@@ -1157,17 +1157,14 @@
struct shmem_inode_info *info = SHMEM_I(inode);
int retval = -ENOMEM;
- if (lock && !can_do_mlock())
- return -EPERM;
-
spin_lock(&info->lock);
if (lock && !(info->flags & VM_LOCKED)) {
- if (!user_can_mlock(inode->i_size, user) && !capable(CAP_IPC_LOCK))
+ if (!user_shm_lock(inode->i_size, user))
goto out_nomem;
info->flags |= VM_LOCKED;
}
if (!lock && (info->flags & VM_LOCKED) && user) {
- user_subtract_mlock(inode->i_size, user);
+ user_shm_unlock(inode->i_size, user);
info->flags &= ~VM_LOCKED;
}
retval = 0;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mlock-as-user for 2.6.8-rc2-mm2
2004-08-04 21:01 ` Chris Wright
@ 2004-08-04 21:06 ` Rik van Riel
2004-08-04 21:24 ` Andrew Morton
0 siblings, 1 reply; 7+ messages in thread
From: Rik van Riel @ 2004-08-04 21:06 UTC (permalink / raw)
To: Chris Wright; +Cc: Andrew Morton, Arjan Van de Ven, linux-kernel
On Wed, 4 Aug 2004, Chris Wright wrote:
> The default lockable amount is one page now (first patch is was 0).
> Why don't we keep it as 0, with the CAP_IPC_LOCK overrides in place?
My mistake, I went from Arjan's 2.6 submitted version to
the version in Fedora. The 0 limits are probably better
for upstream.
> Incremental update below. Ran some simple sanity tests on this plus my
> patch below and didn't find any problems.
Looks good to me.
Andrew, could you please apply Chris's patch in addition
to mine ?
thanks,
Rik
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mlock-as-user for 2.6.8-rc2-mm2
2004-08-04 21:06 ` Rik van Riel
@ 2004-08-04 21:24 ` Andrew Morton
2004-08-04 21:22 ` Arjan van de Ven
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2004-08-04 21:24 UTC (permalink / raw)
To: Rik van Riel; +Cc: chrisw, arjanv, linux-kernel
Rik van Riel <riel@redhat.com> wrote:
>
> Andrew, could you please apply Chris's patch in addition
> to mine ?
OK, but I don't have any confidence that anyone will be testing it.
Can you think of some way in which we can artificially tweak the patch
for testing so that its new features are getting some exercise?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mlock-as-user for 2.6.8-rc2-mm2
2004-08-04 21:24 ` Andrew Morton
@ 2004-08-04 21:22 ` Arjan van de Ven
2004-08-04 21:28 ` Rik van Riel
0 siblings, 1 reply; 7+ messages in thread
From: Arjan van de Ven @ 2004-08-04 21:22 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rik van Riel, chrisw, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 484 bytes --]
On Wed, Aug 04, 2004 at 02:24:01PM -0700, Andrew Morton wrote:
> Rik van Riel <riel@redhat.com> wrote:
> >
> > Andrew, could you please apply Chris's patch in addition
> > to mine ?
>
> OK, but I don't have any confidence that anyone will be testing it.
>
> Can you think of some way in which we can artificially tweak the patch
> for testing so that its new features are getting some exercise?
gpg uses mlock (well it tries to) which is why the fedora patch has a 4Kb
default ;)
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mlock-as-user for 2.6.8-rc2-mm2
2004-08-04 21:22 ` Arjan van de Ven
@ 2004-08-04 21:28 ` Rik van Riel
2004-08-04 21:45 ` Chris Wright
0 siblings, 1 reply; 7+ messages in thread
From: Rik van Riel @ 2004-08-04 21:28 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Andrew Morton, chrisw, linux-kernel
On Wed, 4 Aug 2004, Arjan van de Ven wrote:
> On Wed, Aug 04, 2004 at 02:24:01PM -0700, Andrew Morton wrote:
> > Can you think of some way in which we can artificially tweak the patch
> > for testing so that its new features are getting some exercise?
>
> gpg uses mlock (well it tries to) which is why the fedora patch has a
> 4Kb default ;)
I guess we need to figure out how much memory gpg mlocks by
default (16kB?) and set the default rlimit to that. Then
every gpg user out there will automatically test the code ;)
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mlock-as-user for 2.6.8-rc2-mm2
2004-08-04 21:28 ` Rik van Riel
@ 2004-08-04 21:45 ` Chris Wright
0 siblings, 0 replies; 7+ messages in thread
From: Chris Wright @ 2004-08-04 21:45 UTC (permalink / raw)
To: Rik van Riel; +Cc: Arjan van de Ven, Andrew Morton, chrisw, linux-kernel
* Rik van Riel (riel@redhat.com) wrote:
> On Wed, 4 Aug 2004, Arjan van de Ven wrote:
> > On Wed, Aug 04, 2004 at 02:24:01PM -0700, Andrew Morton wrote:
>
> > > Can you think of some way in which we can artificially tweak the patch
> > > for testing so that its new features are getting some exercise?
> >
> > gpg uses mlock (well it tries to) which is why the fedora patch has a
> > 4Kb default ;)
>
> I guess we need to figure out how much memory gpg mlocks by
> default (16kB?) and set the default rlimit to that. Then
> every gpg user out there will automatically test the code ;)
Last time I checked it wants 8 pages (32k).
thanks,
-chris
--
Linux Security Modules http://lsm.immunix.org http://lsm.bkbits.net
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-08-04 21:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-04 17:55 [PATCH] mlock-as-user for 2.6.8-rc2-mm2 Rik van Riel
2004-08-04 21:01 ` Chris Wright
2004-08-04 21:06 ` Rik van Riel
2004-08-04 21:24 ` Andrew Morton
2004-08-04 21:22 ` Arjan van de Ven
2004-08-04 21:28 ` Rik van Riel
2004-08-04 21:45 ` Chris Wright
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.