From patchwork Wed Feb 6 17:59:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10799791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCB62746 for ; Wed, 6 Feb 2019 18:00:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD43B2C60F for ; Wed, 6 Feb 2019 18:00:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EA592CAA1; Wed, 6 Feb 2019 18:00:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B2352BC7C for ; Wed, 6 Feb 2019 18:00:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECDB38E00E1; Wed, 6 Feb 2019 13:00:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E87948E00D1; Wed, 6 Feb 2019 13:00:03 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF4928E00E1; Wed, 6 Feb 2019 13:00:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 849E18E00D1 for ; Wed, 6 Feb 2019 13:00:03 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id g9so5773851pfe.7 for ; Wed, 06 Feb 2019 10:00:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=RXBW1DWRMZIUr9A+lZvRZCrW1Nuhf8GWt3nfO6WGsWI=; b=i6FXQuPxio9XUQ+l4+HkBZ0OVhpoTzOdQq/qUXJD6LOvVcnXyCWeuKZnKzEHHe1XPw nX27IgQbwrTI5NAciuFY3K54BeK81+KZ8TvXmU3XhJ9h03CDCtbJ8dKOivpX/sRyf0gk kxxAMkYf02jr3dyE63vbyCBCJ8RQ0atJGEBt04WyrCmNxIjpeYfL8oOstJzJV0x/2Lra fRcy/zZizXyNdeEpJd41X0j1px7+9FgoAKD4H74I6h0/3o2URW9/3UXxR8NViusIXI/A Am6LownGpO270Pw+yR2Ewi0hIkaXLGR+EDmpRHFTol43Nl6SAhSDzcselFeV3EZ1W6R3 82Og== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Gm-Message-State: AHQUAuac43i0auNY7AvwtZ2qXil9xzY7Z9tKtxBfrx5zzpd/NYiBrzT3 uJ4elmeTUUt22OzXw2aKrwI6IXqkeW5BHSpkJuTIC/4LgjpBDSb/41yKJ/OBljaZRpW+rwiYK2/ JcjJ2tENJq8n13MnBcpVnv5NdXVn/H3Osd/7/JOyhRqA4tv4sKx+LXd1tNRbVMVk= X-Received: by 2002:a63:1647:: with SMTP id 7mr2356283pgw.53.1549476003135; Wed, 06 Feb 2019 10:00:03 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibhn9RnYtIk4ICcVROnzI5SPW3uPCuIZusdRcqYmYYx+2+lyl2d/bDuqKwOW8ClUYU4qUd1 X-Received: by 2002:a63:1647:: with SMTP id 7mr2356157pgw.53.1549476001247; Wed, 06 Feb 2019 10:00:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476001; cv=none; d=google.com; s=arc-20160816; b=bYqaUlzout1a83b4PE9WLzwdZL6jScdhP9iPQa6dObCEE8AsVbi5uehv2inKI6ow+E FF34mKNMLIZUKe1nfZgeq0+E4ZsAjEkgGTTV7+iZO+C+FhcjaqBKo87ceIJqLkuzoo/5 ekyom3wr8LVC9RAaVnQRYqyGxWku2u1sZtvhOXMb/iOdb3PbHhikwpthaGtw9waIppno uyiaIqiYGIrchJe15CY0u7rRt3qXpRQEKDb9cXIgka3Lk12McPnvIo3B9nlhy7+azpYo PKA/r+VrYdLzu2x2aK5ucuCZNl5ypPhp/j+HaM+hna6lzb+LdtJSKw0IeHYOOsFDsRf+ rtmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=RXBW1DWRMZIUr9A+lZvRZCrW1Nuhf8GWt3nfO6WGsWI=; b=d4e4suKcLU1I3q4JJfiUk2eOGG6F73vAdiEnpvGUUmX75T0ldlZbzxVJSrzJjWRWqB Pc7ClrvMHZNYUxxxcY2Lp00qOblkxscJAcgVpvJDOrkqQvaMCglLt5QYKLfkUVzQpVVc bA1AcDTUGpUdP7d0sxncCGckr/hMFI0Vn9XacEUGdVFNTxERPiv4QNiKd6x+OfUTUzCD Y/e82MXl2nOv+9rU9acbegOimpLj9F1vz8YTa2muG5yAlHEhSZDuhpA8FSe2Ea9v6LME Rm9eaeluVk8oMzkM8BpiGkfm2jm9KF4xZDIKrZX9hFRy8w/kky6yD+5y793EpiyLIe0Y NlZw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id p11si6350101plk.191.2019.02.06.10.00.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 10:00:01 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 18:59:58 +0100 Received: from linux-r8p5.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 17:59:38 +0000 From: Davidlohr Bueso To: jgg@ziepe.ca, akpm@linux-foundation.org Cc: dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, Davidlohr Bueso Subject: [PATCH 1/6] mm: make mm->pinned_vm an atomic64 counter Date: Wed, 6 Feb 2019 09:59:15 -0800 Message-Id: <20190206175920.31082-2-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190206175920.31082-1-dave@stgolabs.net> References: <20190206175920.31082-1-dave@stgolabs.net> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Taking a sleeping lock to _only_ increment a variable is quite the overkill, and pretty much all users do this. Furthermore, some drivers (ie: infiniband and scif) that need pinned semantics can go to quite some trouble to actually delay via workqueue (un)accounting for pinned pages when not possible to acquire it. By making the counter atomic we no longer need to hold the mmap_sem and can simply some code around it for pinned_vm users. The counter is 64-bit such that we need not worry about overflows such as rdma user input controlled from userspace. Reviewed-by: Ira Weiny Reviewed-by: Christoph Lameter Reviewed-by: Daniel Jordan Reviewed-by: Jan Kara Signed-off-by: Davidlohr Bueso --- drivers/infiniband/core/umem.c | 12 ++++++------ drivers/infiniband/hw/hfi1/user_pages.c | 6 +++--- drivers/infiniband/hw/qib/qib_user_pages.c | 4 ++-- drivers/infiniband/hw/usnic/usnic_uiom.c | 8 ++++---- drivers/misc/mic/scif/scif_rma.c | 6 +++--- fs/proc/task_mmu.c | 2 +- include/linux/mm_types.h | 2 +- kernel/events/core.c | 8 ++++---- kernel/fork.c | 2 +- mm/debug.c | 5 +++-- 10 files changed, 28 insertions(+), 27 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 1efe0a74e06b..678abe1afcba 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -166,13 +166,13 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; down_write(&mm->mmap_sem); - if (check_add_overflow(mm->pinned_vm, npages, &new_pinned) || - (new_pinned > lock_limit && !capable(CAP_IPC_LOCK))) { + new_pinned = atomic64_read(&mm->pinned_vm) + npages; + if (new_pinned > lock_limit && !capable(CAP_IPC_LOCK)) { up_write(&mm->mmap_sem); ret = -ENOMEM; goto out; } - mm->pinned_vm = new_pinned; + atomic64_set(&mm->pinned_vm, new_pinned); up_write(&mm->mmap_sem); cur_base = addr & PAGE_MASK; @@ -234,7 +234,7 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, __ib_umem_release(context->device, umem, 0); vma: down_write(&mm->mmap_sem); - mm->pinned_vm -= ib_umem_num_pages(umem); + atomic64_sub(ib_umem_num_pages(umem), &mm->pinned_vm); up_write(&mm->mmap_sem); out: if (vma_list) @@ -263,7 +263,7 @@ static void ib_umem_release_defer(struct work_struct *work) struct ib_umem *umem = container_of(work, struct ib_umem, work); down_write(&umem->owning_mm->mmap_sem); - umem->owning_mm->pinned_vm -= ib_umem_num_pages(umem); + atomic64_sub(ib_umem_num_pages(umem), &umem->owning_mm->pinned_vm); up_write(&umem->owning_mm->mmap_sem); __ib_umem_release_tail(umem); @@ -302,7 +302,7 @@ void ib_umem_release(struct ib_umem *umem) } else { down_write(&umem->owning_mm->mmap_sem); } - umem->owning_mm->pinned_vm -= ib_umem_num_pages(umem); + atomic64_sub(ib_umem_num_pages(umem), &umem->owning_mm->pinned_vm); up_write(&umem->owning_mm->mmap_sem); __ib_umem_release_tail(umem); diff --git a/drivers/infiniband/hw/hfi1/user_pages.c b/drivers/infiniband/hw/hfi1/user_pages.c index e341e6dcc388..40a6e434190f 100644 --- a/drivers/infiniband/hw/hfi1/user_pages.c +++ b/drivers/infiniband/hw/hfi1/user_pages.c @@ -92,7 +92,7 @@ bool hfi1_can_pin_pages(struct hfi1_devdata *dd, struct mm_struct *mm, size = DIV_ROUND_UP(size, PAGE_SIZE); down_read(&mm->mmap_sem); - pinned = mm->pinned_vm; + pinned = atomic64_read(&mm->pinned_vm); up_read(&mm->mmap_sem); /* First, check the absolute limit against all pinned pages. */ @@ -112,7 +112,7 @@ int hfi1_acquire_user_pages(struct mm_struct *mm, unsigned long vaddr, size_t np return ret; down_write(&mm->mmap_sem); - mm->pinned_vm += ret; + atomic64_add(ret, &mm->pinned_vm); up_write(&mm->mmap_sem); return ret; @@ -131,7 +131,7 @@ void hfi1_release_user_pages(struct mm_struct *mm, struct page **p, if (mm) { /* during close after signal, mm can be NULL */ down_write(&mm->mmap_sem); - mm->pinned_vm -= npages; + atomic64_sub(npages, &mm->pinned_vm); up_write(&mm->mmap_sem); } } diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c b/drivers/infiniband/hw/qib/qib_user_pages.c index 075f09fb7ce3..c6c81022d313 100644 --- a/drivers/infiniband/hw/qib/qib_user_pages.c +++ b/drivers/infiniband/hw/qib/qib_user_pages.c @@ -75,7 +75,7 @@ static int __qib_get_user_pages(unsigned long start_page, size_t num_pages, goto bail_release; } - current->mm->pinned_vm += num_pages; + atomic64_add(num_pages, ¤t->mm->pinned_vm); ret = 0; goto bail; @@ -156,7 +156,7 @@ void qib_release_user_pages(struct page **p, size_t num_pages) __qib_release_user_pages(p, num_pages, 1); if (current->mm) { - current->mm->pinned_vm -= num_pages; + atomic64_sub(num_pages, ¤t->mm->pinned_vm); up_write(¤t->mm->mmap_sem); } } diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c index ce01a59fccc4..854436a2b437 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.c +++ b/drivers/infiniband/hw/usnic/usnic_uiom.c @@ -129,7 +129,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, uiomr->owning_mm = mm = current->mm; down_write(&mm->mmap_sem); - locked = npages + current->mm->pinned_vm; + locked = npages + atomic64_read(¤t->mm->pinned_vm); lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) { @@ -187,7 +187,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, if (ret < 0) usnic_uiom_put_pages(chunk_list, 0); else { - mm->pinned_vm = locked; + atomic64_set(&mm->pinned_vm, locked); mmgrab(uiomr->owning_mm); } @@ -441,7 +441,7 @@ static void usnic_uiom_release_defer(struct work_struct *work) container_of(work, struct usnic_uiom_reg, work); down_write(&uiomr->owning_mm->mmap_sem); - uiomr->owning_mm->pinned_vm -= usnic_uiom_num_pages(uiomr); + atomic64_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm); up_write(&uiomr->owning_mm->mmap_sem); __usnic_uiom_release_tail(uiomr); @@ -469,7 +469,7 @@ void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr, } else { down_write(&uiomr->owning_mm->mmap_sem); } - uiomr->owning_mm->pinned_vm -= usnic_uiom_num_pages(uiomr); + atomic64_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm); up_write(&uiomr->owning_mm->mmap_sem); __usnic_uiom_release_tail(uiomr); diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c index 749321eb91ae..2448368f181e 100644 --- a/drivers/misc/mic/scif/scif_rma.c +++ b/drivers/misc/mic/scif/scif_rma.c @@ -285,7 +285,7 @@ __scif_dec_pinned_vm_lock(struct mm_struct *mm, } else { down_write(&mm->mmap_sem); } - mm->pinned_vm -= nr_pages; + atomic64_sub(nr_pages, &mm->pinned_vm); up_write(&mm->mmap_sem); return 0; } @@ -299,7 +299,7 @@ static inline int __scif_check_inc_pinned_vm(struct mm_struct *mm, return 0; locked = nr_pages; - locked += mm->pinned_vm; + locked += atomic64_read(&mm->pinned_vm); lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) { dev_err(scif_info.mdev.this_device, @@ -307,7 +307,7 @@ static inline int __scif_check_inc_pinned_vm(struct mm_struct *mm, locked, lock_limit); return -ENOMEM; } - mm->pinned_vm = locked; + atomic64_set(&mm->pinned_vm, locked); return 0; } diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f0ec9edab2f3..d2902962244d 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -59,7 +59,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm) SEQ_PUT_DEC("VmPeak:\t", hiwater_vm); SEQ_PUT_DEC(" kB\nVmSize:\t", total_vm); SEQ_PUT_DEC(" kB\nVmLck:\t", mm->locked_vm); - SEQ_PUT_DEC(" kB\nVmPin:\t", mm->pinned_vm); + SEQ_PUT_DEC(" kB\nVmPin:\t", atomic64_read(&mm->pinned_vm)); SEQ_PUT_DEC(" kB\nVmHWM:\t", hiwater_rss); SEQ_PUT_DEC(" kB\nVmRSS:\t", total_rss); SEQ_PUT_DEC(" kB\nRssAnon:\t", anon); diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 2c471a2c43fa..acea2ea2d6c4 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -405,7 +405,7 @@ struct mm_struct { unsigned long total_vm; /* Total pages mapped */ unsigned long locked_vm; /* Pages that have PG_mlocked set */ - unsigned long pinned_vm; /* Refcount permanently increased */ + atomic64_t pinned_vm; /* Refcount permanently increased */ unsigned long data_vm; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */ unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */ unsigned long stack_vm; /* VM_STACK */ diff --git a/kernel/events/core.c b/kernel/events/core.c index 3cd13a30f732..8df0b77a4687 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5459,7 +5459,7 @@ static void perf_mmap_close(struct vm_area_struct *vma) /* now it's safe to free the pages */ atomic_long_sub(rb->aux_nr_pages, &mmap_user->locked_vm); - vma->vm_mm->pinned_vm -= rb->aux_mmap_locked; + atomic64_sub(rb->aux_mmap_locked, &vma->vm_mm->pinned_vm); /* this has to be the last one */ rb_free_aux(rb); @@ -5532,7 +5532,7 @@ static void perf_mmap_close(struct vm_area_struct *vma) */ atomic_long_sub((size >> PAGE_SHIFT) + 1, &mmap_user->locked_vm); - vma->vm_mm->pinned_vm -= mmap_locked; + atomic64_sub(mmap_locked, &vma->vm_mm->pinned_vm); free_uid(mmap_user); out_put: @@ -5680,7 +5680,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) lock_limit = rlimit(RLIMIT_MEMLOCK); lock_limit >>= PAGE_SHIFT; - locked = vma->vm_mm->pinned_vm + extra; + locked = atomic64_read(&vma->vm_mm->pinned_vm) + extra; if ((locked > lock_limit) && perf_paranoid_tracepoint_raw() && !capable(CAP_IPC_LOCK)) { @@ -5721,7 +5721,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) unlock: if (!ret) { atomic_long_add(user_extra, &user->locked_vm); - vma->vm_mm->pinned_vm += extra; + atomic64_add(extra, &vma->vm_mm->pinned_vm); atomic_inc(&event->mmap_count); } else if (rb) { diff --git a/kernel/fork.c b/kernel/fork.c index a60459947f18..fe4a051a8d15 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -980,7 +980,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, mm_pgtables_bytes_init(mm); mm->map_count = 0; mm->locked_vm = 0; - mm->pinned_vm = 0; + atomic64_set(&mm->pinned_vm, 0); memset(&mm->rss_stat, 0, sizeof(mm->rss_stat)); spin_lock_init(&mm->page_table_lock); spin_lock_init(&mm->arg_lock); diff --git a/mm/debug.c b/mm/debug.c index 0abb987dad9b..7d13941a72f9 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -135,7 +135,7 @@ void dump_mm(const struct mm_struct *mm) "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n" "pgd %px mm_users %d mm_count %d pgtables_bytes %lu map_count %d\n" "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n" - "pinned_vm %lx data_vm %lx exec_vm %lx stack_vm %lx\n" + "pinned_vm %llx data_vm %lx exec_vm %lx stack_vm %lx\n" "start_code %lx end_code %lx start_data %lx end_data %lx\n" "start_brk %lx brk %lx start_stack %lx\n" "arg_start %lx arg_end %lx env_start %lx env_end %lx\n" @@ -166,7 +166,8 @@ void dump_mm(const struct mm_struct *mm) mm_pgtables_bytes(mm), mm->map_count, mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm, - mm->pinned_vm, mm->data_vm, mm->exec_vm, mm->stack_vm, + atomic64_read(&mm->pinned_vm), + mm->data_vm, mm->exec_vm, mm->stack_vm, mm->start_code, mm->end_code, mm->start_data, mm->end_data, mm->start_brk, mm->brk, mm->start_stack, mm->arg_start, mm->arg_end, mm->env_start, mm->env_end, From patchwork Wed Feb 6 17:59:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10799793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0AE98746 for ; Wed, 6 Feb 2019 18:00:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3D032CC2A for ; Wed, 6 Feb 2019 18:00:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1CEE2CC32; Wed, 6 Feb 2019 18:00:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76E182CC2A for ; Wed, 6 Feb 2019 18:00:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 160018E00E2; Wed, 6 Feb 2019 13:00:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 111BA8E00D1; Wed, 6 Feb 2019 13:00:05 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECEB38E00E2; Wed, 6 Feb 2019 13:00:04 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id A97938E00D1 for ; Wed, 6 Feb 2019 13:00:04 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id y8so5117985pgq.12 for ; Wed, 06 Feb 2019 10:00:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=0n7fg0iJYctopHXS8YxQYYdUHYinmEBkqLo15ZLF1mI=; b=MFUTXTPiON6SQl8aHag+3m1N8WITK4p+wzvAPOCXjak1uVOIeuWiJ//ZwqthkZKmgW ssuxOkgxGph4VeQ9z7p1PZpzRTEvyMXRSnpljIKeAWuBN39hHuHR2QU+rKp5yB6brR57 OOkiPEfSQB8Mjlo0KP3Q/BWYvZf9EeJCKrQEBLq7z0dJQbGnnP44wSUPv7z5127aAXWx UlUDP0CgJkr32yZekUKSCSwAWJ6jYcXFZ09cKTQRVvGv8rNCCPg8DVTt9pXpcarQmDcU 3+DrCx7qf/SocXHJuawjRUtOhfACqcqhKZ3PxxztFPgxKY0iwZK9DSu4rg5qHU+IXuqy Ig+g== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Gm-Message-State: AHQUAuYd9IL8bINr1ngQrCl9Stqowjp6Dw0ojsL3aDzcKxw6uvDUE75R 0pc7lqFfCGQooTlXKVdpwz/TAZePLWOXvSiKM1UDxASShJic4ZzBL434RuEILLD5TRcZQu5oF8r TuRnimqp5NrFWNr7+L01CkHY7I292Bvhd4MokY0TZjLwBCxYBHWxTmIouoOdT97g= X-Received: by 2002:a17:902:9687:: with SMTP id n7mr11644971plp.94.1549476004319; Wed, 06 Feb 2019 10:00:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IarUuMPHOIEVIhQ4zMdp6cpoWN2BW+F4qruxiKRCnykNmqrgc0vfqcKb+RPgJF8tHsLaUZN X-Received: by 2002:a17:902:9687:: with SMTP id n7mr11644879plp.94.1549476003120; Wed, 06 Feb 2019 10:00:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476003; cv=none; d=google.com; s=arc-20160816; b=lAyppG5iEfekU1CAGzgvko4YhkZPQazgaSiKW7J2Bo9aWBD60sZTU/xaJGq9Oq7dv8 P07w1U1dS84NkSlvP8Od6bt0K6wchvIxrhs7XI1AkEL0KRoanOmHC6KGpjOpFl25ywFp ymEbGOYNZ0W712/I9c9M1h1ue3ShpHYfV6/TP4G/t3ws7w/paPI1ciBMx0szJvC9pMQ1 iBZsNBxkzo/s3F4JqV5w1rdQSZQCd3FXhIowppCdTiyIhGs1XB1ahRjK5iPV5jTnMocK 3lZmQOZn2HwpjD4DtvCLUwKoKMB5QbSLvO/UFo/ZVUDv1YjyIIpZEVizWWOmcbW26vA8 bdKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=0n7fg0iJYctopHXS8YxQYYdUHYinmEBkqLo15ZLF1mI=; b=RyCxvoYc/GrKNaYz1v/FxgnI4jMhMbZ0C38o28bgjl98vTYb6o/d28g28q618RgB9n rRx+7qjdc7tTo7ILJZXOFIVozFkzkpMKgFTrzsra8im+UM3kRdTv4lWtQEE/LQZibQWO kVSJHxQTSIj1Yv1sTR8XWhoJhYa1VGC3CigvRZwYaDHgStwjykqLG3zTC32msRXZ//ld mQIE8GjcwIFlBKBQlb8We2d+ihD6TE0V8GviOqHnDqEJ1Uzjl2TmU5DJQVVEvt5Nwoyw zvq4A4bsUG4aDFtlWWVLgxKcyxVMiSYoVOuPphQSSRLhoVvIdZE1VnppFcsjci8AQGqy kkVg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id cb16si2468902plb.290.2019.02.06.10.00.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 10:00:03 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 19:00:00 +0100 Received: from linux-r8p5.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 17:59:41 +0000 From: Davidlohr Bueso To: jgg@ziepe.ca, akpm@linux-foundation.org Cc: dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, sudeep.dutt@intel.com, ashutosh.dixit@intel.com, Davidlohr Bueso Subject: [PATCH 2/6] drivers/mic/scif: do not use mmap_sem Date: Wed, 6 Feb 2019 09:59:16 -0800 Message-Id: <20190206175920.31082-3-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190206175920.31082-1-dave@stgolabs.net> References: <20190206175920.31082-1-dave@stgolabs.net> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The driver uses mmap_sem for both pinned_vm accounting and get_user_pages(). By using gup_fast() and letting the mm handle the lock if needed, we can no longer rely on the semaphore and simplify the whole thing. Cc: sudeep.dutt@intel.com Cc: ashutosh.dixit@intel.com Reviewed-by: Ira Weiny Signed-off-by: Davidlohr Bueso --- drivers/misc/mic/scif/scif_rma.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c index 2448368f181e..263b8ad507ea 100644 --- a/drivers/misc/mic/scif/scif_rma.c +++ b/drivers/misc/mic/scif/scif_rma.c @@ -272,21 +272,12 @@ static inline void __scif_release_mm(struct mm_struct *mm) static inline int __scif_dec_pinned_vm_lock(struct mm_struct *mm, - int nr_pages, bool try_lock) + int nr_pages) { if (!mm || !nr_pages || !scif_ulimit_check) return 0; - if (try_lock) { - if (!down_write_trylock(&mm->mmap_sem)) { - dev_err(scif_info.mdev.this_device, - "%s %d err\n", __func__, __LINE__); - return -1; - } - } else { - down_write(&mm->mmap_sem); - } + atomic64_sub(nr_pages, &mm->pinned_vm); - up_write(&mm->mmap_sem); return 0; } @@ -298,16 +289,16 @@ static inline int __scif_check_inc_pinned_vm(struct mm_struct *mm, if (!mm || !nr_pages || !scif_ulimit_check) return 0; - locked = nr_pages; - locked += atomic64_read(&mm->pinned_vm); lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; + locked = atomic64_add_return(nr_pages, &mm->pinned_vm); + if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) { + atomic64_sub(nr_pages, &mm->pinned_vm); dev_err(scif_info.mdev.this_device, "locked(%lu) > lock_limit(%lu)\n", locked, lock_limit); return -ENOMEM; } - atomic64_set(&mm->pinned_vm, locked); return 0; } @@ -326,7 +317,7 @@ int scif_destroy_window(struct scif_endpt *ep, struct scif_window *window) might_sleep(); if (!window->temp && window->mm) { - __scif_dec_pinned_vm_lock(window->mm, window->nr_pages, 0); + __scif_dec_pinned_vm_lock(window->mm, window->nr_pages); __scif_release_mm(window->mm); window->mm = NULL; } @@ -737,7 +728,7 @@ int scif_unregister_window(struct scif_window *window) ep->rma_info.dma_chan); } else { if (!__scif_dec_pinned_vm_lock(window->mm, - window->nr_pages, 1)) { + window->nr_pages)) { __scif_release_mm(window->mm); window->mm = NULL; } @@ -1385,28 +1376,23 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot, prot |= SCIF_PROT_WRITE; retry: mm = current->mm; - down_write(&mm->mmap_sem); if (ulimit) { err = __scif_check_inc_pinned_vm(mm, nr_pages); if (err) { - up_write(&mm->mmap_sem); pinned_pages->nr_pages = 0; goto error_unmap; } } - pinned_pages->nr_pages = get_user_pages( + pinned_pages->nr_pages = get_user_pages_fast( (u64)addr, nr_pages, (prot & SCIF_PROT_WRITE) ? FOLL_WRITE : 0, - pinned_pages->pages, - NULL); - up_write(&mm->mmap_sem); + pinned_pages->pages); if (nr_pages != pinned_pages->nr_pages) { if (try_upgrade) { if (ulimit) - __scif_dec_pinned_vm_lock(mm, - nr_pages, 0); + __scif_dec_pinned_vm_lock(mm, nr_pages); /* Roll back any pinned pages */ for (i = 0; i < pinned_pages->nr_pages; i++) { if (pinned_pages->pages[i]) @@ -1433,7 +1419,7 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot, return err; dec_pinned: if (ulimit) - __scif_dec_pinned_vm_lock(mm, nr_pages, 0); + __scif_dec_pinned_vm_lock(mm, nr_pages); /* Something went wrong! Rollback */ error_unmap: pinned_pages->nr_pages = nr_pages; From patchwork Wed Feb 6 17:59:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10799795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 906E51390 for ; Wed, 6 Feb 2019 18:00:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 810572CC2B for ; Wed, 6 Feb 2019 18:00:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ED3C2CC41; Wed, 6 Feb 2019 18:00:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F37E52CD90 for ; Wed, 6 Feb 2019 18:00:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57FFB8E00DF; Wed, 6 Feb 2019 13:00:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 504BD8E00D1; Wed, 6 Feb 2019 13:00:06 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 385928E00DF; Wed, 6 Feb 2019 13:00:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id DB7588E00D1 for ; Wed, 6 Feb 2019 13:00:05 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id f3so5123731pgq.13 for ; Wed, 06 Feb 2019 10:00:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=S/67tRKTlxOYP+sBkMKRSV2F+ob/jIFmPIustnrAhjE=; b=AX3ur8O1POIg9m4Q1CjXvfUz09VemIgsr3QzKY2xs0B5h4VrC5Z7uWqdPCua9ggofw 9vDKgVtu+k7b+cY0z6lr7H/aO2WCIUb4q7qiVrrbd4j3r4QTlpUikdUJUWDXkqe0Hpri NIFeZ4AqTHDVw3ANTbHeongTevOci8k08koq/JnalMnFuJ67Rz8QUPHHI2Wp2w8OQ6E1 tzXac8wXrgdrPMan9X3l85KjXhvdoTytuxLcORy9+obW4SOoMJptr8EbFg2sM+E7TcCa RM9a+qJLKdVaogvIPnhTQi/73qC0JmepKPGvOUKnYC8DbJc292FDXri3g6piNTL77Qw1 RfDQ== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Gm-Message-State: AHQUAuZM1OKFXqgSrtk0qPabXLy/dbSLdZ5K+YLzMNSavsmXo4oHsMJR rYgc/IryEnz443JEl0Lv+4apvleht4NTsKF/8rt2yOtQL2tnBg+NP3awyKekhe9pyokDfdq3f4g nhRy3VpHWDsn/oXbNN2oIvrSO+FW0n9at6Qex2HoX7dP1wVdR0aDEnNb3qtZCY3Y= X-Received: by 2002:aa7:8245:: with SMTP id e5mr2838401pfn.172.1549476005526; Wed, 06 Feb 2019 10:00:05 -0800 (PST) X-Google-Smtp-Source: AHgI3IZQ5VeiRRV4mB20kYFBTxkeRII4c9gv2PsW5igEV69LTci9Z4hDhz7G0ODD5hl/PBTwvo3g X-Received: by 2002:aa7:8245:: with SMTP id e5mr2838319pfn.172.1549476004412; Wed, 06 Feb 2019 10:00:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476004; cv=none; d=google.com; s=arc-20160816; b=ThTTjwXawhtg05YqseiAeoeZIPoxStmR/vIwlfn8Xma6DiApwoxVXLa4r4J8CMXUPB jWVsQz+yaAhgMwhnukcNRc5TuP0TijcG8C2zOTDS8wGasiPRarf0nBHajJysgtyafLqq 2GITyVlNHVNo5NeALEXIb8Mv+xBTNYqWtXrEEhnMTAkmM4DJfsnhlrpYmlkD0Io7Mwu8 vtjeGfU8FuLllAZ1k0WV3kVnxYFXqH2a6aAhDxk1hEYZBGx/52Qdtjh0aPWyBUp6kos+ BjLTZzKD2GhWXS2XMjjwKLAVvj+2sbcLlV7FBZ4MdfL+J/2GTz9c/lJNoUgCIlHqwIyY d31g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=S/67tRKTlxOYP+sBkMKRSV2F+ob/jIFmPIustnrAhjE=; b=h92dAcDcomElDHK4k2Ab/17Czn5ZvEr7XSd5AZI/MHv+bpQ2n4UL9rSelTQCLr5B+S qmbKI0OLWuIOtOCZZKOLC94mSCo8qblsXiAVCAuD6Y/e0+viR7e8758sSf5b19M083/U vkHwYWJDXT+CDBu6iSoxJE6I3VJ5nheMAQVAhj+Y3Oh2kdZklOw1vnxkG9PSMmhMb6VB +bhPMGrsQWENOGWEHRE7VJlTBHcuukU7DJZanlbCJfXgFfxYMh4g+mzZoH2oPAVABiil f9OlpMMU5Dku5bczSp7jKrC7PQiPjjVbJLWplbUvm6lsVb/UUmvQj3exvP9twnlHrYqr dNBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id j20si5479577pgb.520.2019.02.06.10.00.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 10:00:04 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 19:00:02 +0100 Received: from linux-r8p5.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 17:59:46 +0000 From: Davidlohr Bueso To: jgg@ziepe.ca, akpm@linux-foundation.org Cc: dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, dennis.dalessandro@intel.com, mike.marciniszyn@intel.com, Davidlohr Bueso Subject: [PATCH 3/6] drivers/IB,qib: optimize mmap_sem usage Date: Wed, 6 Feb 2019 09:59:17 -0800 Message-Id: <20190206175920.31082-4-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190206175920.31082-1-dave@stgolabs.net> References: <20190206175920.31082-1-dave@stgolabs.net> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The driver uses mmap_sem for both pinned_vm accounting and get_user_pages(). Because rdma drivers might want to use gup_longterm() in the future we still need some sort of mmap_sem serialization (as opposed to removing it entirely by using gup_fast()). Now that pinned_vm is atomic the writer lock can therefore be converted to reader. This also fixes a bug that __qib_get_user_pages was not taking into account the current value of pinned_vm. Cc: dennis.dalessandro@intel.com Cc: mike.marciniszyn@intel.com Reviewed-by: Ira Weiny Signed-off-by: Davidlohr Bueso --- drivers/infiniband/hw/qib/qib_user_pages.c | 73 +++++++++++------------------- 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c b/drivers/infiniband/hw/qib/qib_user_pages.c index c6c81022d313..ef8bcf366ddc 100644 --- a/drivers/infiniband/hw/qib/qib_user_pages.c +++ b/drivers/infiniband/hw/qib/qib_user_pages.c @@ -49,43 +49,6 @@ static void __qib_release_user_pages(struct page **p, size_t num_pages, } } -/* - * Call with current->mm->mmap_sem held. - */ -static int __qib_get_user_pages(unsigned long start_page, size_t num_pages, - struct page **p) -{ - unsigned long lock_limit; - size_t got; - int ret; - - lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - - if (num_pages > lock_limit && !capable(CAP_IPC_LOCK)) { - ret = -ENOMEM; - goto bail; - } - - for (got = 0; got < num_pages; got += ret) { - ret = get_user_pages_longterm(start_page + got * PAGE_SIZE, - num_pages - got, - FOLL_WRITE | FOLL_FORCE, - p + got, NULL); - if (ret < 0) - goto bail_release; - } - - atomic64_add(num_pages, ¤t->mm->pinned_vm); - - ret = 0; - goto bail; - -bail_release: - __qib_release_user_pages(p, got, 0); -bail: - return ret; -} - /** * qib_map_page - a safety wrapper around pci_map_page() * @@ -137,26 +100,44 @@ int qib_map_page(struct pci_dev *hwdev, struct page *page, dma_addr_t *daddr) int qib_get_user_pages(unsigned long start_page, size_t num_pages, struct page **p) { + unsigned long locked, lock_limit; + size_t got; int ret; - down_write(¤t->mm->mmap_sem); + lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; + locked = atomic64_add_return(num_pages, ¤t->mm->pinned_vm); - ret = __qib_get_user_pages(start_page, num_pages, p); + if (num_pages > lock_limit && !capable(CAP_IPC_LOCK)) { + ret = -ENOMEM; + goto bail; + } - up_write(¤t->mm->mmap_sem); + down_read(¤t->mm->mmap_sem); + for (got = 0; got < num_pages; got += ret) { + ret = get_user_pages_longterm(start_page + got * PAGE_SIZE, + num_pages - got, + FOLL_WRITE | FOLL_FORCE, + p + got, NULL); + if (ret < 0) { + up_read(¤t->mm->mmap_sem); + goto bail_release; + } + } + up_read(¤t->mm->mmap_sem); + return 0; +bail_release: + __qib_release_user_pages(p, got, 0); +bail: + atomic64_sub(num_pages, ¤t->mm->pinned_vm); return ret; } void qib_release_user_pages(struct page **p, size_t num_pages) { - if (current->mm) /* during close after signal, mm can be NULL */ - down_write(¤t->mm->mmap_sem); - __qib_release_user_pages(p, num_pages, 1); - if (current->mm) { + /* during close after signal, mm can be NULL */ + if (current->mm) atomic64_sub(num_pages, ¤t->mm->pinned_vm); - up_write(¤t->mm->mmap_sem); - } } From patchwork Wed Feb 6 17:59:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10799797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CAF5746 for ; Wed, 6 Feb 2019 18:00:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20D722CDB5 for ; Wed, 6 Feb 2019 18:00:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E9222CE7C; Wed, 6 Feb 2019 18:00:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7DD82CE95 for ; Wed, 6 Feb 2019 18:00:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AB8A8E00E3; Wed, 6 Feb 2019 13:00:08 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 507618E00D1; Wed, 6 Feb 2019 13:00:08 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3827B8E00E3; Wed, 6 Feb 2019 13:00:08 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id D042B8E00D1 for ; Wed, 6 Feb 2019 13:00:07 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id b24so5420073pls.11 for ; Wed, 06 Feb 2019 10:00:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=etR86pjRrJPXMhNrdnqovLk/Iu8sR1pSlvW/S3et7H4=; b=Pcki+WI3XjPRs1eChRlDT4FT/dCp8+K0e2LsOQTw4c9AjF1/dV+jrIOkR2BFNESU0x uuW98gN7b3e4APB4CRtwRyilBrwn/6S8oMGaVY+GaM99bTu4+XcMITO6aNyMNnhQaAFk tz37SuUon1BzMc2ChKfRDyFMqT5qKG0XVaL2e0Ud8Z1pl0yy1MJbxBwsPdGvRdLQbSur w5QiKng1y8zGFpMhE+Z/eLk+H1hmaGb0cJV1GHIO8P+qlFIkSwtYtXuvlgpROLeQmLpy 8ixD1MARp+3rEoW9ExMjJDpiPz5059TsU5+Jo0oeqqhCZbFWu7CV0iJHY2buFQRJv496 xuDA== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Gm-Message-State: AHQUAuYw78v28yO5bsW2LeGf7HBKV42oO1kZKcJuxNqk0mefMs8PkXO9 ZepKp1wB/7EpROHy1h2EMYTX1ujH9ef4etg3t7XueO5rSoaEsvVtuQ2C3AIxe+D5srhAxcqHo5y OsQumFcqRLAPzZT4sPMcQkQ0fuFRvVd6j060LpCGTuYaASzFDBbpSJGecF7nZit4= X-Received: by 2002:a63:e655:: with SMTP id p21mr10645346pgj.70.1549476007427; Wed, 06 Feb 2019 10:00:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IYWY52JeZFEJOt8/w/kgrMvBP6R+E7w1c+X9LwkwXy/2Bj1dGlMcl94OwVy2g8IH9wEWE7l X-Received: by 2002:a63:e655:: with SMTP id p21mr10645262pgj.70.1549476006247; Wed, 06 Feb 2019 10:00:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476006; cv=none; d=google.com; s=arc-20160816; b=Mpv8jMvkmAOvAg8SxHvxqCuLcokcbrzgyqTmzvsKp55Vkebt9fRChG8A82dCZT7MH+ 5hqbZIeWsSmFeo0CZUhBFln4vFssew7mK7VC9wZHEUp0i0e6HTYsjKfmtElOR3wMqty0 2L7SXRTC0IYhDyNyp31nkOK9cJyPVXmHYGN/6sJnuEPLreT9JH8b9uCIeImkychapEtz jd5wfDCBhTYT9DQH8WHViM31FGHbWP7HxX7meZfgHaFVGZsw8RD5FuZjuVBGrrxwqgNM rwW3GeK3UvYbbcwkKiAGn+fTWNWLUa33mOHI7qYh0cjlFPsTdGa75wG5Cycscj8NX4pn YLUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=etR86pjRrJPXMhNrdnqovLk/Iu8sR1pSlvW/S3et7H4=; b=YNTT90IMHw6EhgzAlhIdVjOfA36Gr4q3WS/d5AzzeoKL3kYpuqqGwnbr5qMoMyKpKX rPm6wKc9Au5Sjcqwy4xFzr2hsXpzghmp1U7+ZKMtZ2AgisGsF1cd3oGRl1sgJ5u762sM 4G99llTyIc+SFO0ZT05aVFiKTopgw6Ct3MJH/ed9qYVzv4oZ/rQvqNdrIK+2sVCUAs6n OggnZck5eNubAl4cKaXjOH/F1oenMiXNeL/ZqmRYNyj+5a/eeoBGoIKSAdFFaExL393o Y29ZZ7X68OVeDA2JiLJdhkwWrzGaijUZBUV8SSBMulrESrKooEnY5Y9jvof0RM4vixjJ 40Og== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id q25si6117300pgv.541.2019.02.06.10.00.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 10:00:06 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 19:00:03 +0100 Received: from linux-r8p5.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 17:59:50 +0000 From: Davidlohr Bueso To: jgg@ziepe.ca, akpm@linux-foundation.org Cc: dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, Davidlohr Bueso Subject: [PATCH 4/6] drivers/IB,hfi1: do not se mmap_sem Date: Wed, 6 Feb 2019 09:59:18 -0800 Message-Id: <20190206175920.31082-5-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190206175920.31082-1-dave@stgolabs.net> References: <20190206175920.31082-1-dave@stgolabs.net> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This driver already uses gup_fast() and thus we can just drop the mmap_sem protection around the pinned_vm counter. Note that the window between when hfi1_can_pin_pages() is called and the actual counter is incremented remains the same as mmap_sem was _only_ used for when ->pinned_vm was touched. Reviewed-by: Ira Weiny Signed-off-by: Davidlohr Bueso --- drivers/infiniband/hw/hfi1/user_pages.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/user_pages.c b/drivers/infiniband/hw/hfi1/user_pages.c index 40a6e434190f..24b592c6522e 100644 --- a/drivers/infiniband/hw/hfi1/user_pages.c +++ b/drivers/infiniband/hw/hfi1/user_pages.c @@ -91,9 +91,7 @@ bool hfi1_can_pin_pages(struct hfi1_devdata *dd, struct mm_struct *mm, /* Convert to number of pages */ size = DIV_ROUND_UP(size, PAGE_SIZE); - down_read(&mm->mmap_sem); pinned = atomic64_read(&mm->pinned_vm); - up_read(&mm->mmap_sem); /* First, check the absolute limit against all pinned pages. */ if (pinned + npages >= ulimit && !can_lock) @@ -111,9 +109,7 @@ int hfi1_acquire_user_pages(struct mm_struct *mm, unsigned long vaddr, size_t np if (ret < 0) return ret; - down_write(&mm->mmap_sem); atomic64_add(ret, &mm->pinned_vm); - up_write(&mm->mmap_sem); return ret; } @@ -130,8 +126,6 @@ void hfi1_release_user_pages(struct mm_struct *mm, struct page **p, } if (mm) { /* during close after signal, mm can be NULL */ - down_write(&mm->mmap_sem); atomic64_sub(npages, &mm->pinned_vm); - up_write(&mm->mmap_sem); } } From patchwork Wed Feb 6 17:59:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10799807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14C25746 for ; Wed, 6 Feb 2019 18:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08F452CD6F for ; Wed, 6 Feb 2019 18:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06B6F2CC2A; Wed, 6 Feb 2019 18:00:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C7B32CD9F for ; Wed, 6 Feb 2019 18:00:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B7DA8E00E4; Wed, 6 Feb 2019 13:00:31 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 63D4C8E00D1; Wed, 6 Feb 2019 13:00:31 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DF728E00E4; Wed, 6 Feb 2019 13:00:31 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 036AC8E00D1 for ; Wed, 6 Feb 2019 13:00:31 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id e89so5752691pfb.17 for ; Wed, 06 Feb 2019 10:00:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Xzy3x4h5nutZbyO2eCbX6bd5zbvk271EwfwoKXubYac=; b=h4CKMU7tj5TDAIySA8R/f62+m1k/95jRbDCmH9Q5cthLxUkF4hukC1ajHjVFkFUHks zkpzoVFR9BNlI48hoU6jnvLDN3z8ph+cF5wr2gK4hEWmt501XQEX0/wavKBASH5uizun WXCOAFrucTBAduZzE4awi6BOCd1tTfbwLuwHNJ+muNDNHacl9njysOrNdfGzs1FDiBUJ 2Zxh2z3m/tEZdgmCdgqpOCgs92+wT6jwMpcfwepATHZS/oPUIzuv4rSf4CgMHJoGU6J2 YWAooN2WO+5tMo8ldruNUkARUHiQGTKMBDAspY6X1LjvxdSMOQtb4NgzBPrHnXav2Yod o6PA== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Gm-Message-State: AHQUAubZ7D/ENB429FRhLwTENZp++cMM9bF2uywmD0MqPS+7hhdc2ljX qqIgPVqxDac5Olo/kAq/bMI+wufQWKgKFiLKnlEUzNBHkfbL7n0h0GlASxfXuiC54gk4/c//jIg HqkVdPNZWPuDwCeMeM7Pd3SsP19g2kX33/0w4FYu5RD7M8y2eU/1Eb8QHqzRKIqk= X-Received: by 2002:a65:6150:: with SMTP id o16mr8439558pgv.434.1549476030577; Wed, 06 Feb 2019 10:00:30 -0800 (PST) X-Google-Smtp-Source: AHgI3IYyKEmAyTulKRj8TXp3HpOzAuANdw57zwwDvVg2mDuoWIQZJyObRC9m3L/oLwS08Tuvqpie X-Received: by 2002:a65:6150:: with SMTP id o16mr8439482pgv.434.1549476029638; Wed, 06 Feb 2019 10:00:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476029; cv=none; d=google.com; s=arc-20160816; b=wy9lMavExLV2RWWihljbG+PGd6BAKd+jZhHsyljxN6APWJGO90e5aYrBtYwC8dTGFx tfbgOh0BmVTUuhDOa9hOPYcosBfOr0WiUMko1Mr9QyVcnJm3J3gBS9vLEUUE6sNBf6zK y2YTsryeQACb2NmssogGd2eY3GSarZYxBq8s8bCzp5yB4bQIWXvcBGomDjtVeZPxZT4G 9kOsuGh7JxEZhSvwwQaHzmOajPsGHDmb17Xe0Tjay5MYcr1enlwCGeQYtBevcyIoanV9 BQoHpZredQQ8JF0h+uUA1qSSQ00ojggB+i0i2JAPv89QE3I6jc8GJfmmV0nNNR7cumeZ zn5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Xzy3x4h5nutZbyO2eCbX6bd5zbvk271EwfwoKXubYac=; b=sy05gRZyDt+iD0WKYF8h+ALOYIv9RxXnx3A0RarA9CxPU7Fka4oAxteRT7qE5DfZmp OUCSUcb8lcbhISxuvnuN/j/Rti8H2dJAC9mgLDSa9tH507TkP+2XLvW7d8ch2uPzRpi+ s9V9UTihB7IbH0emkmQKGXgVK+7KkkX3NK7PzjlRVT79F2P1jbtsMfquo/fIx5xRuCr3 m0nYdTsYAHut8n8eJvB9MUwhvTmI/zcLWhBq5v5SFebbtSbfDA3P9qW7bwpvHpyuqOb9 LD0Z/+Z57olxQnx/5EgyYYdNySxe9VMO5S4y7OBaxXhF3Qzafv7+J1M6IqPp0IHTjRhQ mU3g== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id g63si6744003pfc.60.2019.02.06.10.00.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 10:00:29 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 19:00:27 +0100 Received: from linux-r8p5.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 17:59:54 +0000 From: Davidlohr Bueso To: jgg@ziepe.ca, akpm@linux-foundation.org Cc: dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, benve@cisco.com, neescoba@cisco.com, Davidlohr Bueso Subject: [PATCH 5/6] drivers/IB,usnic: reduce scope of mmap_sem Date: Wed, 6 Feb 2019 09:59:19 -0800 Message-Id: <20190206175920.31082-6-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190206175920.31082-1-dave@stgolabs.net> References: <20190206175920.31082-1-dave@stgolabs.net> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP usnic_uiom_get_pages() uses gup_longterm() so we cannot really get rid of mmap_sem altogether in the driver, but we can get rid of some complexity that mmap_sem brings with only pinned_vm. We can get rid of the wq altogether as we no longer need to defer work to unpin pages as the counter is now atomic. We also share the lock. Cc: benve@cisco.com Cc: neescoba@cisco.com Acked-by: Parvi Kaustubhi Reviewed-by: Ira Weiny Signed-off-by: Davidlohr Bueso --- drivers/infiniband/hw/usnic/usnic_ib_main.c | 2 - drivers/infiniband/hw/usnic/usnic_uiom.c | 58 +++-------------------------- drivers/infiniband/hw/usnic/usnic_uiom.h | 1 - 3 files changed, 6 insertions(+), 55 deletions(-) diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c index 3201dd1899c7..1d363b706314 100644 --- a/drivers/infiniband/hw/usnic/usnic_ib_main.c +++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c @@ -691,7 +691,6 @@ static int __init usnic_ib_init(void) out_pci_unreg: pci_unregister_driver(&usnic_ib_pci_driver); out_umem_fini: - usnic_uiom_fini(); return err; } @@ -704,7 +703,6 @@ static void __exit usnic_ib_destroy(void) unregister_inetaddr_notifier(&usnic_ib_inetaddr_notifier); unregister_netdevice_notifier(&usnic_ib_netdevice_notifier); pci_unregister_driver(&usnic_ib_pci_driver); - usnic_uiom_fini(); } MODULE_DESCRIPTION("Cisco VIC (usNIC) Verbs Driver"); diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c index 854436a2b437..06862a6af185 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.c +++ b/drivers/infiniband/hw/usnic/usnic_uiom.c @@ -47,8 +47,6 @@ #include "usnic_uiom.h" #include "usnic_uiom_interval_tree.h" -static struct workqueue_struct *usnic_uiom_wq; - #define USNIC_UIOM_PAGE_CHUNK \ ((PAGE_SIZE - offsetof(struct usnic_uiom_chunk, page_list)) /\ ((void *) &((struct usnic_uiom_chunk *) 0)->page_list[1] - \ @@ -127,9 +125,9 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, npages = PAGE_ALIGN(size + (addr & ~PAGE_MASK)) >> PAGE_SHIFT; uiomr->owning_mm = mm = current->mm; - down_write(&mm->mmap_sem); + down_read(&mm->mmap_sem); - locked = npages + atomic64_read(¤t->mm->pinned_vm); + locked = atomic64_add_return(npages, ¤t->mm->pinned_vm); lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) { @@ -184,14 +182,13 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, } out: - if (ret < 0) + if (ret < 0) { usnic_uiom_put_pages(chunk_list, 0); - else { - atomic64_set(&mm->pinned_vm, locked); + atomic64_sub(npages, ¤t->mm->pinned_vm); + } else mmgrab(uiomr->owning_mm); - } - up_write(&mm->mmap_sem); + up_read(&mm->mmap_sem); free_page((unsigned long) page_list); return ret; } @@ -435,43 +432,12 @@ static inline size_t usnic_uiom_num_pages(struct usnic_uiom_reg *uiomr) return PAGE_ALIGN(uiomr->length + uiomr->offset) >> PAGE_SHIFT; } -static void usnic_uiom_release_defer(struct work_struct *work) -{ - struct usnic_uiom_reg *uiomr = - container_of(work, struct usnic_uiom_reg, work); - - down_write(&uiomr->owning_mm->mmap_sem); - atomic64_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm); - up_write(&uiomr->owning_mm->mmap_sem); - - __usnic_uiom_release_tail(uiomr); -} - void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr, struct ib_ucontext *context) { __usnic_uiom_reg_release(uiomr->pd, uiomr, 1); - /* - * We may be called with the mm's mmap_sem already held. This - * can happen when a userspace munmap() is the call that drops - * the last reference to our file and calls our release - * method. If there are memory regions to destroy, we'll end - * up here and not be able to take the mmap_sem. In that case - * we defer the vm_locked accounting to a workqueue. - */ - if (context->closing) { - if (!down_write_trylock(&uiomr->owning_mm->mmap_sem)) { - INIT_WORK(&uiomr->work, usnic_uiom_release_defer); - queue_work(usnic_uiom_wq, &uiomr->work); - return; - } - } else { - down_write(&uiomr->owning_mm->mmap_sem); - } atomic64_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm); - up_write(&uiomr->owning_mm->mmap_sem); - __usnic_uiom_release_tail(uiomr); } @@ -600,17 +566,5 @@ int usnic_uiom_init(char *drv_name) return -EPERM; } - usnic_uiom_wq = create_workqueue(drv_name); - if (!usnic_uiom_wq) { - usnic_err("Unable to alloc wq for drv %s\n", drv_name); - return -ENOMEM; - } - return 0; } - -void usnic_uiom_fini(void) -{ - flush_workqueue(usnic_uiom_wq); - destroy_workqueue(usnic_uiom_wq); -} diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.h b/drivers/infiniband/hw/usnic/usnic_uiom.h index b86a9731071b..c88cfa087e3a 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.h +++ b/drivers/infiniband/hw/usnic/usnic_uiom.h @@ -93,5 +93,4 @@ struct usnic_uiom_reg *usnic_uiom_reg_get(struct usnic_uiom_pd *pd, void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr, struct ib_ucontext *ucontext); int usnic_uiom_init(char *drv_name); -void usnic_uiom_fini(void); #endif /* USNIC_UIOM_H_ */ From patchwork Wed Feb 6 17:59:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10799809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69DA4746 for ; Wed, 6 Feb 2019 18:00:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E9D52CB9C for ; Wed, 6 Feb 2019 18:00:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CF382CD72; Wed, 6 Feb 2019 18:00:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D951A2CB9C for ; Wed, 6 Feb 2019 18:00:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 333478E00E5; Wed, 6 Feb 2019 13:00:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2BDB88E00D1; Wed, 6 Feb 2019 13:00:33 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1369E8E00E5; Wed, 6 Feb 2019 13:00:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id B7DF88E00D1 for ; Wed, 6 Feb 2019 13:00:32 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id t26so5106908pgu.18 for ; Wed, 06 Feb 2019 10:00:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=waI1WmmPLoTveHPlnnfdMx1fmeBn1F1egAaxgnJemTY=; b=FwMZeAFPYKA/s37JGGLln0UFq/W0z0MfStDaOnSbTqzJJ+BnOES1F7QXNs8fSZXX/o /2cUx+kZ3y7qQtrvIWC5KQRup8lFXmDUgN+wRwiY5YKrvbAtbQvBh0fDnw/+jZaAHPxQ 6i0l+D0wGuS8U0rj+UUcocftkjpWOlR7SJaVWM10FUxP/PsEQ9HMw5tkF1keqyahY+Y7 2iTYQZM/hAL4GybQmpwMGbtDEoeFOhovzHKe70g6HZtBpf66aZi8T7ppy7i49kKm+/Hx hjRu5G/ET9hFoTO/+Am6+g69XVCE8XcF4mtG8LvBdRy/fMeqqidVJHlObrfMxHEfzg/U R2vA== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Gm-Message-State: AHQUAuYflbHIgOuaS1GIk7C23P9HB3hmCkzKTC8Rq/fjpTCa9CTmsykC WHrxtsLpso7mvEYUpMc78ojfggL3NANBGsiL7hZM4rI+sQosSmUdiVksaryij8EnTnwzkWFsg81 6o2KwH9JHM+lgNRk7wD1pZNH11w3KWkWr9i422J88tDq5FBXlfT5AUmZsadAIIgI= X-Received: by 2002:a17:902:6a4:: with SMTP id 33mr11734311plh.99.1549476032379; Wed, 06 Feb 2019 10:00:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IYpRnvBuCS84Rlk7UkAOi5ApctAgfUdMGC0/olJKLH577QUt2oeLH3fjRxWdSU0o+hIFuCk X-Received: by 2002:a17:902:6a4:: with SMTP id 33mr11734226plh.99.1549476031438; Wed, 06 Feb 2019 10:00:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476031; cv=none; d=google.com; s=arc-20160816; b=S0C8pKsl3dHsHcqciHD8gH97vjyaBCxboZH0K0hgjwKzwmx8PcLl3f5pBWaf9+IBw7 HuMDsXuU1SdWTOsflueKeSeumoB08prehnilVvSc9388UMkxdS11F5vb0F6nFhMLgPgR iZKzEkokgqs/3YZT4yD8e5UCNXzOWCxOTAt5BzXUItbKqL5svY6xOWgS5HrWbEhKHZvV Ax/yYYIu9c5fiwrL3q2NciKxQKwDvuxkbYEsarutmlIewX5B+yjkD9BSOmtznJFXMxzk z7KaNIn+UC0JEDGV9NiL6vc+ssYv8wl/o2+1QFiS/P2/e1NqFD0cgVRYGcCcOjPQVN9Z 21dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=waI1WmmPLoTveHPlnnfdMx1fmeBn1F1egAaxgnJemTY=; b=kpYLe6OhjrHINv1BdjHh18hKbsjrvULtsjaNDp/bs88hXuIGgc45txdTqB/3t0E9e9 rKwZ0Vd1yL4PtJ5ER54M30WjFfatkSnjQXTpMHLJrfTbzjekFEQ+f77DVFQJDaHHv9jI VKtuCoq2K5zj2R+f9fZiGvBZin5fq6BnN9NIfEtUJD5TM8KYEFDq/T3wZNLbGcRWtClC 0FVtp+UENde1JfPPC+gwCl9cy9aa87pzfRqiMsToSdfGfjgY/6vymGU5vcwha6SIWTF+ IVL+7f4DWhNEweAS6cpojjTEhyfj6HqJnhS/ZmJ6AkXw60CUFABgnP7ai8CtDmQWdZ8y zd+A== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id d189si6909175pfa.70.2019.02.06.10.00.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 10:00:31 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.221.5 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 19:00:29 +0100 Received: from linux-r8p5.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Wed, 06 Feb 2019 17:59:58 +0000 From: Davidlohr Bueso To: jgg@ziepe.ca, akpm@linux-foundation.org Cc: dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, Davidlohr Bueso Subject: [PATCH 6/6] drivers/IB,core: reduce scope of mmap_sem Date: Wed, 6 Feb 2019 09:59:20 -0800 Message-Id: <20190206175920.31082-7-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190206175920.31082-1-dave@stgolabs.net> References: <20190206175920.31082-1-dave@stgolabs.net> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP ib_umem_get() uses gup_longterm() and relies on the lock to stabilze the vma_list, so we cannot really get rid of mmap_sem altogether, but now that the counter is atomic, we can get of some complexity that mmap_sem brings with only pinned_vm. Reviewed-by: Ira Weiny Signed-off-by: Davidlohr Bueso --- drivers/infiniband/core/umem.c | 41 ++--------------------------------------- 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 678abe1afcba..b69d3efa8712 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -165,15 +165,12 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - down_write(&mm->mmap_sem); - new_pinned = atomic64_read(&mm->pinned_vm) + npages; + new_pinned = atomic64_add_return(npages, &mm->pinned_vm); if (new_pinned > lock_limit && !capable(CAP_IPC_LOCK)) { - up_write(&mm->mmap_sem); + atomic64_sub(npages, &mm->pinned_vm); ret = -ENOMEM; goto out; } - atomic64_set(&mm->pinned_vm, new_pinned); - up_write(&mm->mmap_sem); cur_base = addr & PAGE_MASK; @@ -233,9 +230,7 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, umem_release: __ib_umem_release(context->device, umem, 0); vma: - down_write(&mm->mmap_sem); atomic64_sub(ib_umem_num_pages(umem), &mm->pinned_vm); - up_write(&mm->mmap_sem); out: if (vma_list) free_page((unsigned long) vma_list); @@ -258,25 +253,12 @@ static void __ib_umem_release_tail(struct ib_umem *umem) kfree(umem); } -static void ib_umem_release_defer(struct work_struct *work) -{ - struct ib_umem *umem = container_of(work, struct ib_umem, work); - - down_write(&umem->owning_mm->mmap_sem); - atomic64_sub(ib_umem_num_pages(umem), &umem->owning_mm->pinned_vm); - up_write(&umem->owning_mm->mmap_sem); - - __ib_umem_release_tail(umem); -} - /** * ib_umem_release - release memory pinned with ib_umem_get * @umem: umem struct to release */ void ib_umem_release(struct ib_umem *umem) { - struct ib_ucontext *context = umem->context; - if (umem->is_odp) { ib_umem_odp_release(to_ib_umem_odp(umem)); __ib_umem_release_tail(umem); @@ -285,26 +267,7 @@ void ib_umem_release(struct ib_umem *umem) __ib_umem_release(umem->context->device, umem, 1); - /* - * We may be called with the mm's mmap_sem already held. This - * can happen when a userspace munmap() is the call that drops - * the last reference to our file and calls our release - * method. If there are memory regions to destroy, we'll end - * up here and not be able to take the mmap_sem. In that case - * we defer the vm_locked accounting a workqueue. - */ - if (context->closing) { - if (!down_write_trylock(&umem->owning_mm->mmap_sem)) { - INIT_WORK(&umem->work, ib_umem_release_defer); - queue_work(ib_wq, &umem->work); - return; - } - } else { - down_write(&umem->owning_mm->mmap_sem); - } atomic64_sub(ib_umem_num_pages(umem), &umem->owning_mm->pinned_vm); - up_write(&umem->owning_mm->mmap_sem); - __ib_umem_release_tail(umem); } EXPORT_SYMBOL(ib_umem_release); From patchwork Thu Feb 7 01:31:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10800341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBEF314E1 for ; Thu, 7 Feb 2019 01:32:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB4302D4F8 for ; Thu, 7 Feb 2019 01:32:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF1F82D54D; Thu, 7 Feb 2019 01:32:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 521062D4F8 for ; Thu, 7 Feb 2019 01:32:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49E608E000E; Wed, 6 Feb 2019 20:32:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 449368E0002; Wed, 6 Feb 2019 20:32:11 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33AB08E000E; Wed, 6 Feb 2019 20:32:11 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id CF8D18E0002 for ; Wed, 6 Feb 2019 20:32:10 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id m11so210872edq.3 for ; Wed, 06 Feb 2019 17:32:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:mail-followup-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=IZe+5zDMpwy+VeAKv/jmgUnsq/9GgHud2PTBFKt9Hjc=; b=q3QW2SfZQo4M/h+ZI+O+mdgRBcGlHqghKRuQfDXffJPGEwtOLHHeJwGyXEkp2TP5I4 ANeOjc3xwnftzVBZKgSI6jkfwrsdj0BDpQrq0BEJixhIVZgWqf8r9UTDrO+iYfR5VOUG ju0VCDbOqjaIjPrZFSBpaiKXBOo1GSuPdL1V5+PGZFEA9YoSyngZZzi9qpkxhMh6xWLS brOzaeVF+ld9tFxByVBjNgdvr3rDVkZLktwsmXxNd4Ukv/ixvCquQy41iHnh48DPqVqk D57vO8Ylg/QXrVINF4aW12r+Ok1tf9gXxHLHCL7jPgeG5kKY3JAcHnnn8rvSNtScI1Vk RkgA== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Gm-Message-State: AHQUAuYuMu1pFBFInqgYomyQNEIIiaHh8NiLXsMB0wT0xFWYGXaS9GVj OzemjKFnF9It94C/I1AzdCMWI3DavpAwPZhLTLOMq3ZOBPl9aYptPVM9vdmRYGYZOK5D6s6tEi3 X0O7hwkUQ4EHZQudvplB/ylLywOek0mJr5G0CcIH25TSdCPUBJZJY1L83PMyrfyw= X-Received: by 2002:a17:906:35d5:: with SMTP id p21mr9289133ejb.229.1549503130299; Wed, 06 Feb 2019 17:32:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IaMcXSzIT3KGmmLWlZ/sdU6A3OWEu7SaoucW5WYXjq/53b/iJ/W7CDrfNSyNZAGY1koOo0o X-Received: by 2002:a17:906:35d5:: with SMTP id p21mr9289092ejb.229.1549503129449; Wed, 06 Feb 2019 17:32:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549503129; cv=none; d=google.com; s=arc-20160816; b=H70sKWhRZ9KaitqI3pKfhn/bKjMQ5kO4YXL7Hes5hsOBPEr9FCCuRW2w2SVq2djK+p jXhIHhewyu+KVdofKX5ZAFVfhFwXD/WQKSrcBryQBMjOi9ILu9MqEtxPZfuoLI4Gjk7P jZzJWtzdT6Xq9dgW5dDwlXnO086p0ugGfjRhGz940ZeSujJ1w1olS0NiY2XvSg5VNO8b PO45SLOQ4z76MH6uqXbYsS8j0jS0OuEAItf0sABLKDGAX4gbsZNYgr2g5hpfmbOYGPzp YDjfjIVFJUVdeVRKmKzS9i7jDFccDsOjyoUSq1tj1IQx+Lyhv5UynNrVgU0kctICLwj7 dZ9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date; bh=IZe+5zDMpwy+VeAKv/jmgUnsq/9GgHud2PTBFKt9Hjc=; b=y1yQecb+LONkA9CCEYxtw39BqXE/y/sK2bqnj51VeGYwxM7Jn+FxB/s71Ehdzm/r7+ Iuz0onr6xSSXeuoABJnboIpvWVO/dHW+lx+a4HLaziaecXHkA6mQgGLrBDZOhUphw1rf GuLe7L5u2r9O7REMMQe9pkZ582imhVzT15m+AjIhz9JaRWu2sryn8vVltd0wL3P+3Rx4 AH5DoIwSV0bMi8hClBM4rfZYy05wf++F0ChxhWjeE5W/aPv0fuMr/3VbCyzmYSXsELq8 DSp+yiYUI4OytfFP2BWNv48DAUcMs6LaKVOJbvfGF6Uks0NDS9b3zP+kzTs+x9HY3C52 7Wyw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=dave@stgolabs.net Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id q47si7207094edd.98.2019.02.06.17.32.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 17:32:09 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning dave@stgolabs.net does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=dave@stgolabs.net X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2EEAAAFA8; Thu, 7 Feb 2019 01:32:06 +0000 (UTC) Date: Wed, 6 Feb 2019 17:31:55 -0800 From: Davidlohr Bueso To: jgg@ziepe.ca, akpm@linux-foundation.org Cc: dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/6] Documentation/infiniband: update from locked to pinned_vm Message-ID: <20190207013155.lq5diwqc2svyt3t3@linux-r8p5> Mail-Followup-To: jgg@ziepe.ca, akpm@linux-foundation.org, dledford@redhat.com, jgg@mellanox.com, jack@suse.cz, willy@infradead.org, ira.weiny@intel.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20190206175920.31082-1-dave@stgolabs.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190206175920.31082-1-dave@stgolabs.net> User-Agent: NeoMutt/20180323 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We are really talking about pinned_vm here. Signed-off-by: Davidlohr Bueso Reviewed-by: Ira Weiny --- Documentation/infiniband/user_verbs.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/infiniband/user_verbs.txt b/Documentation/infiniband/user_verbs.txt index df049b9f5b6e..47ebf2f80b2b 100644 --- a/Documentation/infiniband/user_verbs.txt +++ b/Documentation/infiniband/user_verbs.txt @@ -46,11 +46,11 @@ Memory pinning I/O targets be kept resident at the same physical address. The ib_uverbs module manages pinning and unpinning memory regions via get_user_pages() and put_page() calls. It also accounts for the - amount of memory pinned in the process's locked_vm, and checks that + amount of memory pinned in the process's pinned_vm, and checks that unprivileged processes do not exceed their RLIMIT_MEMLOCK limit. Pages that are pinned multiple times are counted each time they are - pinned, so the value of locked_vm may be an overestimate of the + pinned, so the value of pinned_vm may be an overestimate of the number of pages pinned by a process. /dev files