The patch titled Subject: mm-add-account_locked_vm-utility-function-v3 has been added to the -mm tree. Its filename is mm-add-account_locked_vm-utility-function-v3.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-add-account_locked_vm-utility-function-v3.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-add-account_locked_vm-utility-function-v3.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Daniel Jordan <daniel.m.jordan@xxxxxxxxxx> Subject: mm-add-account_locked_vm-utility-function-v3 - uninline account_locked_vm (Andrew) - fix doc comment (Ira) - retain down_write_killable in vfio type1 (Alex) - leave Alexey's T-b since the code is the same aside from uninlining - sanity tested with vfio type1, sanity-built on ppc Link: http://lkml.kernel.org/r/20190529205019.20927-1-daniel.m.jordan@xxxxxxxxxx Signed-off-by: Daniel Jordan <daniel.m.jordan@xxxxxxxxxx> Tested-by: Alexey Kardashevskiy <aik@xxxxxxxxx> Cc: Alan Tull <atull@xxxxxxxxxx> Cc: Alex Williamson <alex.williamson@xxxxxxxxxx> Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: Christophe Leroy <christophe.leroy@xxxxxx> Cc: Davidlohr Bueso <dave@xxxxxxxxxxxx> Cc: Ira Weiny <ira.weiny@xxxxxxxxx> Cc: Jason Gunthorpe <jgg@xxxxxxxxxxxx> Cc: Mark Rutland <mark.rutland@xxxxxxx> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx> Cc: Moritz Fischer <mdf@xxxxxxxxxx> Cc: Paul Mackerras <paulus@xxxxxxxxxx> Cc: Steve Sistare <steven.sistare@xxxxxxxxxx> Cc: Wu Hao <hao.wu@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/mm.h | 17 +---------------- mm/util.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 18 deletions(-) --- a/include/linux/mm.h~mm-add-account_locked_vm-utility-function-v3 +++ a/include/linux/mm.h @@ -1564,25 +1564,10 @@ long get_user_pages_unlocked(unsigned lo int get_user_pages_fast(unsigned long start, int nr_pages, unsigned int gup_flags, struct page **pages); +int account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc); int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, struct task_struct *task, bool bypass_rlim); -static inline int account_locked_vm(struct mm_struct *mm, unsigned long pages, - bool inc) -{ - int ret; - - if (pages == 0 || !mm) - return 0; - - down_write(&mm->mmap_sem); - ret = __account_locked_vm(mm, pages, inc, current, - capable(CAP_IPC_LOCK)); - up_write(&mm->mmap_sem); - - return ret; -} - /* Container for pinned pfns / pages */ struct frame_vector { unsigned int nr_allocated; /* Number of frames we have space for */ --- a/mm/util.c~mm-add-account_locked_vm-utility-function-v3 +++ a/mm/util.c @@ -350,7 +350,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast); /** * __account_locked_vm - account locked pages to an mm's locked_vm - * @mm: mm to account against, may be NULL + * @mm: mm to account against * @pages: number of pages to account * @inc: %true if @pages should be considered positive, %false if not * @task: task used to check RLIMIT_MEMLOCK @@ -361,7 +361,6 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast); * * Return: * * 0 on success - * * 0 if @mm is NULL (can happen for example if the task is exiting) * * -ENOMEM if RLIMIT_MEMLOCK would be exceeded. */ int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, @@ -370,6 +369,8 @@ int __account_locked_vm(struct mm_struct unsigned long locked_vm, limit; int ret = 0; + lockdep_assert_held_exclusive(&mm->mmap_sem); + locked_vm = mm->locked_vm; if (inc) { if (!bypass_rlim) { @@ -393,6 +394,34 @@ int __account_locked_vm(struct mm_struct } EXPORT_SYMBOL_GPL(__account_locked_vm); +/** + * account_locked_vm - account locked pages to an mm's locked_vm + * @mm: mm to account against, may be NULL + * @pages: number of pages to account + * @inc: %true if @pages should be considered positive, %false if not + * + * Assumes a non-NULL @mm is valid (i.e. at least one reference on it). + * + * Return: + * * 0 on success, or if mm is NULL + * * -ENOMEM if RLIMIT_MEMLOCK would be exceeded. + */ +int account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc) +{ + int ret; + + if (pages == 0 || !mm) + return 0; + + down_write(&mm->mmap_sem); + ret = __account_locked_vm(mm, pages, inc, current, + capable(CAP_IPC_LOCK)); + up_write(&mm->mmap_sem); + + return ret; +} +EXPORT_SYMBOL_GPL(account_locked_vm); + unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flag, unsigned long pgoff) _ Patches currently in -mm which might be from daniel.m.jordan@xxxxxxxxxx are mm-add-account_locked_vm-utility-function.patch mm-add-account_locked_vm-utility-function-v3.patch