From patchwork Wed Oct 19 08:32:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp253793wrs; Wed, 19 Oct 2022 03:58:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PRzkD6bhccVe1zQxPyU8O1Et53vlxmSRl2F/QqxjRLjNVfcR+/cirgewQ6+XK+BeP7ACE X-Received: by 2002:aa7:8893:0:b0:563:89e0:2d43 with SMTP id z19-20020aa78893000000b0056389e02d43mr7608188pfe.25.1666177097450; Wed, 19 Oct 2022 03:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177097; cv=none; d=google.com; s=arc-20160816; b=C/s/JIIGSPxw54O2Grfz7fgSen9G/A4mbE3o4YlTY9jiaJ+h0t2uuFlaq/AISNaP9y WeJEALGpE8j6snGFK4ZYYD4F/jWtmbHwqhkzqzFQa/NcVuXVmi857tSgHefIpPQAU0mY 97JoG6VINn2fxNtVcg1lS1kaCdCmOVKQpBzLHoKaInS9/2It703rMXT7B9sk37MncW6W p+tPKCwGH6nrcgW2oungAVcZK4WvpGlMOKCwN96JIwU/NO9CON/3dCPFXwfsWX8Kpc7R 6bDAAnhC0c3/qWbsiXs7twabDa7AXqVnURE588p7CS1m+TDlYxd2OnJie0cUZpkQrRLK AYjw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i21-20020aa787d5000000b00557c5641be2si15656316pfo.248.2022.10.19.03.58.04; Wed, 19 Oct 2022 03:58:17 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747113316324783929?= X-GMAIL-MSGID: =?utf-8?q?1747113316324783929?= 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;