1 ext4: bugfix for mmaped pages in mpage_release_unused_pages()
3 From: wangguang <wang.guang55@zte.com.cn>
5 Pages clear buffers after ext4 delayed block allocation failed,
6 However, it does not clean its pte_dirty flag.
7 if the pages unmap ,in cording to the pte_dirty ,
8 unmap_page_range may try to call __set_page_dirty,
10 which may lead to the bugon at
11 mpage_prepare_extent_to_map:head = page_buffers(page);.
13 This patch just call clear_page_dirty_for_io to clean pte_dirty
14 at mpage_release_unused_pages for pages mmaped.
16 Steps to reproduce the bug:
18 (1) mmap a file in ext4
19 addr = (char *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED,
21 memset(addr, 'i', 4096);
25 ext4_writepages->mpage_map_and_submit_extent->mpage_map_one_extent
27 which causes this log message to be print:
29 ext4_msg(sb, KERN_CRIT,
30 "Delayed block allocation failed for "
31 "inode %lu at logical offset %llu with"
32 " max blocks %u with error %d",
34 (unsigned long long)map->m_lblk,
35 (unsigned)map->m_len, -err);
37 (3)Unmap the addr cause warning at
39 __set_page_dirty:WARN_ON_ONCE(warn && !PageUptodate(page));
41 (4) wait for a minute,then bugon happen.
43 Signed-off-by: wangguang <wangguang03@zte.com>
44 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
48 fs/ext4/inode.c | 2 ++
49 1 file changed, 2 insertions(+)
51 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
52 index f058afb..9b464e5 100644
55 @@ -1649,6 +1649,8 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
56 BUG_ON(!PageLocked(page));
57 BUG_ON(PageWriteback(page));
59 + if (page_mapped(page))
60 + clear_page_dirty_for_io(page);
61 block_invalidatepage(page, 0, PAGE_SIZE);
62 ClearPageUptodate(page);