f2fs: compress: fix panic in mkwrite
PATCH 1/4 f2fs: compress: fix panic in mkwrite
[ 1237.458208] invalid opcode: 0000 [#1] SMP PTI [ 1237.458228] CPU: 9 PID: 6291 Comm: fsstress Tainted: G OE 5.5.0-rc1 #36 [ 1237.458255] Hardware name: Xen HVM domU, BIOS 4.1.2_115-908.790. 06/05/2017 [ 1237.458299] RIP: 0010:f2fs_vm_page_mkwrite+0x1c6/0x630 [f2fs] [ 1237.458321] Code: d6 fe ff ff 49 8b 75 20 48 89 df e8 24 0a 05 00 85 c0 41 89 c7 78 8e 0f 84 bd fe ff ff 45 31 f6 41 83 ff 02 0f 85 c3 fe ff ff <0f> 0b 45 84 f6 0f 84 e4 00 00 00 ba 01 00 00 00 be 05 00 00 00 48 [ 1237.458374] RSP: 0000:ffffaecdc0c1bd38 EFLAGS: 00010246 [ 1237.458395] RAX: 0000000000000002 RBX: ffff9241c5b5d8c0 RCX: 0000000000000000 [ 1237.458418] RDX: ffffeeb715d42407 RSI: ffff9242d8085168 RDI: 0000000000000000 [ 1237.458441] RBP: ffff9243f1c67000 R08: 0000000000017677 R09: 0000000000000004 [ 1237.458463] R10: 0000000000000000 R11: ffff9242d8085000 R12: ffffaecdc0c1bdf8 [ 1237.458488] R13: ffffeeb715d037c0 R14: 0000000000000000 R15: 0000000000000002 [ 1237.458512] FS: 00007f71f28ce700(0000) GS:ffff92443d840000(0000) knlGS:0000000000000000 [ 1237.458540] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1237.458561] CR2: 00007f71f28c9000 CR3: 00000007e0ba2003 CR4: 00000000001606e0 [ 1237.458586] Call Trace: [ 1237.458611] do_page_mkwrite+0x5a/0xc0 [ 1237.458630] __handle_mm_fault+0xb81/0x12a0 [ 1237.458648] ? do_mmap+0x4bd/0x640 [ 1237.458665] handle_mm_fault+0xe3/0x1d0 [ 1237.458686] __do_page_fault+0x288/0x500 [ 1237.458704] do_page_fault+0x30/0x120 [ 1237.458725] page_fault+0x3e/0x50
--- fs/f2fs/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/file.c +4 -1
@@ -72,7 +72,10 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) err = ret; goto err; }else if (ret) { -f2fs_bug_on (sbi, ret ==CLUSTER_HAS_SPACE ); +if (ret ==CLUSTER_HAS_SPACE ) { + err = -EAGAIN ; + goto err; + } need_alloc = false; } }
Signature · 1 line
2.18.0.rc1
PATCH 2/4 f2fs: compress: revert error path fix
Revert incorrect fix in ("TEMP: f2fs: support data compression - fix1")
--- fs/f2fs/compress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/compress.c +3 -3
@@ -601,7 +601,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, fgp_flag, GFP_NOFS);if (!page) { ret = -ENOMEM ; - goto release_pages; + goto unlock_pages; }if (PageUptodate (page))
@@ -616,13 +616,13 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, ret =f2fs_read_multi_pages (cc, &bio, cc->cluster_size, &last_block_in_bio, false);if (ret) - goto unlock_pages; + goto release_pages;if (bio)f2fs_submit_bio (sbi, bio,DATA ); ret =f2fs_init_compress_ctx (cc);if (ret) - goto unlock_pages; + goto release_pages; }for (i =0 ; i < cc->cluster_size; i++) {
Signature · 1 line
2.18.0.rc1
Jaegeuk Kim
maintainerRe: [PATCH 2/4] f2fs: compress: revert error path fix
Hi Chao,
Could you please check this out?
https://github.com/jaegeuk/f2fs/commits/g-dev-test
Thanks,
Quoted 38 lines · Chao Yu
Revert incorrect fix in ("TEMP: f2fs: support data compression - fix1")
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/compress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/f2fs/compress.c +3
-3@@ -601,7 +601,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, fgp_flag, GFP_NOFS);if (!page) { ret = -ENOMEM ; - goto release_pages; + goto unlock_pages; }if (PageUptodate (page))@@ -616,13 +616,13 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, ret =f2fs_read_multi_pages (cc, &bio, cc->cluster_size, &last_block_in_bio, false);if (ret) - goto unlock_pages; + goto release_pages;if (bio)f2fs_submit_bio (sbi, bio,DATA ); ret =f2fs_init_compress_ctx (cc);if (ret) - goto unlock_pages; + goto release_pages; }for (i =0 ; i < cc->cluster_size; i++) {Signature · 1 line
2.18.0.rc1
Re: [PATCH 2/4] f2fs: compress: revert error path fix
Quoted 4 lines · Jaegeuk Kim
Hi Chao,
Could you please check this out?
https://github.com/jaegeuk/f2fs/commits/g-dev-test
Looks good to me, I add some minor comments on github.
Any comments on below thread?
Re: [f2fs-dev] [PATCH 3/4] f2fs: compress: fix error path in prepare_compress_overwrite()
Thanks,
Quoted 44 lines
Thanks,
Quoted 38 lines · Chao Yu
Revert incorrect fix in ("TEMP: f2fs: support data compression - fix1")
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/compress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/f2fs/compress.c +3
-3@@ -601,7 +601,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, fgp_flag, GFP_NOFS);if (!page) { ret = -ENOMEM ; - goto release_pages; + goto unlock_pages; }if (PageUptodate (page))@@ -616,13 +616,13 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, ret =f2fs_read_multi_pages (cc, &bio, cc->cluster_size, &last_block_in_bio, false);if (ret) - goto unlock_pages; + goto release_pages;if (bio)f2fs_submit_bio (sbi, bio,DATA ); ret =f2fs_init_compress_ctx (cc);if (ret) - goto unlock_pages; + goto release_pages; }for (i =0 ; i < cc->cluster_size; i++) {Signature · 1 line
2.18.0.rc1.
PATCH 3/4 f2fs: compress: fix error path in prepare_compress_overwrite()
In reply to Chao Yu- fix to release cluster pages in retry flow
- fix to call f2fs_put_dnode() & __do_map_lock() in error path
--- fs/f2fs/compress.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
fs/f2fs/compress.c +16 -6
@@ -626,20 +626,26 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, }for (i =0 ; i < cc->cluster_size; i++) { +f2fs_bug_on (sbi, cc->rpages[i]); + page =find_lock_page (mapping, start_idx + i);f2fs_bug_on (sbi, !page);f2fs_wait_on_page_writeback (page,DATA , true, true); - cc->rpages[i] = page; +f2fs_compress_ctx_add_page (cc, page);f2fs_put_page (page,0 );if (!PageUptodate (page)) { -for (idx =0 ; idx < cc->cluster_size; idx++) { -f2fs_put_page (cc->rpages[idx], - (idx <= i) ?1 :0 ); +for (idx =0 ; idx <= i; idx++) { +unlock_page (cc->rpages[idx]); cc->rpages[idx] =NULL ; } +for (idx =0 ; idx < cc->cluster_size; idx++) { + page =find_lock_page (mapping, start_idx + idx); +f2fs_put_page (page,1 ); +f2fs_put_page (page,0 ); + }kvfree (cc->rpages); cc->nr_rpages =0 ; goto retry;
@@ -654,16 +660,20 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,for (i = cc->cluster_size -1 ; i >0 ; i--) { ret =f2fs_get_block (&dn, start_idx + i);if (ret) { -/* TODO: release preallocate blocks */ i = cc->cluster_size; - goto unlock_pages; +break ; }if (dn.data_blkaddr !=NEW_ADDR )break ; } +f2fs_put_dnode (&dn); +__do_map_lock (sbi,F2FS_GET_BLOCK_PRE_AIO , false); + +if (ret) + goto unlock_pages; } *fsdata = cc->rpages;
Signature · 1 line
2.18.0.rc1
Jaegeuk Kim
maintainerRe: [PATCH 3/4] f2fs: compress: fix error path in prepare_compress_overwrite()
Quoted 27 lines · Chao Yu
- fix to release cluster pages in retry flow
- fix to callf2fs_put_dnode()&__do_map_lock()in error pathSigned-off-by Chao Yu <[email protected]>--- fs/f2fs/compress.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)fs/f2fs/compress.c +3
-1@@ -626,20 +626,26 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, }for (i =0 ; i < cc->cluster_size; i++) { +f2fs_bug_on (sbi, cc->rpages[i]); + page =find_lock_page (mapping, start_idx + i);f2fs_bug_on (sbi, !page);f2fs_wait_on_page_writeback (page,DATA , true, true); - cc->rpages[i] = page; +f2fs_compress_ctx_add_page (cc, page);f2fs_put_page (page,0 );
fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 645
Quoted 10 lines
fs/f2fs/compress.c +4
-3if (!PageUptodate (page)) { -for (idx =0 ; idx < cc->cluster_size; idx++) { -f2fs_put_page (cc->rpages[idx], - (idx <= i) ?1 :0 ); +for (idx =0 ; idx <= i; idx++) { +unlock_page (cc->rpages[idx]); cc->rpages[idx] =NULL ; } +for (idx =0 ; idx < cc->cluster_size; idx++) { + page =find_lock_page (mapping, start_idx + idx);
Why do we need to lock the pages again?
Quoted 11 lines
fs/f2fs/compress.c +3
-1+f2fs_put_page (page,1 ); +f2fs_put_page (page,0 ); + }kvfree (cc->rpages); cc->nr_rpages =0 ; goto retry;@@ -654,16 +660,20 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,for (i = cc->cluster_size -1 ; i >0 ; i--) { ret =f2fs_get_block (&dn, start_idx + i);if (ret) { -/* TODO: release preallocate blocks */
fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 671
Quoted 10 lines
fs/f2fs/compress.c +2
-1i = cc->cluster_size; - goto unlock_pages; +break ; }if (dn.data_blkaddr !=NEW_ADDR )break ; } +f2fs_put_dnode (&dn);
We don't neeed this, since f2fs_reserve_block() put the dnode.
Quoted 10 lines
fs/f2fs/compress.c +4
-0+__do_map_lock (sbi,F2FS_GET_BLOCK_PRE_AIO , false); + +if (ret) + goto unlock_pages; } *fsdata = cc->rpages;Signature · 1 line
2.18.0.rc1
Re: [PATCH 3/4] f2fs: compress: fix error path in prepare_compress_overwrite()
Quoted 28 lines · Jaegeuk Kim
Quoted 27 lines · Chao Yu
- fix to release cluster pages in retry flow
- fix to callf2fs_put_dnode()&__do_map_lock()in error pathSigned-off-by Chao Yu <[email protected]>--- fs/f2fs/compress.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)fs/f2fs/compress.c +3
-1@@ -626,20 +626,26 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, }for (i =0 ; i < cc->cluster_size; i++) { +f2fs_bug_on (sbi, cc->rpages[i]); + page =find_lock_page (mapping, start_idx + i);f2fs_bug_on (sbi, !page);f2fs_wait_on_page_writeback (page,DATA , true, true); - cc->rpages[i] = page; +f2fs_compress_ctx_add_page (cc, page);f2fs_put_page (page,0 );
Quoted 12 lines
fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 645
Quoted 10 lines
fs/f2fs/compress.c +4
-3if (!PageUptodate (page)) { -for (idx =0 ; idx < cc->cluster_size; idx++) { -f2fs_put_page (cc->rpages[idx], - (idx <= i) ?1 :0 ); +for (idx =0 ; idx <= i; idx++) { +unlock_page (cc->rpages[idx]); cc->rpages[idx] =NULL ; } +for (idx =0 ; idx < cc->cluster_size; idx++) { + page =find_lock_page (mapping, start_idx + idx);Why do we need to lock the pages again?
Here, all pages in cluster has one extra reference count, we need to find all pages, and release those references on them.
cc->rpages may not record all pages' pointers, so we can not use
f2fs_put_page(cc->rpages[idx], (idx <= i) ? 1 : 0); to release all pages' references.
BTW, find_get_page() should be fine to instead find_lock_page().
Quoted 17 lines
Quoted 17 lines
fs/f2fs/compress.c +4
-2+f2fs_put_page (page,1 ); +f2fs_put_page (page,0 ); + }kvfree (cc->rpages); cc->nr_rpages =0 ; goto retry;@@ -654,16 +660,20 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,for (i = cc->cluster_size -1 ; i >0 ; i--) { ret =f2fs_get_block (&dn, start_idx + i);if (ret) { -/* TODO: release preallocate blocks */ i = cc->cluster_size; - goto unlock_pages; +break ; }
Quoted 7 lines
fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 671
Quoted 5 lines
fs/f2fs/compress.c +1
-0if (dn.data_blkaddr !=NEW_ADDR )break ; } +f2fs_put_dnode (&dn);We don't neeed this, since
f2fs_reserve_block()put the dnode.
Correct.
Thanks,
Quoted 13 lines
Quoted 11 lines
fs/f2fs/compress.c +4
-0+__do_map_lock (sbi,F2FS_GET_BLOCK_PRE_AIO , false); + +if (ret) + goto unlock_pages; } *fsdata = cc->rpages;Signature · 1 line
2.18.0.rc1.
Jaegeuk Kim
maintainerRe: [PATCH 3/4] f2fs: compress: fix error path in prepare_compress_overwrite()
Quoted 42 lines · Chao Yu
Quoted 28 lines · Jaegeuk Kim
Quoted 27 lines · Chao Yu
- fix to release cluster pages in retry flow
- fix to callf2fs_put_dnode()&__do_map_lock()in error pathSigned-off-by Chao Yu <[email protected]>--- fs/f2fs/compress.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)fs/f2fs/compress.c +3
-1@@ -626,20 +626,26 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, }for (i =0 ; i < cc->cluster_size; i++) { +f2fs_bug_on (sbi, cc->rpages[i]); + page =find_lock_page (mapping, start_idx + i);f2fs_bug_on (sbi, !page);f2fs_wait_on_page_writeback (page,DATA , true, true); - cc->rpages[i] = page; +f2fs_compress_ctx_add_page (cc, page);f2fs_put_page (page,0 );Quoted 12 lines
fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 645
Quoted 10 lines
fs/f2fs/compress.c +4
-3if (!PageUptodate (page)) { -for (idx =0 ; idx < cc->cluster_size; idx++) { -f2fs_put_page (cc->rpages[idx], - (idx <= i) ?1 :0 ); +for (idx =0 ; idx <= i; idx++) { +unlock_page (cc->rpages[idx]); cc->rpages[idx] =NULL ; } +for (idx =0 ; idx < cc->cluster_size; idx++) { + page =find_lock_page (mapping, start_idx + idx);Why do we need to lock the pages again?
Quoted 8 lines
Here, all pages in cluster has one extra reference count, we need to find all pages, and release those references on them.
cc->rpagesmay not record all pages' pointers, so we can not use
f2fs_put_page(cc->rpages[idx], (idx <= i) ? 1 : 0); to release all pages' references.BTW,
find_get_page()should be fine to insteadfind_lock_page().
Could you take a look at this?
https://github.com/jaegeuk/f2fs/commit/2e4ea726633dd2666f57ae88dfec5d97694d6495
Thanks,
Quoted 43 lines
Quoted 18 lines
Quoted 18 lines
fs/f2fs/compress.c +4
-2+f2fs_put_page (page,1 ); +f2fs_put_page (page,0 ); + }kvfree (cc->rpages); cc->nr_rpages =0 ; goto retry;@@ -654,16 +660,20 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,for (i = cc->cluster_size -1 ; i >0 ; i--) { ret =f2fs_get_block (&dn, start_idx + i);if (ret) { -/* TODO: release preallocate blocks */ i = cc->cluster_size; - goto unlock_pages; +break ; }Quoted 7 lines
fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 671
Quoted 5 lines
fs/f2fs/compress.c +1
-0if (dn.data_blkaddr !=NEW_ADDR )break ; } +f2fs_put_dnode (&dn);We don't neeed this, since
f2fs_reserve_block()put the dnode.Correct.
Thanks,
Quoted 13 lines
Quoted 11 lines
fs/f2fs/compress.c +4
-0+__do_map_lock (sbi,F2FS_GET_BLOCK_PRE_AIO , false); + +if (ret) + goto unlock_pages; } *fsdata = cc->rpages;Signature · 1 line
2.18.0.rc1.
PATCH 4/4 f2fs: compress: release compress context in caller of f2fs_read_multi_pages()
In reply to Chao YuExecute initialize/destroy flow of compress context outside of f2fs_read_multi_pages()
--- fs/f2fs/compress.c | 1 + fs/f2fs/data.c | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-)
fs/f2fs/compress.c +1 -0
@@ -615,6 +615,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, ret =f2fs_read_multi_pages (cc, &bio, cc->cluster_size, &last_block_in_bio, false); +f2fs_destroy_compress_ctx (cc);if (ret) goto release_pages;if (bio)
fs/f2fs/data.c +3 -7
@@ -2121,7 +2121,6 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, false);f2fs_free_dic (dic);f2fs_put_dnode (&dn); -f2fs_destroy_compress_ctx (cc); *bio_ret = bio;return ret; }
@@ -2139,7 +2138,6 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,f2fs_put_dnode (&dn); -f2fs_destroy_compress_ctx (cc); *bio_ret = bio;return 0 ;
@@ -2213,10 +2211,9 @@ int f2fs_mpage_readpages(struct address_space *mapping, max_nr_pages, &last_block_in_bio, is_readahead); -if (ret) { -f2fs_destroy_compress_ctx (&cc); +f2fs_destroy_compress_ctx (&cc); +if (ret) goto set_error_page; - } } ret =f2fs_is_compressed_cluster (inode, page->index);if (ret <0 )
@@ -2257,8 +2254,7 @@ int f2fs_mpage_readpages(struct address_space *mapping, max_nr_pages, &last_block_in_bio, is_readahead); -if (ret) - f2fs_destroy_compress_ctx(&cc); + f2fs_destroy_compress_ctx(&cc); } }#endif
Signature · 1 line
2.18.0.rc1