All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mlock: operate on any regions with protection != PROT_NONE
@ 2011-02-01  1:03 Michel Lespinasse
  2011-02-01  1:08 ` Michel Lespinasse
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Michel Lespinasse @ 2011-02-01  1:03 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, Linus Torvalds
  Cc: Tao Ma, KOSAKI Motohiro, Rik van Riel, Hugh Dickins

As Tao Ma noticed, change 5ecfda0 breaks blktrace. This is because
blktrace mmaps a file with PROT_WRITE permissions but without PROT_READ,
so my attempt to not unnecessarity break COW during mlock ended up
causing mlock to fail with a permission problem.

I am proposing to let mlock ignore vma protection in all cases except
PROT_NONE. In particular, mlock should not fail for PROT_WRITE regions
(as in the blktrace case, which broke at 5ecfda0) or for PROT_EXEC
regions (which seem to me like they were always broken).

Please review. I am proposing this as a candidate for 2.6.38 inclusion,
because of the behavior change with blktrace.

diff --git a/mm/mlock.c b/mm/mlock.c
index 13e81ee..c3924c7f 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -178,6 +178,13 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
 	if ((vma->vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE)
 		gup_flags |= FOLL_WRITE;
 
+	/*
+	 * We want mlock to succeed for regions that have any permissions
+	 * other than PROT_NONE.
+	 */
+	if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
+		gup_flags |= FOLL_FORCE;
+
 	if (vma->vm_flags & VM_LOCKED)
 		gup_flags |= FOLL_MLOCK;
 

-- 
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mlock: operate on any regions with protection != PROT_NONE
  2011-02-01  1:03 [PATCH] mlock: operate on any regions with protection != PROT_NONE Michel Lespinasse
@ 2011-02-01  1:08 ` Michel Lespinasse
  2011-02-01  5:59 ` Linus Torvalds
  2011-02-01 17:57 ` Rik van Riel
  2 siblings, 0 replies; 7+ messages in thread
From: Michel Lespinasse @ 2011-02-01  1:08 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, Linus Torvalds
  Cc: Tao Ma, KOSAKI Motohiro, Rik van Riel, Hugh Dickins

(forgot the signoff...)

On Mon, Jan 31, 2011 at 5:03 PM, Michel Lespinasse <walken@google.com> wrote:
> As Tao Ma noticed, change 5ecfda0 breaks blktrace. This is because
> blktrace mmaps a file with PROT_WRITE permissions but without PROT_READ,
> so my attempt to not unnecessarity break COW during mlock ended up
> causing mlock to fail with a permission problem.
>
> I am proposing to let mlock ignore vma protection in all cases except
> PROT_NONE. In particular, mlock should not fail for PROT_WRITE regions
> (as in the blktrace case, which broke at 5ecfda0) or for PROT_EXEC
> regions (which seem to me like they were always broken).
>
> Please review. I am proposing this as a candidate for 2.6.38 inclusion,
> because of the behavior change with blktrace.

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

> diff --git a/mm/mlock.c b/mm/mlock.c
> index 13e81ee..c3924c7f 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -178,6 +178,13 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
>        if ((vma->vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE)
>                gup_flags |= FOLL_WRITE;
>
> +       /*
> +        * We want mlock to succeed for regions that have any permissions
> +        * other than PROT_NONE.
> +        */
> +       if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
> +               gup_flags |= FOLL_FORCE;
> +
>        if (vma->vm_flags & VM_LOCKED)
>                gup_flags |= FOLL_MLOCK;

-- 
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mlock: operate on any regions with protection != PROT_NONE
  2011-02-01  1:03 [PATCH] mlock: operate on any regions with protection != PROT_NONE Michel Lespinasse
  2011-02-01  1:08 ` Michel Lespinasse
@ 2011-02-01  5:59 ` Linus Torvalds
  2011-02-01  6:36   ` Michel Lespinasse
  2011-02-01 17:57   ` Rik van Riel
  2011-02-01 17:57 ` Rik van Riel
  2 siblings, 2 replies; 7+ messages in thread
From: Linus Torvalds @ 2011-02-01  5:59 UTC (permalink / raw)
  To: Michel Lespinasse
  Cc: linux-mm, Andrew Morton, Tao Ma, KOSAKI Motohiro, Rik van Riel,
	Hugh Dickins

On Tue, Feb 1, 2011 at 11:03 AM, Michel Lespinasse <walken@google.com> wrote:
>
> I am proposing to let mlock ignore vma protection in all cases except
> PROT_NONE.

What's so special about PROT_NONE? If you want to mlock something
without actually being able to then fault that in, why not?

IOW, why wouldn't it be right to just make FOLL_FORCE be unconditional in mlock?

             Linus

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mlock: operate on any regions with protection != PROT_NONE
  2011-02-01  5:59 ` Linus Torvalds
@ 2011-02-01  6:36   ` Michel Lespinasse
  2011-02-01 17:57   ` Rik van Riel
  1 sibling, 0 replies; 7+ messages in thread
From: Michel Lespinasse @ 2011-02-01  6:36 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: linux-mm, Andrew Morton, Tao Ma, KOSAKI Motohiro, Rik van Riel,
	Hugh Dickins

On Mon, Jan 31, 2011 at 9:59 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> On Tue, Feb 1, 2011 at 11:03 AM, Michel Lespinasse <walken@google.com> wrote:
>>
>> I am proposing to let mlock ignore vma protection in all cases except
>> PROT_NONE.
>
> What's so special about PROT_NONE? If you want to mlock something
> without actually being able to then fault that in, why not?
>
> IOW, why wouldn't it be right to just make FOLL_FORCE be unconditional in mlock?

I agree this would be the most logical thing to do, but I'm afraid
people would complain about it as it'd be yet another behavior change.

I don't have the entire context here, but PROT_NONE regions are
actually common in modern userspace. It seems that for most shared
libraries, ld.so creates 4 vmas, one of them being just under 2MB and
with PROT_NONE protection. From my shell, if I do cat /proc/$$/maps, I
see:
[...]
7f41ebdb5000-7f41ebdc5000 r-xp 00000000 fc:03 669498
  /usr/lib/zsh/4.3.10/zsh/computil.so
7f41ebdc5000-7f41ebfc4000 ---p 00010000 fc:03 669498
  /usr/lib/zsh/4.3.10/zsh/computil.so
7f41ebfc4000-7f41ebfc5000 r--p 0000f000 fc:03 669498
  /usr/lib/zsh/4.3.10/zsh/computil.so
7f41ebfc5000-7f41ebfc6000 rw-p 00010000 fc:03 669498
  /usr/lib/zsh/4.3.10/zsh/computil.so
7f41ebfc6000-7f41ebfce000 r-xp 00000000 fc:03 669508
  /usr/lib/zsh/4.3.10/zsh/parameter.so
7f41ebfce000-7f41ec1ce000 ---p 00008000 fc:03 669508
  /usr/lib/zsh/4.3.10/zsh/parameter.so
7f41ec1ce000-7f41ec1cf000 r--p 00008000 fc:03 669508
  /usr/lib/zsh/4.3.10/zsh/parameter.so
7f41ec1cf000-7f41ec1d0000 rw-p 00009000 fc:03 669508
  /usr/lib/zsh/4.3.10/zsh/parameter.so
[...]

I don't know why userspace does that, but these regions currently
never get any page into RSS, even when processes call mlockall(). I am
told that we need to preserve this property.

-- 
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mlock: operate on any regions with protection != PROT_NONE
  2011-02-01  5:59 ` Linus Torvalds
  2011-02-01  6:36   ` Michel Lespinasse
@ 2011-02-01 17:57   ` Rik van Riel
  1 sibling, 0 replies; 7+ messages in thread
From: Rik van Riel @ 2011-02-01 17:57 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Michel Lespinasse, linux-mm, Andrew Morton, Tao Ma,
	KOSAKI Motohiro, Hugh Dickins

On 02/01/2011 12:59 AM, Linus Torvalds wrote:
> On Tue, Feb 1, 2011 at 11:03 AM, Michel Lespinasse<walken@google.com>  wrote:
>>
>> I am proposing to let mlock ignore vma protection in all cases except
>> PROT_NONE.
>
> What's so special about PROT_NONE? If you want to mlock something
> without actually being able to then fault that in, why not?
>
> IOW, why wouldn't it be right to just make FOLL_FORCE be unconditional in mlock?

I could think of a combination of reasons.

Specifically, some libc/linker magic will set up PROT_NONE
areas for programs automatically.

Some programs use mlockall to lock themselves into memory,
with no idea that PROT_NONE areas were set up behind its
back.

Faulting in the PROT_NONE memory will result is wasted
memory, without the application even realizing it.

-- 
All rights reversed

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mlock: operate on any regions with protection != PROT_NONE
  2011-02-01  1:03 [PATCH] mlock: operate on any regions with protection != PROT_NONE Michel Lespinasse
  2011-02-01  1:08 ` Michel Lespinasse
  2011-02-01  5:59 ` Linus Torvalds
@ 2011-02-01 17:57 ` Rik van Riel
  2011-02-03  0:57   ` KOSAKI Motohiro
  2 siblings, 1 reply; 7+ messages in thread
From: Rik van Riel @ 2011-02-01 17:57 UTC (permalink / raw)
  To: Michel Lespinasse
  Cc: linux-mm, Andrew Morton, Linus Torvalds, Tao Ma, KOSAKI Motohiro,
	Hugh Dickins

On 01/31/2011 08:03 PM, Michel Lespinasse wrote:
> As Tao Ma noticed, change 5ecfda0 breaks blktrace. This is because
> blktrace mmaps a file with PROT_WRITE permissions but without PROT_READ,
> so my attempt to not unnecessarity break COW during mlock ended up
> causing mlock to fail with a permission problem.
>
> I am proposing to let mlock ignore vma protection in all cases except
> PROT_NONE. In particular, mlock should not fail for PROT_WRITE regions
> (as in the blktrace case, which broke at 5ecfda0) or for PROT_EXEC
> regions (which seem to me like they were always broken).
>
> Please review. I am proposing this as a candidate for 2.6.38 inclusion,
> because of the behavior change with blktrace.

Acked-by: Rik van Riel <riel@redhat.com>

-- 
All rights reversed

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mlock: operate on any regions with protection != PROT_NONE
  2011-02-01 17:57 ` Rik van Riel
@ 2011-02-03  0:57   ` KOSAKI Motohiro
  0 siblings, 0 replies; 7+ messages in thread
From: KOSAKI Motohiro @ 2011-02-03  0:57 UTC (permalink / raw)
  To: Rik van Riel
  Cc: kosaki.motohiro, Michel Lespinasse, linux-mm, Andrew Morton,
	Linus Torvalds, Tao Ma, Hugh Dickins

> On 01/31/2011 08:03 PM, Michel Lespinasse wrote:
> > As Tao Ma noticed, change 5ecfda0 breaks blktrace. This is because
> > blktrace mmaps a file with PROT_WRITE permissions but without PROT_READ,
> > so my attempt to not unnecessarity break COW during mlock ended up
> > causing mlock to fail with a permission problem.
> >
> > I am proposing to let mlock ignore vma protection in all cases except
> > PROT_NONE. In particular, mlock should not fail for PROT_WRITE regions
> > (as in the blktrace case, which broke at 5ecfda0) or for PROT_EXEC
> > regions (which seem to me like they were always broken).
> >
> > Please review. I am proposing this as a candidate for 2.6.38 inclusion,
> > because of the behavior change with blktrace.
> 
> Acked-by: Rik van Riel <riel@redhat.com>

Reviewed-by :KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>



--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2011-02-03  0:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-01  1:03 [PATCH] mlock: operate on any regions with protection != PROT_NONE Michel Lespinasse
2011-02-01  1:08 ` Michel Lespinasse
2011-02-01  5:59 ` Linus Torvalds
2011-02-01  6:36   ` Michel Lespinasse
2011-02-01 17:57   ` Rik van Riel
2011-02-01 17:57 ` Rik van Riel
2011-02-03  0:57   ` KOSAKI Motohiro

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.