Skip to content

Commit

Permalink
mm/msync: exit early when the flags is an MS_ASYNC and start < vm_start
Browse files Browse the repository at this point in the history
If an unmapped region was found and the flag is MS_ASYNC (without
MS_INVALIDATE) there is nothing to do and the result would be always
-ENOMEM, so return immediately.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Nikita Ermakov <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
sh1r4s3 authored and torvalds committed Apr 30, 2021
1 parent 4b17f03 commit f6899bc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mm/msync.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
goto out;
/*
* If the interval [start,end) covers some unmapped address ranges,
* just ignore them, but return -ENOMEM at the end.
* just ignore them, but return -ENOMEM at the end. Besides, if the
* flag is MS_ASYNC (w/o MS_INVALIDATE) the result would be -ENOMEM
* anyway and there is nothing left to do, so return immediately.
*/
mmap_read_lock(mm);
vma = find_vma(mm, start);
Expand All @@ -69,6 +71,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
goto out_unlock;
/* Here start < vma->vm_end. */
if (start < vma->vm_start) {
if (flags == MS_ASYNC)
goto out_unlock;
start = vma->vm_start;
if (start >= end)
goto out_unlock;
Expand Down

0 comments on commit f6899bc

Please sign in to comment.