linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm: mlock: document scary-looking stack expansion mlock chain
@ 2013-02-01  6:10 Johannes Weiner
  2013-02-20 12:51 ` Ric Mason
  2013-02-20 14:24 ` Michel Lespinasse
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Weiner @ 2013-02-01  6:10 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Alexander Viro, Hugh Dickins, linux-mm, linux-kernel

The fact that mlock calls get_user_pages, and get_user_pages might
call mlock when expanding a stack looks like a potential recursion.

However, mlock makes sure the requested range is already contained
within a vma, so no stack expansion will actually happen from mlock.

Should this ever change: the stack expansion mlocks only the newly
expanded range and so will not result in recursive expansion.

Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 mm/mlock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/mlock.c b/mm/mlock.c
index b1647fb..78c4924 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -185,6 +185,10 @@ long __mlock_vma_pages_range(struct vm_area_struct *vma,
 	if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
 		gup_flags |= FOLL_FORCE;
 
+	/*
+	 * We made sure addr is within a VMA, so the following will
+	 * not result in a stack expansion that recurses back here.
+	 */
 	return __get_user_pages(current, mm, addr, nr_pages, gup_flags,
 				NULL, NULL, nonblocking);
 }
-- 
1.7.11.7

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [patch] mm: mlock: document scary-looking stack expansion mlock chain
  2013-02-01  6:10 [patch] mm: mlock: document scary-looking stack expansion mlock chain Johannes Weiner
@ 2013-02-20 12:51 ` Ric Mason
  2013-02-20 14:22   ` Michel Lespinasse
  2013-02-20 14:24 ` Michel Lespinasse
  1 sibling, 1 reply; 4+ messages in thread
From: Ric Mason @ 2013-02-20 12:51 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: Andrew Morton, Alexander Viro, Hugh Dickins, linux-mm, linux-kernel

On 02/01/2013 02:10 PM, Johannes Weiner wrote:
> The fact that mlock calls get_user_pages, and get_user_pages might
> call mlock when expanding a stack looks like a potential recursion.

Why expand stack need call mlock? I can't find it in the codes, could 
you point out to me?

>
> However, mlock makes sure the requested range is already contained
> within a vma, so no stack expansion will actually happen from mlock.
>
> Should this ever change: the stack expansion mlocks only the newly
> expanded range and so will not result in recursive expansion.
>
> Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
>   mm/mlock.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/mm/mlock.c b/mm/mlock.c
> index b1647fb..78c4924 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -185,6 +185,10 @@ long __mlock_vma_pages_range(struct vm_area_struct *vma,
>   	if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
>   		gup_flags |= FOLL_FORCE;
>   
> +	/*
> +	 * We made sure addr is within a VMA, so the following will
> +	 * not result in a stack expansion that recurses back here.
> +	 */
>   	return __get_user_pages(current, mm, addr, nr_pages, gup_flags,
>   				NULL, NULL, nonblocking);
>   }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [patch] mm: mlock: document scary-looking stack expansion mlock chain
  2013-02-20 12:51 ` Ric Mason
@ 2013-02-20 14:22   ` Michel Lespinasse
  0 siblings, 0 replies; 4+ messages in thread
From: Michel Lespinasse @ 2013-02-20 14:22 UTC (permalink / raw)
  To: Ric Mason
  Cc: Johannes Weiner, Andrew Morton, Alexander Viro, Hugh Dickins,
	linux-mm, linux-kernel

On Wed, Feb 20, 2013 at 8:51 PM, Ric Mason <ric.masonn@gmail.com> wrote:
> On 02/01/2013 02:10 PM, Johannes Weiner wrote:
>>
>> The fact that mlock calls get_user_pages, and get_user_pages might
>> call mlock when expanding a stack looks like a potential recursion.
>
> Why expand stack need call mlock? I can't find it in the codes, could you
> point out to me?

Its hidden in find_expand_vma(). Basically if the existing stack is
already mlocked, any additional stack expansions get mlocked as well.

-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [patch] mm: mlock: document scary-looking stack expansion mlock chain
  2013-02-01  6:10 [patch] mm: mlock: document scary-looking stack expansion mlock chain Johannes Weiner
  2013-02-20 12:51 ` Ric Mason
@ 2013-02-20 14:24 ` Michel Lespinasse
  1 sibling, 0 replies; 4+ messages in thread
From: Michel Lespinasse @ 2013-02-20 14:24 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: Andrew Morton, Alexander Viro, Hugh Dickins, linux-mm, linux-kernel

On Fri, Feb 1, 2013 at 2:10 PM, Johannes Weiner <hannes@cmpxchg.org> wrote:
> The fact that mlock calls get_user_pages, and get_user_pages might
> call mlock when expanding a stack looks like a potential recursion.
>
> However, mlock makes sure the requested range is already contained
> within a vma, so no stack expansion will actually happen from mlock.
>
> Should this ever change: the stack expansion mlocks only the newly
> expanded range and so will not result in recursive expansion.
>
> Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Acked-by: Michel Lespinasse <walken@google.com>

-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2013-02-20 14:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-01  6:10 [patch] mm: mlock: document scary-looking stack expansion mlock chain Johannes Weiner
2013-02-20 12:51 ` Ric Mason
2013-02-20 14:22   ` Michel Lespinasse
2013-02-20 14:24 ` Michel Lespinasse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox