f2fs: Fix deadlock between f2fs_quota_sync and block_operation
This deadlock is hitting Android users (Pixel 3/3a/4) with Magisk, due to frequent umount/mount operations that trigger quota_sync, hitting the race. See https://github.com/topjohnwu/Magisk/issues/3171 for additional impact discussion. In commit db6ec53b7e03, we added a semaphore to protect quota flags. As part of this commit, we changed f2fs_quota_sync to call f2fs_lock_op, in an attempt to prevent an AB/BA type deadlock with quota_sem locking in block_operation. However, rwsem in Linux is not recursive. Therefore, the following deadlock can occur: f2fs_quota_sync down_read(cp_rwsem) // f2fs_lock_op filemap_fdatawrite f2fs_write_data_pages ... block_opertaion down_write(cp_rwsem) - marks rwsem as "writer pending" down_read_trylock(cp_rwsem) - fails as there is a writer pending. Code keeps on trying, live-locking the filesystem. We solve this by creating a new rwsem, used specifically to synchronize this case, instead of attempting to reuse an existing lock. Signed-off-by: Shachar Raindel <shacharr@gmail.com> Fixes: db6ec53b7e03 f2fs: add a rw_sem to cover quota flag changes Signed-off-by: Pranav Vashi <neobuddy89@gmail.com> Signed-off-by: iusmac <iusico.maxim@libero.it> Signed-off-by: improbir <ghosh_probir@yahoo.com>
Loading
Please register or sign in to comment