LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] mm: mlockall error for flag MCL_ONFAULT
@ 2019-05-22 11:23 Potyra, Stefan
  2019-05-24 21:43 ` Daniel Jordan
  0 siblings, 1 reply; 5+ messages in thread
From: Potyra, Stefan @ 2019-05-22 11:23 UTC (permalink / raw)
  To: linux-mm, linux-kernel; +Cc: Potyra, Stefan, Jordan, Tobias

If mlockall() is called with only MCL_ONFAULT as flag,
it removes any previously applied lockings and does
nothing else.

This behavior is counter-intuitive and doesn't match the
Linux man page.

Consequently, return the error EINVAL, if only MCL_ONFAULT
is passed. That way, applications will at least detect that
they are calling mlockall() incorrectly.

Fixes: b0f205c2a308 ("mm: mlock: add mlock flags to enable VM_LOCKONFAULT usage")
Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>
---
Sparse shows a warning for mlock.c, but it is not related to
this patch.

 mm/mlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/mlock.c b/mm/mlock.c
index e492a155c51a..03f39cbdd4c4 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -797,7 +797,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
 	unsigned long lock_limit;
 	int ret;
 
-	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)))
+	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)) ||
+	    flags == MCL_ONFAULT)
 		return -EINVAL;
 
 	if (!can_do_mlock())
-- 
2.20.1


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

* Re: [PATCH] mm: mlockall error for flag MCL_ONFAULT
  2019-05-22 11:23 [PATCH] mm: mlockall error for flag MCL_ONFAULT Potyra, Stefan
@ 2019-05-24 21:43 ` Daniel Jordan
  2019-05-27  7:04   ` Michal Hocko
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jordan @ 2019-05-24 21:43 UTC (permalink / raw)
  To: Potyra, Stefan
  Cc: linux-mm, linux-kernel, Jordan, Tobias, akpm, vbabka, mhocko,
	kirill.shutemov, linux-api

[ Adding linux-api and some of the people who were involved in the
MCL_ONFAULT/mlock2/etc discussions.  Author of the Fixes patch appears to
have moved on. ]

On Wed, May 22, 2019 at 11:23:37AM +0000, Potyra, Stefan wrote:
> If mlockall() is called with only MCL_ONFAULT as flag,
> it removes any previously applied lockings and does
> nothing else.

The change looks reasonable.  Hard to imagine any application relies on it, and
they really shouldn't be if they are.  Debian codesearch turned up only a few
cases where stress-ng was doing this for unknown reasons[1] and this change
isn't gonna break those.  In this case I think changing the syscall's behavior
is justified.  

> This behavior is counter-intuitive and doesn't match the
> Linux man page.

I'd quote it for the changelog:

  For mlockall():

  EINVAL Unknown  flags were specified or MCL_ONFAULT was specified with‐
         out either MCL_FUTURE or MCL_CURRENT.

With that you can add

Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>

[1] https://sources.debian.org/src/stress-ng/0.09.50-1/stress-mlock.c/?hl=203#L203

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

* Re: [PATCH] mm: mlockall error for flag MCL_ONFAULT
  2019-05-24 21:43 ` Daniel Jordan
@ 2019-05-27  7:04   ` Michal Hocko
  2019-05-27  7:53     ` [PATCH v2] " Potyra, Stefan
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2019-05-27  7:04 UTC (permalink / raw)
  To: Daniel Jordan
  Cc: Potyra, Stefan, linux-mm, linux-kernel, Jordan, Tobias, akpm,
	vbabka, kirill.shutemov, linux-api

On Fri 24-05-19 17:43:04, Daniel Jordan wrote:
> [ Adding linux-api and some of the people who were involved in the
> MCL_ONFAULT/mlock2/etc discussions.  Author of the Fixes patch appears to
> have moved on. ]
> 
> On Wed, May 22, 2019 at 11:23:37AM +0000, Potyra, Stefan wrote:
> > If mlockall() is called with only MCL_ONFAULT as flag,
> > it removes any previously applied lockings and does
> > nothing else.
> 
> The change looks reasonable.  Hard to imagine any application relies on it, and
> they really shouldn't be if they are.  Debian codesearch turned up only a few
> cases where stress-ng was doing this for unknown reasons[1] and this change
> isn't gonna break those.  In this case I think changing the syscall's behavior
> is justified.  
> 
> > This behavior is counter-intuitive and doesn't match the
> > Linux man page.
> 
> I'd quote it for the changelog:
> 
>   For mlockall():
> 
>   EINVAL Unknown  flags were specified or MCL_ONFAULT was specified with‐
>          out either MCL_FUTURE or MCL_CURRENT.
> 
> With that you can add
> 
> Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
> 
> [1] https://sources.debian.org/src/stress-ng/0.09.50-1/stress-mlock.c/?hl=203#L203

Well spotted and the fix looks reasonable as well. Quoting the man page
seems useful as well.

Acked-by: Michal Hocko <mhocko@suse.com>

Thanks!
-- 
Michal Hocko
SUSE Labs

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

* [PATCH v2] mm: mlockall error for flag MCL_ONFAULT
  2019-05-27  7:04   ` Michal Hocko
@ 2019-05-27  7:53     ` Potyra, Stefan
  2019-05-27 13:19       ` Vlastimil Babka
  0 siblings, 1 reply; 5+ messages in thread
From: Potyra, Stefan @ 2019-05-27  7:53 UTC (permalink / raw)
  To: Michal Hocko, Daniel Jordan
  Cc: Potyra, Stefan, linux-mm, linux-kernel, Jordan, Tobias, akpm,
	vbabka, kirill.shutemov, linux-api

If mlockall() is called with only MCL_ONFAULT as flag,
it removes any previously applied lockings and does
nothing else.

This behavior is counter-intuitive and doesn't match the
Linux man page.

  For mlockall():

  EINVAL Unknown  flags were specified or MCL_ONFAULT was specified with‐
         out either MCL_FUTURE or MCL_CURRENT.

Consequently, return the error EINVAL, if only MCL_ONFAULT
is passed. That way, applications will at least detect that
they are calling mlockall() incorrectly.

Fixes: b0f205c2a308 ("mm: mlock: add mlock flags to enable VM_LOCKONFAULT usage")
Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>
Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Acked-by: Michal Hocko <mhocko@suse.com>
---
 mm/mlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/mlock.c b/mm/mlock.c
index e492a155c51a..03f39cbdd4c4 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -797,7 +797,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
 	unsigned long lock_limit;
 	int ret;
 
-	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)))
+	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)) ||
+	    flags == MCL_ONFAULT)
 		return -EINVAL;
 
 	if (!can_do_mlock())
-- 
2.20.1


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

* Re: [PATCH v2] mm: mlockall error for flag MCL_ONFAULT
  2019-05-27  7:53     ` [PATCH v2] " Potyra, Stefan
@ 2019-05-27 13:19       ` Vlastimil Babka
  0 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka @ 2019-05-27 13:19 UTC (permalink / raw)
  To: Potyra, Stefan, Michal Hocko, Daniel Jordan
  Cc: linux-mm, linux-kernel, Jordan, Tobias, akpm, kirill.shutemov, linux-api

On 5/27/19 9:53 AM, Potyra, Stefan wrote:
> If mlockall() is called with only MCL_ONFAULT as flag,
> it removes any previously applied lockings and does
> nothing else.
> 
> This behavior is counter-intuitive and doesn't match the
> Linux man page.
> 
>   For mlockall():
> 
>   EINVAL Unknown  flags were specified or MCL_ONFAULT was specified with‐
>          out either MCL_FUTURE or MCL_CURRENT.
> 
> Consequently, return the error EINVAL, if only MCL_ONFAULT
> is passed. That way, applications will at least detect that
> they are calling mlockall() incorrectly.
> 
> Fixes: b0f205c2a308 ("mm: mlock: add mlock flags to enable VM_LOCKONFAULT usage")
> Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>
> Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
> Acked-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks, shame we didn't catch it during review. Hope nobody will report
a regression.

> ---
>  mm/mlock.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/mlock.c b/mm/mlock.c
> index e492a155c51a..03f39cbdd4c4 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -797,7 +797,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
>  	unsigned long lock_limit;
>  	int ret;
>  
> -	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)))
> +	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)) ||
> +	    flags == MCL_ONFAULT)
>  		return -EINVAL;
>  
>  	if (!can_do_mlock())
> 


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

end of thread, other threads:[~2019-05-27 13:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 11:23 [PATCH] mm: mlockall error for flag MCL_ONFAULT Potyra, Stefan
2019-05-24 21:43 ` Daniel Jordan
2019-05-27  7:04   ` Michal Hocko
2019-05-27  7:53     ` [PATCH v2] " Potyra, Stefan
2019-05-27 13:19       ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).