f2fs: Avoid using empty extent_tree when look up extent cache

If CONFIG_F2FS_CHECK_FS is not enabled, the lookup_extent_tree function will continue to run when
the extent_tree is NULL, causing the kernel to crash. The dump like this:
[05-13 09:41:14][ 3309.526262] Unable to handle kernel NULL pointer dereference at virtual a5ddress 0000000000000040
[05-13 09:41:14][ 3309.715348] Mem abort info:
[05-13 09:41:14][ 3309.715618]   ESR = 0x96000006
[05-13 09:41:14][ 3309.715899]   Exception class = DABT (current EL), IL = 32 bits
[05-13 09:41:14][ 3309.716416]   SET = 0, FnV = 0
[05-13 09:41:14][ 3309.716693]   EA = 0, S1PTW = 0
[05-13 09:41:14][ 3309.717003] Data abort info:
[05-13 09:41:14][ 3309.717260]   ISV = 0, ISS = 0x00000006
[05-13 09:41:14]  0): Mem abort info:
[05-13 09:41:14]05-13 01:40:58.784 F/        (    0): ESR = 0x96000006
[05-13 09:41:14]05-13 01:40:58.784 F/        (    0): Exception class = DABT (current EL), IL = 32 bits
[05-13 09:41:14]05-13 01:40:58.785 F/        (    0): SET = 0, FnV = 0
[05-13 09:41:14]05-13 01:40:58.785 F/        (    0): EA = 0, S1PTW = 0
[05-13 09:41:14]05-13 01:40:58.785 F/        (    0): Data abort info:
[05-13 09:41:14]05-13 01:40:58.785 F/        (    0): ISV = 0, ISS = 0x00000006
[05-13 09:41:14]05-13 01:40:58.792 F/Internal error(    0): Oops: 96000006 [#1] PREEMPT SMP
[05-13 09:41:14][ 3309.726031] Process Binder:382_1 (pid: 396, stack limit = 0x00000000b36c00c5)
[05-13 09:41:14][ 3309.726670] CPU: 3 PID: 396 Comm: Binder:382_1 Tainted: G        W         4.19.172 #166
[05-13 09:41:14][ 3309.727380] Hardware name: Rockchip RK3566 RK817 TABLET LP4X Board (DT)
[05-13 09:41:14][ 3309.727968] pstate: 60400009 (nZCv daif +PAN -UAO)
[05-13 09:41:14][ 3309.728412] pc : _raw_read_lock+0x20/0x48
[05-13 09:41:14][ 3309.728779] lr : f2fs_lookup_extent_tree+0xd0/0x330
[05-13 09:41:14][ 3309.729216] sp : ffffff800cc3b700
[05-13 09:41:14][ 3309.818050] Call trace:
[05-13 09:41:14][ 3309.818288]  _raw_read_lock+0x20/0x48
[05-13 09:41:14][ 3309.818617]  f2fs_lookup_extent_tree+0xd0/0x330
[05-13 09:41:14][ 3309.819021]  f2fs_lookup_extent_cache+0x4c/0x60
[05-13 09:41:14][ 3309.819427]  f2fs_map_blocks+0x84/0x9e8
[05-13 09:41:14][ 3309.819774]  f2fs_mpage_readpages+0x1e8/0x604
[05-13 09:41:14][ 3309.820166]  f2fs_read_data_pages+0xf4/0x11c
[05-13 09:41:14][ 3309.820551]  read_pages+0x64/0x148
[05-13 09:41:14][ 3309.820852]  __do_page_cache_readahead+0x164/0x1c4
[05-13 09:41:14][ 3309.821278]  ondemand_readahead+0x1e4/0x264
[05-13 09:41:14][ 3309.821647]  page_cache_async_readahead+0xb4/0xd0
[05-13 09:41:14][ 3309.822066]  generic_file_read_iter+0x168/0x8b4
[05-13 09:41:14][ 3309.822474]  f2fs_file_read_iter+0x34/0xa0
[05-13 09:41:14][ 3309.822848]  generic_file_splice_read+0xc8/0x144
[05-13 09:41:14][ 3309.823263]  splice_direct_to_actor+0xf8/0x274
[05-13 09:41:14][ 3309.823655]  do_splice_direct+0x78/0xc8
[05-13 09:41:14][ 3309.824008]  do_sendfile+0x1cc/0x404
[05-13 09:41:14][ 3309.824336]  __se_compat_sys_sendfile+0x9c/0x26c
[05-13 09:41:14][ 3309.824750]  __arm64_compat_sys_sendfile+0x18/0x20
[05-13 09:41:14][ 3309.825181]  el0_svc_common+0x98/0x160
[05-13 09:41:14][ 3309.825518]  el0_svc_compat_handler+0x18/0x20
[05-13 09:41:14][ 3309.825913]  el0_svc_compat+0x8/0x34
[05-13 09:41:14][ 3309.826244] Code: aa0003e1 52804000 11000529 b9001909 (b8a0003e)

Signed-off-by: Cliff Chen <cliff.chen@rock-chips.com>
Change-Id: Ic7d144eb2518ecc255428eff1c493dbcb36d7976
This commit is contained in:
Cliff Chen
2021-06-07 11:46:55 +08:00
committed by Tao Huang
parent f8d073dcd3
commit ce02e6a41d

View File

@@ -383,6 +383,9 @@ static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
f2fs_bug_on(sbi, !et);
if (!et)
return ret;
trace_f2fs_lookup_extent_tree_start(inode, pgofs);
read_lock(&et->lock);