Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp869930rwi; Wed, 19 Oct 2022 04:07:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54s3SzByAUUw46Dsmz/VFXtOfZs4lGgkN2EX4/5v6M5VSX9wpi0qHTxRoeARB7A6v7gwNj X-Received: by 2002:a17:907:2721:b0:78d:4e30:df36 with SMTP id d1-20020a170907272100b0078d4e30df36mr6271827ejl.508.1666177652555; Wed, 19 Oct 2022 04:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177652; cv=none; d=google.com; s=arc-20160816; b=LJ0yk+YDQgc43qfaxxU9LYD6QE8XS1pihWgYZJYhsp+6ei9rkJIp1PfERjFISx8YSf iAODl/JFa1omq31Ts0am9uuIr4EtUpHcWMpxS9WEquY4K9uLEZHDz7bgaSCDTGZzFOfi PH92Tu7kXWOoW7Fe6vTKlQIDYlc17xK76lrJ+W46vBngJF0IMHUdS1q8fn3t2zILae+P F6jDlJj8+EMC6z1TySjUIrswdXXf2ZqKWYm22oSuXmyvE0YG1Ei71G7IA86w9HY/0BWj dQUdvILoHmoR16iI0r9tj/21d9lBRWrTiT2YW8gmY+Uy/DNhBmA5rKVK7KWe/ekkFlBV juZw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mRjNevsjHmu6soZypnH8AnuQIel6+ino/dMijUWye8w=; b=XQP0/MeCyASZuNEI1g11HW+1moVCFZcz9qj+AQdJ+BbuvrSMG1lGaNeaaxRzOsdOo0 W1AnMW72AKorsBJAen9CmXe1ung+ixHELe5j8vsFOue+5mNdo+Jer5GQMspeUXYLlLll K3ptcOrEtLyONaNGH8cPzsbFptAk2Vbzbmda+Gz7P0MJEnl1xOOv8xO0jhq2nxSA+lA7 5H+deeJd+fCbzyWrhCTXYaJ5bgwey9ehDnhjGIr14qeT4IjkW3KMzs38utu7TUljkoXN LBxHy1391e4NeeRADGAznesvMmWGlS1qtKERml1lpwsicL0wsIZNP5y0PX/2qvIHdgD8 wF7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZDsRjMuf; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a05640251c700b0045d523bee48si11835619edd.178.2022.10.19.04.06.56; Wed, 19 Oct 2022 04:07:32 -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=@linuxfoundation.org header.s=korg header.b=ZDsRjMuf; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234716AbiJSK5Z (ORCPT + 99 others); Wed, 19 Oct 2022 06:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbiJSK43 (ORCPT ); Wed, 19 Oct 2022 06:56:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D5DFF6C16; Wed, 19 Oct 2022 03:27:32 -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 ams.source.kernel.org (Postfix) with ESMTPS id 30BF2B82487; Wed, 19 Oct 2022 09:07:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 870FCC433B5; Wed, 19 Oct 2022 09:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170435; bh=VvCdVM0o6p1PxXk6TZ1vPl1OdkJWcfXxLrIRwfpPLSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZDsRjMufKt3839bql0sNPPOqH6LE1sFAIYJrtUoR4ewgjyxptHKfQbbwRSJaiTuxG vK/tidnewu2EzimXWJbDI4/Z0YbpxKwD1DeWgLE5WxkQ3Vc31WVv125mjIGnlqA+gn kSIZT7yNes9YgmqMQsXEv4p6mprn1mKVieurRCi0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Qilong , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.0 655/862] f2fs: fix race condition on setting FI_NO_EXTENT flag Date: Wed, 19 Oct 2022 10:32:22 +0200 Message-Id: <20221019083318.888624637@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 From: Zhang Qilong [ Upstream commit 07725adc55c0a414c10acb5c8c86cea34b95ddef ] The following scenarios exist. process A: process B: ->f2fs_drop_extent_tree ->f2fs_update_extent_cache_range ->f2fs_update_extent_tree_range ->write_lock ->set_inode_flag ->is_inode_flag_set ->__free_extent_tree // Shouldn't // have been // cleaned up // here ->write_lock In this case, the "FI_NO_EXTENT" flag is set between f2fs_update_extent_tree_range and is_inode_flag_set by other process. it leads to clearing the whole exten tree which should not have happened. And we fix it by move the setting it to the range of write_lock. Fixes:5f281fab9b9a3 ("f2fs: disable extent_cache for fcollapse/finsert inodes") Signed-off-by: Zhang Qilong Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/extent_cache.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 866e72b29bd5..761fd42c93f2 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -804,9 +804,8 @@ void f2fs_drop_extent_tree(struct inode *inode) if (!f2fs_may_extent_tree(inode)) return; - set_inode_flag(inode, FI_NO_EXTENT); - write_lock(&et->lock); + set_inode_flag(inode, FI_NO_EXTENT); __free_extent_tree(sbi, et); if (et->largest.len) { et->largest.len = 0; -- 2.35.1