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: 81343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1634684vqo; Sun, 9 Apr 2023 19:22:16 -0700 (PDT) X-Google-Smtp-Source: AKy350bVgof0EMTKn4fGXxZkR1Qc6MYngYl805Tp84x+OebZODQKVjKvxs0A8RsDowVE5k4GyCxE X-Received: by 2002:a17:902:cec8:b0:1a5:eb:9d3f with SMTP id d8-20020a170902cec800b001a500eb9d3fmr12737617plg.56.1681093336091; Sun, 09 Apr 2023 19:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681093336; cv=none; d=google.com; s=arc-20160816; b=Aeg2tPZvQev3ZdUsKvxpBUUjup8PHDHV0frdi+9S0KWx6JkpINHj8+SCnLjZW6ercl zEmi2u9ivvh1h6NzCpM8a2z1C/gFbrpkwyUMCskXbS4YNFI1q4l/GgzPPYaYF1dSnmMM CqgOoj80Xufp41BvWq92sZZlHp+k9DIj6B0vSWYspqqxovbnZagSXii3Su0sqN3sJeqY zwvk5oYBKdtuqoCs1JG6p9AMgVk0NZHp53w9f2K5ulO0oGyRP6vY+89C+dgG2h5vhKbG yxfmWMYdps2jW9ksDDxDP54DelwZRcmI+Xr9YhdYKYoOO3jG9HQ4ZWmkoq+wbdtpoEn/ 2ATQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=WTjECS3+MEmvqP0P0eaewt9U+dBn58t16mLqbukmkrE=; b=uSGeXt7+tD0F4pQyLl69vxa0D9udmFKfG9qR0kvQk8nTbxX1/1aafU/USTvP3MCWi8 hBDR4YZv7X5MADJO/zI1UxI0ajyv2llNHn+IgenBTASiTsDpFFuDQOXQQVqaAqxqVid2 qz4/jsa3exB581ZfU0Q1Azg3ImOqby50ketCvq83w1NiJ+XxHj/htdnAAQ5cO42VO4+J pkwXhkA9EPtK2WQHKvHgkO6N26+QbW+oXt1jWLrjrTkwIMmEE1jCwoyvhjAnVwB1E634 2IRtiem39lgCP3DqxJs3OB8Hs6bRquURrXLQSs5QPB0a6kOSs76zB6zNXJZs+sL7hvT+ MqTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GVo5eO0r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x7-20020a17090aca0700b00240262caf83si9501873pjt.82.2023.04.09.19.22.04; Sun, 09 Apr 2023 19:22:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GVo5eO0r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjDJCLv (ORCPT + 99 others); Sun, 9 Apr 2023 22:11:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjDJCLv (ORCPT ); Sun, 9 Apr 2023 22:11:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B2992D58 for ; Sun, 9 Apr 2023 19:11:50 -0700 (PDT) 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 12C6761720 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 Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: fix to keep consistent i_gc_rwsem lock order 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-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762754126325212291?= X-GMAIL-MSGID: =?utf-8?q?1762754126325212291?= 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);