From patchwork Wed Oct 2 14:28:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 2975131 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8A5A39F288 for ; Wed, 2 Oct 2013 14:31:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D7B2B201FA for ; Wed, 2 Oct 2013 14:31:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0DB42017B for ; Wed, 2 Oct 2013 14:31:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753823Ab3JBOaE (ORCPT ); Wed, 2 Oct 2013 10:30:04 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49067 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753392Ab3JBO3B (ORCPT ); Wed, 2 Oct 2013 10:29:01 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 23CB4A5527; Wed, 2 Oct 2013 16:28:58 +0200 (CEST) Received: by quack.suse.cz (Postfix, from userid 1000) id 2B4D980ED4; Wed, 2 Oct 2013 16:28:55 +0200 (CEST) From: Jan Kara To: LKML Cc: linux-mm@kvack.org, Jan Kara , Mike Marciniszyn , Roland Dreier , linux-rdma@vger.kernel.org Subject: [PATCH 21/26] ib: Convert ipath_get_user_pages() to get_user_pages_unlocked() Date: Wed, 2 Oct 2013 16:28:02 +0200 Message-Id: <1380724087-13927-22-git-send-email-jack@suse.cz> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1380724087-13927-1-git-send-email-jack@suse.cz> References: <1380724087-13927-1-git-send-email-jack@suse.cz> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert ipath_get_user_pages() to use get_user_pages_unlocked(). This shortens the section where we hold mmap_sem for writing and also removes the knowledge about get_user_pages() locking from ipath driver. We also fix a bug in testing pinned number of pages when changing the code. CC: Mike Marciniszyn CC: Roland Dreier CC: linux-rdma@vger.kernel.org Signed-off-by: Jan Kara --- drivers/infiniband/hw/ipath/ipath_user_pages.c | 62 +++++++++++--------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/drivers/infiniband/hw/ipath/ipath_user_pages.c b/drivers/infiniband/hw/ipath/ipath_user_pages.c index dc66c4506916..a89af9654112 100644 --- a/drivers/infiniband/hw/ipath/ipath_user_pages.c +++ b/drivers/infiniband/hw/ipath/ipath_user_pages.c @@ -52,40 +52,58 @@ static void __ipath_release_user_pages(struct page **p, size_t num_pages, } } -/* call with current->mm->mmap_sem held */ -static int __ipath_get_user_pages(unsigned long start_page, size_t num_pages, - struct page **p, struct vm_area_struct **vma) +/** + * ipath_get_user_pages - lock user pages into memory + * @start_page: the start page + * @num_pages: the number of pages + * @p: the output page structures + * + * This function takes a given start page (page aligned user virtual + * address) and pins it and the following specified number of pages. For + * now, num_pages is always 1, but that will probably change at some point + * (because caller is doing expected sends on a single virtually contiguous + * buffer, so we can do all pages at once). + */ +int ipath_get_user_pages(unsigned long start_page, size_t num_pages, + struct page **p) { unsigned long lock_limit; size_t got; int ret; + down_write(¤t->mm->mmap_sem); lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - if (num_pages > lock_limit) { + if (current->mm->pinned_vm + num_pages > lock_limit && + !capable(CAP_IPC_LOCK)) { + up_write(¤t->mm->mmap_sem); ret = -ENOMEM; goto bail; } + current->mm->pinned_vm += num_pages; + up_write(¤t->mm->mmap_sem); ipath_cdbg(VERBOSE, "pin %lx pages from vaddr %lx\n", (unsigned long) num_pages, start_page); for (got = 0; got < num_pages; got += ret) { - ret = get_user_pages(current, current->mm, - start_page + got * PAGE_SIZE, - num_pages - got, 1, 1, - p + got, vma); + ret = get_user_pages_unlocked(current, current->mm, + start_page + got * PAGE_SIZE, + num_pages - got, 1, 1, + p + got); if (ret < 0) goto bail_release; } - current->mm->pinned_vm += num_pages; ret = 0; goto bail; bail_release: __ipath_release_user_pages(p, got, 0); + down_write(¤t->mm->mmap_sem); + current->mm->pinned_vm -= num_pages; + up_write(¤t->mm->mmap_sem); bail: return ret; } @@ -146,32 +164,6 @@ dma_addr_t ipath_map_single(struct pci_dev *hwdev, void *ptr, size_t size, return phys; } -/** - * ipath_get_user_pages - lock user pages into memory - * @start_page: the start page - * @num_pages: the number of pages - * @p: the output page structures - * - * This function takes a given start page (page aligned user virtual - * address) and pins it and the following specified number of pages. For - * now, num_pages is always 1, but that will probably change at some point - * (because caller is doing expected sends on a single virtually contiguous - * buffer, so we can do all pages at once). - */ -int ipath_get_user_pages(unsigned long start_page, size_t num_pages, - struct page **p) -{ - int ret; - - down_write(¤t->mm->mmap_sem); - - ret = __ipath_get_user_pages(start_page, num_pages, p, NULL); - - up_write(¤t->mm->mmap_sem); - - return ret; -} - void ipath_release_user_pages(struct page **p, size_t num_pages) { down_write(¤t->mm->mmap_sem);