From patchwork Mon Oct 24 11:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp430896wru; Mon, 24 Oct 2022 05:42:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55zK1SyoxYkbASxJC2+l1PItgF/6dliP8SUsXZEm3cfgz9P0vw9kfyQV8WGTO0h+GaT1f8 X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr27159923ejt.4.1666615339076; Mon, 24 Oct 2022 05:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615339; cv=none; d=google.com; s=arc-20160816; b=C3V3mA6UtsWsHpdtSnpJzAfyKQrBvhYATLIxbXvbF1us8uaGnSUKCbXltbOZG1FMee Y8JUSV1kBDcm+0+BDWhfjAO4+u1B7X68GkuHSF+Ivrizrbldb4HhRAbOtyDdMaMUCV8i 1q1y5UDhQdEKkvDhYFBbaCtgDZ/ajJanzoDKYiP5DaaJKk5tDtAYva8CD9mwRVwqjF77 3y9RZbQ+qQ+j1lS6wP0eUe4YeYGUsB5ZWXL+JOnH+FZkS3RFTUxgadxJDZ9Gy3eiWEhU YJiKDnIx3Rd8pZ4QLGq55Zr1xplY/d7pTnhqEOGLeCkKbsT5zCKKexcaWeugN079F7jl b0nw== 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=b6tgijmBOdfylRaTgEyt84O9jv+5p4pByTqRckpPwHc=; b=MmRuckPLfu0L0oMTB/3L/dL57XKTIYY93MLlkwur+qNbhXGzHp8jl59ZCOyEx3Ipd1 LrSFYG03G5liOYQj0+i7KHIn4KSqgmYUBqO3KGLTJQRub/0wa1XjCPaq0WhECEoECOE2 i18rDq5uxNWeLY3tAnAy9ELzfZ8PRET22foPp0O3lt8E7pK/TIz/eRu+BAP2dDGblBd2 dZrYyJgq+ZWjA6Yw7wOLwHLbQ6zmgtNZRPkUcvAEJvP2OahERuFwwfrr3m/4tbI9BgCy oDQIpzozyPupPr68YFR0/t/1H8jjr3oNhMWQ/qSJF6xFknKiBE2/RQl9G5Jn6cKF5O39 KGqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bz0xO5au; 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 q6-20020a1709064cc600b0078fcfc5d24esi19436513ejt.618.2022.10.24.05.41.50; Mon, 24 Oct 2022 05:42:19 -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=bz0xO5au; 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 S231631AbiJXMbY (ORCPT + 99 others); Mon, 24 Oct 2022 08:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233909AbiJXM2j (ORCPT ); Mon, 24 Oct 2022 08:28:39 -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 B763287093; Mon, 24 Oct 2022 05:02:24 -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 81137612D5; Mon, 24 Oct 2022 12:02:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94678C433D7; Mon, 24 Oct 2022 12:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612919; bh=jPrX3JYqFBkAlWxjVzRpOOxHlvy7AnOKaq25fXbAEdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bz0xO5au1ibPFJWZW7KocO1bijNui7cWuWLute0dlg4e5lRV1JSMdOSqyaYzthnzA 66Tu8xCoFNmDmEfPbf0aRoIRiJkwD5OVwBdDNV1n3lBVZkRstSXU++VWKHOKSljRPu fjYK2FHmKNtBOu4VsjAQLojt9k464kIEC4uz9deg= 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 4.19 169/229] f2fs: fix race condition on setting FI_NO_EXTENT flag Date: Mon, 24 Oct 2022 13:31:28 +0200 Message-Id: <20221024113004.554242119@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747572846180187921?= X-GMAIL-MSGID: =?utf-8?q?1747572846180187921?= 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 a70cd2580eae..36d6b561b524 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -717,9 +717,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;