From patchwork Sat Oct 6 02:49:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john.hubbard@gmail.com X-Patchwork-Id: 10629075 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 20D52933 for ; Sat, 6 Oct 2018 02:50:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E2BD2970D for ; Sat, 6 Oct 2018 02:50:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F301929713; Sat, 6 Oct 2018 02:50:13 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B97129702 for ; Sat, 6 Oct 2018 02:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729355AbeJFJv0 (ORCPT ); Sat, 6 Oct 2018 05:51:26 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36908 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726812AbeJFJvZ (ORCPT ); Sat, 6 Oct 2018 05:51:25 -0400 Received: by mail-pl1-f196.google.com with SMTP id az3-v6so7619642plb.4; Fri, 05 Oct 2018 19:49:54 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=FVIsmZsD2UYUIajD9wCWvufUKrPcgTlr9PeHswP0yEs=; b=TtFCbeUQABKwJQNsY1ARZNCx4FpkA64f1mZStu96EEXotHAt9mhWVKYMxISGgZIuAy e9XH9h3UlTqIpFJMnHvv/F8ZM3YpgWBol0G9MgMTvKLfdMDQz8waroBAE9BLt5i93eVi unxz3ToLsqxZShV8nWoWz6xE75lLYMtfFYZa6ryBouDtkU2CFbENDu0gwAipIPucI4/f f0dfgBXLY34NZf5lVhC7Qpdg5v8kHXASNVpHN+Fzx8XoIQ0xnffM0N42BrjnGZSmJbKE YHf+gQbLgTWl94iN98FCxVLbs7fd8BDOird5jcNZ0YsgMma0hW3XG/ZtLeo0SFW8+VQ9 z43Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=FVIsmZsD2UYUIajD9wCWvufUKrPcgTlr9PeHswP0yEs=; b=Zy4hxmTA+QTudPryYRt/LBenb43SipAeeeA+JYpVicfCEx2cznd7tr0jKV4+ZV0boH QzA1Famlsjg2bLDdKCh1Q8SNG+J4Fx7ugCKhnsRGZIy9VGSHACdDIEEf3mfA2JXDiFs/ PonFBbl4mHVcNa2QKF5kzxDHto/NwSwDT3UXvne3lgLh8cLz7pkuNk7P9rUrTns5RZrn G0LX1Hrxk5u6nEMoo7woH8cJduuyBZz3yfgPvH+0dq9dLsV3f3sxdBXyCbw984UO2aP2 kLnT8moDmcnLCIuZfXct9l6X7deaaXXBkfanXLlWeClyuXhWYKQ56wltflq7Pk0hCYab DIjw== X-Gm-Message-State: ABuFfojgEjPZ62dcd/gHT0Htc6CMJra0eay4DFKl43SMRI7kQyvIZWmH 6o17LVDYKDRkhP/CScA/L5s= X-Google-Smtp-Source: ACcGV62BmgctjFnuEzcUrQCVuDXjZsdW3sOw7lJYocd8SSwA0nJNtMPSF930/XkeU2sheSeUcgT72w== X-Received: by 2002:a17:902:a618:: with SMTP id u24-v6mr14096438plq.77.1538794193757; Fri, 05 Oct 2018 19:49:53 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id n63-v6sm3962785pfn.9.2018.10.05.19.49.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Oct 2018 19:49:52 -0700 (PDT) From: john.hubbard@gmail.com X-Google-Original-From: jhubbard@nvidia.com To: Matthew Wilcox , Michal Hocko , Christopher Lameter , Jason Gunthorpe , Dan Williams , Jan Kara Cc: linux-mm@kvack.org, LKML , linux-rdma , linux-fsdevel@vger.kernel.org, John Hubbard Subject: [PATCH v3 1/3] mm: get_user_pages: consolidate error handling Date: Fri, 5 Oct 2018 19:49:47 -0700 Message-Id: <20181006024949.20691-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181006024949.20691-1-jhubbard@nvidia.com> References: <20181006024949.20691-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: John Hubbard An upcoming patch requires a way to operate on each page that any of the get_user_pages_*() variants returns. In preparation for that, consolidate the error handling for __get_user_pages(). This provides a single location (the "out:" label) for operating on the collected set of pages that are about to be returned. As long every use of the "ret" variable is being edited, rename "ret" --> "err", so that its name matches its true role. This also gets rid of two shadowed variable declarations, as a tiny beneficial a side effect. Reviewed-by: Jan Kara Signed-off-by: John Hubbard --- mm/gup.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 1abc8b4afff6..05ee7c18e59a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -660,6 +660,7 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, struct vm_area_struct **vmas, int *nonblocking) { long i = 0; + int err = 0; unsigned int page_mask; struct vm_area_struct *vma = NULL; @@ -685,18 +686,19 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, if (!vma || start >= vma->vm_end) { vma = find_extend_vma(mm, start); if (!vma && in_gate_area(mm, start)) { - int ret; - ret = get_gate_page(mm, start & PAGE_MASK, + err = get_gate_page(mm, start & PAGE_MASK, gup_flags, &vma, pages ? &pages[i] : NULL); - if (ret) - return i ? : ret; + if (err) + goto out; page_mask = 0; goto next_page; } - if (!vma || check_vma_flags(vma, gup_flags)) - return i ? : -EFAULT; + if (!vma || check_vma_flags(vma, gup_flags)) { + err = -EFAULT; + goto out; + } if (is_vm_hugetlb_page(vma)) { i = follow_hugetlb_page(mm, vma, pages, vmas, &start, &nr_pages, i, @@ -709,23 +711,25 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, * If we have a pending SIGKILL, don't keep faulting pages and * potentially allocating memory. */ - if (unlikely(fatal_signal_pending(current))) - return i ? i : -ERESTARTSYS; + if (unlikely(fatal_signal_pending(current))) { + err = -ERESTARTSYS; + goto out; + } cond_resched(); page = follow_page_mask(vma, start, foll_flags, &page_mask); if (!page) { - int ret; - ret = faultin_page(tsk, vma, start, &foll_flags, + err = faultin_page(tsk, vma, start, &foll_flags, nonblocking); - switch (ret) { + switch (err) { case 0: goto retry; case -EFAULT: case -ENOMEM: case -EHWPOISON: - return i ? i : ret; + goto out; case -EBUSY: - return i; + err = 0; + goto out; case -ENOENT: goto next_page; } @@ -737,7 +741,8 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, */ goto next_page; } else if (IS_ERR(page)) { - return i ? i : PTR_ERR(page); + err = PTR_ERR(page); + goto out; } if (pages) { pages[i] = page; @@ -757,7 +762,9 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, start += page_increm * PAGE_SIZE; nr_pages -= page_increm; } while (nr_pages); - return i; + +out: + return i ? i : err; } static bool vma_permits_fault(struct vm_area_struct *vma,