提交 732751fc 编写于 作者: J Jan Kara 提交者: Xie XiuQi

mm: Handle MADV_WILLNEED through vfs_fadvise()

mainline inclusion
from mainline-5.4-rc1
commit 692fe62433d4ca47605b39f7c416efd6679ba694
category: bugfix
bugzilla: 22583
CVE: NA

---------------------------

Currently handling of MADV_WILLNEED hint calls directly into readahead
code. Handle it by calling vfs_fadvise() instead so that filesystem can
use its ->fadvise() callback to acquire necessary locks or otherwise
prepare for the request.
Suggested-by: NAmir Goldstein <amir73il@gmail.com>
Reviewed-by: NBoaz Harrosh <boazh@netapp.com>
CC: stable@vger.kernel.org
Signed-off-by: NJan Kara <jack@suse.cz>
Reviewed-by: NDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: NDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Nyu kuai <yukuai3@huawei.com>
Reviewed-by: NHou Tao <houtao1@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 43691ad7
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/userfaultfd_k.h> #include <linux/userfaultfd_k.h>
#include <linux/hugetlb.h> #include <linux/hugetlb.h>
#include <linux/falloc.h> #include <linux/falloc.h>
#include <linux/fadvise.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/ksm.h> #include <linux/ksm.h>
#include <linux/fs.h> #include <linux/fs.h>
...@@ -275,6 +276,7 @@ static long madvise_willneed(struct vm_area_struct *vma, ...@@ -275,6 +276,7 @@ static long madvise_willneed(struct vm_area_struct *vma,
unsigned long start, unsigned long end) unsigned long start, unsigned long end)
{ {
struct file *file = vma->vm_file; struct file *file = vma->vm_file;
loff_t offset;
*prev = vma; *prev = vma;
#ifdef CONFIG_SWAP #ifdef CONFIG_SWAP
...@@ -298,12 +300,20 @@ static long madvise_willneed(struct vm_area_struct *vma, ...@@ -298,12 +300,20 @@ static long madvise_willneed(struct vm_area_struct *vma,
return 0; return 0;
} }
start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; /*
if (end > vma->vm_end) * Filesystem's fadvise may need to take various locks. We need to
end = vma->vm_end; * explicitly grab a reference because the vma (and hence the
end = ((end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; * vma's reference to the file) can go away as soon as we drop
* mmap_sem.
force_page_cache_readahead(file->f_mapping, file, start, end - start); */
*prev = NULL; /* tell sys_madvise we drop mmap_sem */
get_file(file);
up_read(&current->mm->mmap_sem);
offset = (loff_t)(start - vma->vm_start)
+ ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
vfs_fadvise(file, offset, end - start, POSIX_FADV_WILLNEED);
fput(file);
down_read(&current->mm->mmap_sem);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册