From patchwork Mon Oct 8 21:16:21 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: 10631441 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 666D014DB for ; Mon, 8 Oct 2018 21:16:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57F6929816 for ; Mon, 8 Oct 2018 21:16:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C03C298FE; Mon, 8 Oct 2018 21:16: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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 B91AD29816 for ; Mon, 8 Oct 2018 21:16:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D1AE6B0269; Mon, 8 Oct 2018 17:16:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2802C6B026A; Mon, 8 Oct 2018 17:16:33 -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 0F9746B026B; Mon, 8 Oct 2018 17:16:33 -0400 (EDT) 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 C340D6B0269 for ; Mon, 8 Oct 2018 17:16:32 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id d40-v6so18637130pla.14 for ; Mon, 08 Oct 2018 14:16:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=FVIsmZsD2UYUIajD9wCWvufUKrPcgTlr9PeHswP0yEs=; b=A2PTKzSK8Ayr7xJTfDlUeIVnvBdSlDnmAgq2i3grMWn9confGMmk+b4mJ7w5uHoXXr iu2BAX8R4Yfbd+Ujqftw+lY247bxcZGKFpfm3LgpnCeiF2OL4vkbvo//MtrfPme+pg+i J41FPw+aIFszgkZRQJYCOkdxDToKULF/p5aF44mkz041MGG/G2IWIySVNsbh7Je9GY1t UQnXMz8maBynEHgdI02vCwNU8it9W2hIcgS53CxbUEm7s4ok0LOOHk280eiiSxZMT/2E PKTqGymscQvdKUaOPnWgdCawAc2CBWkx/jQ3Tao8qm2aNCWG5ZqQAp3DmW9IaRX+dDGs 33ow== X-Gm-Message-State: ABuFfog5bT+u7yHIqEXfCRtpzFgcNosmwrPG9aT+OpTCMX4SEeUvIY4k KsXu4IQCGCqgcbzkkvUghrV5vBck+1cxFUHbwxvoIvo/Vn3rR2dUPXcE6SafJOV2ezvHY3IMa2i uSaGulYTx2tBTOtWMY/FvtlmQO+g4ySUj5uAbK/db7RLWlStlD/kfbOpZkZOmYb3UGOrfei7goR Niq5k4eE8WOjI1Weodq/GFOsioEt831ox7xJf+U+AHWe9YMjmZW2/kIqYN0WZPaVkY9OCthE+x3 K2k9hXGgsEV2CzMKTd9XuhjSTomgv4rAfE66BL6OVXmEtdbazsssA2ikhcnh5HtpspAR155/K5v nZTfDssnwBhahgEZQXVhW6ZcjtdzYdR20kStzocQIQK+7SMqIS4awHH83QM+lj4uaQDGwDKf8JE m X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr26022123plb.87.1539033392481; Mon, 08 Oct 2018 14:16:32 -0700 (PDT) X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr26022097plb.87.1539033391583; Mon, 08 Oct 2018 14:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539033391; cv=none; d=google.com; s=arc-20160816; b=UmM+inCPzMkvDyBBBBZjsBIK0rOxHFYVQnZD5x4sDVQ0hagmUs4ld8sIkYWpq30afP eEIUsm/Y/h2zEH2rNTmGvl8w/dw/y9FiBiXdwluhn7gjHG101RaXqB9TczHsIHq/TKip p0XQRqWOcMyvnR6cprim27/6uL2H/LZDgzHx/ERCOmdFxP8zxuxU63gaGqtNEVlVMlnE 9GjATUtcxAFq/aSXfHksb2544of1D60WfCsBCeWxWDkbZsrtp4KrlyvuAbuxm31HoUkA OUhUmN79+xqAEgfpc5d94AMvZ9cwH1s/6F4nTMDD5NlfWnrWE90QLS/bz1wBFULmSo0L 10Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=FVIsmZsD2UYUIajD9wCWvufUKrPcgTlr9PeHswP0yEs=; b=Rt46/ZjssubHKcBoS+DxddcLdiRgvnvRHIevgy4XYrGHfPfJ1kweDpsybOTIwbj8w5 RlpOFU/vZh4d+t3eiZCZgZMMvl0j8/4R98ks5MXy6uZE5oe73CLZsbefEAYd7cTxgGwC CU75Q9QwmCLL8spBN3WKjXloW82Qo44yn0b12ix08vOIUU8eOdser/l9zpacG3tA+9z3 Id9ssh2rg8a/nKJfV7/X/ouQzJgg8fmSAmrnmwmdv8GZ3jnOBS1fMI4SOu4EQbN5lIIG wkkVsDY7ZOli0RXxZSFU1BFFt7MFkWBcbwjyPku9psCAuX7wOLG3WEcLVylEJuosgGY+ c/yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KtRdHhB0; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id j62-v6sor14265372pgd.42.2018.10.08.14.16.31 for (Google Transport Security); Mon, 08 Oct 2018 14:16:31 -0700 (PDT) Received-SPF: pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KtRdHhB0; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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=KtRdHhB0TCig2y75Kke1hlMVtbsRYuIxehy0tyoHB5CxNfdOJNFD432pphe0UuMqt0 iIy5Z83K+zy46HGxlbqqDsXsVdTjIXRXl0FHbMDk8CGz/wdWxekIFD2tP7G3OmX3tjjT TB+eR/mDXBavM5skuUEQjfrhm6ZbN7qTgEGd5Ie9zhzUcZ1jQLQysuhT1yCjNtqJF5AC 0R/ngkbwnLfoVkTfM46z7wDcBd908tUL+gd04Y3jqEHColQOuCf+4ZFSmBz7B5icsXwB nCsOndufh/mFykG7tBO5gpkH3Tu4QqT1BKx5okpt33/lKnXShpV1aKyFbuRV8z7Eco7D 8iGA== X-Google-Smtp-Source: ACcGV62z1JG6uLWKoscZWokp7sITSTbr35JddE1XhG5ebAVUJIKrHM52PfMrmwGo/yuduL9YGbh6Sw== X-Received: by 2002:a63:b305:: with SMTP id i5-v6mr22403816pgf.46.1539033391198; Mon, 08 Oct 2018 14:16:31 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id w127-v6sm23480045pfd.112.2018.10.08.14.16.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 14:16:30 -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 v4 1/3] mm: get_user_pages: consolidate error handling Date: Mon, 8 Oct 2018 14:16:21 -0700 Message-Id: <20181008211623.30796-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008211623.30796-1-jhubbard@nvidia.com> References: <20181008211623.30796-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public 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 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 Reviewed-by: Andrew Morton --- 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,