All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: 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: Mon, 30 Aug 2021 18:55:02 +0800	[thread overview]
Message-ID: <CALOAHbB8YSBUwwU2S6vBbhUPzEezNXgaPfhzJzBA6X5zfaRW+g@mail.gmail.com> (raw)
In-Reply-To: <YSyuB11GjXg4MBig@infradead.org>

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.

#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


  reply	other threads:[~2021-08-30 10:55 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 [this message]
2021-08-31  1:36         ` Kirill A. Shutemov
2021-08-31 12:32           ` Yafang Shao

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=CALOAHbB8YSBUwwU2S6vBbhUPzEezNXgaPfhzJzBA6X5zfaRW+g@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=kirill.shutemov@linux.intel.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.