提交 499ecade 编写于 作者: Y Yu Kuai 提交者: Zheng Zengkai

mm/filemap: fix that first page is not mark accessed in filemap_read()

hulk inclusion
category: bugfix
bugzilla: 186896, https://gitee.com/src-openeuler/kernel/issues/I5FRAP
CVE: NA

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

In filemap_read(), first page will not mark accessed if previous page
is equal to the current page:

if (iocb->ki_pos >> PAGE_SHIFT != ra->prev_pos >> PAGE_SHIFT))
	folio_mark_accessed(fbatch.folios[0]);

However, 'prev_pos' is set to 'ki_pos + copied' during last read, which
means 'prev_pos' can be equal to 'ki_pos' in this read, thus previous
page can be miscaculated.

Fix the problem by setting 'prev_pos' to the start offset of last read,
so that 'prev_pos >> PAGE_SHIFT' will be previous page as expected.

Fixes: 06c04442 ("mm/filemap.c: generic_file_buffered_read() now uses find_get_pages_contig")
Signed-off-by: NYu Kuai <yukuai3@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 2ed9d17c
......@@ -2549,10 +2549,11 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb,
flush_dcache_page(pages[i]);
copied = copy_page_to_iter(pages[i], offset, bytes, iter);
written += copied;
iocb->ki_pos += copied;
ra->prev_pos = iocb->ki_pos;
if (copied) {
ra->prev_pos = iocb->ki_pos;
written += copied;
iocb->ki_pos += copied;
}
if (copied < bytes) {
error = -EFAULT;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册