Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2453825pxk; Mon, 14 Sep 2020 13:54:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRKqyrHjyOQ6Qi/kLbg7rbaK9RvNiw4UVnMvF65b7ARBRv82RXJlXalDPbvozV/oy7liy9 X-Received: by 2002:a17:906:60d3:: with SMTP id f19mr17097730ejk.141.1600116873418; Mon, 14 Sep 2020 13:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600116873; cv=none; d=google.com; s=arc-20160816; b=qwaW0/LUjGDGYhso5vxYGGHO7rlspa/E7SnPMajTBGtMFZoJHFZdVu619dKBk30QQF Q/WSQpTWXxes5unftRCgQuZQKm6MsRvDodd58lzpvzta92i+AA/d+f1ST5wZAw2COyDQ hG28q+GcxcEyvAOUz0Nen0JK94f0tnNghk6uwSYh7TUt8cwI1tNnabCJjqPju1lIf9a/ Xe/zo+wTyc/l0evzxD9AIbkKUWFMEv0BHrxYLqTAdHLNuOqTUWhwco9VTBzrS7Wuwe8x NMzbRukj0NikKKMcgK9G97uLNzP3vZSPM+936N8MRw0o8CAD79hRNq1tHsFGrSoonAge xGJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=t1FP4AWnie2gjJ2+aQoHhQuSZMsBtLy6T/hgMEanh9c=; b=ZQAGOP+2hamtoYr02PUYvqSySU/+tfY+UnbQDN1yoZtduXL3ffO4i1TXXZbY4Yfmy/ sBWuEAkySfJNGk12gUTVSghXt12uv7mZQ5tmp00Gc/MBc8Wpu2dSA+wrY76xPGuEG2XM F+uCaFdYOrNbhV7i3nfLP3q1Oh5RfBaMJdEORaGpZ4MjOWtJvPJ5TiiuUH49H5heX4q8 jAYvA+jZEVBEmc8VisaqDRiG2VEEQew6yrRVaLMfZT9QVL5lcDhFn2MiORTjbzGNkBdc r3xAAoKw44ZrwQ3bTHMYcAEnMZrcQm8Gbi4Ym7LlPrDSjaIj1WsaaprHk5Wu/27Ju0y5 6mWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ZjGO/JUJ"; 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 f6si1813271edc.423.2020.09.14.13.54.11; Mon, 14 Sep 2020 13:54:33 -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="ZjGO/JUJ"; 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 S1726244AbgINUwu (ORCPT + 99 others); Mon, 14 Sep 2020 16:52:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726062AbgINUws (ORCPT ); Mon, 14 Sep 2020 16:52:48 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7DF5C06174A for ; Mon, 14 Sep 2020 13:52:46 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id x69so768136lff.3 for ; Mon, 14 Sep 2020 13:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=t1FP4AWnie2gjJ2+aQoHhQuSZMsBtLy6T/hgMEanh9c=; b=ZjGO/JUJ1x3wgc51FKgZnYti+5XGDOnE976o9x4witZRtmCeaTcv5mfWN3lnNeRG05 Jnzc/hwQnJDND5G1g4jX3abSBcfjYfXDM4QHOxv6aYN2SxX48UnMQW2WLoUgrX2qCD0R 1Loc/e6NuAoyrlubjERjsWCqn5a6aZD7mMdhOwk1tgl0XukhLF37EbGYxMuEIWAIyYrZ WQeJZGRMx5QwqijZO2nynQjBz5l6mMqAnaJDzE4NaRYqCndBa9vcy+ZfTyJI4GWBXO0b pYC3AHRpFqmI3//nOBpoyXWhUiDmf+WQGw2fVz9+m68Fs3Meg815lB6RatDm462cKD79 5Qkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=t1FP4AWnie2gjJ2+aQoHhQuSZMsBtLy6T/hgMEanh9c=; b=HdK/OqN/Goug65ZDd/jWMUhijmf64AQBtoN8Ecijhj8RksclZNMU1C/w2dZkJOuex/ 0tIFxgfZULa07ACUCvphzQJwpe6r1WoEYo3UB+AnFOeVx84g8tE/C84wp6u/28Dtxh0A /Tt1jPjUgVMdFsidryUnG5M/GO6xKnkndY7+LruVdzaO5R4l/PCAvuyHgrpRu0QstuJM UXoN+l1Gw4vJaaCkDBaQMF811ZWTccfyEIF1KHMPS4M0yufAwkiCty+VGHFVkdwIg3/K 5mSUULF/sNSLjjpIc75QvFTFggOEwIaA3uSWH+11QHf48zMNvx/po4LsswbrLRHtkU/U wW+Q== X-Gm-Message-State: AOAM531Ne2QkhKMZHGRL01YrIurx8nEiafJj1WDLDofA/0zlMwdSZQIU EH0kEREIHshWXmYtylKYzci4MCC9LsLoqx3AHt+olm40ULGMZg== X-Received: by 2002:a19:c801:: with SMTP id y1mr4642218lff.217.1600116765367; Mon, 14 Sep 2020 13:52:45 -0700 (PDT) MIME-Version: 1.0 References: <1600007555-11650-1-git-send-email-jrdr.linux@gmail.com> <20200913145520.GH6583@casper.infradead.org> <20200914140814.GE1221970@ziepe.ca> In-Reply-To: <20200914140814.GE1221970@ziepe.ca> From: Souptick Joarder Date: Tue, 15 Sep 2020 02:22:33 +0530 Message-ID: Subject: Re: [PATCH] mm/gup.c: Handling ERR within unpin_user_pages() To: Jason Gunthorpe Cc: Matthew Wilcox , Andrew Morton , Linux-MM , linux-kernel@vger.kernel.org, John Hubbard Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.