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=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 D8B90C432BE for ; Tue, 31 Aug 2021 12:32:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7802E6103E for ; Tue, 31 Aug 2021 12:32:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7802E6103E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9BD946B0071; Tue, 31 Aug 2021 08:32:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 947256B0072; Tue, 31 Aug 2021 08:32:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C0076B0073; Tue, 31 Aug 2021 08:32:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id 676C96B0071 for ; Tue, 31 Aug 2021 08:32:43 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 116221814C6FC for ; Tue, 31 Aug 2021 12:32:43 +0000 (UTC) X-FDA: 78535314606.18.9C30042 Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) by imf18.hostedemail.com (Postfix) with ESMTP id 704844002092 for ; Tue, 31 Aug 2021 12:32:42 +0000 (UTC) Received: by mail-il1-f171.google.com with SMTP id i13so19734568ilm.4 for ; Tue, 31 Aug 2021 05:32:42 -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=fr66vStjdEuQWSF5Yhl4gfsuunAgXNe9T3yYh3NS55g=; b=jF3A+gqK/voliTRQoMHU0lFbqIK0AD83iUduwY+mxP6FEVqjkA8zCiBA0ZOkv9BkyS TqYk18dWFiQSBlrLhphKJJVa0Ng7A8VG5lMWKMj+DCFtaPmiijRaTM++RTtulM3ZoQ3E goNfLT2rNVKs+HDvrnr3eTKfW4vBxyHtIrcwbYXscFr430xXSe0ORfef+tF9QhUnfQqy xm11UTlMRkK5JaMOJ37fvhgIu1aK7KmhV3XrmhaBg06IcHZZSA23x1Coq0M10jh0edHn OGMITmmZ7VPfiFgK0Lzat+5Y3SiR+ShuwePVIffu/o9hwvIpwBE65rANWSxUvGpxfo6A PQ3w== 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=fr66vStjdEuQWSF5Yhl4gfsuunAgXNe9T3yYh3NS55g=; b=tYGprP2ivtoo1Yq+oAfdqDMuwfdPW3+aLEs9+DYbZgmFtEqEEYhQsxX18/toTl5FAQ GMBmiUBFqSZq2vL3JJCFcdkQjr0PWduS8zSifFszfi7s6U4xckxCOSIw0ghN3YqX/lU5 QP9iuj489w48DLJQA4NIECd2w2rP1rh+fA7V3RkLWAdktvPvUG85aoyZrEX06+hmE2Av OOsuLaGHv5vbsO+Sh4OLD3CG0c/4lO6nNa5qkqFmXwNlRsK2zW773AmaD+hcVmPobHDV arfKp9eoLd4HLLcTlwYeb8YUnKeiluJzXOXwwbWkl/pxWEwMOfObsfv6tpTvBzEflHX9 xIRw== X-Gm-Message-State: AOAM532l9Sgju5K85+niHIJ0KFmNdf9ZwaibiHpza4BrAnbOAjQxkATM BJwRjye7bmrfk9knK6HbHkp5BvxzWsQhdFNqyVw= X-Google-Smtp-Source: ABdhPJyKy5ZFhzw2Tuk/r2a7soAATTeq7hPr6PkCT+LKuEL5HL5gT9H/nSPWtDOvKUDWYMLG9gSbk/nuYJ6+8sfy8ms= X-Received: by 2002:a05:6e02:1aa2:: with SMTP id l2mr20394732ilv.168.1630413161726; Tue, 31 Aug 2021 05:32:41 -0700 (PDT) MIME-Version: 1.0 References: <20210829011953.9051-1-laoar.shao@gmail.com> <20210831013647.3ipichkrvpxmcnqc@box.shutemov.name> In-Reply-To: <20210831013647.3ipichkrvpxmcnqc@box.shutemov.name> From: Yafang Shao Date: Tue, 31 Aug 2021 20:32:05 +0800 Message-ID: Subject: Re: [PATCH] mm, gpu: fix error when FOLL_MLOCK an unpresent page To: "Kirill A. Shutemov" Cc: Christoph Hellwig , Andrew Morton , Linux MM , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=jF3A+gqK; spf=pass (imf18.hostedemail.com: domain of laoarshao@gmail.com designates 209.85.166.171 as permitted sender) smtp.mailfrom=laoarshao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: y6f8kiea58x8t87iyqkcozzod6qfkcg5 X-Rspamd-Queue-Id: 704844002092 X-Rspamd-Server: rspam04 X-HE-Tag: 1630413162-641065 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 Tue, Aug 31, 2021 at 9:36 AM Kirill A. Shutemov wrote: > > On Mon, Aug 30, 2021 at 06:55:02PM +0800, Yafang Shao wrote: > > On Mon, Aug 30, 2021 at 6:08 PM Christoph Hellwig wrote: > > > > > > On Mon, Aug 30, 2021 at 05:12:32PM +0800, Yafang Shao wrote: > > > > > Which is not a valid way to call get_user_pages. What we need to do is > > > > > to reject that case. > > > > > > > > Do you mean below change ? > > > > > > Sory of. I think once touching this we should do a few more cleanups > > > including making many of the flags private to gup.c. I'll try to find > > > some time to post a more complete series. > > > > JFYI, below test case can also hit the bug I reported above. > > How does the bug manifests with the test case? I don't see any crash with > it in my setup. > > Or do you mean you can hit __get_user_pages() with FOLL_MLOCK, but without > FOLL_POPULATE? > Right, that is what I meant. > My guess is that you have wrong expectation from GUP: it will return a > number of pages it advanced in the mapping, not number of present pages > there. For your case it means that the array of pages can have gaps and > it's okay. > Right, I misunderstood __get_user_pages(). Thanks for the explanation. > Fill the array with zeros before calling GUP and check if the entry is > non-NULL before dereferencing it. > Sure. > > > > #define _GNU_SOURCE > > #include > > #include > > > > #define LEN 4096 > > > > int main() > > { > > char *addr; > > int ret; > > > > addr = mmap(NULL, LEN, PROT_READ|PROT_WRITE, MAP_PRIVATE | > > MAP_ANON , -1, 0); > > if (addr == MAP_FAILED) { > > perror("mmap"); > > return ret; > > } > > > > /* > > * MLOCK_ONFAULT will hit below if condition. > > * if ((*flags & (FOLL_POPULATE | FOLL_MLOCK)) == FOLL_MLOCK) > > * return -ENOENT; > > */ > > ret = mlock2(addr, LEN, MLOCK_ONFAULT); > > // ret = mlock2(addr, LEN, 0); > > if (ret < 0) { > > perror("mlock2"); > > return ret; > > } > > > > return 0; > > } > > > > -- > > Thanks > > Yafang > > > > -- > Kirill A. Shutemov -- Thanks Yafang