linux/fs/nilfs2
Ryusuke Konishi eb85dace89 nilfs2: fix potential hang in nilfs_detach_log_writer()
Syzbot has reported a potential hang in nilfs_detach_log_writer() called
during nilfs2 unmount.

Analysis revealed that this is because nilfs_segctor_sync(), which
synchronizes with the log writer thread, can be called after
nilfs_segctor_destroy() terminates that thread, as shown in the call trace
below:

nilfs_detach_log_writer
  nilfs_segctor_destroy
    nilfs_segctor_kill_thread  --> Shut down log writer thread
    flush_work
      nilfs_iput_work_func
        nilfs_dispose_list
          iput
            nilfs_evict_inode
              nilfs_transaction_commit
                nilfs_construct_segment (if inode needs sync)
                  nilfs_segctor_sync  --> Attempt to synchronize with
                                          log writer thread
                           *** DEADLOCK ***

Fix this issue by changing nilfs_segctor_sync() so that the log writer
thread returns normally without synchronizing after it terminates, and by
forcing tasks that are already waiting to complete once after the thread
terminates.

The skipped inode metadata flushout will then be processed together in the
subsequent cleanup work in nilfs_segctor_destroy().

Link: https://lkml.kernel.org/r/20240520132621.4054-4-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+e3973c409251e136fdd0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e3973c409251e136fdd0
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Cc: "Bai, Shuangpeng" <sjb7183@psu.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-05-24 11:55:07 -07:00
..
alloc.c nilfs2: convert persistent object allocator to use kmap_local 2024-02-22 15:38:53 -08:00
alloc.h
bmap.c nilfs2: do not acquire rwsem in nilfs_bmap_write() 2024-02-22 15:38:53 -08:00
bmap.h
btnode.c
btnode.h
btree.c nilfs2: add kernel-doc comments to nilfs_btree_convert_and_insert() 2024-04-25 21:07:08 -07:00
btree.h
cpfile.c nilfs2: use div64_ul() instead of do_div() 2024-03-12 13:09:23 -07:00
cpfile.h nilfs2: remove nilfs_cpfile_{get,put}_checkpoint() 2024-02-22 15:38:53 -08:00
dat.c nilfs2: use div64_ul() instead of do_div() 2024-03-12 13:09:23 -07:00
dat.h
dir.c Mainly singleton patches, documented in their respective changelogs. 2024-05-19 14:02:03 -07:00
direct.c nilfs2: fix failure to detect DAT corruption in btree and direct mappings 2024-03-14 09:17:29 -07:00
direct.h
export.h
file.c
gcinode.c nilfs2: add kernel-doc comments to nilfs_remove_all_gcinodes() 2024-04-25 21:07:08 -07:00
ifile.c nilfs2: localize highmem mapping for checkpoint reading within cpfile 2024-02-22 15:38:53 -08:00
ifile.h nilfs2: localize highmem mapping for checkpoint reading within cpfile 2024-02-22 15:38:53 -08:00
inode.c nilfs2: prevent kernel bug at submit_bh_wbc() 2024-03-14 09:17:30 -07:00
ioctl.c nilfs2: fix out-of-range warning 2024-04-09 10:52:12 +02:00
Kconfig
Makefile
mdt.c nilfs2: convert metadata file common code to use kmap_local 2024-02-22 15:38:53 -08:00
mdt.h
namei.c
nilfs.h nilfs2: convert to use the new mount API 2024-05-08 08:41:27 -07:00
page.c
page.h
recovery.c nilfs2: make block erasure safe in nilfs_finish_roll_forward() 2024-05-19 14:36:21 -07:00
segbuf.c
segbuf.h
segment.c nilfs2: fix potential hang in nilfs_detach_log_writer() 2024-05-24 11:55:07 -07:00
segment.h
sufile.c nilfs2: use div64_ul() instead of do_div() 2024-03-12 13:09:23 -07:00
sufile.h
super.c nilfs2: convert to use the new mount API 2024-05-08 08:41:27 -07:00
sysfs.c
sysfs.h
the_nilfs.c nilfs2: make superblock data array index computation sparse friendly 2024-05-08 08:41:28 -07:00
the_nilfs.h nilfs2: convert to use the new mount API 2024-05-08 08:41:27 -07:00