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=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 8CAF9C433E2 for ; Mon, 14 Sep 2020 14:08:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E1F212074B for ; Mon, 14 Sep 2020 14:08:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="grP9mBb4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1F212074B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 447346B0068; Mon, 14 Sep 2020 10:08:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F5996B006C; Mon, 14 Sep 2020 10:08:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 295A26B006E; Mon, 14 Sep 2020 10:08:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0149.hostedemail.com [216.40.44.149]) by kanga.kvack.org (Postfix) with ESMTP id 13F126B0068 for ; Mon, 14 Sep 2020 10:08:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A65DC180AD820 for ; Mon, 14 Sep 2020 14:08:19 +0000 (UTC) X-FDA: 77261846718.28.gun95_0a06dfc27109 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 431D01DFF for ; Mon, 14 Sep 2020 14:08:17 +0000 (UTC) X-HE-Tag: gun95_0a06dfc27109 X-Filterd-Recvd-Size: 4269 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 14:08:16 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id y9so9048622ilq.2 for ; Mon, 14 Sep 2020 07:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fctxu7rmqR9iwM1SRRmUo1RPPdPeoBrrnFYgiya+56E=; b=grP9mBb4KNUrt6s5j5aZDliofeFad5VWpNdpG7QV94Lq30LC+iL4EExE7kyGKWB5Gf /gSh5AyuAed2NYgfVl+TGjM6+PvxmXzc4hKIQBH3SfoUY3P3t1LV4232yJI75e/YJNG6 Q+FpLdX/A/RXeNFtq9e2HUk91tNk7d+VWEdYqzgF6WJmp5TR26CFRkEIeLDEiTdr9ACA 91aJyHqx2eQWN4Z4enVwN2LT4t1ICt9n0QjRRgL80aVofbYWfiyzEIrTWcE0URGKvlZS 8W5ulQtbKbTyaYpofTmquomWBpZFd+9ywGLaRsd5cZ9vgh5cJeBQ4LzVp0OOFE78katd Sm9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fctxu7rmqR9iwM1SRRmUo1RPPdPeoBrrnFYgiya+56E=; b=cOV3mIU4m4Tx8WHCUI091tUhR97H9KcsJLQkaAB9wBnpHescyave/G55gJxf3UBPlL 0XetZcjs0go4BmPkg/AD6i/DEe2nU303Itr0dp1YJNo8eiuuneCS5HpTApYTIoBT+eTo kl2TPT6STZPNv9Oo+bLxa3S0EP5jZkBO+b//+F+CaWWFMrq3sMqutJzN3D1Kw25HDaYh jZ0t6rGg+xyZuFbev1fCBU43HAipHOQGbiXXjzR9RRCtztfUo+AVMVQwGYG5TQwWXhFR 7hkROiHoTQEjR4V1WZqQcseOtk3zbuehkykms9RQxRLP+2lJzkaIOOEmBXR3h2nUbDoj j5Ww== X-Gm-Message-State: AOAM533CLFFUnYUui8wFkiUUhd4FxmsbowDEOM1sI3Jrr9ZMcubXxcUN p56+7HTc51S9jaK3JDPX9+Fm0lT7NkMKrA== X-Google-Smtp-Source: ABdhPJxqHuHFmUi4XSYUrDn5jbXri907X+UgEsG3mAQAgDE1Hk4Av6GNH2lJfQO/tH0rRUWPkMdG3w== X-Received: by 2002:a92:5893:: with SMTP id z19mr3854498ilf.158.1600092495877; Mon, 14 Sep 2020 07:08:15 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id c12sm6771213ilm.17.2020.09.14.07.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 07:08:15 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kHp9S-005y8Y-9k; Mon, 14 Sep 2020 11:08:14 -0300 Date: Mon, 14 Sep 2020 11:08:14 -0300 From: Jason Gunthorpe To: Souptick Joarder Cc: Matthew Wilcox , Andrew Morton , Linux-MM , linux-kernel@vger.kernel.org, John Hubbard Subject: Re: [PATCH] mm/gup.c: Handling ERR within unpin_user_pages() Message-ID: <20200914140814.GE1221970@ziepe.ca> References: <1600007555-11650-1-git-send-email-jrdr.linux@gmail.com> <20200913145520.GH6583@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 431D01DFF X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 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? Jason