2013-10-02 14:34:18

by Jan Kara

[permalink] [raw]
Subject: [PATCH 16/26] mm: Provide get_user_pages_unlocked()

Provide a wrapper for get_user_pages() which takes care of acquiring and
releasing mmap_sem. Using this function reduces amount of places in
which we deal with mmap_sem.

Signed-off-by: Jan Kara <[email protected]>
---
include/linux/mm.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8b6e55ee8855..70031ead06a5 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1031,6 +1031,20 @@ long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
struct vm_area_struct **vmas);
int get_user_pages_fast(unsigned long start, int nr_pages, int write,
struct page **pages);
+static inline long
+get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
+ unsigned long start, unsigned long nr_pages,
+ int write, int force, struct page **pages)
+{
+ long ret;
+
+ down_read(&mm->mmap_sem);
+ ret = get_user_pages(tsk, mm, start, nr_pages, write, force, pages,
+ NULL);
+ up_read(&mm->mmap_sem);
+ return ret;
+}
+
struct kvec;
int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
struct page **pages);
--
1.8.1.4


2013-10-02 16:25:20

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 16/26] mm: Provide get_user_pages_unlocked()

On Wed, Oct 02, 2013 at 04:27:57PM +0200, Jan Kara wrote:
> Provide a wrapper for get_user_pages() which takes care of acquiring and
> releasing mmap_sem. Using this function reduces amount of places in
> which we deal with mmap_sem.
>
> Signed-off-by: Jan Kara <[email protected]>

Seem like this should be the default one and the one without the locked
should be __unlocked. Maybe a grand rename is in order?


get_user_pages_fast -> get_user_pages
get_user_pages_unlocked -> __get_user_pages
get_user_pages_unlocked -> __get_user_pages_locked

steering people to the most sensible ones by default?

2013-10-02 16:27:37

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH 16/26] mm: Provide get_user_pages_unlocked()

(10/2/13 10:27 AM), Jan Kara wrote:
> Provide a wrapper for get_user_pages() which takes care of acquiring and
> releasing mmap_sem. Using this function reduces amount of places in
> which we deal with mmap_sem.
>
> Signed-off-by: Jan Kara <[email protected]>
> ---
> include/linux/mm.h | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 8b6e55ee8855..70031ead06a5 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1031,6 +1031,20 @@ long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
> struct vm_area_struct **vmas);
> int get_user_pages_fast(unsigned long start, int nr_pages, int write,
> struct page **pages);
> +static inline long
> +get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
> + unsigned long start, unsigned long nr_pages,
> + int write, int force, struct page **pages)
> +{
> + long ret;
> +
> + down_read(&mm->mmap_sem);
> + ret = get_user_pages(tsk, mm, start, nr_pages, write, force, pages,
> + NULL);
> + up_read(&mm->mmap_sem);
> + return ret;
> +}

Hmmm. I like the idea, but I really dislike this name. I don't like xx_unlocked
function takes a lock. It is a source of confusing, I believe.






2013-10-02 19:39:37

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 16/26] mm: Provide get_user_pages_unlocked()

On Wed 02-10-13 12:28:11, KOSAKI Motohiro wrote:
> (10/2/13 10:27 AM), Jan Kara wrote:
> > Provide a wrapper for get_user_pages() which takes care of acquiring and
> > releasing mmap_sem. Using this function reduces amount of places in
> > which we deal with mmap_sem.
> >
> > Signed-off-by: Jan Kara <[email protected]>
> > ---
> > include/linux/mm.h | 14 ++++++++++++++
> > 1 file changed, 14 insertions(+)
> >
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index 8b6e55ee8855..70031ead06a5 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -1031,6 +1031,20 @@ long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
> > struct vm_area_struct **vmas);
> > int get_user_pages_fast(unsigned long start, int nr_pages, int write,
> > struct page **pages);
> > +static inline long
> > +get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
> > + unsigned long start, unsigned long nr_pages,
> > + int write, int force, struct page **pages)
> > +{
> > + long ret;
> > +
> > + down_read(&mm->mmap_sem);
> > + ret = get_user_pages(tsk, mm, start, nr_pages, write, force, pages,
> > + NULL);
> > + up_read(&mm->mmap_sem);
> > + return ret;
> > +}
>
> Hmmm. I like the idea, but I really dislike this name. I don't like xx_unlocked
> function takes a lock. It is a source of confusing, I believe.
Sure, I'm not very happy about the name either. As Christoph wrote
probably renaming all get_user_pages() variants might be appropriate. I'll
think about names some more.

Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR