linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM
@ 2020-08-19 11:01 Barry Song
  2020-08-19 17:44 ` Ira Weiny
  2020-08-19 18:14 ` John Hubbard
  0 siblings, 2 replies; 7+ messages in thread
From: Barry Song @ 2020-08-19 11:01 UTC (permalink / raw)
  To: akpm, linux-mm, linux-kernel
  Cc: linuxarm, Barry Song, John Hubbard, Jan Kara,
	Jérôme Glisse, Matthew Wilcox (Oracle),
	Al Viro, Christoph Hellwig, Dan Williams, Dave Chinner,
	Jason Gunthorpe, Jonathan Corbet, Michal Hocko, Mike Kravetz,
	Shuah Khan, Vlastimil Babka

gug prohibits users from calling get_user_pages() with FOLL_PIN. But it
allows users to call get_user_pages() with FOLL_LONGTERM only. It seems
insensible.

since FOLL_LONGTERM is a stricter case of FOLL_PIN, we should prohibit
users from calling get_user_pages() with FOLL_LONGTERM while not with
FOLL_PIN.

mm/gup_benchmark.c used to be the only user who did this improperly.
But it has been fixed by moving to use pin_user_pages().

Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
---
 mm/gup.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index ae096ea7583f..4da669f79566 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1789,6 +1789,25 @@ static long __get_user_pages_remote(struct mm_struct *mm,
 				       gup_flags | FOLL_TOUCH | FOLL_REMOTE);
 }
 
+static bool is_valid_gup_flags(unsigned int gup_flags)
+{
+	/*
+	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
+	 * never directly by the caller, so enforce that with an assertion:
+	 */
+	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
+		return false;
+	/*
+	 * FOLL_PIN is a prerequisite to FOLL_LONGTERM. Another way of saying
+	 * that is, FOLL_LONGTERM is a specific case, more restrictive case of
+	 * FOLL_PIN.
+	 */
+	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
+		return false;
+
+	return true;
+}
+
 /**
  * get_user_pages_remote() - pin user pages in memory
  * @mm:		mm_struct of target mm
@@ -1854,11 +1873,7 @@ long get_user_pages_remote(struct mm_struct *mm,
 		unsigned int gup_flags, struct page **pages,
 		struct vm_area_struct **vmas, int *locked)
 {
-	/*
-	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
-	 * never directly by the caller, so enforce that with an assertion:
-	 */
-	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
+	if (!is_valid_gup_flags(gup_flags))
 		return -EINVAL;
 
 	return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
@@ -1904,11 +1919,7 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
 		unsigned int gup_flags, struct page **pages,
 		struct vm_area_struct **vmas)
 {
-	/*
-	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
-	 * never directly by the caller, so enforce that with an assertion:
-	 */
-	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
+	if (!is_valid_gup_flags(gup_flags))
 		return -EINVAL;
 
 	return __gup_longterm_locked(current->mm, start, nr_pages,
@@ -2810,11 +2821,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast_only);
 int get_user_pages_fast(unsigned long start, int nr_pages,
 			unsigned int gup_flags, struct page **pages)
 {
-	/*
-	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
-	 * never directly by the caller, so enforce that:
-	 */
-	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
+	if (!is_valid_gup_flags(gup_flags))
 		return -EINVAL;
 
 	/*
-- 
2.27.0




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM
  2020-08-19 11:01 [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM Barry Song
@ 2020-08-19 17:44 ` Ira Weiny
  2020-08-19 18:14 ` John Hubbard
  1 sibling, 0 replies; 7+ messages in thread
From: Ira Weiny @ 2020-08-19 17:44 UTC (permalink / raw)
  To: Barry Song
  Cc: akpm, linux-mm, linux-kernel, linuxarm, John Hubbard, Jan Kara,
	Jérôme Glisse, Matthew Wilcox (Oracle),
	Al Viro, Christoph Hellwig, Dan Williams, Dave Chinner,
	Jason Gunthorpe, Jonathan Corbet, Michal Hocko, Mike Kravetz,
	Shuah Khan, Vlastimil Babka

On Wed, Aug 19, 2020 at 11:01:00PM +1200, Barry Song wrote:
> gug prohibits users from calling get_user_pages() with FOLL_PIN. But it
> allows users to call get_user_pages() with FOLL_LONGTERM only. It seems
> insensible.
> 
> since FOLL_LONGTERM is a stricter case of FOLL_PIN, we should prohibit
> users from calling get_user_pages() with FOLL_LONGTERM while not with
> FOLL_PIN.
> 
> mm/gup_benchmark.c used to be the only user who did this improperly.
> But it has been fixed by moving to use pin_user_pages().
> 
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Jérôme Glisse <jglisse@redhat.com>
> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Dave Chinner <david@fromorbit.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>

Seems reasonable to me.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> ---
>  mm/gup.c | 37 ++++++++++++++++++++++---------------
>  1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index ae096ea7583f..4da669f79566 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1789,6 +1789,25 @@ static long __get_user_pages_remote(struct mm_struct *mm,
>  				       gup_flags | FOLL_TOUCH | FOLL_REMOTE);
>  }
>  
> +static bool is_valid_gup_flags(unsigned int gup_flags)
> +{
> +	/*
> +	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> +	 * never directly by the caller, so enforce that with an assertion:
> +	 */
> +	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +		return false;
> +	/*
> +	 * FOLL_PIN is a prerequisite to FOLL_LONGTERM. Another way of saying
> +	 * that is, FOLL_LONGTERM is a specific case, more restrictive case of
> +	 * FOLL_PIN.
> +	 */
> +	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
> +		return false;
> +
> +	return true;
> +}
> +
>  /**
>   * get_user_pages_remote() - pin user pages in memory
>   * @mm:		mm_struct of target mm
> @@ -1854,11 +1873,7 @@ long get_user_pages_remote(struct mm_struct *mm,
>  		unsigned int gup_flags, struct page **pages,
>  		struct vm_area_struct **vmas, int *locked)
>  {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that with an assertion:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>  		return -EINVAL;
>  
>  	return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
> @@ -1904,11 +1919,7 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
>  		unsigned int gup_flags, struct page **pages,
>  		struct vm_area_struct **vmas)
>  {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that with an assertion:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>  		return -EINVAL;
>  
>  	return __gup_longterm_locked(current->mm, start, nr_pages,
> @@ -2810,11 +2821,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast_only);
>  int get_user_pages_fast(unsigned long start, int nr_pages,
>  			unsigned int gup_flags, struct page **pages)
>  {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>  		return -EINVAL;
>  
>  	/*
> -- 
> 2.27.0
> 
> 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM
  2020-08-19 11:01 [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM Barry Song
  2020-08-19 17:44 ` Ira Weiny
@ 2020-08-19 18:14 ` John Hubbard
  2020-09-03  7:12   ` Souptick Joarder
  1 sibling, 1 reply; 7+ messages in thread
From: John Hubbard @ 2020-08-19 18:14 UTC (permalink / raw)
  To: Barry Song, akpm, linux-mm, linux-kernel
  Cc: linuxarm, Jan Kara, Jérôme Glisse,
	Matthew Wilcox (Oracle),
	Al Viro, Christoph Hellwig, Dan Williams, Dave Chinner,
	Jason Gunthorpe, Jonathan Corbet, Michal Hocko, Mike Kravetz,
	Shuah Khan, Vlastimil Babka

On 8/19/20 4:01 AM, Barry Song wrote:
> gug prohibits users from calling get_user_pages() with FOLL_PIN. But it

Maybe Andrew can fix the typo above: gug --> gup.


> allows users to call get_user_pages() with FOLL_LONGTERM only. It seems
> insensible.
> 
> since FOLL_LONGTERM is a stricter case of FOLL_PIN, we should prohibit
> users from calling get_user_pages() with FOLL_LONGTERM while not with
> FOLL_PIN.
> 
> mm/gup_benchmark.c used to be the only user who did this improperly.
> But it has been fixed by moving to use pin_user_pages().

For future patches, you don't have to write everything in the
commit log. Some things are better placed in a cover letter or after
the "---" line, because they don't need to be recorded forever.

Anyway, the diffs seem fine, assuming that you've audited the call sites.

thanks,
-- 
John Hubbard
NVIDIA

> 
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Jérôme Glisse <jglisse@redhat.com>
> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Dave Chinner <david@fromorbit.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
> ---
>   mm/gup.c | 37 ++++++++++++++++++++++---------------
>   1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index ae096ea7583f..4da669f79566 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1789,6 +1789,25 @@ static long __get_user_pages_remote(struct mm_struct *mm,
>   				       gup_flags | FOLL_TOUCH | FOLL_REMOTE);
>   }
>   
> +static bool is_valid_gup_flags(unsigned int gup_flags)
> +{
> +	/*
> +	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> +	 * never directly by the caller, so enforce that with an assertion:
> +	 */
> +	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +		return false;
> +	/*
> +	 * FOLL_PIN is a prerequisite to FOLL_LONGTERM. Another way of saying
> +	 * that is, FOLL_LONGTERM is a specific case, more restrictive case of
> +	 * FOLL_PIN.
> +	 */
> +	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
> +		return false;
> +
> +	return true;
> +}
> +
>   /**
>    * get_user_pages_remote() - pin user pages in memory
>    * @mm:		mm_struct of target mm
> @@ -1854,11 +1873,7 @@ long get_user_pages_remote(struct mm_struct *mm,
>   		unsigned int gup_flags, struct page **pages,
>   		struct vm_area_struct **vmas, int *locked)
>   {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that with an assertion:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>   		return -EINVAL;
>   
>   	return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
> @@ -1904,11 +1919,7 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
>   		unsigned int gup_flags, struct page **pages,
>   		struct vm_area_struct **vmas)
>   {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that with an assertion:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>   		return -EINVAL;
>   
>   	return __gup_longterm_locked(current->mm, start, nr_pages,
> @@ -2810,11 +2821,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast_only);
>   int get_user_pages_fast(unsigned long start, int nr_pages,
>   			unsigned int gup_flags, struct page **pages)
>   {
> -	/*
> -	 * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> -	 * never directly by the caller, so enforce that:
> -	 */
> -	if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> +	if (!is_valid_gup_flags(gup_flags))
>   		return -EINVAL;
>   
>   	/*
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM
  2020-08-19 18:14 ` John Hubbard
@ 2020-09-03  7:12   ` Souptick Joarder
  2020-09-03  7:23     ` John Hubbard
  2020-09-03 18:39     ` Matthew Wilcox
  0 siblings, 2 replies; 7+ messages in thread
From: Souptick Joarder @ 2020-09-03  7:12 UTC (permalink / raw)
  To: John Hubbard
  Cc: Barry Song, Andrew Morton, Linux-MM, linux-kernel, linuxarm,
	Jan Kara, Jérôme Glisse, Matthew Wilcox (Oracle),
	Al Viro, Christoph Hellwig, Dan Williams, Dave Chinner,
	Jason Gunthorpe, Jonathan Corbet, Michal Hocko, Mike Kravetz,
	Shuah Khan, Vlastimil Babka

On Wed, Aug 19, 2020 at 11:45 PM John Hubbard <jhubbard@nvidia.com> wrote:
>
> On 8/19/20 4:01 AM, Barry Song wrote:
> > gug prohibits users from calling get_user_pages() with FOLL_PIN. But it
>
> Maybe Andrew can fix the typo above: gug --> gup.
>
>
> > allows users to call get_user_pages() with FOLL_LONGTERM only. It seems
> > insensible.
> >
> > since FOLL_LONGTERM is a stricter case of FOLL_PIN, we should prohibit
> > users from calling get_user_pages() with FOLL_LONGTERM while not with
> > FOLL_PIN.
> >
> > mm/gup_benchmark.c used to be the only user who did this improperly.
> > But it has been fixed by moving to use pin_user_pages().
>
> For future patches, you don't have to write everything in the
> commit log. Some things are better placed in a cover letter or after
> the "---" line, because they don't need to be recorded forever.
>
> Anyway, the diffs seem fine, assuming that you've audited the call sites.

We can use is_valid_gup_flags() inside ->
get_user_pages_locked(),
get_user_pages_unlocked(),
pin_user_pages_locked() as well.

Are you planning to add it in future patches ?

>
> thanks,
> --
> John Hubbard
> NVIDIA
>
> >
> > Cc: John Hubbard <jhubbard@nvidia.com>
> > Cc: Jan Kara <jack@suse.cz>
> > Cc: Jérôme Glisse <jglisse@redhat.com>
> > Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> > Cc: Al Viro <viro@zeniv.linux.org.uk>
> > Cc: Christoph Hellwig <hch@infradead.org>
> > Cc: Dan Williams <dan.j.williams@intel.com>
> > Cc: Dave Chinner <david@fromorbit.com>
> > Cc: Jason Gunthorpe <jgg@ziepe.ca>
> > Cc: Jonathan Corbet <corbet@lwn.net>
> > Cc: Michal Hocko <mhocko@suse.com>
> > Cc: Mike Kravetz <mike.kravetz@oracle.com>
> > Cc: Shuah Khan <shuah@kernel.org>
> > Cc: Vlastimil Babka <vbabka@suse.cz>
> > Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
> > ---
> >   mm/gup.c | 37 ++++++++++++++++++++++---------------
> >   1 file changed, 22 insertions(+), 15 deletions(-)
> >
> > diff --git a/mm/gup.c b/mm/gup.c
> > index ae096ea7583f..4da669f79566 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -1789,6 +1789,25 @@ static long __get_user_pages_remote(struct mm_struct *mm,
> >                                      gup_flags | FOLL_TOUCH | FOLL_REMOTE);
> >   }
> >
> > +static bool is_valid_gup_flags(unsigned int gup_flags)
> > +{
> > +     /*
> > +      * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> > +      * never directly by the caller, so enforce that with an assertion:
> > +      */
> > +     if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> > +             return false;
> > +     /*
> > +      * FOLL_PIN is a prerequisite to FOLL_LONGTERM. Another way of saying
> > +      * that is, FOLL_LONGTERM is a specific case, more restrictive case of
> > +      * FOLL_PIN.
> > +      */
> > +     if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
> > +             return false;
> > +
> > +     return true;
> > +}
> > +
> >   /**
> >    * get_user_pages_remote() - pin user pages in memory
> >    * @mm:             mm_struct of target mm
> > @@ -1854,11 +1873,7 @@ long get_user_pages_remote(struct mm_struct *mm,
> >               unsigned int gup_flags, struct page **pages,
> >               struct vm_area_struct **vmas, int *locked)
> >   {
> > -     /*
> > -      * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> > -      * never directly by the caller, so enforce that with an assertion:
> > -      */
> > -     if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> > +     if (!is_valid_gup_flags(gup_flags))
> >               return -EINVAL;
> >
> >       return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
> > @@ -1904,11 +1919,7 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
> >               unsigned int gup_flags, struct page **pages,
> >               struct vm_area_struct **vmas)
> >   {
> > -     /*
> > -      * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> > -      * never directly by the caller, so enforce that with an assertion:
> > -      */
> > -     if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> > +     if (!is_valid_gup_flags(gup_flags))
> >               return -EINVAL;
> >
> >       return __gup_longterm_locked(current->mm, start, nr_pages,
> > @@ -2810,11 +2821,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast_only);
> >   int get_user_pages_fast(unsigned long start, int nr_pages,
> >                       unsigned int gup_flags, struct page **pages)
> >   {
> > -     /*
> > -      * FOLL_PIN must only be set internally by the pin_user_pages*() APIs,
> > -      * never directly by the caller, so enforce that:
> > -      */
> > -     if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
> > +     if (!is_valid_gup_flags(gup_flags))
> >               return -EINVAL;
> >
> >       /*
> >
>
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM
  2020-09-03  7:12   ` Souptick Joarder
@ 2020-09-03  7:23     ` John Hubbard
  2020-09-03 18:39     ` Matthew Wilcox
  1 sibling, 0 replies; 7+ messages in thread
From: John Hubbard @ 2020-09-03  7:23 UTC (permalink / raw)
  To: Souptick Joarder
  Cc: Barry Song, Andrew Morton, Linux-MM, linux-kernel, linuxarm,
	Jan Kara, Jérôme Glisse, Matthew Wilcox (Oracle),
	Al Viro, Christoph Hellwig, Dan Williams, Dave Chinner,
	Jason Gunthorpe, Jonathan Corbet, Michal Hocko, Mike Kravetz,
	Shuah Khan, Vlastimil Babka

On 9/3/20 12:12 AM, Souptick Joarder wrote:
> On Wed, Aug 19, 2020 at 11:45 PM John Hubbard <jhubbard@nvidia.com> wrote:
>>
>> On 8/19/20 4:01 AM, Barry Song wrote:
>>> gug prohibits users from calling get_user_pages() with FOLL_PIN. But it
>>
>> Maybe Andrew can fix the typo above: gug --> gup.
>>
>>
>>> allows users to call get_user_pages() with FOLL_LONGTERM only. It seems
>>> insensible.
>>>
>>> since FOLL_LONGTERM is a stricter case of FOLL_PIN, we should prohibit
>>> users from calling get_user_pages() with FOLL_LONGTERM while not with
>>> FOLL_PIN.
>>>
>>> mm/gup_benchmark.c used to be the only user who did this improperly.
>>> But it has been fixed by moving to use pin_user_pages().
>>
>> For future patches, you don't have to write everything in the
>> commit log. Some things are better placed in a cover letter or after
>> the "---" line, because they don't need to be recorded forever.
>>
>> Anyway, the diffs seem fine, assuming that you've audited the call sites.
> 
> We can use is_valid_gup_flags() inside ->
> get_user_pages_locked(),
> get_user_pages_unlocked(),
> pin_user_pages_locked() as well.

Probably it's best to discern between valid pup flags, and valid gup flags.
As in: separate functions for those. Maybe one is a subset of the other, but
still.

> 
> Are you planning to add it in future patches ?
> 

It's not on my list. I don't see anything wrong with doing so, other
than avoiding the minor pitfall I called out above. So if you want to
do that, then feel free...


thanks,
-- 
John Hubbard
NVIDIA


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM
  2020-09-03  7:12   ` Souptick Joarder
  2020-09-03  7:23     ` John Hubbard
@ 2020-09-03 18:39     ` Matthew Wilcox
  2020-09-05  1:11       ` Souptick Joarder
  1 sibling, 1 reply; 7+ messages in thread
From: Matthew Wilcox @ 2020-09-03 18:39 UTC (permalink / raw)
  To: Souptick Joarder
  Cc: John Hubbard, Barry Song, Andrew Morton, Linux-MM, linux-kernel,
	linuxarm, Jan Kara, Jérôme Glisse, Al Viro,
	Christoph Hellwig, Dan Williams, Dave Chinner, Jason Gunthorpe,
	Jonathan Corbet, Michal Hocko, Mike Kravetz, Shuah Khan,
	Vlastimil Babka

On Thu, Sep 03, 2020 at 12:42:44PM +0530, Souptick Joarder wrote:
> We can use is_valid_gup_flags() inside ->
> get_user_pages_locked(),
> get_user_pages_unlocked(),
> pin_user_pages_locked() as well.
> 
> Are you planning to add it in future patches ?

If you're looking for a new project, adding a foll_t or gup_t or
something for the FOLL flags (like we have for gfp_t or vm_fault_t)
would be helpful.  We're inconsistent with our naming here.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM
  2020-09-03 18:39     ` Matthew Wilcox
@ 2020-09-05  1:11       ` Souptick Joarder
  0 siblings, 0 replies; 7+ messages in thread
From: Souptick Joarder @ 2020-09-05  1:11 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: John Hubbard, Barry Song, Andrew Morton, Linux-MM, linux-kernel,
	linuxarm, Jan Kara, Jérôme Glisse, Al Viro,
	Christoph Hellwig, Dan Williams, Dave Chinner, Jason Gunthorpe,
	Jonathan Corbet, Michal Hocko, Mike Kravetz, Shuah Khan,
	Vlastimil Babka

On Fri, Sep 4, 2020 at 12:09 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Thu, Sep 03, 2020 at 12:42:44PM +0530, Souptick Joarder wrote:
> > We can use is_valid_gup_flags() inside ->
> > get_user_pages_locked(),
> > get_user_pages_unlocked(),
> > pin_user_pages_locked() as well.
> >
> > Are you planning to add it in future patches ?
>
> If you're looking for a new project, adding a foll_t or gup_t or
> something for the FOLL flags (like we have for gfp_t or vm_fault_t)
> would be helpful.  We're inconsistent with our naming here.

Sure. I will start looking into this and come up with a RFC version.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-09-05  1:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 11:01 [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM Barry Song
2020-08-19 17:44 ` Ira Weiny
2020-08-19 18:14 ` John Hubbard
2020-09-03  7:12   ` Souptick Joarder
2020-09-03  7:23     ` John Hubbard
2020-09-03 18:39     ` Matthew Wilcox
2020-09-05  1:11       ` Souptick Joarder

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).