linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Linux MM <linux-mm@kvack.org>,
	 "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH] mm, gpu: fix error when FOLL_MLOCK an unpresent page
Date: Tue, 31 Aug 2021 20:32:05 +0800	[thread overview]
Message-ID: <CALOAHbB7MxrbBDJAxyRU3wFv915FtS3RcK0k5zJ+85eD1vrwSg@mail.gmail.com> (raw)
In-Reply-To: <20210831013647.3ipichkrvpxmcnqc@box.shutemov.name>

On Tue, Aug 31, 2021 at 9:36 AM Kirill A. Shutemov <kirill@shutemov.name> 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 <hch@infradead.org> 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 <stdio.h>
> > #include <sys/mman.h>
> >
> > #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


      reply	other threads:[~2021-08-31 12:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-29  1:19 [PATCH] mm, gpu: fix error when FOLL_MLOCK an unpresent page Yafang Shao
2021-08-30  7:00 ` Christoph Hellwig
2021-08-30  9:12   ` Yafang Shao
2021-08-30 10:08     ` Christoph Hellwig
2021-08-30 10:55       ` Yafang Shao
2021-08-31  1:36         ` Kirill A. Shutemov
2021-08-31 12:32           ` Yafang Shao [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALOAHbB7MxrbBDJAxyRU3wFv915FtS3RcK0k5zJ+85eD1vrwSg@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).