Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1052882ybj; Tue, 5 May 2020 12:08:58 -0700 (PDT) X-Google-Smtp-Source: APiQypI5dj3BvIU4H4VIpvpuci+yHLiGdw/lZlgzJ3SKluXmI1Hxue/ZWoTb6xB2g872Xz1TqKXm X-Received: by 2002:aa7:d481:: with SMTP id b1mr4126485edr.226.1588705738292; Tue, 05 May 2020 12:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588705738; cv=none; d=google.com; s=arc-20160816; b=y8w3ejuHbgIwD6dzacGmiDn0o257Mk0x8HcWfmi03GFS2fRKuU1Gffk9b1O+ZBBPuk 5WccLmQGesJ3rhq2pCeZjH6KzoX93VRAqZLALzWzLnEDziRw9W9XpMEGv5D5WAVBiS3X GKoH2hxd1yPQuw9Wd/40VGX7Jx/+9ye3ZiMl2EGxLO0/W1SLZzslPZ8D3YYm0RDyCjd+ 1tHOWxeGqm0awXI4g7H7N6jPyTVrElNe8zieLyCJWRctLCAOwcvFIjYz/R280BVPXu/T jKBRsmIu4HtX+cwUb4bGtt2cfBHR46uX1nOa3OYv2MxithNamPrXoFx0G35lea92LBL2 +S5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=fWyOOrvUK77uA/msSZdDDnmybty7hQPcowq4Z58m++0=; b=xk0/84VnZ/NnYYgY8SfZaSYpkz4mrS02D/1qBYJIh/NpPim8RgdiOj2whbysRaoBaT mllhCcIUJ5ai2xD2hhkgnMWwkTdDUGbP6QfVJLsKYP9IpdVFIeo8D4xGHjHK7FBMsQMk Q8SsbRee+Qn6qMZ+4fAEAhq7aq2xwqIDUr9LxOn7Bk+4MwY0OyZWG/eM8KgPdI0ov6+R 5FQ/etbLAKJFxCwlTCe/KFzn4xEIq+1ihWo7YfftYPPXi7oOfsGFmiscUcM3ONBiXsDM 5F2v8ZhmbNtezJyEdbs8dLZD0zSqYdn2bxwIS9XsXic3yO4J1NgHOubF3WH8GZxG+Ovx bZhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BPHouBLZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si1869471edl.2.2020.05.05.12.08.33; Tue, 05 May 2020 12:08:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BPHouBLZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728810AbgEETHJ (ORCPT + 99 others); Tue, 5 May 2020 15:07:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727857AbgEETHI (ORCPT ); Tue, 5 May 2020 15:07:08 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 406B4C061A0F; Tue, 5 May 2020 12:07:08 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id f8so1221493plt.2; 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=nzv3F2dYOyGwxTUdlk87VcPVjNHiXWw9cPwe8cRrhqbv5jxXnXyRSghlIFt74mBQhV oEyu3I4Kqi+exZraqiwzr4+wfWCaOqOQ+r3oW6IKOY9fW3QeLxQmsKb6G8OQ+HVfaCRH yyxHWkZnjn1OBGv6L3Q8+gG8JQu4ABcBTIZoxmbSS2vgVIALt0M7sAtIcFn3kps2K1yH 16BM3Z4x312aO1qKCNvCSefWLEO9v8fins037atjsYvd6gVdxLTHrxjYOd6o8CN+9Hqt LyWQSz4jPnvYQDhxL0pnnuv9HyjwGM+B+KH3kprvGiGb9OHSxzQ7TYUyItnHpDXxTkvx pXjw== X-Gm-Message-State: AGi0PuYot68TqWr8+ASfoLiF0RvCl8HLHBbO0ASRhDxrSXn0/zDpFlwu Bvkqj6eVWG4QgvKhKepp/vg= 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 1.9.1