drivers/IB,qib: Fix pinned/locked limit check in qib_get_user_pages()
authorDavidlohr Bueso <dave@stgolabs.net>
Sat, 16 Feb 2019 12:15:52 +0000 (04:15 -0800)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 20 Feb 2019 21:42:41 +0000 (14:42 -0700)
The current check does not take into account the previous value of
pinned_vm; thus it is quite bogus as is. Fix this by checking the
new value after the (optimistic) atomic inc.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/qib/qib_user_pages.c

index ef8bcf3..123ca8f 100644 (file)
@@ -107,7 +107,7 @@ int qib_get_user_pages(unsigned long start_page, size_t num_pages,
        lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
        locked = atomic64_add_return(num_pages, &current->mm->pinned_vm);
 
-       if (num_pages > lock_limit && !capable(CAP_IPC_LOCK)) {
+       if (locked > lock_limit && !capable(CAP_IPC_LOCK)) {
                ret = -ENOMEM;
                goto bail;
        }