* mlock() return value issue in kernel 2.6.23.17
@ 2008-07-31 10:15 Halesh
2008-07-31 12:50 ` KOSAKI Motohiro
0 siblings, 1 reply; 9+ messages in thread
From: Halesh @ 2008-07-31 10:15 UTC (permalink / raw)
To: linux-kernel
Hi all,
Please find the below testcase provide to test mlock.
Test Case :
===========================
#include <sys/resource.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
int main(void)
{
int fd,ret, i = 0;
char *addr, *addr1 = NULL;
unsigned int page_size;
struct rlimit rlim;
if (0 != geteuid())
{
printf("Execute this pgm as root\n");
exit(1);
}
/* create a file */
if ((fd = open("mmap_test.c",O_RDWR|O_CREAT,0755)) == -1)
{
printf("cant create test file\n");
exit(1);
}
page_size = sysconf(_SC_PAGE_SIZE);
/* set the MEMLOCK limit */
rlim.rlim_cur = 2000;
rlim.rlim_max = 2000;
if ((ret = setrlimit(RLIMIT_MEMLOCK,&rlim)) != 0)
{
printf("Cant change limit values\n");
exit(1);
}
addr = 0;
while (1)
{
/* map a page into memory each time*/
if ((addr = (char *) mmap(addr,page_size, PROT_READ |
PROT_WRITE,MAP_SHARED,fd,0)) == MAP_FAILED)
{
printf("cant do mmap on file\n");
exit(1);
}
if (0 == i)
addr1 = addr;
i++;
errno = 0;
/* lock the mapped memory pagewise*/
if ((ret = mlock((char *)addr, 1500)) == -1)
{
printf("errno value is %d\n", errno);
printf("cant lock maped region\n");
exit(1);
}
addr = addr + page_size;
}
}
======================================================
This testcase results with mlock failure with errno 14 that is EFAULT, but this
has been no where reported that mlock will give EFAULT, When i tested the same
on older kernel like 2.6.18, I got the correct result i.e errno 12 (ENOMEM).
I think in source code mlock(2), setting errno ENOMEM has been missed in
do_mlock() , on mlock_fixup() failure.
Let me know if my understanding is wrong!
Thanks,
Halesh
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: mlock() return value issue in kernel 2.6.23.17
2008-07-31 10:15 mlock() return value issue in kernel 2.6.23.17 Halesh
@ 2008-07-31 12:50 ` KOSAKI Motohiro
2008-07-31 21:30 ` Andrew Morton
0 siblings, 1 reply; 9+ messages in thread
From: KOSAKI Motohiro @ 2008-07-31 12:50 UTC (permalink / raw)
To: Halesh; +Cc: kosaki.motohiro, linux-kernel
>
> This testcase results with mlock failure with errno 14 that is EFAULT, but this
> has been no where reported that mlock will give EFAULT, When i tested the same
> on older kernel like 2.6.18, I got the correct result i.e errno 12 (ENOMEM).
>
>
> I think in source code mlock(2), setting errno ENOMEM has been missed in
> do_mlock() , on mlock_fixup() failure.
>
> Let me know if my understanding is wrong!
Hi Halesh,
Could you try to following patch?
-----------------------------------------------------
SUSv3 require following behavior to mlock(2).
[ENOMEM]
Some or all of the address range specified by the addr and
len arguments does not correspond to valid mapped pages
in the address space of the process.
[EAGAIN]
Some or all of the memory identified by the operation could not
be locked when the call was made.
This rule isn't so nice and slighly strange.
but many people think POSIX/SUS compliance is important.
---
mm/memory.c | 16 +++++++++++++---
mm/mlock.c | 2 --
2 files changed, 13 insertions(+), 5 deletions(-)
Index: b/mm/memory.c
===================================================================
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2736,16 +2736,26 @@ int make_pages_present(unsigned long add
vma = find_vma(current->mm, addr);
if (!vma)
- return -1;
+ return -ENOMEM;
write = (vma->vm_flags & VM_WRITE) != 0;
BUG_ON(addr >= end);
BUG_ON(end > vma->vm_end);
len = DIV_ROUND_UP(end, PAGE_SIZE) - addr/PAGE_SIZE;
ret = get_user_pages(current, current->mm, addr,
len, write, 0, NULL, NULL);
- if (ret < 0)
+ if (ret < 0) {
+ /*
+ SUS require strange return value to mlock
+ - invalid addr generate to ENOMEM.
+ - out of memory should generate EAGAIN.
+ */
+ if (ret == -EFAULT)
+ ret = -ENOMEM;
+ else if (ret == -ENOMEM)
+ ret = -EAGAIN;
return ret;
- return ret == len ? 0 : -1;
+ }
+ return ret == len ? 0 : -ENOMEM;
}
#if !defined(__HAVE_ARCH_GATE_AREA)
Index: b/mm/mlock.c
===================================================================
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -78,8 +78,6 @@ success:
mm->locked_vm -= pages;
out:
- if (ret == -ENOMEM)
- ret = -EAGAIN;
return ret;
}
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: mlock() return value issue in kernel 2.6.23.17
2008-07-31 12:50 ` KOSAKI Motohiro
@ 2008-07-31 21:30 ` Andrew Morton
2008-08-01 7:23 ` KOSAKI Motohiro
0 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2008-07-31 21:30 UTC (permalink / raw)
To: KOSAKI Motohiro; +Cc: halesh.s, kosaki.motohiro, linux-kernel
On Thu, 31 Jul 2008 21:50:06 +0900
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:
> >
> > This testcase results with mlock failure with errno 14 that is EFAULT, but this
> > has been no where reported that mlock will give EFAULT, When i tested the same
> > on older kernel like 2.6.18, I got the correct result i.e errno 12 (ENOMEM).
> >
> >
> > I think in source code mlock(2), setting errno ENOMEM has been missed in
> > do_mlock() , on mlock_fixup() failure.
> >
> > Let me know if my understanding is wrong!
>
> Hi Halesh,
>
> Could you try to following patch?
>
> -----------------------------------------------------
> SUSv3 require following behavior to mlock(2).
>
> [ENOMEM]
> Some or all of the address range specified by the addr and
> len arguments does not correspond to valid mapped pages
> in the address space of the process.
>
> [EAGAIN]
> Some or all of the memory identified by the operation could not
> be locked when the call was made.
>
>
> This rule isn't so nice and slighly strange.
> but many people think POSIX/SUS compliance is important.
>
>
> ---
> mm/memory.c | 16 +++++++++++++---
> mm/mlock.c | 2 --
> 2 files changed, 13 insertions(+), 5 deletions(-)
>
> Index: b/mm/memory.c
> ===================================================================
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2736,16 +2736,26 @@ int make_pages_present(unsigned long add
>
> vma = find_vma(current->mm, addr);
> if (!vma)
> - return -1;
> + return -ENOMEM;
> write = (vma->vm_flags & VM_WRITE) != 0;
> BUG_ON(addr >= end);
> BUG_ON(end > vma->vm_end);
> len = DIV_ROUND_UP(end, PAGE_SIZE) - addr/PAGE_SIZE;
> ret = get_user_pages(current, current->mm, addr,
> len, write, 0, NULL, NULL);
> - if (ret < 0)
> + if (ret < 0) {
> + /*
> + SUS require strange return value to mlock
> + - invalid addr generate to ENOMEM.
> + - out of memory should generate EAGAIN.
> + */
> + if (ret == -EFAULT)
> + ret = -ENOMEM;
> + else if (ret == -ENOMEM)
> + ret = -EAGAIN;
> return ret;
> - return ret == len ? 0 : -1;
> + }
> + return ret == len ? 0 : -ENOMEM;
> }
>
> #if !defined(__HAVE_ARCH_GATE_AREA)
> Index: b/mm/mlock.c
> ===================================================================
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -78,8 +78,6 @@ success:
>
> mm->locked_vm -= pages;
> out:
> - if (ret == -ENOMEM)
> - ret = -EAGAIN;
> return ret;
> }
>
>
I assume that you tested it too?
If it comes down to a choice between complying with SuS versus
complying with earlier Linux versions then we'd usually prefer to
comply with earlier Linux versions.
I queued this, but would prefer to await confirmation that it has been
tested to take us back to the 2.6.18 interface, please.
Also, please send a Signed-off-by: for this change.
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: mlock() return value issue in kernel 2.6.23.17
2008-07-31 21:30 ` Andrew Morton
@ 2008-08-01 7:23 ` KOSAKI Motohiro
0 siblings, 0 replies; 9+ messages in thread
From: KOSAKI Motohiro @ 2008-08-01 7:23 UTC (permalink / raw)
To: Andrew Morton; +Cc: kosaki.motohiro, halesh.s, linux-kernel
Hi Andrew,
> I assume that you tested it too?
Yes, my x86_64 box works well.
sorry, ambiguity e-mail.
halesh's test check two point.
- mlock rlimit
- invlid address range
and, I think rlimit already works well.
So, I ask halesh re-confirming.
> If it comes down to a choice between complying with SuS versus
> complying with earlier Linux versions then we'd usually prefer to
> comply with earlier Linux versions.
I see.
> I queued this, but would prefer to await confirmation that it has been
> tested to take us back to the 2.6.18 interface, please.
Yes.
this patch wasn't tested on split-lru yet.
I'll do that. (and probably fix it)
> Also, please send a Signed-off-by: for this change.
Agghh, sorry. it is stupid forgotten.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mlock() return value issue in kernel 2.6.23.17
@ 2008-08-01 8:30 Halesh S
2008-08-01 8:56 ` KOSAKI Motohiro
0 siblings, 1 reply; 9+ messages in thread
From: Halesh S @ 2008-08-01 8:30 UTC (permalink / raw)
To: KOSAKI Motohiro, Andrew Morton
Cc: kosaki.motohiro, halesh.s, linux-kernel, madhvesh.s,
halesh.sadashiv
Hi,
Thanks everyone.
I confirm that the patch fixes the issue with Rlimit and invalid address.
Signed-off-by: halesh.sadashiv@ap.sony.com
Thanks,
Halesh
> ----- Original Message -----
> From: "KOSAKI Motohiro" <kosaki.motohiro@jp.fujitsu.com>
> To: "Andrew Morton" <akpm@linux-foundation.org>
> Subject: Re: mlock() return value issue in kernel 2.6.23.17
> Date: Fri, 01 Aug 2008 16:23:40 +0900
>
>
> Hi Andrew,
>
> > I assume that you tested it too?
>
> Yes, my x86_64 box works well.
>
> sorry, ambiguity e-mail.
>
> halesh's test check two point.
> - mlock rlimit
> - invlid address range
>
> and, I think rlimit already works well.
> So, I ask halesh re-confirming.
>
> > If it comes down to a choice between complying with SuS versus
> > complying with earlier Linux versions then we'd usually prefer to
> > comply with earlier Linux versions.
>
> I see.
>
> > I queued this, but would prefer to await confirmation that it has been
> > tested to take us back to the 2.6.18 interface, please.
>
> Yes.
> this patch wasn't tested on split-lru yet.
> I'll do that. (and probably fix it)
>
> > Also, please send a Signed-off-by: for this change.
>
> Agghh, sorry. it is stupid forgotten.
>
=
--
_______________________________________________
Search for products and services at:
http://search.mail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mlock() return value issue in kernel 2.6.23.17
@ 2008-08-01 10:06 Halesh S
0 siblings, 0 replies; 9+ messages in thread
From: Halesh S @ 2008-08-01 10:06 UTC (permalink / raw)
To: KOSAKI Motohiro
Cc: kosaki.motohiro, Andrew Morton, linux-kernel, madhvesh.s,
halesh.sadashiv
Hi,
> ----- Original Message -----
> From: "KOSAKI Motohiro" <kosaki.motohiro@jp.fujitsu.com>
> To: "Halesh S" <halesh.s@india.com>
> Subject: Re: mlock() return value issue in kernel 2.6.23.17
> Date: Fri, 01 Aug 2008 17:56:55 +0900
>
>
> Hi
>
> > Thanks everyone.
> > I confirm that the patch fixes the issue with Rlimit and invalid address.
> >
> > Signed-off-by: halesh.sadashiv@ap.sony.com
>
> No.
> your test program need run as root.
> then, it doesn't test rlimit.
>
Sorry, test program not checks the rlimit.as it run as root.
Your patch fixes the issue for invalid address.
It confirms the SUSv3.
Signed-off-by: halesh.sadashiv@ap.sony.com
Thanks,
Halesh
=
--
_______________________________________________
Search for products and services at:
http://search.mail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mlock() return value issue in kernel 2.6.23.17
@ 2008-10-07 22:24 Yanping Du
2008-10-08 0:59 ` KOSAKI Motohiro
0 siblings, 1 reply; 9+ messages in thread
From: Yanping Du @ 2008-10-07 22:24 UTC (permalink / raw)
To: linux-kernel; +Cc: yanping.du
Hi Kosaki,
Seems SUSv3 has more requirements beyond errno return code. Upon
failure (EAGAIN, etc), it requires .no change is made to any locks in
the address space of the process., but Linux mlock(2) will set vma flag
as VM_LOCKED even if make_pages_present() fails for some pages in the
vma. Any comment on this ?
SUSv3: http://www.unix.org/single_unix_specification/
"Upon successful completion, the mlock() and munlock() functions shall
return a value of zero. Otherwise, no change is made to any locks in the
address space of the process, and the function shall return a value of
-1 and set errno to indicate the error."
Thanks!
-Yanping
Re: mlock() return value issue in kernel 2.6.23.17
From: KOSAKI Motohiro
Date: Thu Jul 31 2008 - 08:50:41 EST
Next message: w.landgraf: "ref: my kernel bug report of July 29 ref
2.6.27-rc1 -- addition: kernel config"
Previous message: Alistair John Strachan: "Re: Oops in microcode sysfs
registration,"
In reply to: Halesh: "mlock() return value issue in kernel 2.6.23.17"
Next in thread: Andrew Morton: "Re: mlock() return value issue in kernel
2.6.23.17"
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
size=2 width="100%" noshade color="#aca899" align=center>
>
> This testcase results with mlock failure with errno 14 that is EFAULT,
> but this has been no where reported that mlock will give EFAULT, When
> i tested the same on older kernel like 2.6.18, I got the correct
result i.e errno 12 (ENOMEM).
>
>
> I think in source code mlock(2), setting errno ENOMEM has been missed
> in
> do_mlock() , on mlock_fixup() failure.
>
> Let me know if my understanding is wrong!
Hi Halesh,
Could you try to following patch?
-----------------------------------------------------
SUSv3 require following behavior to mlock(2).
[ENOMEM]
Some or all of the address range specified by the addr and len arguments
does not correspond to valid mapped pages in the address space of the
process.
[EAGAIN]
Some or all of the memory identified by the operation could not be
locked when the call was made.
This rule isn't so nice and slighly strange.
but many people think POSIX/SUS compliance is important.
---
mm/memory.c | 16 +++++++++++++---
mm/mlock.c | 2 --
2 files changed, 13 insertions(+), 5 deletions(-)
Index: b/mm/memory.c
===================================================================
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2736,16 +2736,26 @@ int make_pages_present(unsigned long add
vma = find_vma(current->mm, addr);
if (!vma)
- return -1;
+ return -ENOMEM;
write = (vma->vm_flags & VM_WRITE) != 0; BUG_ON(addr >= end); BUG_ON(end
> vma->vm_end); len = DIV_ROUND_UP(end, PAGE_SIZE) - addr/PAGE_SIZE; ret
= get_user_pages(current, current->mm, addr, len, write, 0, NULL, NULL);
- if (ret < 0)
+ if (ret < 0) {
+ /*
+ SUS require strange return value to mlock
+ - invalid addr generate to ENOMEM.
+ - out of memory should generate EAGAIN.
+ */
+ if (ret == -EFAULT)
+ ret = -ENOMEM;
+ else if (ret == -ENOMEM)
+ ret = -EAGAIN;
return ret;
- return ret == len ? 0 : -1;
+ }
+ return ret == len ? 0 : -ENOMEM;
}
#if !defined(__HAVE_ARCH_GATE_AREA)
Index: b/mm/mlock.c
===================================================================
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -78,8 +78,6 @@ success:
mm->locked_vm -= pages;
out:
- if (ret == -ENOMEM)
- ret = -EAGAIN;
return ret;
}
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: mlock() return value issue in kernel 2.6.23.17
2008-10-07 22:24 Yanping Du
@ 2008-10-08 0:59 ` KOSAKI Motohiro
0 siblings, 0 replies; 9+ messages in thread
From: KOSAKI Motohiro @ 2008-10-08 0:59 UTC (permalink / raw)
To: Yanping Du; +Cc: kosaki.motohiro, linux-kernel, yanping.du
Hi Yanping,
> Hi Kosaki,
>
> Seems SUSv3 has more requirements beyond errno return code. Upon
> failure (EAGAIN, etc), it requires .no change is made to any locks in
> the address space of the process., but Linux mlock(2) will set vma flag
> as VM_LOCKED even if make_pages_present() fails for some pages in the
> vma. Any comment on this ?
>
> SUSv3: http://www.unix.org/single_unix_specification/
>
> "Upon successful completion, the mlock() and munlock() functions shall
> return a value of zero. Otherwise, no change is made to any locks in the
> address space of the process, and the function shall return a value of
> -1 and set errno to indicate the error."
Correct.
However, I haven't seen this behavior cause any trouble.
Do you know any case?
So, if nobody feel awful, I don't interest it so much ;)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-10-08 0:59 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-31 10:15 mlock() return value issue in kernel 2.6.23.17 Halesh
2008-07-31 12:50 ` KOSAKI Motohiro
2008-07-31 21:30 ` Andrew Morton
2008-08-01 7:23 ` KOSAKI Motohiro
-- strict thread matches above, loose matches on Subject: below --
2008-08-01 8:30 Halesh S
2008-08-01 8:56 ` KOSAKI Motohiro
2008-08-01 10:06 Halesh S
2008-10-07 22:24 Yanping Du
2008-10-08 0:59 ` KOSAKI Motohiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox