diff options
author | Chao Yu <yuchao0@huawei.com> | 2019-07-12 04:55:42 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-08-23 10:57:10 -0400 |
commit | c72db71ed61ff51c2b8189ac9889dd18f22eb612 (patch) | |
tree | 4bef38d6caa090bd0de2d8d504763b33881350c1 | |
parent | 8896cbdfed0ca34452252b72d6ee97bcfca9abd2 (diff) |
f2fs: fix panic of IO alignment feature
Since 07173c3ec276 ("block: enable multipage bvecs"), one bio vector
can store multi pages, so that we can not calculate max IO size of
bio as PAGE_SIZE * bio->bi_max_vecs. However IO alignment feature of
f2fs always has that assumption, so finally, it may cause panic during
IO submission as below stack.
kernel BUG at fs/f2fs/data.c:317!
RIP: 0010:__submit_merged_bio+0x8b0/0x8c0
Call Trace:
f2fs_submit_page_write+0x3cd/0xdd0
do_write_page+0x15d/0x360
f2fs_outplace_write_data+0xd7/0x210
f2fs_do_write_data_page+0x43b/0xf30
__write_data_page+0xcf6/0x1140
f2fs_write_cache_pages+0x3ba/0xb40
f2fs_write_data_pages+0x3dd/0x8b0
do_writepages+0xbb/0x1e0
__writeback_single_inode+0xb6/0x800
writeback_sb_inodes+0x441/0x910
wb_writeback+0x261/0x650
wb_workfn+0x1f9/0x7a0
process_one_work+0x503/0x970
worker_thread+0x7d/0x820
kthread+0x1ad/0x210
ret_from_fork+0x35/0x40
This patch adds one extra condition to check left space in bio while
trying merging page to bio, to avoid panic.
This bug was reported in bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=204043
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | fs/f2fs/data.c | 10 | ||||
-rw-r--r-- | fs/f2fs/super.c | 2 | ||||
-rw-r--r-- | include/linux/f2fs_fs.h | 1 |
3 files changed, 12 insertions, 1 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 0686306ed988..5bce20005add 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c | |||
@@ -503,6 +503,16 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, | |||
503 | block_t last_blkaddr, | 503 | block_t last_blkaddr, |
504 | block_t cur_blkaddr) | 504 | block_t cur_blkaddr) |
505 | { | 505 | { |
506 | if (F2FS_IO_ALIGNED(sbi) && (fio->type == DATA || fio->type == NODE)) { | ||
507 | unsigned int filled_blocks = | ||
508 | F2FS_BYTES_TO_BLK(bio->bi_iter.bi_size); | ||
509 | unsigned int io_size = F2FS_IO_SIZE(sbi); | ||
510 | unsigned int left_vecs = bio->bi_max_vecs - bio->bi_vcnt; | ||
511 | |||
512 | /* IOs in bio is aligned and left space of vectors is not enough */ | ||
513 | if (!(filled_blocks % io_size) && left_vecs < io_size) | ||
514 | return false; | ||
515 | } | ||
506 | if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr)) | 516 | if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr)) |
507 | return false; | 517 | return false; |
508 | return io_type_is_mergeable(io, fio); | 518 | return io_type_is_mergeable(io, fio); |
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 78a1b873e48a..720f2e6d6f0a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -3202,7 +3202,7 @@ try_onemore: | |||
3202 | if (err) | 3202 | if (err) |
3203 | goto free_bio_info; | 3203 | goto free_bio_info; |
3204 | 3204 | ||
3205 | if (F2FS_IO_SIZE(sbi) > 1) { | 3205 | if (F2FS_IO_ALIGNED(sbi)) { |
3206 | sbi->write_io_dummy = | 3206 | sbi->write_io_dummy = |
3207 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); | 3207 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); |
3208 | if (!sbi->write_io_dummy) { | 3208 | if (!sbi->write_io_dummy) { |
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 65559900d4d7..52af9ac164b4 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h | |||
@@ -41,6 +41,7 @@ | |||
41 | #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */ | 41 | #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */ |
42 | #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */ | 42 | #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */ |
43 | #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1) | 43 | #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1) |
44 | #define F2FS_IO_ALIGNED(sbi) (F2FS_IO_SIZE(sbi) > 1) | ||
44 | 45 | ||
45 | /* This flag is used by node and meta inodes, and by recovery */ | 46 | /* This flag is used by node and meta inodes, and by recovery */ |
46 | #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) | 47 | #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) |