From patchwork Mon Oct 24 11:31:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp462237wru; Mon, 24 Oct 2022 06:45:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM661rRc2cww6j/xqv7enfQv1RqconFYLcTGsG9RvEGRp8CwZLw/GXZNZNh7mn01P7leDvSB X-Received: by 2002:a17:907:763b:b0:7aa:1ae6:900b with SMTP id jy27-20020a170907763b00b007aa1ae6900bmr2200578ejc.416.1666619135571; Mon, 24 Oct 2022 06:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619135; cv=none; d=google.com; s=arc-20160816; b=OEIpT1YGeAtuFFClG/h9OUq5liKVllc3Ee53vGQr2xJ31UkbGlnxcQRvGyD1DqPstP WzuPIWXPmwr4jf3WZVHZMJvAgq4Q2tCa/UQ3/h6b9xFuzfI495otj+QnIl1dZkuIHXVi znpUkkRDRhAaKxYhpkgblJouk5/HPxD76XiSb2h0pqQ569sVj7sIxHYPEza7VZ0Elzd3 C4SO/JLilAJttv5FDnWb3n6DU4BhXvtGQ44JS4J7N0FVCdvlDyccs6MByBnjU30QjH3H jeSlF3OnrC146nw2n4WYFXKKdjdsC/T08Vl0zbUWsp/UirgnW03RZOY//v2nkAMCYW1+ pHlA== 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=uW5wb3sVvTRrENcojP0jk3pSISBRN2g1TlGtyHZqLYM=; b=Fq7EBl6iqon3XXGfpMlGJuydrtXJQ7nir2mpkIMw0cCRqADiFVUCU7Fg+nhnBPCCfN fvseC33cM/CH/M7qHQxcQbh9wb/0A/ev+me/vKkzrRgeYEBNBIkKCcRzztexSWdJ3BQQ JtPZC/4jxo0k3cxWJ1BgX4ehdhhr6fI2JaSEPonIed2V4qzyQvGuKOEzkOF3QkpiVUxu gXyVa3gIALaKXVkOJ1wAPiKkkX6b0sgEIJe3tAyYlT5PZPPDahJO4R7+wiMs3QpcqJqn KKEpDHeVe8g2H0COt07E8GtKwhsM1dyvJgy0A0MTkxn2J0dot9NMkvFabecs1MtKW3d3 +Pfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fiV66G3L; 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 cw20-20020a170906479400b0078db3ae83d0si26710921ejc.3.2022.10.24.06.45.11; Mon, 24 Oct 2022 06:45:35 -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=fiV66G3L; 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 S236248AbiJXNnI (ORCPT + 99 others); Mon, 24 Oct 2022 09:43:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236750AbiJXNlL (ORCPT ); Mon, 24 Oct 2022 09:41:11 -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 C8210B449D; Mon, 24 Oct 2022 05:38:27 -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 6237C612FB; Mon, 24 Oct 2022 12:12:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 749F8C433D6; Mon, 24 Oct 2022 12:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613565; bh=2AM3Eiz+r0aH+ko3xrd6rXYRvTAlxBHpaH2e5ElP4F8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fiV66G3LgKCTNwT6KE7Dxkydsv16fhPatOD6JFCDtEIm1ODLlcHpvbR02LyOzSAzz 9AfxQvhb9igSVWGvs1WmLpD+uRDbjEk/WiYYBxKjFFsagHQH1Gqs/wJ0clsqBdGjX2 pJOh7j57OfXeW5ElDPJ4yteenSUcWrHU2qy9J28o= 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 5.4 184/255] f2fs: fix race condition on setting FI_NO_EXTENT flag Date: Mon, 24 Oct 2022 13:31:34 +0200 Message-Id: <20221024113009.030107508@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747576826956506011?= X-GMAIL-MSGID: =?utf-8?q?1747576826956506011?= 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 e60078460ad1..05b17a741ccc 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -729,9 +729,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;