From patchwork Tue May 5 19:14:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 11529795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABFC5139A for ; Tue, 5 May 2020 19:07:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 615E02083B for ; Tue, 5 May 2020 19:07:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BPHouBLZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 615E02083B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8451F8E0005; Tue, 5 May 2020 15:07:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7F5DF8E0003; Tue, 5 May 2020 15:07:09 -0400 (EDT) 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 6E3B28E0005; Tue, 5 May 2020 15:07:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id 52DF88E0003 for ; Tue, 5 May 2020 15:07:09 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0D03E181AC9CB for ; Tue, 5 May 2020 19:07:09 +0000 (UTC) X-FDA: 76783598178.15.fear52_5b7eaa9792f4a X-Spam-Summary: 2,0,0,9d3291e69abe7b93,d41d8cd98f00b204,jrdr.linux@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1437:1535:1544:1711:1730:1747:1777:1792:1801:2198:2199:2393:2553:2559:2562:2693:2736:2895:3138:3139:3140:3141:3142:3353:3865:3866:3868:3871:4118:4321:4605:5007:6261:6653:6737:7514:7875:9413:10004:11026:11473:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12895:12986:13972:14096:14181:14687:14721:21080:21324:21433:21444:21451:21627:21666:21795:21990:30003:30029:30034:30051:30054:30070:30090,0,RBL:209.85.214.194:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: fear52_5b7eaa9792f4a X-Filterd-Recvd-Size: 7440 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 5 May 2020 19:07:08 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id t7so1225817plr.0 for ; Tue, 05 May 2020 12:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=fWyOOrvUK77uA/msSZdDDnmybty7hQPcowq4Z58m++0=; b=BPHouBLZVWeHaubUI19wpiMPuNtIWM6/YUERDUNe9MNgSmVVq0+cuxhz5bbxK3kGR/ UxcdfDx5R8f3MQ80bBtDEUMhM0+5IrSRG1k40tEN/KtDJEk+cwmfyVkJy8XAOFHr8iZV F4yJrLmDlhHmTlklDWECl6sk8bPgMQ2UzPK0tbwjp46p+Zg9ks/sU6Oi6OCWWSH+iOB3 W0bCCNjZW9NvvDQZt7CCmoZ3WNfRiAeq9LraUzBiD/CEpqKX37b7yIu+KkT6Sg0vWC5i 0TcYCFn7ETDBN3JI4s/uaXI2hQlYqm7S+dmA9jFiQBQtqioeyCarQZr4EkFEIw6owo/M F3dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fWyOOrvUK77uA/msSZdDDnmybty7hQPcowq4Z58m++0=; b=XSvShf5rjb84smgLGbbyNd9kge091AP9zwTc1kdgA29AkEm7vezEB3sj7jM3ac+JX5 +Ypd1dP3olZAaosXP+5BW9a6vvzkO9b+DBAyfylUuQIQQEtd8sHhE9npEyn77acDS9AQ V6HjJvGopFn2bxnoFEJlCX5iRW+q2taTMqm5eSNnJz94jL4GLwzqSwwOY4KC2xuL39dU 01u/tzADJc7bAh207jB5wYxJhnEZDNh7FaN3nwuGeZIgz53uTg6Rbhv5PM4WOzzLMdcO Gkne9SUSiGyl0/tTPpxj7hD3DeElKOpAk0uFqZt+D0tuwPs3923dZv6sGDCYCw9tHgUE gx1w== X-Gm-Message-State: AGi0Pua8ese1gd8KjL4QKwevo7NVBKyUJZXXp0c5dBGe17YfCtS2J/Dr cBERY0DpfNyTtZUL+nuO2rQ= X-Google-Smtp-Source: APiQypIii3zV6Elp7IO251v6M6vB2QPxZ+fMr3HRaeN0DRbvD8NEebNCns+Io+5802VclUQUQzICSw== X-Received: by 2002:a17:90a:9e9:: with SMTP id 96mr4913003pjo.41.1588705627557; Tue, 05 May 2020 12:07:07 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC.domain.name ([122.167.156.195]) by smtp.gmail.com with ESMTPSA id 138sm2664906pfz.31.2020.05.05.12.07.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 May 2020 12:07:06 -0700 (PDT) From: Souptick Joarder To: tony.luck@intel.com, fenghua.yu@intel.com, rspringer@google.com, toddpoynor@google.com, benchan@chromium.org, gregkh@linuxfoundation.org, jens.wiklander@linaro.org, akpm@linux-foundation.org, santosh.shilimkar@oracle.com, davem@davemloft.net, kuba@kernel.org, jack@suse.cz, jhubbard@nvidia.com, ira.weiny@intel.com, jglisse@redhat.com Cc: inux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, tee-dev@lists.linaro.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, Souptick Joarder Subject: [RFC] mm/gup.c: Updated return value of {get|pin}_user_pages_fast() Date: Wed, 6 May 2020 00:44:19 +0530 Message-Id: <1588706059-4208-1-git-send-email-jrdr.linux@gmail.com> X-Mailer: git-send-email 1.9.1 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: Currently {get|pin}_user_pages_fast() have 3 return value 0, -errno and no of pinned pages. The only case where these two functions will return 0, is for nr_pages <= 0, which doesn't find a valid use case. But if at all any, then a -ERRNO will be returned instead of 0, which means {get|pin}_user_pages_fast() will have 2 return values -errno & no of pinned pages. Update all the callers which deals with return value 0 accordingly. Signed-off-by: Souptick Joarder --- arch/ia64/kernel/err_inject.c | 2 +- drivers/platform/goldfish/goldfish_pipe.c | 2 +- drivers/staging/gasket/gasket_page_table.c | 4 ++-- drivers/tee/tee_shm.c | 2 +- mm/gup.c | 6 +++--- net/rds/rdma.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c index 8b5b8e6b..fd72218 100644 --- a/arch/ia64/kernel/err_inject.c +++ b/arch/ia64/kernel/err_inject.c @@ -143,7 +143,7 @@ static DEVICE_ATTR(name, 0644, show_##name, store_##name) int ret; ret = get_user_pages_fast(virt_addr, 1, FOLL_WRITE, NULL); - if (ret<=0) { + if (ret < 0) { #ifdef ERR_INJ_DEBUG printk("Virtual address %lx is not existing.\n",virt_addr); #endif diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c index 1ab207e..831449d 100644 --- a/drivers/platform/goldfish/goldfish_pipe.c +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -277,7 +277,7 @@ static int goldfish_pin_pages(unsigned long first_page, ret = pin_user_pages_fast(first_page, requested_pages, !is_write ? FOLL_WRITE : 0, pages); - if (ret <= 0) + if (ret < 0) return -EFAULT; if (ret < requested_pages) *iter_last_page_size = PAGE_SIZE; diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c index f6d7157..1d08e1d 100644 --- a/drivers/staging/gasket/gasket_page_table.c +++ b/drivers/staging/gasket/gasket_page_table.c @@ -489,11 +489,11 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl, ret = get_user_pages_fast(page_addr - offset, 1, FOLL_WRITE, &page); - if (ret <= 0) { + if (ret < 0) { dev_err(pg_tbl->device, "get user pages failed for addr=0x%lx, offset=0x%lx [ret=%d]\n", page_addr, offset, ret); - return ret ? ret : -ENOMEM; + return ret; } ++pg_tbl->num_active_pages; diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index bd679b7..2706a1f 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -230,7 +230,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, if (rc > 0) shm->num_pages = rc; if (rc != num_pages) { - if (rc >= 0) + if (rc > 0) rc = -ENOMEM; ret = ERR_PTR(rc); goto err; diff --git a/mm/gup.c b/mm/gup.c index 50681f0..8d293ed 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2760,7 +2760,7 @@ static int internal_get_user_pages_fast(unsigned long start, int nr_pages, end = start + len; if (end <= start) - return 0; + return -EINVAL; if (unlikely(!access_ok((void __user *)start, len))) return -EFAULT; @@ -2805,8 +2805,8 @@ static int internal_get_user_pages_fast(unsigned long start, int nr_pages, * calling get_user_pages(). * * Returns number of pages pinned. This may be fewer than the number requested. - * If nr_pages is 0 or negative, returns 0. If no pages were pinned, returns - * -errno. + * If nr_pages is 0 or negative, returns -errno. If no pages were pinned, + * returns -errno. */ int get_user_pages_fast(unsigned long start, int nr_pages, unsigned int gup_flags, struct page **pages) diff --git a/net/rds/rdma.c b/net/rds/rdma.c index a7ae118..44b96e6 100644 --- a/net/rds/rdma.c +++ b/net/rds/rdma.c @@ -161,7 +161,7 @@ static int rds_pin_pages(unsigned long user_addr, unsigned int nr_pages, gup_flags |= FOLL_WRITE; ret = pin_user_pages_fast(user_addr, nr_pages, gup_flags, pages); - if (ret >= 0 && ret < nr_pages) { + if (ret > 0 && ret < nr_pages) { unpin_user_pages(pages, ret); ret = -EFAULT; }