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=-0.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 01DB6C04AB5 for ; Mon, 3 Jun 2019 17:12:08 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 46967275D7 for ; Mon, 3 Jun 2019 17:12:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="WxopflXf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 46967275D7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 45HhS51K7rzDqRS for ; Tue, 4 Jun 2019 03:12:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=linuxfoundation.org (client-ip=2a00:1450:4864:20::241; helo=mail-lj1-x241.google.com; envelope-from=torvalds@linuxfoundation.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="WxopflXf"; dkim-atps=neutral Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45HhQd0Vd1zDqNp for ; Tue, 4 Jun 2019 03:10:48 +1000 (AEST) Received: by mail-lj1-x241.google.com with SMTP id t28so5836544lje.9 for ; Mon, 03 Jun 2019 10:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O+yPhSShogh4P3ENVap3W5oMkAXveVWtK8AHmfJ6K4g=; b=WxopflXf16/Ij+BgtcycHtZ4Hmf9aaeOSPmXtzqGSQ8pDwEzPIMOBMYFkAoo4wEYeT 8VeRq+J0v+JDAfheb+586kInV+Sa1f85J5zB8gURyeRKoOLNnlPfX9pmOGSsXGwefMUi 0J3B6sJE1Hr8n5WVFsXQ5gn72CRPCxqM1IM0U= 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=O+yPhSShogh4P3ENVap3W5oMkAXveVWtK8AHmfJ6K4g=; b=H+OBrC44emRVyw5sr4voCH8HmIKqPPXZG5GqDoTf+bTF96r28MHLfuo/aiQRq30LaO 6st1f37u02loUKKjJWlN9uUlk+hNHAMIpSTfMdhyIOzV/g9YmzOJr18iKsEYqdbVt7/O JlcRxeo7G9YT1IJkZt9VPeM5WbAvxMArpnjxwS68Jwdvujeqg+O7DZvjWvbZkAypUJ1G OqN2mtj5bPtbN/lbZ5fMvbIVvHxw136INjaD2Qh+Q2pzsGO/e1dDXmKrh6O2ZBwOJqx5 i8TTWBzg2WgEF7zHsOBLZm6pQVc0B/Nj+Zo2vZGTltDk8TOOIKlJF0zAtpbZ6iWQH/lx 3aQw== X-Gm-Message-State: APjAAAVXfo4Pq94rESNI2cEsvGgmC0MYwLwPBoRfUy/Pkm1raHkXZ2VN qY2xofIPNvkf2/hE6kKH4FMdi2XOaaU= X-Google-Smtp-Source: APXvYqx7fW8731hZtOFw40tDQ3a1UQhCKhUWSKSjS9j2DuNVLzN0T2SioAQWFuFKWzIYC2ZFb/W44g== X-Received: by 2002:a2e:8591:: with SMTP id b17mr3198262lji.71.1559581840087; Mon, 03 Jun 2019 10:10:40 -0700 (PDT) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com. [209.85.167.46]) by smtp.gmail.com with ESMTPSA id k12sm3233941lfm.90.2019.06.03.10.10.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 10:10:39 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id a25so14218878lfg.2 for ; Mon, 03 Jun 2019 10:10:39 -0700 (PDT) X-Received: by 2002:a19:2d41:: with SMTP id t1mr13904609lft.79.1559581346039; Mon, 03 Jun 2019 10:02:26 -0700 (PDT) MIME-Version: 1.0 References: <20190601074959.14036-1-hch@lst.de> <20190601074959.14036-4-hch@lst.de> <20190603074121.GA22920@lst.de> In-Reply-To: From: Linus Torvalds Date: Mon, 3 Jun 2019 10:02:10 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 03/16] mm: simplify gup_fast_permitted To: Christoph Hellwig Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rich Felker , Yoshinori Sato , Linux-sh list , James Hogan , the arch/x86 maintainers , Khalid Aziz , Nicholas Piggin , linux-mips@vger.kernel.org, Linux-MM , Paul Burton , Paul Mackerras , Andrey Konovalov , sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "David S. Miller" , Linux List Kernel Mailing Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, Jun 3, 2019 at 9:08 AM Linus Torvalds wrote: > > The new code has no test at all for "nr_pages == 0", afaik. Note that it really is important to check for that, because right now we do if (gup_fast_permitted(start, nr_pages)) { local_irq_save(flags); gup_pgd_range(start, end, write ? FOLL_WRITE : 0, pages, &nr); local_irq_restore(flags); } and that gup_pgd_range() function *depends* on the range being non-zero, and does pgdp = pgd_offset(current->mm, addr); do { pgd_t pgd = READ_ONCE(*pgdp); ... } while (pgdp++, addr = next, addr != end); Note how a zero range would turn into an infinite range here. And the only check for 0 was that if (nr_pages <= 0) return 0; in get_user_pages_fast() that you removed. (Admittedly, it would be much better to have that check in __get_user_pages_fast() itself, because we do have callers that call the double-underscore version) Now, I sincerely hope that we don't have anybody that passes in a zero nr_pages (or a negative one), but we do actually have a comment saying it's ok. Note that the check for "if (end < start)" not only does not check for 0, it also doesn't really check for negative. It checks for _overflow_. Admittedly most negative values would be expected to overflow, but it's still a very different issue. Maybe you added the check for negative somewhere else (in another patch), but I don't see it. Linus