linux-stable/fs/nilfs2
Ryusuke Konishi bcb5016559 nilfs2: fix unexpected freezing of nilfs_segctor_sync()
commit 936184eadd upstream.

A potential and reproducible race issue has been identified where
nilfs_segctor_sync() would block even after the log writer thread writes a
checkpoint, unless there is an interrupt or other trigger to resume log
writing.

This turned out to be because, depending on the execution timing of the
log writer thread running in parallel, the log writer thread may skip
responding to nilfs_segctor_sync(), which causes a call to schedule()
waiting for completion within nilfs_segctor_sync() to lose the opportunity
to wake up.

The reason why waking up the task waiting in nilfs_segctor_sync() may be
skipped is that updating the request generation issued using a shared
sequence counter and adding an wait queue entry to the request wait queue
to the log writer, are not done atomically.  There is a possibility that
log writing and request completion notification by nilfs_segctor_wakeup()
may occur between the two operations, and in that case, the wait queue
entry is not yet visible to nilfs_segctor_wakeup() and the wake-up of
nilfs_segctor_sync() will be carried over until the next request occurs.

Fix this issue by performing these two operations simultaneously within
the lock section of sc_state_lock.  Also, following the memory barrier
guidelines for event waiting loops, move the call to set_current_state()
in the same location into the event waiting loop to ensure that a memory
barrier is inserted just before the event condition determination.

Link: https://lkml.kernel.org/r/20240520132621.4054-3-konishi.ryusuke@gmail.com
Fixes: 9ff05123e3 ("nilfs2: segment constructor")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-06-16 13:28:30 +02:00
..
alloc.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
alloc.h
bmap.c nilfs2: fix infinite loop in nilfs_mdt_get_block() 2023-05-17 11:35:54 +02:00
bmap.h
btnode.c nilfs2: fix incomplete buffer cleanup in nilfs_btnode_abort_change_key() 2023-06-21 15:44:10 +02:00
btnode.h nilfs2: fix lockdep warnings in page operations for btree nodes 2022-05-25 09:14:33 +02:00
btree.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
btree.h
cpfile.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
cpfile.h
dat.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
dat.h
dir.c nilfs2: fix OOB in nilfs_set_de_type 2024-05-02 16:18:32 +02:00
direct.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
direct.h
export.h
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-23 08:25:12 +01:00
gcinode.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
ifile.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
ifile.h
inode.c nilfs2: prevent kernel bug at submit_bh_wbc() 2024-04-13 12:51:28 +02:00
ioctl.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
Kconfig
Makefile
mdt.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
mdt.h nilfs2: fix lockdep warnings during disk space reclamation 2022-05-25 09:14:33 +02:00
namei.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
nilfs.h nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
page.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
page.h
recovery.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
segbuf.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
segbuf.h
segment.c nilfs2: fix unexpected freezing of nilfs_segctor_sync() 2024-06-16 13:28:30 +02:00
segment.h
sufile.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
sufile.h
super.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
sysfs.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
sysfs.h
the_nilfs.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
the_nilfs.h nilfs2: fix use-after-free of nilfs_root in dirtying inodes via iput 2023-08-16 18:19:23 +02:00