mirror of
https://github.com/team-infusion-developers/android_kernel_samsung_msm8976.git
synced 2024-11-01 02:21:16 +00:00
mm/mmap.c: add mlock_future_check() helper
Both do_brk and do_mmap_pgoff verify that we are actually capable of locking future pages if the corresponding VM_LOCKED flags are used. Encapsulate this logic into a single mlock_future_check() helper function. Signed-off-by: Davidlohr Bueso <davidlohr@hp.com> Cc: Rik van Riel <riel@redhat.com> Reviewed-by: Michel Lespinasse <walken@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
1f4fe1597a
commit
a90ae42ef5
1 changed files with 23 additions and 22 deletions
45
mm/mmap.c
45
mm/mmap.c
|
@ -1226,6 +1226,24 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
|
||||||
return hint;
|
return hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int mlock_future_check(struct mm_struct *mm,
|
||||||
|
unsigned long flags,
|
||||||
|
unsigned long len)
|
||||||
|
{
|
||||||
|
unsigned long locked, lock_limit;
|
||||||
|
|
||||||
|
/* mlock MCL_FUTURE? */
|
||||||
|
if (flags & VM_LOCKED) {
|
||||||
|
locked = len >> PAGE_SHIFT;
|
||||||
|
locked += mm->locked_vm;
|
||||||
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
||||||
|
lock_limit >>= PAGE_SHIFT;
|
||||||
|
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline u64 file_mmap_size_max(struct file *file, struct inode *inode)
|
static inline u64 file_mmap_size_max(struct file *file, struct inode *inode)
|
||||||
{
|
{
|
||||||
if (S_ISREG(inode->i_mode))
|
if (S_ISREG(inode->i_mode))
|
||||||
|
@ -1316,16 +1334,8 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
|
||||||
if (!can_do_mlock())
|
if (!can_do_mlock())
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
/* mlock MCL_FUTURE? */
|
if (mlock_future_check(mm, vm_flags, len))
|
||||||
if (vm_flags & VM_LOCKED) {
|
return -EAGAIN;
|
||||||
unsigned long locked, lock_limit;
|
|
||||||
locked = len >> PAGE_SHIFT;
|
|
||||||
locked += mm->locked_vm;
|
|
||||||
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
|
||||||
lock_limit >>= PAGE_SHIFT;
|
|
||||||
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
|
||||||
return -EAGAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
struct inode *inode = file_inode(file);
|
struct inode *inode = file_inode(file);
|
||||||
|
@ -2693,18 +2703,9 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
|
||||||
if (error & ~PAGE_MASK)
|
if (error & ~PAGE_MASK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
/*
|
error = mlock_future_check(mm, mm->def_flags, len);
|
||||||
* mlock MCL_FUTURE?
|
if (error)
|
||||||
*/
|
return error;
|
||||||
if (mm->def_flags & VM_LOCKED) {
|
|
||||||
unsigned long locked, lock_limit;
|
|
||||||
locked = len >> PAGE_SHIFT;
|
|
||||||
locked += mm->locked_vm;
|
|
||||||
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
|
||||||
lock_limit >>= PAGE_SHIFT;
|
|
||||||
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
|
||||||
return -EAGAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mm->mmap_sem is required to protect against another thread
|
* mm->mmap_sem is required to protect against another thread
|
||||||
|
|
Loading…
Reference in a new issue