From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E960C43461 for ; Mon, 14 Sep 2020 20:56:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E54F62193E for ; Mon, 14 Sep 2020 20:56:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="lxOEgomU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E54F62193E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3269B8E0006; Mon, 14 Sep 2020 16:56:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D51B8E0001; Mon, 14 Sep 2020 16:56:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C4BE8E0006; Mon, 14 Sep 2020 16:56:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id 060018E0001 for ; Mon, 14 Sep 2020 16:56:23 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B64263634 for ; Mon, 14 Sep 2020 20:56:22 +0000 (UTC) X-FDA: 77262875004.22.bread59_4c0b8bf2710b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 5B00318038E68 for ; Mon, 14 Sep 2020 20:56:22 +0000 (UTC) X-HE-Tag: bread59_4c0b8bf2710b X-Filterd-Recvd-Size: 4455 Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 20:56:21 +0000 (UTC) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 14 Sep 2020 13:56:07 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 14 Sep 2020 13:56:20 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 14 Sep 2020 13:56:20 -0700 Received: from [10.2.52.22] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 14 Sep 2020 20:56:19 +0000 Subject: Re: [PATCH] mm/gup.c: Handling ERR within unpin_user_pages() To: Souptick Joarder , Jason Gunthorpe CC: Matthew Wilcox , Andrew Morton , Linux-MM , References: <1600007555-11650-1-git-send-email-jrdr.linux@gmail.com> <20200913145520.GH6583@casper.infradead.org> <20200914140814.GE1221970@ziepe.ca> From: John Hubbard Message-ID: Date: Mon, 14 Sep 2020 13:56:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1600116967; bh=+oWEarvEQBjCBkRKG8S6c1RiGqvrOZjaYdIkoM8VZak=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=lxOEgomUBCeFRQfM06OboOEEMpuSYIM1iyaBr3WI8AKriJzrsnI1SRg08LANEPTYv U7L8Nc3YNQbbNqdGzEiEhnjxPnM+hEaAdwn13wHAy/lUry/ocsvIVzA4Sy9GWRy0wL nTz3ChKIy0byq8u7cc7O8VpdxADX7YnR7ulzMEwR0WL5eRaRXAnMOyja8gCNQBdRLS q8pqDeF8wsICChU8kSfv7p6jCNjh5/fyOG6CRPm9bolkr/fLhWbxGoqAtDpS1hH8Pf fFKR7wx8HsG1Y0RJmRhgVAvByGa07r+Wy8f+Eugz8bj8TfwP5JsiaNT3/5M4MNqm0W qo1FTAerE34dg== X-Rspamd-Queue-Id: 5B00318038E68 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: On 9/14/20 1:52 PM, Souptick Joarder wrote: > On Mon, Sep 14, 2020 at 7:38 PM Jason Gunthorpe wrote: >> >> On Mon, Sep 14, 2020 at 07:20:34AM +0530, Souptick Joarder wrote: >>> On Sun, Sep 13, 2020 at 8:25 PM Matthew Wilcox wrote: >>>> >>>> On Sun, Sep 13, 2020 at 08:02:35PM +0530, Souptick Joarder wrote: >>>>> It is possible that a buggy caller of unpin_user_pages() >>>>> (specially in error handling path) may end up calling it with >>>>> npages < 0 which is unnecessary. >>>>> @@ -328,6 +328,9 @@ void unpin_user_pages(struct page **pages, unsigned long npages) >>>>> { >>>>> unsigned long index; >>>>> >>>>> + if (WARN_ON_ONCE(npages < 0)) >>>>> + return; >>>> >>>> But npages is unsigned long. So it can't be less than zero. >>> >>> Sorry, I missed it. >>> >>> Then, it means if npages is assigned with -ERRNO by caller, unpin_user_pages() >>> may end up calling a big loop, which is unnecessary. >> >> How will a caller allocate memory of the right size and still manage >> to call with the wrong npages? Do you have an example of a broken caller? > > These are two broken callers which might end up calling unpin_user_pages() > with -ERRNO. > drivers/rapidio/devices/rio_mport_cdev.c#L952 > drivers/misc/mic/scif/scif_rma.c#L1399 > > They both are in error handling paths, so might not have any serious impact. > But theoretically possible. > Eventually, I settled on fixing up the callers so that they match the gup/pup API better. In other words, gup/pup has signed int for both input and return value, and the callers need to handle that perfectly. So let's fix up the callers. thanks, -- John Hubbard NVIDIA