Re: f2fs F2FS_IOC_SHUTDOWN hang issue
From: Jaegeuk Kim
Date: Wed Mar 20 2024 - 16:06:39 EST
Can you try this?
https://patchwork.kernel.org/project/f2fs/patch/20240320001442.497813-1-jaegeuk@xxxxxxxxxx/
On 03/20, Light Hsieh (謝明燈) wrote:
> Hi Jaegeuk:
>
> We encounter a deadlock issue when Android is going to poweroff.
> Please help check.
>
> When unmounting of f2fs partition fail in Android poweroff procedure, init thread (pid = 1) invoke F2FS_IOC_SHUTDOWN ioctl with arg F2FS_GOING_DOWN_FULLSYNC.
> This ioctl cause down_write of a semaphore in the following call sequence:
> f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().
>
> f2fs_ioc_shutdown() will later invoke f2fs_stop_discard_thread() and wait for stopping of f2fs_discard thread in the following call sequence:
> f2fs_ioc_shutdown() -->f2fs_stop_discard_thread() -->kthread_stop(discard_thread) --> wait_for_completion().
> That is, init thread go sleep with a write semaphore.
>
> f2fs_discard thread is then waken up to process f2fs discard.
> However, f2fs_discard threshold may then hang because failing to get the semaphore aleady obtained by the slept init thread:
> issue_discard_thread() --> sb_start_intwrite() -->sb_start_write(sb, SB_FREEZE_FS) --> percpu_down_read()
>
> Light