]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - mm/msync.c
Fix "fs: convert core functions to zero_user_page"
[mirror_ubuntu-bionic-kernel.git] / mm / msync.c
CommitLineData
1da177e4
LT
1/*
2 * linux/mm/msync.c
3 *
4 * Copyright (C) 1994-1999 Linus Torvalds
5 */
6
7/*
8 * The msync() system call.
9 */
8f2e9f15 10#include <linux/fs.h>
1da177e4
LT
11#include <linux/mm.h>
12#include <linux/mman.h>
9c50823e 13#include <linux/file.h>
1da177e4
LT
14#include <linux/syscalls.h>
15
1da177e4
LT
16/*
17 * MS_SYNC syncs the entire file - including mappings.
18 *
204ec841
PZ
19 * MS_ASYNC does not start I/O (it used to, up to 2.5.67).
20 * Nor does it marks the relevant pages dirty (it used to up to 2.6.17).
21 * Now it doesn't do anything, since dirty pages are properly tracked.
22 *
23 * The application may now run fsync() to
1da177e4
LT
24 * write out the dirty pages and wait on the writeout and check the result.
25 * Or the application may run fadvise(FADV_DONTNEED) against the fd to start
26 * async writeout immediately.
16538c40 27 * So by _not_ starting I/O in MS_ASYNC we provide complete flexibility to
1da177e4
LT
28 * applications.
29 */
1da177e4
LT
30asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
31{
32 unsigned long end;
204ec841 33 struct mm_struct *mm = current->mm;
1da177e4 34 struct vm_area_struct *vma;
676758bd
AM
35 int unmapped_error = 0;
36 int error = -EINVAL;
1da177e4 37
1da177e4
LT
38 if (flags & ~(MS_ASYNC | MS_INVALIDATE | MS_SYNC))
39 goto out;
40 if (start & ~PAGE_MASK)
41 goto out;
42 if ((flags & MS_ASYNC) && (flags & MS_SYNC))
43 goto out;
44 error = -ENOMEM;
45 len = (len + ~PAGE_MASK) & PAGE_MASK;
46 end = start + len;
47 if (end < start)
48 goto out;
49 error = 0;
50 if (end == start)
51 goto out;
52 /*
53 * If the interval [start,end) covers some unmapped address ranges,
54 * just ignore them, but return -ENOMEM at the end.
55 */
204ec841
PZ
56 down_read(&mm->mmap_sem);
57 vma = find_vma(mm, start);
58 for (;;) {
9c50823e
AM
59 struct file *file;
60
204ec841
PZ
61 /* Still start < end. */
62 error = -ENOMEM;
63 if (!vma)
64 goto out_unlock;
1da177e4
LT
65 /* Here start < vma->vm_end. */
66 if (start < vma->vm_start) {
1da177e4 67 start = vma->vm_start;
204ec841
PZ
68 if (start >= end)
69 goto out_unlock;
70 unmapped_error = -ENOMEM;
1da177e4
LT
71 }
72 /* Here vma->vm_start <= start < vma->vm_end. */
204ec841
PZ
73 if ((flags & MS_INVALIDATE) &&
74 (vma->vm_flags & VM_LOCKED)) {
75 error = -EBUSY;
76 goto out_unlock;
1da177e4 77 }
9c50823e 78 file = vma->vm_file;
1da177e4 79 start = vma->vm_end;
204ec841 80 if ((flags & MS_SYNC) && file &&
707c21c8 81 (vma->vm_flags & VM_SHARED)) {
707c21c8 82 get_file(file);
204ec841 83 up_read(&mm->mmap_sem);
8f2e9f15 84 error = do_fsync(file, 0);
707c21c8 85 fput(file);
204ec841
PZ
86 if (error || start >= end)
87 goto out;
88 down_read(&mm->mmap_sem);
89 vma = find_vma(mm, start);
9c50823e 90 } else {
204ec841
PZ
91 if (start >= end) {
92 error = 0;
93 goto out_unlock;
94 }
9c50823e
AM
95 vma = vma->vm_next;
96 }
204ec841 97 }
9c50823e 98out_unlock:
204ec841 99 up_read(&mm->mmap_sem);
9c50823e 100out:
204ec841 101 return error ? : unmapped_error;
1da177e4 102}