From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9581C433EF for ; Tue, 4 Jan 2022 15:48:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbiADPsd (ORCPT ); Tue, 4 Jan 2022 10:48:33 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:46220 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbiADPsb (ORCPT ); Tue, 4 Jan 2022 10:48:31 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AADADB816F9 for ; Tue, 4 Jan 2022 15:48:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDABCC36AED; Tue, 4 Jan 2022 15:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641311309; bh=JhpOCub1C8JKAe8Xx/XjYFctuvGH7dqRVs206RpUSeM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=AVqgS7EOB/Nu/S776pX8sLCCKM2DqBOroODt8HwZxIdMqJE5AXK31TMny8rdEmCNR /JD8lA9A3NHzkxpMLAw0GQ05aikZgfuJI0Fg9Vwi6ivp9D+bccqKX7+LDXb8XF3Wgk qH+mgooNs3fWKvCAgGxgpJd2vYpyWoUXCpjG5ttQjp+EOe2ew4V3Qf1KeO2eTzU+m/ w06k39GkeUcNTcHIcRBsdVrMghg5DrmcaTi6iT7T0OFc1fTbWH1frhKmnBxd/LTV11 KUY01e7qU8+xmAZa4hUTuo9ZGZ2bw5Ii6Y487MBT59X6uJpj1yw81/QeFL/A4CzYZI B+J3FgAWVmIDA== Message-ID: Date: Tue, 4 Jan 2022 23:48:25 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] f2fs: quota: fix potential deadlock Content-Language: en-US To: Greg KH Cc: stable@vger.kernel.org, jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, Yi Zhuang References: <20220104130513.3077-1-chao@kernel.org> <53d75d26-2289-a66a-a7fa-62593bad81c8@kernel.org> From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On 2022/1/4 23:17, Greg KH wrote: > On Tue, Jan 04, 2022 at 11:05:36PM +0800, Chao Yu wrote: >> On 2022/1/4 21:18, Greg KH wrote: >>> On Tue, Jan 04, 2022 at 09:05:13PM +0800, Chao Yu wrote: >>>> 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. >>>> >>>> Fixes: db6ec53b7e03 ("f2fs: add a rw_sem to cover quota flag changes") >>>> Cc: stable@vger.kernel.org # v5.3+ >>>> Reported-by: Yi Zhuang >>>> Signed-off-by: Chao Yu >>>> Signed-off-by: Jaegeuk Kim >>>> --- >>>> fs/f2fs/checkpoint.c | 3 ++- >>>> 1 file changed, 2 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c >>>> index 83e9bc0f91ff..7b0282724231 100644 >>>> --- a/fs/f2fs/checkpoint.c >>>> +++ b/fs/f2fs/checkpoint.c >>>> @@ -1162,7 +1162,8 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi) >>>> 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)) { >>>> -- >>>> 2.32.0 >>>> >>> >>> What stable tree(s) is this for? >> >> Oh, please help to try applying to 5.4, 5.10, and 5.15 stable trees, thanks! > > This is already in the 5.15.6 kernel release, do you need it applied > there again? :) Oops, no, so 5.4 and 5.10 is enough. ;) We can skip 5.15 since this patch was merged in 5.15-rc1 at the first time. > >> Let me know if I should send patches for different trees separately. > > If the same commit here works for all of the above, it's fine. But for > some reason I don't think it will work in 5.15.y... Copied. Thank you for the help! Thanks, > > thanks, > > greg k-h From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DAC82C433F5 for ; Tue, 4 Jan 2022 15:48:41 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1n4m3D-00060A-SE; Tue, 04 Jan 2022 15:48:39 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n4m3B-000603-NR for linux-f2fs-devel@lists.sourceforge.net; Tue, 04 Jan 2022 15:48:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=bq+MId+NKm13zzhRTfLqPdWB2dcv1BIsh+KimD1sbk8=; b=W8FkFEVye89lYLqnHnARTjT0Xz G3DoMI7ez4TtY+P6DpjO5QG4xeFP0RGGVaosGMiFlCU5iyKSHVrOKSVBfe6i9h7DukOF+GxeQ6gDB QOkwIciOtQlZTZ0zLfgVWUT6kJhxFAIh+AMBV8QpPjWuJVOBk+O9mOTUhblQXCVY/70U=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=bq+MId+NKm13zzhRTfLqPdWB2dcv1BIsh+KimD1sbk8=; b=dnXYihS8wU9e/xqv9DpTLqHvf3 E8BKBRD8NT39ZMCuyxT1EAWgXy7h42pa3mTKnE65XsYvj2D6NaoIA3FvapDKH5IMKqMtAhCRvTHUH cC7nUmkr5HuAy2GdzHlbVoguF7G+CjvnPGLe4EfU91JwZonrO7baFBDo6MOLs8QucPVA=; Received: from ams.source.kernel.org ([145.40.68.75]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1n4m3A-0020bS-Sg for linux-f2fs-devel@lists.sourceforge.net; Tue, 04 Jan 2022 15:48:37 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A7A85B816F8; Tue, 4 Jan 2022 15:48:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDABCC36AED; Tue, 4 Jan 2022 15:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641311309; bh=JhpOCub1C8JKAe8Xx/XjYFctuvGH7dqRVs206RpUSeM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=AVqgS7EOB/Nu/S776pX8sLCCKM2DqBOroODt8HwZxIdMqJE5AXK31TMny8rdEmCNR /JD8lA9A3NHzkxpMLAw0GQ05aikZgfuJI0Fg9Vwi6ivp9D+bccqKX7+LDXb8XF3Wgk qH+mgooNs3fWKvCAgGxgpJd2vYpyWoUXCpjG5ttQjp+EOe2ew4V3Qf1KeO2eTzU+m/ w06k39GkeUcNTcHIcRBsdVrMghg5DrmcaTi6iT7T0OFc1fTbWH1frhKmnBxd/LTV11 KUY01e7qU8+xmAZa4hUTuo9ZGZ2bw5Ii6Y487MBT59X6uJpj1yw81/QeFL/A4CzYZI B+J3FgAWVmIDA== Message-ID: Date: Tue, 4 Jan 2022 23:48:25 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Content-Language: en-US To: Greg KH References: <20220104130513.3077-1-chao@kernel.org> <53d75d26-2289-a66a-a7fa-62593bad81c8@kernel.org> From: Chao Yu In-Reply-To: X-Headers-End: 1n4m3A-0020bS-Sg Subject: Re: [f2fs-dev] [PATCH] f2fs: quota: fix potential deadlock X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jaegeuk@kernel.org, Yi Zhuang , stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 2022/1/4 23:17, Greg KH wrote: > On Tue, Jan 04, 2022 at 11:05:36PM +0800, Chao Yu wrote: >> On 2022/1/4 21:18, Greg KH wrote: >>> On Tue, Jan 04, 2022 at 09:05:13PM +0800, Chao Yu wrote: >>>> 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. >>>> >>>> Fixes: db6ec53b7e03 ("f2fs: add a rw_sem to cover quota flag changes") >>>> Cc: stable@vger.kernel.org # v5.3+ >>>> Reported-by: Yi Zhuang >>>> Signed-off-by: Chao Yu >>>> Signed-off-by: Jaegeuk Kim >>>> --- >>>> fs/f2fs/checkpoint.c | 3 ++- >>>> 1 file changed, 2 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c >>>> index 83e9bc0f91ff..7b0282724231 100644 >>>> --- a/fs/f2fs/checkpoint.c >>>> +++ b/fs/f2fs/checkpoint.c >>>> @@ -1162,7 +1162,8 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi) >>>> 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)) { >>>> -- >>>> 2.32.0 >>>> >>> >>> What stable tree(s) is this for? >> >> Oh, please help to try applying to 5.4, 5.10, and 5.15 stable trees, thanks! > > This is already in the 5.15.6 kernel release, do you need it applied > there again? :) Oops, no, so 5.4 and 5.10 is enough. ;) We can skip 5.15 since this patch was merged in 5.15-rc1 at the first time. > >> Let me know if I should send patches for different trees separately. > > If the same commit here works for all of the above, it's fine. But for > some reason I don't think it will work in 5.15.y... Copied. Thank you for the help! Thanks, > > thanks, > > greg k-h _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel