From patchwork Mon Apr 10 02:11:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13206057 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 1FB1AC77B6E for ; Mon, 10 Apr 2023 02:11:57 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1plh0f-0004XS-F0; Mon, 10 Apr 2023 02:11:56 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1plh0f-0004XM-66 for linux-f2fs-devel@lists.sourceforge.net; Mon, 10 Apr 2023 02:11:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=WTjECS3+MEmvqP0P0eaewt9U+dBn58t16mLqbukmkrE=; b=E+RBlQbVbPvnLdOeTMyZMN/fKo XfWXutTy7tU/HEGa72zh2mE8ZULYfMUhXnso65nHZ7TdqYkJ5KQA3rnfxx1XpViBmq0tSm1MwRv7n tEUz5XfrD2wDWGIZ9oJ+8PxpRKr08JZs/Ts0F2HpRgLA9UjsglN8yhwsTBIPvb3cBk94=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=WTjECS3+MEmvqP0P0eaewt9U+dBn58t16mLqbukmkrE=; b=L gTmlaEaP13nQF16ysgfX/GI7G4wqWgE1Pd4QW4UyjmXnUid1JNaM9fZ2emLCNbQ34+ZSxak/3Kqof NQCk956RDC5ooSC/xhuxeJv6Qfqw6QWpHFpqnifW/nQW1qiCdyDtBCcS7Cwzu3xBSKfD3x+NyU0zs rT/hQcK0KGQIgsFc=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1plh0d-0007Ap-Pc for linux-f2fs-devel@lists.sourceforge.net; Mon, 10 Apr 2023 02:11:56 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 0E35760C16 for ; Mon, 10 Apr 2023 02:11:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48D6DC433EF; Mon, 10 Apr 2023 02:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681092709; bh=FCFxu4X+5woHhI20a2ADjfDUIjQHOiUKAW2OcY/taSU=; h=From:To:Cc:Subject:Date:From; b=GVo5eO0r5KNTpseagjx5UOIXexQSj7cY1aYA70unARObaF3Vy2Gg5RHgGBS7M8ykA ZkN7zgxHJo6XXjKz/WM67RpcFqVoXxuZ2GMVr8db0ktArAsCdmCsWcBi0kJ194aker qQMdTFlXNlzefSChOx47n0bOIsIm12vlB5VNyVKfrpPknMC6tHkDsFaP06rrTTsqQA 3odseNBjD2flrUMYpaC5p0JWfPgQnE+aN7DovQjCjP8HLQL3yKy0t4i5s4A526G81k y++VA4kZ0VSgQB2Gx2SQWyCaZHLcXERiXWu9PjrDVfHLQD7pH4U+l/hYNj8+wxVVkT NSTFx2YqgLiCA== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 10 Apr 2023 10:11:40 +0800 Message-Id: <20230410021140.1825781-1-chao@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Headers-End: 1plh0d-0007Ap-Pc Subject: [f2fs-dev] [PATCH] f2fs: fix to keep consistent i_gc_rwsem lock order 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: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net i_gc_rwsem[WRITE] and i_gc_rwsem[READ] lock order is reversed in gc_data_segment() and f2fs_dio_write_iter(), fix to keep consistent lock order as below: 1. lock i_gc_rwsem[WRITE] 2. lock i_gc_rwsem[READ] Signed-off-by: Chao Yu --- fs/f2fs/gc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 6dc2bc710ba8..91841b0057ba 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1616,14 +1616,14 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, int err; if (S_ISREG(inode->i_mode)) { - if (!f2fs_down_write_trylock(&fi->i_gc_rwsem[READ])) { + if (!f2fs_down_write_trylock(&fi->i_gc_rwsem[WRITE])) { sbi->skipped_gc_rwsem++; continue; } if (!f2fs_down_write_trylock( - &fi->i_gc_rwsem[WRITE])) { + &fi->i_gc_rwsem[READ])) { sbi->skipped_gc_rwsem++; - f2fs_up_write(&fi->i_gc_rwsem[READ]); + f2fs_up_write(&fi->i_gc_rwsem[WRITE]); continue; } locked = true; @@ -1646,8 +1646,8 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, submitted++; if (locked) { - f2fs_up_write(&fi->i_gc_rwsem[WRITE]); f2fs_up_write(&fi->i_gc_rwsem[READ]); + f2fs_up_write(&fi->i_gc_rwsem[WRITE]); } stat_inc_data_blk_count(sbi, 1, gc_type);