summaryrefslogtreecommitdiffstats
path: root/fs/f2fs
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2017-03-16 21:55:52 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2017-03-21 22:34:10 -0400
commit8c242db9b8c01b252290e23827163787f07e01d1 (patch)
tree1a250cbfbdf0313f5297536872166862c3143c89 /fs/f2fs
parentaa51d08a11784a431266055d58d28b4c4c76a79e (diff)
f2fs: fix stale ATOMIC_WRITTEN_PAGE private pointer
When I forced to enable atomic operations intentionally, I could hit the below panic, since we didn't clear page->private in f2fs_invalidate_page called by file truncation. The panic occurs due to NULL mapping having page->private. BUG: unable to handle kernel paging request at ffffffffffffffff IP: drop_buffers+0x38/0xe0 PGD 5d00c067 PUD 5d00e067 PMD 0 CPU: 3 PID: 1648 Comm: fsstress Tainted: G D OE 4.10.0+ #5 Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 task: ffff9151952863c0 task.stack: ffffaaec40db4000 RIP: 0010:drop_buffers+0x38/0xe0 RSP: 0018:ffffaaec40db74c8 EFLAGS: 00010292 Call Trace: ? page_referenced+0x8b/0x170 try_to_free_buffers+0xc5/0xe0 try_to_release_page+0x49/0x50 shrink_page_list+0x8bc/0x9f0 shrink_inactive_list+0x1dd/0x500 ? shrink_active_list+0x2c0/0x430 shrink_node_memcg+0x5eb/0x7c0 shrink_node+0xe1/0x320 do_try_to_free_pages+0xef/0x2e0 try_to_free_pages+0xe9/0x190 __alloc_pages_slowpath+0x390/0xe70 __alloc_pages_nodemask+0x291/0x2b0 alloc_pages_current+0x95/0x140 __page_cache_alloc+0xc4/0xe0 pagecache_get_page+0xab/0x2a0 grab_cache_page_write_begin+0x20/0x40 get_read_data_page+0x2e6/0x4c0 [f2fs] ? f2fs_mark_inode_dirty_sync+0x16/0x30 [f2fs] ? truncate_data_blocks_range+0x238/0x2b0 [f2fs] get_lock_data_page+0x30/0x190 [f2fs] __exchange_data_block+0xaaf/0xf40 [f2fs] f2fs_fallocate+0x418/0xd00 [f2fs] vfs_fallocate+0x157/0x220 SyS_fallocate+0x48/0x80 Signed-off-by: Yunlei He <heyunlei@huawei.com> Signed-off-by: Chao Yu <yuchao0@huawei.com> [Chao Yu: use INMEM_INVALIDATE for better tracing] Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r--fs/f2fs/data.c2
-rw-r--r--fs/f2fs/f2fs.h2
-rw-r--r--fs/f2fs/segment.c30
3 files changed, 33 insertions, 1 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 1602b4bccae6..e341d446205a 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1951,7 +1951,7 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
1951 1951
1952 /* This is atomic written page, keep Private */ 1952 /* This is atomic written page, keep Private */
1953 if (IS_ATOMIC_WRITTEN_PAGE(page)) 1953 if (IS_ATOMIC_WRITTEN_PAGE(page))
1954 return; 1954 return drop_inmem_page(inode, page);
1955 1955
1956 set_page_private(page, 0); 1956 set_page_private(page, 0);
1957 ClearPagePrivate(page); 1957 ClearPagePrivate(page);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 0a6e115562f6..264c219f41a5 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -722,6 +722,7 @@ enum page_type {
722 META_FLUSH, 722 META_FLUSH,
723 INMEM, /* the below types are used by tracepoints only. */ 723 INMEM, /* the below types are used by tracepoints only. */
724 INMEM_DROP, 724 INMEM_DROP,
725 INMEM_INVALIDATE,
725 INMEM_REVOKE, 726 INMEM_REVOKE,
726 IPU, 727 IPU,
727 OPU, 728 OPU,
@@ -2184,6 +2185,7 @@ void destroy_node_manager_caches(void);
2184 */ 2185 */
2185void register_inmem_page(struct inode *inode, struct page *page); 2186void register_inmem_page(struct inode *inode, struct page *page);
2186void drop_inmem_pages(struct inode *inode); 2187void drop_inmem_pages(struct inode *inode);
2188void drop_inmem_page(struct inode *inode, struct page *page);
2187int commit_inmem_pages(struct inode *inode); 2189int commit_inmem_pages(struct inode *inode);
2188void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2190void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need);
2189void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2191void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi);
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 4d7bf84dc393..cb6d9ed634a3 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -250,6 +250,36 @@ void drop_inmem_pages(struct inode *inode)
250 stat_dec_atomic_write(inode); 250 stat_dec_atomic_write(inode);
251} 251}
252 252
253void drop_inmem_page(struct inode *inode, struct page *page)
254{
255 struct f2fs_inode_info *fi = F2FS_I(inode);
256 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
257 struct list_head *head = &fi->inmem_pages;
258 struct inmem_pages *cur = NULL;
259
260 f2fs_bug_on(sbi, !IS_ATOMIC_WRITTEN_PAGE(page));
261
262 mutex_lock(&fi->inmem_lock);
263 list_for_each_entry(cur, head, list) {
264 if (cur->page == page)
265 break;
266 }
267
268 f2fs_bug_on(sbi, !cur || cur->page != page);
269 list_del(&cur->list);
270 mutex_unlock(&fi->inmem_lock);
271
272 dec_page_count(sbi, F2FS_INMEM_PAGES);
273 kmem_cache_free(inmem_entry_slab, cur);
274
275 ClearPageUptodate(page);
276 set_page_private(page, 0);
277 ClearPagePrivate(page);
278 f2fs_put_page(page, 0);
279
280 trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE);
281}
282
253static int __commit_inmem_pages(struct inode *inode, 283static int __commit_inmem_pages(struct inode *inode,
254 struct list_head *revoke_list) 284 struct list_head *revoke_list)
255{ 285{