linux-stable/fs/ubifs
Zhihao Cheng 81f076b88f ubifs: Fix deadlock in concurrent bulk-read and writepage
commit f5de5b8330 upstream.

In ubifs, concurrent execution of writepage and bulk read on the same file
may cause ABBA deadlock, for example (Reproduce method see Link):

Process A(Bulk-read starts from page4)         Process B(write page4 back)
  vfs_read                                       wb_workfn or fsync
  ...                                            ...
  generic_file_buffered_read                     write_cache_pages
    ubifs_readpage                                 LOCK(page4)

      ubifs_bulk_read                              ubifs_writepage
        LOCK(ui->ui_mutex)                           ubifs_write_inode

	  ubifs_do_bulk_read                           LOCK(ui->ui_mutex)
	    find_or_create_page(alloc page4)                  ↑
	      LOCK(page4)                   <--     ABBA deadlock occurs!

In order to ensure the serialization execution of bulk read, we can't
remove the big lock 'ui->ui_mutex' in ubifs_bulk_read(). Instead, we
allow ubifs_do_bulk_read() to lock page failed by replacing
find_or_create_page(FGP_LOCK) with
pagecache_get_page(FGP_LOCK | FGP_NOWAIT).

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Suggested-by: zhangyi (F) <yi.zhang@huawei.com>
Cc: <Stable@vger.kernel.org>
Fixes: 4793e7c5e1 ("UBIFS: add bulk-read facility")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206153
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-11 04:34:00 -08:00
..
budget.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
commit.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
compress.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
crypto.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
debug.c ubifs: Rework ubifs_assert() 2018-08-15 00:25:21 +02:00
debug.h ubifs: Rework ubifs_assert() 2018-08-15 00:25:21 +02:00
dir.c ubifs: don't trigger assertion on invalid no-key filename 2020-02-11 04:34:00 -08:00
file.c ubifs: Fix deadlock in concurrent bulk-read and writepage 2020-02-11 04:34:00 -08:00
find.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
gc.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
io.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
ioctl.c ubifs: Fix FS_IOC_SETFLAGS unexpectedly clearing encrypt flag 2020-02-11 04:34:00 -08:00
journal.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
Kconfig ubifs: introduce Kconfig symbol for xattr support 2018-08-15 00:25:14 +02:00
key.h ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
log.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
lprops.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
lpt.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
lpt_commit.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
Makefile ubifs: introduce Kconfig symbol for xattr support 2018-08-15 00:25:14 +02:00
master.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
misc.c ubifs: Allow setting assert action as mount parameter 2018-08-15 00:25:21 +02:00
misc.h ubifs: Allow setting assert action as mount parameter 2018-08-15 00:25:21 +02:00
orphan.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
recovery.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
replay.c ubifs: Handle re-linking of inodes correctly while recovery 2018-12-29 13:37:55 +01:00
sb.c ubifs: Fix default compression selection in ubifs 2019-12-05 09:20:09 +01:00
scan.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
shrinker.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
super.c ubifs: Fix WARN_ON logic in exit path 2018-10-13 11:05:02 +02:00
tnc.c ubifs: Correctly use tnc_next() in search_dh_cookie() 2019-09-19 09:09:37 +02:00
tnc_commit.c ubifs: ubifs_tnc_start_commit: Fix OOB in layout_in_gaps 2020-01-09 10:19:09 +01:00
tnc_misc.c ubifs: Pass struct ubifs_info to ubifs_assert() 2018-08-15 00:25:21 +02:00
ubifs-media.h ubifs: Raise write version to 5 2016-12-12 23:07:38 +01:00
ubifs.h ubifs: Rework ubifs_assert() 2018-08-15 00:25:21 +02:00
xattr.c Revert "ubifs: xattr: Don't operate on deleted inodes" 2018-09-20 21:37:41 +02:00