Skip to contentSkip to conversation

mm: mlock: document scary-looking stack expansion mlock chain

PATCH In review Johannes Weiner 3 participants 4 messages Feb 1, 2013 – Feb 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: mlock: document scary-looking stack expansion mlock chain

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.

---
 mm/mlock.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/mlock.c +4 -0
index b1647fb..78c4924 100644
@@ -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);
 }
Signature · 7 lines
1.7.11.7

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 2 lines · Johannes Weiner

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?

Quoted 18 lines

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.

---
  mm/mlock.c | 4 ++++
  1 file changed, 4 insertions(+)
mm/mlock.c +0 -0
index b1647fb..78c4924 100644

mm/mlock.c long __mlock_vma_pages_range(struct vm_area_struct *vma, · line 194

Quoted 10 lines
mm/mlock.c +4 -0
@@ -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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 7 lines · Ric Mason
Quoted 3 lines · Johannes Weiner

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.

Signature · 8 lines
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 [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#3 lore raw
In reply to Johannes Weiner
Quoted 11 lines · Johannes Weiner

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.

Signature · 8 lines
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 [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>