From 150005444c1b4ff0de5ee6822d5942682814bbf1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 5 Jan 2022 16:00:43 +0100 Subject: [PATCH] 5.10-stable patches added patches: f2fs-quota-fix-potential-deadlock.patch --- .../f2fs-quota-fix-potential-deadlock.patch | 60 +++++++++++++++++++ queue-5.10/series | 1 + 2 files changed, 61 insertions(+) create mode 100644 queue-5.10/f2fs-quota-fix-potential-deadlock.patch create mode 100644 queue-5.10/series diff --git a/queue-5.10/f2fs-quota-fix-potential-deadlock.patch b/queue-5.10/f2fs-quota-fix-potential-deadlock.patch new file mode 100644 index 00000000000..318e1048629 --- /dev/null +++ b/queue-5.10/f2fs-quota-fix-potential-deadlock.patch @@ -0,0 +1,60 @@ +From a5c0042200b28fff3bde6fa128ddeaef97990f8d Mon Sep 17 00:00:00 2001 +From: Chao Yu +Date: Fri, 3 Sep 2021 10:38:11 +0800 +Subject: f2fs: quota: fix potential deadlock + +From: Chao Yu + +commit a5c0042200b28fff3bde6fa128ddeaef97990f8d upstream. + +As Yi Zhuang reported in bugzilla: + +https://bugzilla.kernel.org/show_bug.cgi?id=214299 + +There is potential deadlock during quota data flush as below: + +Thread A: Thread B: +f2fs_dquot_acquire +down_read(&sbi->quota_sem) + f2fs_write_checkpoint + block_operations + f2fs_look_all + down_write(&sbi->cp_rwsem) +f2fs_quota_write +f2fs_write_begin +__do_map_lock +f2fs_lock_op +down_read(&sbi->cp_rwsem) + __need_flush_qutoa + down_write(&sbi->quota_sem) + +This patch changes block_operations() to use trylock, if it fails, +it means there is potential quota data updater, in this condition, +let's flush quota data first and then trylock again to check dirty +status of quota data. + +The side effect is: in heavy race condition (e.g. multi quota data +upaters vs quota data flusher), it may decrease the probability of +synchronizing quota data successfully in checkpoint() due to limited +retry time of quota flush. + +Reported-by: Yi Zhuang +Signed-off-by: Chao Yu +Signed-off-by: Jaegeuk Kim +Signed-off-by: Greg Kroah-Hartman +--- + fs/f2fs/checkpoint.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/fs/f2fs/checkpoint.c ++++ b/fs/f2fs/checkpoint.c +@@ -1147,7 +1147,8 @@ static bool __need_flush_quota(struct f2 + if (!is_journalled_quota(sbi)) + return false; + +- down_write(&sbi->quota_sem); ++ if (!down_write_trylock(&sbi->quota_sem)) ++ return true; + if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) { + ret = false; + } else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR)) { diff --git a/queue-5.10/series b/queue-5.10/series new file mode 100644 index 00000000000..a73b51d993e --- /dev/null +++ b/queue-5.10/series @@ -0,0 +1 @@ +f2fs-quota-fix-potential-deadlock.patch -- 2.47.3