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: 9154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp457761wru; Mon, 24 Oct 2022 06:36:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XL2qcXs68Gt4aFNvelgyXJyNV8s6gT5/1qRgkhItOikNNOX6UkaI8++1kOQ5FdALlg4LL X-Received: by 2002:a05:6402:2073:b0:461:5462:9dc9 with SMTP id bd19-20020a056402207300b0046154629dc9mr15512979edb.52.1666618589323; Mon, 24 Oct 2022 06:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618589; cv=none; d=google.com; s=arc-20160816; b=oescngMZGbLfQG71NUvxfOQOLR0Mf7G2DTbF2hXBVGvPoJrql5olYh/DLjiXCfGZ75 s2THgjQDvTr6vN66hYvo0aSI2vEWS2QsxfNUtQa89AAPYZWyfLk78yXr6AQPm8npUN3U 2Y+D5F/Vwqeur8v2cjaYNIZD7Pz1bQBy8yb1Q9Sidjv6SPvRA9/gwKLZjNfP3XxUq/t7 bfUK/jFJUDqUQZs/q+X7uu2Nw1PSTNxl1jS68gzUYMg6PoxKq3/9blhDviEl8h7kTkzE SUhdhgb4F2SvLy/LoAhbYhrS//ixjDzGf+eA6SBGP+/SzDrBga1UeptBeV1zkbEQG/xV H3zA== 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=FbC/e+wJxcCvquUUbOiQGM7d2pvdSawDmN5qj1qnV78=; b=phvOiXJtUwo17PCZaChL3dSWc7no/hoM5dGjPPQKENyz1Mm6Sa4qZ8KocBi/OV81HT vP9xWziaOksdHjH0rMpT5AKhbTOfGgj1WGgg7Wzon+aNlqASxGWPh9Oka9pOyIiZrlPz bi88Ezxx7EXogYZVq0saQLWgCV2P1hbtgnlQlLiWXeO1vlTlNnw1wYzKUNJ5tBVgWQcD 3xy95Pcl6xN5E0iEqT5W5c4g2yhPbkthdmEulu4WtS5zqucDqZVsweDJgaZ1LJDPO5vS slhS4hXzWUSixE3VEltcVFW8BSuBqcKAoQnX4DFPTK8Jj+v1IzYhWiVaME6OARC9qhqB kkmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QGur3clO; 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 dd11-20020a1709069b8b00b007a7d37e4684si3580721ejc.803.2022.10.24.06.35.57; Mon, 24 Oct 2022 06:36:29 -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=QGur3clO; 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 S232927AbiJXN1o (ORCPT + 99 others); Mon, 24 Oct 2022 09:27:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236311AbiJXNZB (ORCPT ); Mon, 24 Oct 2022 09:25:01 -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 2FCEEA8CCA; Mon, 24 Oct 2022 05:30:56 -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 2314361333; Mon, 24 Oct 2022 12:29:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 378ECC433C1; Mon, 24 Oct 2022 12:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614594; bh=VwMcaMFBPeYFXLMeNt06awjTRxjiHCwvRjs5lqUYO/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QGur3clOEnokqvXyVlNaFPpoYcYv62tH74PSfEveZMEih3s4G0FVO779+fHJIWNJN Lld+wTVqeeRHTYaDCBzrYxzgwRQhJ40TCx+91VMWrrbNa/qSVr21qGlXX50Uf8nuxH 71Ge76Da9zBKj7e3Zt/qeIpuhjj2rchGyuRAuqvI= 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.10 291/390] f2fs: fix race condition on setting FI_NO_EXTENT flag Date: Mon, 24 Oct 2022 13:31:28 +0200 Message-Id: <20221024113035.374091493@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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=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?1747576253963411252?= X-GMAIL-MSGID: =?utf-8?q?1747576253963411252?= 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 3ebf976a682d..bd16c78b5bf2 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -762,9 +762,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;