linux-stable/fs/erofs
Sandeep Dhavale 597fb60c75 erofs: Fix detection of atomic context
[ Upstream commit 12d0a24afd ]

Current check for atomic context is not sufficient as
z_erofs_decompressqueue_endio can be called under rcu lock
from blk_mq_flush_plug_list(). See the stacktrace [1]

In such case we should hand off the decompression work for async
processing rather than trying to do sync decompression in current
context. Patch fixes the detection by checking for
rcu_read_lock_any_held() and while at it use more appropriate
!in_task() check than in_atomic().

Background: Historically erofs would always schedule a kworker for
decompression which would incur the scheduling cost regardless of
the context. But z_erofs_decompressqueue_endio() may not always
be in atomic context and we could actually benefit from doing the
decompression in z_erofs_decompressqueue_endio() if we are in
thread context, for example when running with dm-verity.
This optimization was later added in patch [2] which has shown
improvement in performance benchmarks.

==============================================
[1] Problem stacktrace
[name:core&]BUG: sleeping function called from invalid context at kernel/locking/mutex.c:291
[name:core&]in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 1615, name: CpuMonitorServi
[name:core&]preempt_count: 0, expected: 0
[name:core&]RCU nest depth: 1, expected: 0
CPU: 7 PID: 1615 Comm: CpuMonitorServi Tainted: G S      W  OE      6.1.25-android14-5-maybe-dirty-mainline #1
Hardware name: MT6897 (DT)
Call trace:
 dump_backtrace+0x108/0x15c
 show_stack+0x20/0x30
 dump_stack_lvl+0x6c/0x8c
 dump_stack+0x20/0x48
 __might_resched+0x1fc/0x308
 __might_sleep+0x50/0x88
 mutex_lock+0x2c/0x110
 z_erofs_decompress_queue+0x11c/0xc10
 z_erofs_decompress_kickoff+0x110/0x1a4
 z_erofs_decompressqueue_endio+0x154/0x180
 bio_endio+0x1b0/0x1d8
 __dm_io_complete+0x22c/0x280
 clone_endio+0xe4/0x280
 bio_endio+0x1b0/0x1d8
 blk_update_request+0x138/0x3a4
 blk_mq_plug_issue_direct+0xd4/0x19c
 blk_mq_flush_plug_list+0x2b0/0x354
 __blk_flush_plug+0x110/0x160
 blk_finish_plug+0x30/0x4c
 read_pages+0x2fc/0x370
 page_cache_ra_unbounded+0xa4/0x23c
 page_cache_ra_order+0x290/0x320
 do_sync_mmap_readahead+0x108/0x2c0
 filemap_fault+0x19c/0x52c
 __do_fault+0xc4/0x114
 handle_mm_fault+0x5b4/0x1168
 do_page_fault+0x338/0x4b4
 do_translation_fault+0x40/0x60
 do_mem_abort+0x60/0xc8
 el0_da+0x4c/0xe0
 el0t_64_sync_handler+0xd4/0xfc
 el0t_64_sync+0x1a0/0x1a4

[2] Link: https://lore.kernel.org/all/20210317035448.13921-1-huangjianan@oppo.com/

Reported-by: Will Shiu <Will.Shiu@mediatek.com>
Suggested-by: Gao Xiang <xiang@kernel.org>
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Link: https://lore.kernel.org/r/20230621220848.3379029-1-dhavale@google.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-07-27 08:56:46 +02:00
..
Kconfig erofs: use HIPRI by default if per-cpu kthreads are enabled 2023-05-23 16:57:08 +08:00
Makefile erofs: avoid pcpubuf.c inclusion if CONFIG_EROFS_FS_ZIP is off 2023-05-23 16:56:40 +08:00
compress.h erofs: introduce multi-reference pclusters (fully-referenced) 2022-07-22 21:44:27 +08:00
data.c erofs: keep meta inode into erofs_buf 2023-04-17 01:15:50 +08:00
decompressor.c erofs: avoid hardcoded blocksize for subpage block support 2023-04-17 01:15:44 +08:00
decompressor_lzma.c erofs: avoid hardcoded blocksize for subpage block support 2023-04-17 01:15:44 +08:00
dir.c erofs: keep meta inode into erofs_buf 2023-04-17 01:15:50 +08:00
erofs_fs.h erofs: cleanup i_format-related stuffs 2023-04-17 01:15:55 +08:00
fscache.c erofs: avoid hardcoded blocksize for subpage block support 2023-04-17 01:15:44 +08:00
inode.c erofs: fix fsdax unavailability for chunk-based regular files 2023-07-23 13:53:47 +02:00
internal.h erofs: avoid pcpubuf.c inclusion if CONFIG_EROFS_FS_ZIP is off 2023-05-23 16:56:40 +08:00
namei.c erofs: sunset erofs_dbg() 2023-04-17 01:15:54 +08:00
pcpubuf.c erofs: mark z_erofs_lzma_init/erofs_pcpubuf_init w/ __init 2023-03-09 22:49:30 +08:00
super.c erofs: enable long extended attribute name prefixes 2023-04-17 01:15:53 +08:00
sysfs.c erofs: make kobj_type structures constant 2023-02-15 08:11:26 +08:00
utils.c mm: shrinkers: provide shrinkers with names 2022-07-03 18:08:40 -07:00
xattr.c erofs: fix null-ptr-deref caused by erofs_xattr_prefixes_init 2023-05-23 16:56:21 +08:00
xattr.h Changes since last update: 2023-04-24 14:25:39 -07:00
zdata.c erofs: Fix detection of atomic context 2023-07-27 08:56:46 +02:00
zmap.c erofs: fix compact 4B support for 16k block size 2023-07-19 16:35:12 +02:00