From: Andrew Morton <akpm@linux-foundation.org>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: halesh.s@india.com, kosaki.motohiro@jp.fujitsu.com,
linux-kernel@vger.kernel.org
Subject: Re: mlock() return value issue in kernel 2.6.23.17
Date: Thu, 31 Jul 2008 14:30:32 -0700 [thread overview]
Message-ID: <20080731143032.2a211c18.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080731211811.3CA9.KOSAKI.MOTOHIRO@jp.fujitsu.com>
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.
next prev parent reply other threads:[~2008-07-31 21:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080731143032.2a211c18.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=halesh.s@india.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox